diff --git a/Kernel/API/prctl_numbers.h b/Kernel/API/prctl_numbers.h index 9f627a527c..68042deb25 100644 --- a/Kernel/API/prctl_numbers.h +++ b/Kernel/API/prctl_numbers.h @@ -8,3 +8,5 @@ #define PR_SET_DUMPABLE 1 #define PR_GET_DUMPABLE 2 +#define PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS 3 +#define PR_GET_NO_NEW_SYSCALL_REGION_ANNOTATIONS 4 diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 0091116d12..787b056566 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -578,6 +578,9 @@ ErrorOr Process::sys$annotate_mapping(Userspace address, int fla if (flags == to_underlying(VirtualMemoryRangeFlags::None)) return EINVAL; + if (!address) + return EINVAL; + if (!Memory::is_user_address(address.vaddr())) return EFAULT; @@ -585,11 +588,6 @@ ErrorOr Process::sys$annotate_mapping(Userspace address, int fla if (space->enforces_syscall_regions() && (flags & to_underlying(VirtualMemoryRangeFlags::SyscallCode))) return EPERM; - if (!address) { - space->set_enforces_syscall_regions(true); - return 0; - } - auto* region = space->find_region_containing(Memory::VirtualRange { address.vaddr(), 1 }); if (!region) return EINVAL; diff --git a/Kernel/Syscalls/prctl.cpp b/Kernel/Syscalls/prctl.cpp index 4838a758da..08305b89f6 100644 --- a/Kernel/Syscalls/prctl.cpp +++ b/Kernel/Syscalls/prctl.cpp @@ -21,6 +21,22 @@ ErrorOr Process::sys$prctl(int option, FlatPtr arg1, [[maybe_unused]] F return EINVAL; protected_data.dumpable = arg1; return 0; + case PR_GET_NO_NEW_SYSCALL_REGION_ANNOTATIONS: + return address_space().with([&](auto& space) -> ErrorOr { + return space->enforces_syscall_regions(); + }); + case PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS: + if (arg1 != 0 && arg1 != 1) + return EINVAL; + bool prohibit_new_annotated_syscall_regions = (arg1 == 1); + return address_space().with([&](auto& space) -> ErrorOr { + if (space->enforces_syscall_regions() && !prohibit_new_annotated_syscall_regions) + return EPERM; + + space->set_enforces_syscall_regions(prohibit_new_annotated_syscall_regions); + return 0; + }); + return 0; } return EINVAL; }); diff --git a/Userland/Libraries/LibELF/DynamicLinker.cpp b/Userland/Libraries/LibELF/DynamicLinker.cpp index 6ba24599a2..38a7c4bfbc 100644 --- a/Userland/Libraries/LibELF/DynamicLinker.cpp +++ b/Userland/Libraries/LibELF/DynamicLinker.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -677,7 +678,7 @@ void ELF::DynamicLinker::linker_main(DeprecatedString&& main_program_path, int m s_loaders.clear(); - int rc = syscall(SC_annotate_mapping, nullptr); + int rc = syscall(SC_prctl, PR_SET_NO_NEW_SYSCALL_REGION_ANNOTATIONS, 1, 0); if (rc < 0) { VERIFY_NOT_REACHED(); }