mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-18 17:12:54 +00:00
Kernel: Enable the x86 WP bit to catch invalid memory writes in ring 0
Setting this bit will cause the CPU to generate a page fault when writing to read-only memory, even if we're executing in the kernel. Seemingly the only change needed to make this work was to have the inode-backed page fault handler use a temporary mapping for writing the read-from-disk data into the newly-allocated physical page.
This commit is contained in:
parent
70865e5a5d
commit
ae2d72377d
Notes:
sideshowbarker
2024-07-19 10:47:06 +09:00
Author: https://github.com/awesomekling
Commit: ae2d72377d
2 changed files with 6 additions and 3 deletions
|
@ -174,7 +174,7 @@ void MemoryManager::initialize_paging()
|
||||||
asm volatile("movl %%eax, %%cr3" ::"a"(kernel_page_directory().cr3()));
|
asm volatile("movl %%eax, %%cr3" ::"a"(kernel_page_directory().cr3()));
|
||||||
asm volatile(
|
asm volatile(
|
||||||
"movl %%cr0, %%eax\n"
|
"movl %%cr0, %%eax\n"
|
||||||
"orl $0x80000001, %%eax\n"
|
"orl $0x80010001, %%eax\n"
|
||||||
"movl %%eax, %%cr0\n" ::
|
"movl %%eax, %%cr0\n" ::
|
||||||
: "%eax", "memory");
|
: "%eax", "memory");
|
||||||
|
|
||||||
|
|
|
@ -431,8 +431,11 @@ PageFaultResponse Region::handle_inode_fault(size_t page_index_in_region)
|
||||||
kprintf("MM: handle_inode_fault was unable to allocate a physical page\n");
|
kprintf("MM: handle_inode_fault was unable to allocate a physical page\n");
|
||||||
return PageFaultResponse::ShouldCrash;
|
return PageFaultResponse::ShouldCrash;
|
||||||
}
|
}
|
||||||
remap_page(page_index_in_region);
|
|
||||||
u8* dest_ptr = vaddr().offset(page_index_in_region * PAGE_SIZE).as_ptr();
|
u8* dest_ptr = MM.quickmap_page(*vmobject_physical_page_entry);
|
||||||
memcpy(dest_ptr, page_buffer, PAGE_SIZE);
|
memcpy(dest_ptr, page_buffer, PAGE_SIZE);
|
||||||
|
MM.unquickmap_page();
|
||||||
|
|
||||||
|
remap_page(page_index_in_region);
|
||||||
return PageFaultResponse::Continue;
|
return PageFaultResponse::Continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue