]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
exec: Reimplement stack address randomization
authorMark Johnston <markj@FreeBSD.org>
Mon, 17 Jan 2022 16:42:56 +0000 (11:42 -0500)
committerMark Johnston <markj@FreeBSD.org>
Mon, 17 Jan 2022 21:12:36 +0000 (16:12 -0500)
commit1811c1e957ee1250b08b3246fc0db37ddf64b736
treec207d515f5beee99ffad9202e9e9b1ae3c6e765c
parent758d98debec43ff83b8a1ed9a3d3a8441b83b3cc
exec: Reimplement stack address randomization

The approach taken by the stack gap implementation was to insert a
random gap between the top of the fixed stack mapping and the true top
of the main process stack.  This approach was chosen so as to avoid
randomizing the previously fixed address of certain process metadata
stored at the top of the stack, but had some shortcomings.  In
particular, mlockall(2) calls would wire the gap, bloating the process'
memory usage, and RLIMIT_STACK included the size of the gap so small
(< several MB) limits could not be used.

There is little value in storing each process' ps_strings at a fixed
location, as only very old programs hard-code this address; consumers
were converted decades ago to use a sysctl-based interface for this
purpose.  Thus, this change re-implements stack address randomization by
simply breaking the convention of storing ps_strings at a fixed
location, and randomizing the location of the entire stack mapping.
This implementation is simpler and avoids the problems mentioned above,
while being unlikely to break compatibility anywhere the default ASLR
settings are used.

The kern.elfN.aslr.stack_gap sysctl is renamed to kern.elfN.aslr.stack,
and is re-enabled by default.

PR: 260303
Reviewed by: kib
Discussed with: emaste, mw
MFC after: 1 month
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D33704
share/man/man7/security.7
sys/i386/linux/imgact_linux.c
sys/kern/imgact_aout.c
sys/kern/imgact_elf.c
sys/kern/kern_exec.c
sys/sys/exec.h
sys/sys/imgact.h
sys/vm/vm_map.c
sys/vm/vm_map.h