Skip to content

Commit

Permalink
map: fix mprotected pages not being copied
Browse files Browse the repository at this point in the history
When a memory region with prot read-write got changed to read, then the
memory would not be copied on fork. This result in child and parent
sharing this page that can be changed back to being writeable.

JIRA: RTOS-953
  • Loading branch information
badochov committed Oct 16, 2024
1 parent 67fecaa commit 00b9289
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion vm/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,10 @@ int vm_mprotect(vm_map_t *map, void *vaddr, size_t len, int prot)
e->prot = prot;

attr = vm_protToAttr(e->prot) | vm_flagsToAttr(e->flags);
/* If an entry needs copy, enter it as a readonly to copy it on first access. */
if ((e->flags & MAP_NEEDSCOPY) != 0) {
attr &= ~(vm_protToAttr(PROT_WRITE));
}
for (currVaddr = e->vaddr; currVaddr < (e->vaddr + e->size); currVaddr += SIZE_PAGE) {
pa = pmap_resolve(&map->pmap, currVaddr);
if (pa != 0) {
Expand Down Expand Up @@ -1048,7 +1052,7 @@ int vm_mapCopy(process_t *proc, vm_map_t *dst, vm_map_t *src)
vm_mapEntryCopy(f, e, 1);
_map_add(proc, dst, f);

if (((e->prot & PROT_WRITE) != 0) && ((e->flags & MAP_DEVICE) == 0)) {
if (((e->protOrig & PROT_WRITE) != 0) && ((e->flags & MAP_DEVICE) == 0)) {
e->flags |= MAP_NEEDSCOPY;
f->flags |= MAP_NEEDSCOPY;

Expand Down

0 comments on commit 00b9289

Please sign in to comment.