diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-08-24 12:53:47 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-08-25 00:18:42 +0200 |
commit | 485f51690d528379ef30a6a2e5c3d853cbc0f6c0 (patch) | |
tree | be1b1ece3d45b0c5cf12dceb1e8f142902ef2cf8 /Kernel/Syscalls/mmap.cpp | |
parent | 0ae5de8c3cf3db350ee271c1c58008375036e7e9 (diff) | |
download | serenity-485f51690d528379ef30a6a2e5c3d853cbc0f6c0.zip |
Kernel: Always observe the return value of Region::map and remap
We have seen cases where the map fails, but we return the region
to the caller, causing them to page fault later on when they touch
the region.
The fix is to always observe the return code of map/remap.
Diffstat (limited to 'Kernel/Syscalls/mmap.cpp')
-rw-r--r-- | Kernel/Syscalls/mmap.cpp | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 4ad3550bb2..6fcd86d2ae 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -347,7 +347,7 @@ KResultOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int } // Remove the old region from our regions tree, since were going to add another region - // with the exact same start address, but dont deallocate it yet + // with the exact same start address, but do not deallocate it yet auto region = address_space().take_region(*old_region); // Unmap the old region here, specifying that we *don't* want the VM deallocated. @@ -371,9 +371,11 @@ KResultOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int // Map the new regions using our page directory (they were just allocated and don't have one). for (auto* adjacent_region : adjacent_regions) { - adjacent_region->map(address_space().page_directory()); + if (!adjacent_region->map(address_space().page_directory())) + return ENOMEM; } - new_region.map(address_space().page_directory()); + if (!new_region.map(address_space().page_directory())) + return ENOMEM; return 0; } @@ -438,9 +440,11 @@ KResultOr<FlatPtr> Process::sys$mprotect(Userspace<void*> addr, size_t size, int // Map the new region using our page directory (they were just allocated and don't have one) if any. if (adjacent_regions.size()) - adjacent_regions[0]->map(address_space().page_directory()); + if (!adjacent_regions[0]->map(address_space().page_directory())) + return ENOMEM; - new_region.map(address_space().page_directory()); + if (!new_region.map(address_space().page_directory())) + return ENOMEM; } return 0; |