]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Extend mmap/mprotect API to specify the max page protections.
authorbrooks <brooks@FreeBSD.org>
Thu, 20 Jun 2019 18:24:16 +0000 (18:24 +0000)
committerbrooks <brooks@FreeBSD.org>
Thu, 20 Jun 2019 18:24:16 +0000 (18:24 +0000)
commit0165ccc850ff0291d9cb31616cac4b2f2b707e1d
tree9b13988cfc7df08063726d1cddd2d44034c7c577
parent517712e7a8c56e54b6b725d569346f5eee78e757
Extend mmap/mprotect API to specify the max page protections.

A new macro PROT_MAX() alters a protection value so it can be OR'd with
a regular protection value to specify the maximum permissions.  If
present, these flags specify the maximum permissions.

While these flags are non-portable, they can be used in portable code
with simple ifdefs to expand PROT_MAX() to 0.

This change allows (e.g.) a region that must be writable during run-time
linking or JIT code generation to be made permanently read+execute after
writes are complete.  This complements W^X protections allowing more
precise control by the programmer.

This change alters mprotect argument checking and returns an error when
unhandled protection flags are set.  This differs from POSIX (in that
POSIX only specifies an error), but is the documented behavior on Linux
and more closely matches historical mmap behavior.

In addition to explicit setting of the maximum permissions, an
experimental sysctl vm.imply_prot_max causes mmap to assume that the
initial permissions requested should be the maximum when the sysctl is
set to 1.  PROT_NONE mappings are excluded from this for compatibility
with rtld and other consumers that use such mappings to reserve
address space before mapping contents into part of the reservation.  A
final version this is expected to provide per-binary and per-process
opt-in/out options and this sysctl will go away in its current form.
As such it is undocumented.

Reviewed by: emaste, kib (prior version), markj
Additional suggestions from: alc
Obtained from: CheriBSD
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D18880
lib/libc/sys/mmap.2
lib/libc/sys/mprotect.2
sys/sys/mman.h
sys/vm/vm_mmap.c