From bbd6beb7ee2b2dcee1d82ea5612d375093cf586c Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Fri, 12 May 2023 20:23:59 +1000 Subject: [PATCH] kernel/vm: Allow more maximum protection for mmap'ed areas MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Always allow a memory region mapped by `map_file` to change its protection to any user protection flags other than `B_WRITE_AREA`. This flag should only be settable when the file is opened with write access. Change-Id: Icc00c08fc033b3bd6b6ceb2833bf566c72914007 Reviewed-on: https://review.haiku-os.org/c/haiku/+/6389 Reviewed-by: Jérôme Duval Reviewed-by: John Scipione Tested-by: Commit checker robot Reviewed-by: waddlesplash --- src/system/kernel/vm/vm.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 4ba4e85edf..0fe2eeadd5 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -2055,9 +2055,10 @@ _vm_map_file(team_id team, const char* name, void** _address, uint32 protectionMax = 0; if (mapping != REGION_PRIVATE_MAP) { - protectionMax = protection | B_READ_AREA; if ((openMode & O_ACCMODE) == O_RDWR) - protectionMax |= B_WRITE_AREA; + protectionMax = protection | B_USER_PROTECTION; + else + protectionMax = protection | (B_USER_PROTECTION & ~B_WRITE_AREA); } // get the vnode for the object, this also grabs a ref to it