From 578d45b480c5b167df916ebc42e13bc1bd6153c1 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 6 Jul 2021 20:25:22 -0600 Subject: [PATCH] Kernel: Create and use USER_RANGE_CEILING We had an inconsistency in valid user addresses. is_user_range() was checking against the kernel base address, but previous changes caused the maximum valid user addressable range to be 32 MiB below that. This patch stops mmap(MAP_FIXED) of a range between these two bounds from panic-ing the kernel in RangeAllocator::allocate_specific. --- Kernel/Sections.h | 2 ++ Kernel/VM/MemoryManager.h | 2 +- Kernel/VM/PageDirectory.cpp | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Kernel/Sections.h b/Kernel/Sections.h index dede1e7462..61b5d57e29 100644 --- a/Kernel/Sections.h +++ b/Kernel/Sections.h @@ -19,3 +19,5 @@ #define KERNEL_QUICKMAP_PD (KERNEL_PT1024_BASE + 0x7000) #define KERNEL_QUICKMAP_PER_CPU_BASE (KERNEL_PT1024_BASE + 0x8000) #define KERNEL_PHYSICAL_PAGES_BASE (KERNEL_BASE + KERNEL_PD_OFFSET) + +#define USER_RANGE_CEILING 0xBE000000 diff --git a/Kernel/VM/MemoryManager.h b/Kernel/VM/MemoryManager.h index 2be1fb9db8..16d695e7c2 100644 --- a/Kernel/VM/MemoryManager.h +++ b/Kernel/VM/MemoryManager.h @@ -278,7 +278,7 @@ void VMObject::for_each_region(Callback callback) inline bool is_user_address(VirtualAddress vaddr) { - return vaddr.get() < KERNEL_BASE; + return vaddr.get() < USER_RANGE_CEILING; } inline bool is_user_range(VirtualAddress vaddr, size_t size) diff --git a/Kernel/VM/PageDirectory.cpp b/Kernel/VM/PageDirectory.cpp index 3fd515697f..08897da286 100644 --- a/Kernel/VM/PageDirectory.cpp +++ b/Kernel/VM/PageDirectory.cpp @@ -63,7 +63,7 @@ UNMAP_AFTER_INIT void PageDirectory::allocate_kernel_directory() PageDirectory::PageDirectory(const RangeAllocator* parent_range_allocator) { constexpr FlatPtr userspace_range_base = 0x00800000; - constexpr FlatPtr userspace_range_ceiling = 0xbe000000; + constexpr FlatPtr userspace_range_ceiling = USER_RANGE_CEILING; ScopedSpinLock lock(s_mm_lock); if (parent_range_allocator) {