mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 14:02:46 +00:00 
			
		
		
		
	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:
		
							parent
							
								
									d71f64b97f
								
							
						
					
					
						commit
						c6b7b98b64
					
				
					 3 changed files with 6 additions and 6 deletions
				
			
		|  | @ -190,7 +190,7 @@ void syscall_handler(TrapFrame* trap) | ||||||
|         handle_crash(regs, "Bad stack on syscall entry", SIGSTKFLT); |         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) { |     if (!calling_region) { | ||||||
|         dbgln("Syscall from {:p} which has no associated region", regs.eip); |         dbgln("Syscall from {:p} which has no associated region", regs.eip); | ||||||
|         handle_crash(regs, "Syscall from unknown region", SIGSEGV); |         handle_crash(regs, "Syscall from unknown region", SIGSEGV); | ||||||
|  |  | ||||||
|  | @ -431,7 +431,7 @@ Region* MemoryManager::kernel_region_from_vaddr(VirtualAddress vaddr) | ||||||
|     return nullptr; |     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()); |     ScopedSpinLock lock(space.get_lock()); | ||||||
|     return space.find_region_containing({ vaddr, 1 }); |     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) | Region* MemoryManager::find_region_from_vaddr(Space& space, VirtualAddress vaddr) | ||||||
| { | { | ||||||
|     ScopedSpinLock lock(s_mm_lock); |     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 region; | ||||||
|     return kernel_region_from_vaddr(vaddr); |     return kernel_region_from_vaddr(vaddr); | ||||||
| } | } | ||||||
|  | @ -454,7 +454,7 @@ Region* MemoryManager::find_region_from_vaddr(VirtualAddress vaddr) | ||||||
|     if (!page_directory) |     if (!page_directory) | ||||||
|         return nullptr; |         return nullptr; | ||||||
|     VERIFY(page_directory->space()); |     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) | 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)) |     if (!is_user_address(vaddr)) | ||||||
|         return false; |         return false; | ||||||
|     ScopedSpinLock lock(s_mm_lock); |     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(); |     return region && region->is_user() && region->is_stack(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -188,6 +188,7 @@ public: | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static Region* find_region_from_vaddr(Space&, VirtualAddress); |     static Region* find_region_from_vaddr(Space&, VirtualAddress); | ||||||
|  |     static Region* find_user_region_from_vaddr(Space&, VirtualAddress); | ||||||
| 
 | 
 | ||||||
|     void dump_kernel_regions(); |     void dump_kernel_regions(); | ||||||
| 
 | 
 | ||||||
|  | @ -215,7 +216,6 @@ private: | ||||||
|     static void flush_tlb_local(VirtualAddress, size_t page_count = 1); |     static void flush_tlb_local(VirtualAddress, size_t page_count = 1); | ||||||
|     static void flush_tlb(const PageDirectory*, 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* kernel_region_from_vaddr(VirtualAddress); | ||||||
| 
 | 
 | ||||||
|     static Region* find_region_from_vaddr(VirtualAddress); |     static Region* find_region_from_vaddr(VirtualAddress); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling