From d3134fec7ecaea369be3eba371a8bb9f9f4a4c7f Mon Sep 17 00:00:00 2001 From: Yuekai Jia Date: Mon, 5 Aug 2024 15:45:38 +0800 Subject: [PATCH] Fix entry present check in page table unmap & protect Otherwise there may be bugs when manipulate empty mappings on lazy mapping. --- page_table_multiarch/src/bits64.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/page_table_multiarch/src/bits64.rs b/page_table_multiarch/src/bits64.rs index bbcdb3d..118a4da 100644 --- a/page_table_multiarch/src/bits64.rs +++ b/page_table_multiarch/src/bits64.rs @@ -104,7 +104,7 @@ impl PageTable64 PagingResult<(PageSize, TlbFlush)> { let (entry, size) = self.get_entry_mut(vaddr)?; - if entry.is_unused() { + if !entry.is_present() { return Err(PagingError::NotMapped); } entry.set_flags(flags, size.is_huge()); @@ -117,7 +117,8 @@ impl PageTable64 PagingResult<(PhysAddr, PageSize, TlbFlush)> { let (entry, size) = self.get_entry_mut(vaddr)?; - if entry.is_unused() { + if !entry.is_present() { + entry.clear(); return Err(PagingError::NotMapped); } let paddr = entry.paddr();