summaryrefslogtreecommitdiff
path: root/Kernel/Syscalls
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2023-01-19 20:59:55 +0200
committerLinus Groh <mail@linusgroh.de>2023-02-24 22:26:07 +0100
commit08de5abc6d45d29fb18dcd0ac6f20717b1c1b40a (patch)
tree1173485461c7a50a6ee349e07b0ed0d57fced1d8 /Kernel/Syscalls
parentbedd90b1f07e2da8326f2e520c985431fda73a25 (diff)
downloadserenity-08de5abc6d45d29fb18dcd0ac6f20717b1c1b40a.zip
Kernel: Do 2 validations in annotate_mapping syscall outside a spinlock
Diffstat (limited to 'Kernel/Syscalls')
-rw-r--r--Kernel/Syscalls/mmap.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp
index af63ab1fe3..0091116d12 100644
--- a/Kernel/Syscalls/mmap.cpp
+++ b/Kernel/Syscalls/mmap.cpp
@@ -575,11 +575,13 @@ ErrorOr<FlatPtr> Process::sys$allocate_tls(Userspace<char const*> initial_data,
ErrorOr<FlatPtr> Process::sys$annotate_mapping(Userspace<void*> address, int flags)
{
VERIFY_NO_PROCESS_BIG_LOCK(this);
+ if (flags == to_underlying(VirtualMemoryRangeFlags::None))
+ return EINVAL;
- return address_space().with([&](auto& space) -> ErrorOr<FlatPtr> {
- if (flags == to_underlying(VirtualMemoryRangeFlags::None))
- return EINVAL;
+ if (!Memory::is_user_address(address.vaddr()))
+ return EFAULT;
+ return address_space().with([&](auto& space) -> ErrorOr<FlatPtr> {
if (space->enforces_syscall_regions() && (flags & to_underlying(VirtualMemoryRangeFlags::SyscallCode)))
return EPERM;
@@ -588,9 +590,6 @@ ErrorOr<FlatPtr> Process::sys$annotate_mapping(Userspace<void*> address, int fla
return 0;
}
- if (!Memory::is_user_address(address.vaddr()))
- return EFAULT;
-
auto* region = space->find_region_containing(Memory::VirtualRange { address.vaddr(), 1 });
if (!region)
return EINVAL;