From b807f1c3fc709d7b1fd1ceefcf22eea4ff71d0c8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 28 Jul 2021 20:40:37 +0200 Subject: [PATCH] Kernel: Fail madvise() volatile change with EINVAL for non-purgeable mem AnonymousVMObject::set_volatile() assumes that nobody ever calls it on non-purgeable objects, so let's make sure we don't do that. Also return EINVAL instead of EPERM for non-anonymous VM objects so the error codes match. --- Kernel/Syscalls/mmap.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 3bcfbbdc39..515b054d9b 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -472,8 +472,10 @@ KResultOr Process::sys$madvise(Userspace address, size_t size, i return EINVAL; if (set_volatile || set_nonvolatile) { if (!region->vmobject().is_anonymous()) - return EPERM; + return EINVAL; auto& vmobject = static_cast(region->vmobject()); + if (!vmobject.is_purgeable()) + return EINVAL; bool was_purged = false; auto result = vmobject.set_volatile(set_volatile, was_purged); if (result.is_error())