freebsd-dev/usr.bin
Konstantin Belousov fa50a3552d Implement Address Space Layout Randomization (ASLR)
With this change, randomization can be enabled for all non-fixed
mappings.  It means that the base address for the mapping is selected
with a guaranteed amount of entropy (bits). If the mapping was
requested to be superpage aligned, the randomization honours the
superpage attributes.

Although the value of ASLR is diminshing over time as exploit authors
work out simple ASLR bypass techniques, it elimintates the trivial
exploitation of certain vulnerabilities, at least in theory.  This
implementation is relatively small and happens at the correct
architectural level.  Also, it is not expected to introduce
regressions in existing cases when turned off (default for now), or
cause any significant maintaince burden.

The randomization is done on a best-effort basis - that is, the
allocator falls back to a first fit strategy if fragmentation prevents
entropy injection.  It is trivial to implement a strong mode where
failure to guarantee the requested amount of entropy results in
mapping request failure, but I do not consider that to be usable.

I have not fine-tuned the amount of entropy injected right now. It is
only a quantitive change that will not change the implementation.  The
current amount is controlled by aslr_pages_rnd.

To not spoil coalescing optimizations, to reduce the page table
fragmentation inherent to ASLR, and to keep the transient superpage
promotion for the malloced memory, locality clustering is implemented
for anonymous private mappings, which are automatically grouped until
fragmentation kicks in.  The initial location for the anon group range
is, of course, randomized.  This is controlled by vm.cluster_anon,
enabled by default.

The default mode keeps the sbrk area unpopulated by other mappings,
but this can be turned off, which gives much more breathing bits on
architectures with small address space, such as i386.  This is tied
with the question of following an application's hint about the mmap(2)
base address. Testing shows that ignoring the hint does not affect the
function of common applications, but I would expect more demanding
code could break. By default sbrk is preserved and mmap hints are
satisfied, which can be changed by using the
kern.elf{32,64}.aslr.honor_sbrk sysctl.

ASLR is enabled on per-ABI basis, and currently it is only allowed on
FreeBSD native i386 and amd64 (including compat 32bit) ABIs.  Support
for additional architectures will be added after further testing.

Both per-process and per-image controls are implemented:
- procctl(2) adds PROC_ASLR_CTL/PROC_ASLR_STATUS;
- NT_FREEBSD_FCTL_ASLR_DISABLE feature control note bit makes it possible
  to force ASLR off for the given binary.  (A tool to edit the feature
  control note is in development.)
Global controls are:
- kern.elf{32,64}.aslr.enable - for non-fixed mappings done by mmap(2);
- kern.elf{32,64}.aslr.pie_enable - for PIE image activation mappings;
- kern.elf{32,64}.aslr.honor_sbrk - allow to use sbrk area for mmap(2);
- vm.cluster_anon - enables anon mapping clustering.

PR:	208580 (exp runs)
Exp-runs done by:	antoine
Reviewed by:	markj (previous version)
Discussed with:	emaste
Tested by:	pho
MFC after:	1 month
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D5603
2019-02-10 17:19:45 +00:00
..
addr2line
alias
apply
ar ar: detect and error out on 32-bit symbol table overflow 2018-12-28 22:47:55 +00:00
asa
at
atm
awk
banner
basename
bc Sync with OpenBSD. 2019-01-12 12:35:02 +00:00
biff
bluetooth
bmake Merge bmake-20181221 2018-12-23 01:05:52 +00:00
brandelf brandelf: capsicumize it 2018-11-18 12:23:03 +00:00
bsdcat MFV r338519: 2018-09-11 20:51:34 +00:00
bsdiff bspatch: simplify capsicumization 2018-11-07 21:01:14 +00:00
bzip2
bzip2recover
c89
c99
caesar
calendar Add myself to committers-src.dot and calendar.freebsd 2019-02-09 16:53:39 +00:00
cap_mkdb
chat
chkey
chpass
cksum
clang Merge ^/head r340918 through r341763. 2018-12-09 11:39:45 +00:00
cmp Fix cmp(1) tests for "special" mode. 2019-01-21 03:57:49 +00:00
col
colldef
colrm
column
comm
compile_et
compress Fix descriptor/memory leak in compress(1) code 2019-01-18 00:26:25 +00:00
cpio MFV r338519: 2018-09-11 20:51:34 +00:00
cpuset
csplit
ctags
ctlstat
cut
cxxfilt
dc Make dc(1) buildable. 2018-09-19 07:08:27 +00:00
diff capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
diff3 capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
dirname
dpv
drill
dtc dtc(1): Update to 0892ec7; HACKING and implicit header fixes 2018-08-23 02:26:40 +00:00
du
ee
elf2aout
elfdump elfdump: use designated array initialization for note types 2019-01-31 16:49:06 +00:00
enigma
env
etdump
expand
factor Make factor(6) buildable. 2018-09-19 07:09:09 +00:00
false
fetch Through a combination of insufficient variable initialization and 2018-09-10 19:39:20 +00:00
file
file2c
find Fix whiteout support in find(1) 2019-01-28 02:00:39 +00:00
finger
fmt
fold
fortune A few corrections and clarifications to r343406. 2019-01-28 19:54:58 +00:00
from
fstat Print type designator 'D' for the KF_TYPE_DEV files. 2018-12-03 23:42:04 +00:00
fsync
ftp
gcore
gencat
getaddrinfo
getconf Add Linux compatibility support for SC_NPROCESSORS_{CONF,ONLN} as _SC_NPROCESSORS_{CONF,ONLN} 2019-01-11 22:28:18 +00:00
getent
getopt
gprof
grdc
grep Fix bsdgrep manpage clobbering grep(1) with default build options 2019-01-09 02:47:07 +00:00
gzip Correct documentation year. 2019-01-07 08:29:27 +00:00
head head: sandbox using capsicum 2018-11-12 17:59:15 +00:00
hesinfo
hexdump
host
iconv
id
ident
indent capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
ipcrm
ipcs ipcs(1): drop obsolete error checking 2019-02-07 14:29:45 +00:00
iscsictl iscsictl.8: Add missing flag parameters 2018-12-27 14:44:01 +00:00
join
jot capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
kdump
keylogin
keylogout
killall
ktrace
ktrdump capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
lam The lam(1) man page is unclear about the uppercase versions of the flags 2019-01-04 02:48:43 +00:00
last A single comma was missing to separate the "see also" items in 2018-10-20 17:22:04 +00:00
lastcomm
ldd Add an IMPLEMENTATION NOTES section to ldd.1. 2018-10-23 13:49:53 +00:00
leave
less
lessecho
lesskey
lex
limits
locale
localedef localedef: define characters in "space" class also as "print", except 2018-10-27 23:31:42 +00:00
locate Move install of locate.rc to usr.bin/locate/locate/ 2018-09-18 20:50:07 +00:00
lock
lockf
logger
login Move fbtab, login.conf, and motd to usr.bin/login/ 2018-08-30 15:52:03 +00:00
logins
logname
look
lorder
lsvfs
lzmainfo
m4
mail Move mail.rc install to usr.bin/mail. 2018-09-18 20:47:06 +00:00
man Teach man(1) about C.UTF-8. 2018-11-04 16:58:55 +00:00
mandoc Import mandoc 1.14.4 2018-09-20 10:58:52 +00:00
mesg
minigzip
ministat
mkcsmapper
mkcsmapper_static
mkdep
mkesdb
mkesdb_static
mkfifo
mkimg Remove unneeded headers. 2019-01-06 20:39:23 +00:00
mklocale
mkstr
mktemp
mkuzip
morse
msgs
mt
nc
ncal
netstat
newgrp
newkey newkey(8): fix 'tmpname' memory leak (always) and input file descriptor leak 2019-02-08 14:31:44 +00:00
nfsstat Remove references to the "new" NFS clients and servers. The "old" 2018-10-01 18:26:41 +00:00
nice
nl
nm
nohup Cross-reference nohup(1) and daemon(8). 2018-11-09 13:47:06 +00:00
number
objcopy remove doubled name in objcopy manpage 2018-09-11 20:32:57 +00:00
ofed
opieinfo
opiekey
opiepasswd
pagesize
pamtest
passwd
paste
patch
pathchk
perror
pom pom: Fix fencepost bugs. 2018-11-20 00:06:53 +00:00
pr
primes Remove unneeded assert.h (there is no assertion in this file). 2019-01-06 20:42:09 +00:00
printenv
printf
proccontrol Implement Address Space Layout Randomization (ASLR) 2019-02-10 17:19:45 +00:00
procstat Temporarily skip flakey test cases 2018-12-06 09:22:35 +00:00
protect
quota
random
rctl
readelf
renice
resizewin
rev
revoke
rpcgen
rpcinfo
rs
rup
ruptime Fix indentation in ruptime command output for hosts in the "down" state. 2019-01-12 12:57:32 +00:00
rusers
rwall
rwho capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
script
sdiff
sdiotool
sed usr.bin/sed/tests: fix one of the regression test cases by adding its 2018-10-31 15:04:41 +00:00
seq
setchannel
shar Shar files may be seen as binary by grep. 2019-01-31 23:21:18 +00:00
showmount
size
smbutil
sockstat
soelim
sort Don't use absolute path to sed when building usr.bin/join 2018-08-23 18:18:43 +00:00
split
ssh-copy-id
stat
stdbuf
strings
su
svn
systat Fix systat's :only command parser for the multiple arguments case 2019-01-23 02:46:35 +00:00
tabs
tail
talk Use a private definition of osockaddr rather then relying on type 2019-01-18 21:30:06 +00:00
tar MFV r338519: 2018-09-11 20:51:34 +00:00
tcopy
tee capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
telnet
tests
tftp tftp(1): switch default transfer mode to binary 2018-08-23 17:00:07 +00:00
time
timeout
tip Move remote & phones to usr.bin/tip/tip/ 2018-09-19 14:56:53 +00:00
top Fix the first couple of AddressSanitizer violations in usr.bin/top. 2019-02-10 13:44:36 +00:00
touch
tput
tr
true
truncate
truss Validate the string size parameter passed to -s. 2018-12-10 21:47:19 +00:00
tset
tsort
tty
ul
uname
unexpand
unifdef
uniq capsicum: use a new capsicum helpers in tools 2018-11-04 19:24:49 +00:00
units Correct a typo: was -> way. 2019-01-21 15:27:58 +00:00
unvis
unzip
usbhidaction
usbhidctl
users
uudecode
uuencode Make outfile constant. 2018-11-12 07:14:34 +00:00
vacation
vgrind
vi
vis
vmstat Dynamically allocate IRQ ranges on x86. 2018-08-28 21:09:19 +00:00
vtfontcvt vtfontcvt: whitespace cleanup 2019-02-06 18:50:48 +00:00
w
wall
wc s/caph_enter_capser/caph_enter_casper/g 2018-11-12 18:43:51 +00:00
what
whereis Silence Clang Scan warnings regarding the use of strcp(). 2019-01-24 18:39:45 +00:00
which
who
whois
write Remove extraneous setutxent() calls in write(1). 2019-01-23 20:02:17 +00:00
xargs
xinstall install(1): Fix relative path calculation with partial common dest/src 2019-01-31 05:20:11 +00:00
xo
xohtml
xolint
xopo
xstr
xz
xzdec
yacc
yes
ypcat
ypmatch
ypwhich
zstd Update to Zstandard 1.3.8 2018-12-29 21:18:01 +00:00
Makefile Move trim(1) from usr.bin to usr.sbin to become trim(8). 2018-11-29 16:08:16 +00:00
Makefile.amd64
Makefile.arm
Makefile.i386
Makefile.inc
Makefile.powerpc
Makefile.sparc64