summaryrefslogtreecommitdiff
path: root/Kernel/Memory
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-28 15:04:34 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-28 23:41:18 +0100
commita12e19c0152e1236a0e26a0b82a2a8c10ba8a55b (patch)
treeaaa16729536c2861661cec49f01d46b9ffae801a /Kernel/Memory
parent5092813a45daab9bb44f51b1575603c0521af8c8 (diff)
downloadserenity-a12e19c0152e1236a0e26a0b82a2a8c10ba8a55b.zip
Kernel: Move kernel region checks from x86 page fault handler to MM
Ideally the x86 fault handler would only do x86 specific things and delegate the rest of the work to MemoryManager. This patch moves some of the address checks to a more generic place.
Diffstat (limited to 'Kernel/Memory')
-rw-r--r--Kernel/Memory/MemoryManager.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/Kernel/Memory/MemoryManager.cpp b/Kernel/Memory/MemoryManager.cpp
index d76a802ed0..d6b0701b6d 100644
--- a/Kernel/Memory/MemoryManager.cpp
+++ b/Kernel/Memory/MemoryManager.cpp
@@ -12,6 +12,7 @@
#include <Kernel/CMOS.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/Heap/kmalloc.h>
+#include <Kernel/KSyms.h>
#include <Kernel/Memory/AnonymousVMObject.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Memory/PageDirectory.h>
@@ -720,6 +721,22 @@ Region* MemoryManager::find_region_from_vaddr(VirtualAddress vaddr)
PageFaultResponse MemoryManager::handle_page_fault(PageFault const& fault)
{
VERIFY_INTERRUPTS_DISABLED();
+
+ auto faulted_in_range = [&fault](auto const* start, auto const* end) {
+ return fault.vaddr() >= VirtualAddress { start } && fault.vaddr() < VirtualAddress { end };
+ };
+
+ if (faulted_in_range(&start_of_ro_after_init, &end_of_ro_after_init))
+ PANIC("Attempt to write into READONLY_AFTER_INIT section");
+
+ if (faulted_in_range(&start_of_unmap_after_init, &end_of_unmap_after_init)) {
+ auto const* kernel_symbol = symbolicate_kernel_address(fault.vaddr().get());
+ PANIC("Attempt to access UNMAP_AFTER_INIT section ({:p}: {})", fault.vaddr(), kernel_symbol ? kernel_symbol->name : "(Unknown)");
+ }
+
+ if (faulted_in_range(&start_of_kernel_ksyms, &end_of_kernel_ksyms))
+ PANIC("Attempt to access KSYMS section");
+
if (Processor::current_in_irq()) {
dbgln("CPU[{}] BUG! Page fault while handling IRQ! code={}, vaddr={}, irq level: {}",
Processor::current_id(), fault.code(), fault.vaddr(), Processor::current_in_irq());