From 6634da31d962dcca96b580dad3626980fb064791 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 30 Jan 2020 21:55:49 +0100 Subject: [PATCH] Kernel: Disallow empty ranges in munmap/mprotect/madvise --- Kernel/Process.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 6c933a4d9a..644de98500 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -458,6 +458,9 @@ int Process::sys$munmap(void* addr, size_t size) { REQUIRE_PROMISE(stdio); + if (!size) + return -EINVAL; + if (!is_user_range(VirtualAddress(addr), size)) return -EFAULT; @@ -499,6 +502,9 @@ int Process::sys$mprotect(void* addr, size_t size, int prot) { REQUIRE_PROMISE(stdio); + if (!size) + return -EINVAL; + if (!is_user_range(VirtualAddress(addr), size)) return -EFAULT; @@ -566,6 +572,9 @@ int Process::sys$madvise(void* address, size_t size, int advice) { REQUIRE_PROMISE(stdio); + if (!size) + return -EINVAL; + if (!is_user_range(VirtualAddress(address), size)) return -EFAULT;