瀏覽代碼

Kernel: Fix off-by-one in Memory::is_user_range() check

This function was checking 1 byte after the provided range, which caused
it to reject valid userspace ranges that happened to end exactly at the
top of the user address space.

This fixes a long-standing issue with mysterious Optional errors in
Coredump::write_regions(). (It happened when trying to add a memory
region at the very top of the address space to a coredump.)
Andreas Kling 3 年之前
父節點
當前提交
890c647e0f
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      Kernel/Memory/MemoryManager.h

+ 5 - 1
Kernel/Memory/MemoryManager.h

@@ -302,7 +302,11 @@ inline bool is_user_range(VirtualAddress vaddr, size_t size)
 {
     if (vaddr.offset(size) < vaddr)
         return false;
-    return is_user_address(vaddr) && is_user_address(vaddr.offset(size));
+    if (!is_user_address(vaddr))
+        return false;
+    if (size <= 1)
+        return true;
+    return is_user_address(vaddr.offset(size - 1));
 }
 
 inline bool is_user_range(VirtualRange const& range)