mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 12:57:35 +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:
parent
ea52fe528a
commit
e56daf547c
5 changed files with 27 additions and 5 deletions
|
@ -105,6 +105,19 @@ void syscall_trap_entry(RegisterDump regs)
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
auto* calling_region = MM.region_from_vaddr(process, VirtualAddress(regs.eip));
|
||||
if (!calling_region) {
|
||||
dbgprintf("Syscall from %p which has no region\n", regs.eip);
|
||||
handle_crash(regs, "Syscall from unknown region", SIGSEGV);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
if (calling_region->is_writable()) {
|
||||
dbgprintf("Syscall from writable memory at %p\n", regs.eip);
|
||||
handle_crash(regs, "Syscall from writable memory", SIGSEGV);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
process.big_lock().lock();
|
||||
u32 function = regs.eax;
|
||||
u32 arg1 = regs.edx;
|
||||
|
|
|
@ -289,7 +289,6 @@ Region* MemoryManager::user_region_from_vaddr(Process& process, VirtualAddress v
|
|||
|
||||
Region* MemoryManager::region_from_vaddr(Process& process, VirtualAddress vaddr)
|
||||
{
|
||||
ASSERT_INTERRUPTS_DISABLED();
|
||||
if (auto* region = kernel_region_from_vaddr(vaddr))
|
||||
return region;
|
||||
return user_region_from_vaddr(process, vaddr);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/Bitmap.h>
|
||||
#include <AK/ByteBuffer.h>
|
||||
|
@ -8,6 +7,7 @@
|
|||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/String.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <AK/Weakable.h>
|
||||
|
@ -79,6 +79,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
static Region* region_from_vaddr(Process&, VirtualAddress);
|
||||
static const Region* region_from_vaddr(const Process&, VirtualAddress);
|
||||
|
||||
private:
|
||||
MemoryManager(u32 physical_address_for_kernel_page_tables);
|
||||
~MemoryManager();
|
||||
|
@ -96,9 +99,6 @@ private:
|
|||
|
||||
void create_identity_mapping(PageDirectory&, VirtualAddress, size_t length);
|
||||
|
||||
static Region* region_from_vaddr(Process&, VirtualAddress);
|
||||
static const Region* region_from_vaddr(const Process&, VirtualAddress);
|
||||
|
||||
static Region* user_region_from_vaddr(Process&, VirtualAddress);
|
||||
static Region* kernel_region_from_vaddr(VirtualAddress);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue