From f27bbec7b285e7aa93b230ee4bd55fa631f88ff8 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 1 Dec 2021 19:20:52 +0200 Subject: [PATCH] Kernel: Move incorrect early return in sys$mprotect Since we're iterating over multiple regions that interesect with the requested range, just one of them having the requested access flags is not enough to finish the syscall early. --- Kernel/Syscalls/mmap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 4d2856fab8..065c8add69 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -331,8 +331,6 @@ ErrorOr Process::sys$mprotect(Userspace addr, size_t size, int p return EPERM; if (!validate_mmap_prot(prot, region->is_stack(), region->vmobject().is_anonymous(), region)) return EINVAL; - if (region->access() == Memory::prot_to_region_access_flags(prot)) - return 0; if (region->vmobject().is_inode() && !validate_inode_mmap_prot(*this, prot, static_cast(region->vmobject()).inode(), region->is_shared())) { return EACCES; @@ -345,6 +343,9 @@ ErrorOr Process::sys$mprotect(Userspace addr, size_t size, int p // then do all the other stuff for (auto* old_region : regions) { + if (old_region->access() == Memory::prot_to_region_access_flags(prot)) + continue; + const auto intersection_to_mprotect = range_to_mprotect.intersect(old_region->range()); // full sub region if (intersection_to_mprotect == old_region->range()) {