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 <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
Augustin Cavalier
2022-03-12 17:12:49 +00:00
committed by waddlesplash
parent 4c51faeb59
commit a09dd6bb6c
+8 -10
View File
@@ -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;
}