From 4ebff10bde58c6780a8b0b11bbe60d3e2982b675 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 20 Jan 2020 13:06:55 +0100 Subject: [PATCH] Kernel: Write-only regions should still be mapped as present There is no real "read protection" on x86, so we have no choice but to map write-only pages simply as "present & read/write". If we get a read page fault in a non-readable region, that's still a correctness issue, so we crash the process. It's by no means a complete protection against invalid reads, since it's trivial to fool the kernel by first causing a write fault in the same region. --- Kernel/VM/Region.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp index 4a1fec5955..4ed61ac3f8 100644 --- a/Kernel/VM/Region.cpp +++ b/Kernel/VM/Region.cpp @@ -259,7 +259,7 @@ void Region::map_individual_page_impl(size_t page_index) } else { pte.set_cache_disabled(!m_cacheable); pte.set_physical_page_base(physical_page->paddr().get()); - pte.set_present(is_readable()); + pte.set_present(true); if (should_cow(page_index)) pte.set_writable(false); else @@ -331,7 +331,7 @@ PageFaultResponse Region::handle_fault(const PageFault& fault) { auto page_index_in_region = page_index_from_address(fault.vaddr()); if (fault.type() == PageFault::Type::PageNotPresent) { - if (!is_readable()) { + if (fault.is_read() && !is_readable()) { dbgprintf("NP(non-readable) fault in Region{%p}[%u]\n", this, page_index_in_region); return PageFaultResponse::ShouldCrash; }