aboutsummaryrefslogtreecommitdiff
path: root/sys/sys/exec.h
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-01-17 16:42:56 +0000
committerMark Johnston <markj@FreeBSD.org>2022-02-16 16:55:03 +0000
commit5fa005e91560785dad5183db080209447afde3c2 (patch)
tree569fd689ff3aa18e452bbc104b9e487576878ce6 /sys/sys/exec.h
parente3b852f99bc5f51e99f8fda67e71ab3639f60f4e (diff)
downloadsrc-5fa005e91560785dad5183db080209447afde3c2.tar.gz
src-5fa005e91560785dad5183db080209447afde3c2.zip
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)
Diffstat (limited to 'sys/sys/exec.h')
-rw-r--r--sys/sys/exec.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/sys/exec.h b/sys/sys/exec.h
index ccd7eb0ecd7d..94d2f698bd63 100644
--- a/sys/sys/exec.h
+++ b/sys/sys/exec.h
@@ -77,7 +77,8 @@ struct execsw {
* Prefer the kern.ps_strings or kern.proc.ps_strings sysctls to this constant.
*/
#define PS_STRINGS (USRSTACK - sizeof(struct ps_strings))
-#define PROC_PS_STRINGS(p) ((p)->p_sysent->sv_psstrings)
+#define PROC_PS_STRINGS(p) \
+ ((p)->p_vmspace->vm_stacktop - (p)->p_sysent->sv_psstringssz)
int exec_map_first_page(struct image_params *);
void exec_unmap_first_page(struct image_params *);