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.
This commit is contained in:
Idan Horowitz 2021-12-01 19:20:52 +02:00
commit f27bbec7b2
Notes: sideshowbarker 2024-07-17 23:13:34 +09:00

View file

@ -331,8 +331,6 @@ ErrorOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int p
return EPERM; return EPERM;
if (!validate_mmap_prot(prot, region->is_stack(), region->vmobject().is_anonymous(), region)) if (!validate_mmap_prot(prot, region->is_stack(), region->vmobject().is_anonymous(), region))
return EINVAL; return EINVAL;
if (region->access() == Memory::prot_to_region_access_flags(prot))
return 0;
if (region->vmobject().is_inode() if (region->vmobject().is_inode()
&& !validate_inode_mmap_prot(*this, prot, static_cast<Memory::InodeVMObject const&>(region->vmobject()).inode(), region->is_shared())) { && !validate_inode_mmap_prot(*this, prot, static_cast<Memory::InodeVMObject const&>(region->vmobject()).inode(), region->is_shared())) {
return EACCES; return EACCES;
@ -345,6 +343,9 @@ ErrorOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int p
// then do all the other stuff // then do all the other stuff
for (auto* old_region : regions) { 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()); const auto intersection_to_mprotect = range_to_mprotect.intersect(old_region->range());
// full sub region // full sub region
if (intersection_to_mprotect == old_region->range()) { if (intersection_to_mprotect == old_region->range()) {