mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-12 01:10:42 +00:00
Kernel: Add "prot_exec" pledge promise and require it for PROT_EXEC
This prevents sys$mmap() and sys$mprotect() from creating executable memory mappings in pledged programs that don't have this promise. Note that the dynamic loader runs before pledging happens, so it's unaffected by this.
This commit is contained in:
parent
df30b3e54c
commit
d0c5979d96
Notes:
sideshowbarker
2024-07-18 22:46:07 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/d0c5979d96f
3 changed files with 11 additions and 1 deletions
|
@ -53,6 +53,7 @@ If the process later attempts to use any system functionality it has previously
|
|||
* `sendfd`: Send file descriptors over a local socket
|
||||
* `recvfd`: Receive file descriptors over a local socket
|
||||
* `ptrace`: The [`ptrace(2)`](ptrace.md) syscall (\*)
|
||||
* `prot_exec`: [`mmap(2)`](mmap.md) and [`mprotect(2)`](mprotect.md) with `PROT_EXEC` (\*)
|
||||
|
||||
Promises marked with an asterisk (\*) are SerenityOS specific extensions not supported by the original OpenBSD `pledge()`.
|
||||
|
||||
|
|
|
@ -81,7 +81,8 @@ extern VirtualAddress g_return_to_ring3_from_signal_trampoline;
|
|||
__ENUMERATE_PLEDGE_PROMISE(accept) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(settime) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(sigaction) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(setkeymap)
|
||||
__ENUMERATE_PLEDGE_PROMISE(setkeymap) \
|
||||
__ENUMERATE_PLEDGE_PROMISE(prot_exec)
|
||||
|
||||
enum class Pledge : u32 {
|
||||
#define __ENUMERATE_PLEDGE_PROMISE(x) x,
|
||||
|
|
|
@ -163,6 +163,10 @@ void* Process::sys$mmap(Userspace<const Syscall::SC_mmap_params*> user_params)
|
|||
int fd = params.fd;
|
||||
int offset = params.offset;
|
||||
|
||||
if (prot & PROT_EXEC) {
|
||||
REQUIRE_PROMISE(prot_exec);
|
||||
}
|
||||
|
||||
if (alignment & ~PAGE_MASK)
|
||||
return (void*)-EINVAL;
|
||||
|
||||
|
@ -274,6 +278,10 @@ int Process::sys$mprotect(void* addr, size_t size, int prot)
|
|||
{
|
||||
REQUIRE_PROMISE(stdio);
|
||||
|
||||
if (prot & PROT_EXEC) {
|
||||
REQUIRE_PROMISE(prot_exec);
|
||||
}
|
||||
|
||||
if (!size)
|
||||
return -EINVAL;
|
||||
|
||||
|
|
Loading…
Reference in a new issue