* VM_KERNEL_UNSLIDE_OR_ADDRPERM:
* Use this macro when you are exposing an address to userspace that could
* come from either kernel text/data *or* the heap. This is a rare case,
- * but one that does come up and must be handled correctly.
+ * but one that does come up and must be handled correctly. If the argument
+ * is known to be lower than any potential heap address, no transformation
+ * is applied, to avoid revealing the operation on a constant.
*
* Nesting of these macros should be considered invalid.
*/
VM_KERNEL_IS_PRELINKINFO(_v) || \
VM_KERNEL_IS_KEXT_LINKEDIT(_v)) ? \
(vm_offset_t)(_v) - vm_kernel_slide : \
- VM_KERNEL_ADDRPERM(_v))
+ ((vm_offset_t)(_v) >= VM_MIN_KERNEL_AND_KEXT_ADDRESS ? VM_KERNEL_ADDRPERM(_v) : (vm_offset_t)(_v)))
#endif /* XNU_KERNEL_PRIVATE */