Kernel: Unmap non-readable pages

This was caught by running all crash tests with "crash -A".
Basically, non-readable pages need to not be mapped *at all* so that
a "page not present" exception is provoked on access.

Unfortunately x86 does not support write-only mappings, so this is
the best we can do.

Fixes #1336.
This commit is contained in:
Andreas Kling 2020-03-06 09:58:59 +01:00
parent af29dff224
commit 94f287b1c0
Notes: sideshowbarker 2024-07-19 08:53:07 +09:00

View File

@ -213,7 +213,7 @@ void Region::map_individual_page_impl(size_t page_index)
auto page_vaddr = vaddr().offset(page_index * PAGE_SIZE);
auto& pte = MM.ensure_pte(*m_page_directory, page_vaddr);
auto& physical_page = vmobject().physical_pages()[first_page_index() + page_index];
if (!physical_page) {
if (!physical_page || !is_readable()) {
pte.clear();
} else {
pte.set_cache_disabled(!m_cacheable);
@ -291,7 +291,10 @@ PageFaultResponse Region::handle_fault(const PageFault& fault)
dbg() << "NP(non-readable) fault in Region{" << this << "}[" << page_index_in_region << "]";
return PageFaultResponse::ShouldCrash;
}
if (fault.is_write() && !is_writable()) {
dbg() << "NP(non-writable) write fault in Region{" << this << "}[" << page_index_in_region << "] at " << fault.vaddr();
return PageFaultResponse::ShouldCrash;
}
if (vmobject().is_inode()) {
#ifdef PAGE_FAULT_DEBUG
dbg() << "NP(inode) fault in Region{" << this << "}[" << page_index_in_region << "]";