mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:27:45 +00:00
Kernel: Re-enable protection of the kernel image in memory
This commit is contained in:
parent
59b584d983
commit
f71fc88393
2 changed files with 23 additions and 19 deletions
|
@ -45,25 +45,6 @@ void MemoryManager::initialize_paging()
|
||||||
dbgprintf("MM: Kernel page directory @ %p\n", kernel_page_directory().cr3());
|
dbgprintf("MM: Kernel page directory @ %p\n", kernel_page_directory().cr3());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0
|
|
||||||
// Disable writing to the kernel text and rodata segments.
|
|
||||||
extern u32 start_of_kernel_text;
|
|
||||||
extern u32 start_of_kernel_data;
|
|
||||||
for (size_t i = (u32)&start_of_kernel_text; i < (u32)&start_of_kernel_data; i += PAGE_SIZE) {
|
|
||||||
auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
|
||||||
pte.set_writable(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (g_cpu_supports_nx) {
|
|
||||||
// Disable execution of the kernel data and bss segments.
|
|
||||||
extern u32 end_of_kernel_bss;
|
|
||||||
for (size_t i = (u32)&start_of_kernel_data; i < (u32)&end_of_kernel_bss; i += PAGE_SIZE) {
|
|
||||||
auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
|
||||||
pte.set_execute_disabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
m_quickmap_addr = VirtualAddress(0xffe00000);
|
m_quickmap_addr = VirtualAddress(0xffe00000);
|
||||||
#ifdef MM_DEBUG
|
#ifdef MM_DEBUG
|
||||||
dbgprintf("MM: Quickmap will use %p\n", m_quickmap_addr.get());
|
dbgprintf("MM: Quickmap will use %p\n", m_quickmap_addr.get());
|
||||||
|
@ -136,11 +117,33 @@ void MemoryManager::initialize_paging()
|
||||||
|
|
||||||
setup_low_1mb();
|
setup_low_1mb();
|
||||||
|
|
||||||
|
protect_kernel_image();
|
||||||
|
|
||||||
#ifdef MM_DEBUG
|
#ifdef MM_DEBUG
|
||||||
dbgprintf("MM: Paging initialized.\n");
|
dbgprintf("MM: Paging initialized.\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MemoryManager::protect_kernel_image()
|
||||||
|
{
|
||||||
|
// Disable writing to the kernel text and rodata segments.
|
||||||
|
extern u32 start_of_kernel_text;
|
||||||
|
extern u32 start_of_kernel_data;
|
||||||
|
for (size_t i = (u32)&start_of_kernel_text; i < (u32)&start_of_kernel_data; i += PAGE_SIZE) {
|
||||||
|
auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||||
|
pte.set_writable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cpu_supports_nx) {
|
||||||
|
// Disable execution of the kernel data and bss segments.
|
||||||
|
extern u32 end_of_kernel_bss;
|
||||||
|
for (size_t i = (u32)&start_of_kernel_data; i < (u32)&end_of_kernel_bss; i += PAGE_SIZE) {
|
||||||
|
auto& pte = ensure_pte(kernel_page_directory(), VirtualAddress(i));
|
||||||
|
pte.set_execute_disabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MemoryManager::setup_low_1mb()
|
void MemoryManager::setup_low_1mb()
|
||||||
{
|
{
|
||||||
m_low_page_table = allocate_supervisor_physical_page();
|
m_low_page_table = allocate_supervisor_physical_page();
|
||||||
|
|
|
@ -123,6 +123,7 @@ private:
|
||||||
void detect_cpu_features();
|
void detect_cpu_features();
|
||||||
void initialize_paging();
|
void initialize_paging();
|
||||||
void setup_low_1mb();
|
void setup_low_1mb();
|
||||||
|
void protect_kernel_image();
|
||||||
void parse_memory_map();
|
void parse_memory_map();
|
||||||
void flush_entire_tlb();
|
void flush_entire_tlb();
|
||||||
void flush_tlb(VirtualAddress);
|
void flush_tlb(VirtualAddress);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue