]> 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>
Wed, 16 Feb 2022 16:55:03 +0000 (11:55 -0500)
commit5fa005e91560785dad5183db080209447afde3c2
tree569fd689ff3aa18e452bbc104b9e487576878ce6
parente3b852f99bc5f51e99f8fda67e71ab3639f60f4e
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
Sponsored by: The FreeBSD Foundation

(cherry picked from commit 1811c1e957ee1250b08b3246fc0db37ddf64b736)
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