1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:58:11 +00:00

Map pages in read-only ELF sections as non-writable.

This is so cool! :^) Now you'll crash if you try to write into your
.text or .rodata segments.
This commit is contained in:
Andreas Kling 2018-11-03 11:36:45 +01:00
parent aa6d06b47e
commit da13c9a264
4 changed files with 26 additions and 6 deletions

View file

@ -304,8 +304,8 @@ void MemoryManager::map_region_at_address(PageDirectory* page_directory, Region&
auto page_laddr = laddr.offset(i * PAGE_SIZE);
auto pte = ensurePTE(page_directory, page_laddr);
pte.setPhysicalPageBase(zone.m_pages[i].get());
pte.setPresent(true);
pte.setWritable(true);
pte.setPresent(true); // FIXME: Maybe we could use the is_readable flag here?
pte.setWritable(region.is_writable);
pte.setUserAllowed(user_allowed);
flushTLB(page_laddr);
#ifdef MM_DEBUG
@ -430,7 +430,7 @@ RetainPtr<Region> Region::clone()
// FIXME: Implement COW regions.
auto clone_zone = MM.createZone(zone->size());
auto clone_region = adopt(*new Region(linearAddress, size, move(clone_zone), String(name)));
auto clone_region = adopt(*new Region(linearAddress, size, move(clone_zone), String(name), is_readable, is_writable));
// FIXME: It would be cool to make the src_alias a read-only mapping.
byte* src_alias = MM.create_kernel_alias_for_region(*this);