From a09dd6bb6cbe4618b0c73359b200d5a14479c24c Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 11 Mar 2022 14:20:50 -0500 Subject: [PATCH] kernel/vm: Cleanups and minor fixes to get_area_page_protection. * We should not assume all non-kernel areas have KERNEL_READ_AREA permission, but follow the other permission flags directly. This way the kernel will be blocked from accessing guard pages, too. * Compute kernelProtection only once, and either return it directly or return it OR'd with the user protections. Change-Id: Id6daa1cd15eb3102e23f95c08672ad97344e0722 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5096 Reviewed-by: Alex von Gluck IV Reviewed-by: waddlesplash Tested-by: Commit checker robot --- src/system/kernel/vm/vm.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 622f7bbf48..367f43030d 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -505,19 +505,17 @@ get_area_page_protection(VMArea* area, addr_t pageAddress) else protection >>= 4; - // If this is a kernel area we translate the user flags to kernel flags. - if (area->address_space == VMAddressSpace::Kernel()) { - uint32 kernelProtection = 0; - if ((protection & B_READ_AREA) != 0) - kernelProtection |= B_KERNEL_READ_AREA; - if ((protection & B_WRITE_AREA) != 0) - kernelProtection |= B_KERNEL_WRITE_AREA; + uint32 kernelProtection = 0; + if ((protection & B_READ_AREA) != 0) + kernelProtection |= B_KERNEL_READ_AREA; + if ((protection & B_WRITE_AREA) != 0) + kernelProtection |= B_KERNEL_WRITE_AREA; + // If this is a kernel area we return only the kernel flags. + if (area->address_space == VMAddressSpace::Kernel()) return kernelProtection; - } - return protection | B_KERNEL_READ_AREA - | (protection & B_WRITE_AREA ? B_KERNEL_WRITE_AREA : 0); + return protection | kernelProtection; }