freebsd-dev/sys
Marcin Wojtas b014e0f15b Enable ASLR by default for 64-bit executables
Address Space Layout Randomization (ASLR) is an exploit mitigation
technique implemented in the majority of modern operating systems.
It involves randomly positioning the base address of an executable
and the position of libraries, heap, and stack, in a process's address
space. Although over the years ASLR proved to not guarantee full OS
security on its own, this mechanism can make exploitation more difficult.

Tests on the tier 1 64-bit architectures demonstrated that the ASLR is
stable and does not result in noticeable performance degradation,
therefore it should be safe to enable this mechanism by default.
Moreover its effectiveness is increased for PIE (Position Independent
Executable) binaries. Thanks to commit 9a227a2fd6 ("Enable PIE by
default on 64-bit architectures"), building from src is not necessary
to have PIE binaries. It is enough to control usage of ASLR in the
OS solely by setting the appropriate sysctls.

This patch toggles the kernel settings to use address map randomization
for PIE & non-PIE 64-bit binaries. It also disables SBRK, in order
to allow utilization of the bss grow region for mappings. The latter
has no effect if ASLR is disabled, so apply it to all architectures.

As for the drawbacks, a consequence of using the ASLR is more
significant VM fragmentation, hence the issues may be encountered
in the systems with a limited address space in high memory consumption
cases, such as buildworld. As a result, although the tests on 32-bit
architectures with ASLR enabled were mostly on par with what was
observed on 64-bit ones, the defaults for the former are not changed
at this time. Also, for the sake of safety keep the feature disabled
for 32-bit executables on 64-bit machines, too.

The committed change affects the overall OS operation, so the
following should be taken into consideration:
* Address space fragmentation.
* A changed ABI due to modified layout of address space.
* More complicated debugging due to:
  * Non-reproducible address space layout between runs.
  * Some debuggers automatically disable ASLR for spawned processes,
    making target's environment different between debug and
    non-debug runs.

In order to confirm/rule-out the dependency of any encountered issue
on ASLR it is strongly advised to re-run the test with the feature
disabled - it can be done by setting the following sysctls
in the /etc/sysctl.conf file:
kern.elf64.aslr.enable=0
kern.elf64.aslr.pie_enable=0

Co-developed by: Dawid Gorecki <dgr@semihalf.com>
Reviewed by: emaste, kib
Obtained from: Semihalf
Sponsored by: Stormshield
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D27666
2021-11-16 23:16:09 +01:00
..
amd64 amd64: Reduce the amount of cpuset copying done for TLB shootdowns 2021-11-15 13:01:31 -05:00
arm tcp: better congestion control defaults 2021-11-12 12:16:11 -07:00
arm64 arm64: rockchip: Move rk805 pmic driver to dev/iicbus/pmic/rockchip 2021-11-14 12:31:07 +01:00
bsm
cam sddadone: 'error' gets assigned only errno codes, never MMC_ERR codes 2021-11-13 11:20:14 +02:00
cddl Allow ddb and dtrace use the DMAP region on arm64 2021-10-01 11:27:33 +01:00
compat syscalls: regen 2021-11-15 18:34:28 +00:00
conf pmic: rockchip: Split the driver in rk805 and rk808 2021-11-14 12:31:26 +01:00
contrib zfs: merge openzfs/zfs@6c8f03232 (master) into main 2021-11-10 14:22:37 +01:00
crypto aesni: Avoid a potential out-of-bounds load in AES_GCM_encrypt() 2021-11-16 13:30:22 -05:00
ddb Create sys/reg.h for the common code previously in machine/reg.h 2021-08-30 12:50:53 +01:00
dev kvmclock: Expose implied TSC frequency via sysctl 2021-11-16 10:27:27 -08:00
dts add rk3328 overlay for enabling analog sound 2021-11-13 11:09:23 +02:00
fs nfsclient: upgrade vnode lock in VOP_OPEN()/VOP_CLOSE() if we need to flush buffers 2021-11-16 19:13:29 +02:00
gdb
geom ffs: fix newly introduced LOR between mntfs vnode lock and topology lock 2021-11-16 20:01:31 +02:00
gnu
i386 tcp: better congestion control defaults 2021-11-12 12:16:11 -07:00
isa
kern Enable ASLR by default for 64-bit executables 2021-11-16 23:16:09 +01:00
kgssapi
libkern libkern: remove bcopy 2021-08-24 11:24:07 +00:00
mips tcp: better congestion control defaults 2021-11-12 12:16:11 -07:00
modules modules: rockchip: Add a module for rk808 PMIC 2021-11-14 20:26:33 +01:00
net net: whack "set but not used" warnings in net/rtsock.c 2021-11-14 17:20:46 +00:00
net80211 net80211: add a driver-private pointer to struct ieee80211_node 2021-10-31 19:08:28 +00:00
netgraph Add ETHER_ALIGN support to ng_device(4). 2021-11-14 13:37:41 +01:00
netinet sctp: Remove now-unneeded mb_unmapped_to_ext() calls 2021-11-16 13:38:09 -05:00
netinet6 Add net.inet6.ip6.source_address_validation 2021-11-12 09:01:40 -08:00
netipsec sctp: Remove now-unneeded mb_unmapped_to_ext() calls 2021-11-16 13:38:09 -05:00
netpfil sctp: Remove now-unneeded mb_unmapped_to_ext() calls 2021-11-16 13:38:09 -05:00
netsmb
nfs kernel: partially revert e9efb1125a15, default inet mask 2021-11-14 14:12:25 -06:00
nfsclient
nfsserver
nlm
ofed socket: De-duplicate SBLOCKWAIT() definitions 2021-09-14 09:01:32 -04:00
opencrypto ktls: Split encrypt vs decrypt OCF counters. 2021-11-16 09:58:52 -08:00
powerpc tcp: better congestion control defaults 2021-11-12 12:16:11 -07:00
riscv tcp: better congestion control defaults 2021-11-12 12:16:11 -07:00
rpc mbuf: Only allow extpg mbufs if the system has a direct map 2021-11-16 13:31:04 -05:00
security
sys ommap: fix signed len and pos arguments 2021-11-15 18:34:28 +00:00
teken
tests routing: add IPv6 fib validation procedure. 2021-08-16 23:04:01 +00:00
tools ipq4018: add TCSR definitions from Linux. 2021-10-18 19:18:01 +00:00
ufs ffs: fix newly introduced LOR between mntfs vnode lock and topology lock 2021-11-16 20:01:31 +02:00
vm ommap: fix signed len and pos arguments 2021-11-15 18:34:28 +00:00
x86 x86: Implement deferred TSC calibration 2021-11-15 16:13:24 -05:00
xdr
xen
Makefile