1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

Kernel: Disallow syscalls from writeable memory

Processes will now crash with SIGSEGV if they attempt making a syscall
from PROT_WRITE memory.

This neat idea comes from OpenBSD. :^)
This commit is contained in:
Andreas Kling 2019-11-29 16:15:30 +01:00
parent ea52fe528a
commit e56daf547c
5 changed files with 27 additions and 5 deletions

View file

@ -1,4 +1,5 @@
#include <AK/String.h>
#include <Kernel/Syscall.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
@ -24,6 +25,7 @@ int main(int argc, char** argv)
WriteToReadonlyMemory,
InvalidStackPointerOnSyscall,
InvalidStackPointerOnPageFault,
SyscallFromWritableMemory,
};
Mode mode = SegmentationViolation;
@ -52,6 +54,8 @@ int main(int argc, char** argv)
mode = InvalidStackPointerOnSyscall;
else if (String(argv[1]) == "-t")
mode = InvalidStackPointerOnPageFault;
else if (String(argv[1]) == "-S")
mode = SyscallFromWritableMemory;
else
print_usage_and_exit();
@ -152,6 +156,11 @@ int main(int argc, char** argv)
ASSERT_NOT_REACHED();
}
if (mode == SyscallFromWritableMemory) {
u8 buffer[] = { 0xb8, Syscall::SC_getuid, 0, 0, 0, 0xcd, 0x82 };
((void(*)())buffer)();
}
ASSERT_NOT_REACHED();
return 0;
}