Kernel: Don't consider kernel memory regions for syscall origin check

We should never enter the syscall handler from a kernel address.
This commit is contained in:
Andreas Kling 2021-04-20 21:01:13 +02:00
parent d71f64b97f
commit c6b7b98b64
Notes: sideshowbarker 2024-07-18 19:19:24 +09:00
3 changed files with 6 additions and 6 deletions

View file

@ -190,7 +190,7 @@ void syscall_handler(TrapFrame* trap)
handle_crash(regs, "Bad stack on syscall entry", SIGSTKFLT);
}
auto* calling_region = MM.find_region_from_vaddr(process.space(), VirtualAddress(regs.eip));
auto* calling_region = MM.find_user_region_from_vaddr(process.space(), VirtualAddress(regs.eip));
if (!calling_region) {
dbgln("Syscall from {:p} which has no associated region", regs.eip);
handle_crash(regs, "Syscall from unknown region", SIGSEGV);

View file

@ -431,7 +431,7 @@ Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr)
return nullptr;
}
Region* MemoryManager::user_region_from_vaddr(Space& space, VirtualAddress vaddr)
Region* MemoryManager::find_user_region_from_vaddr(Space& space, VirtualAddress vaddr)
{
ScopedSpinLock lock(space.get_lock());
return space.find_region_containing({ vaddr, 1 });
@ -440,7 +440,7 @@ Region* MemoryManager::user_region_from_vaddr(Space& space, VirtualAddress vaddr
Region* MemoryManager::find_region_from_vaddr(Space& space, VirtualAddress vaddr)
{
ScopedSpinLock lock(s_mm_lock);
if (auto* region = user_region_from_vaddr(space, vaddr))
if (auto* region = find_user_region_from_vaddr(space, vaddr))
return region;
return kernel_region_from_vaddr(vaddr);
}
@ -454,7 +454,7 @@ Region* MemoryManager::find_region_from_vaddr(VirtualAddress vaddr)
if (!page_directory)
return nullptr;
VERIFY(page_directory->space());
return user_region_from_vaddr(*page_directory->space(), vaddr);
return find_user_region_from_vaddr(*page_directory->space(), vaddr);
}
PageFaultResponse MemoryManager::handle_page_fault(const PageFault& fault)
@ -855,7 +855,7 @@ bool MemoryManager::validate_user_stack(const Process& process, VirtualAddress v
if (!is_user_address(vaddr))
return false;
ScopedSpinLock lock(s_mm_lock);
auto* region = user_region_from_vaddr(const_cast<Process&>(process).space(), vaddr);
auto* region = find_user_region_from_vaddr(const_cast<Process&>(process).space(), vaddr);
return region && region->is_user() && region->is_stack();
}

View file

@ -188,6 +188,7 @@ public:
}
static Region* find_region_from_vaddr(Space&, VirtualAddress);
static Region* find_user_region_from_vaddr(Space&, VirtualAddress);
void dump_kernel_regions();
@ -215,7 +216,6 @@ private:
static void flush_tlb_local(VirtualAddress, size_t page_count = 1);
static void flush_tlb(const PageDirectory*, VirtualAddress, size_t page_count = 1);
static Region* user_region_from_vaddr(Space&, VirtualAddress);
static Region* kernel_region_from_vaddr(VirtualAddress);
static Region* find_region_from_vaddr(VirtualAddress);