linux/Documentation
Alexander Potapenko 6471384af2 mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options
Patch series "add init_on_alloc/init_on_free boot options", v10.

Provide init_on_alloc and init_on_free boot options.

These are aimed at preventing possible information leaks and making the
control-flow bugs that depend on uninitialized values more deterministic.

Enabling either of the options guarantees that the memory returned by the
page allocator and SL[AU]B is initialized with zeroes.  SLOB allocator
isn't supported at the moment, as its emulation of kmem caches complicates
handling of SLAB_TYPESAFE_BY_RCU caches correctly.

Enabling init_on_free also guarantees that pages and heap objects are
initialized right after they're freed, so it won't be possible to access
stale data by using a dangling pointer.

As suggested by Michal Hocko, right now we don't let the heap users to
disable initialization for certain allocations.  There's not enough
evidence that doing so can speed up real-life cases, and introducing ways
to opt-out may result in things going out of control.

This patch (of 2):

The new options are needed to prevent possible information leaks and make
control-flow bugs that depend on uninitialized values more deterministic.

This is expected to be on-by-default on Android and Chrome OS.  And it
gives the opportunity for anyone else to use it under distros too via the
boot args.  (The init_on_free feature is regularly requested by folks
where memory forensics is included in their threat models.)

init_on_alloc=1 makes the kernel initialize newly allocated pages and heap
objects with zeroes.  Initialization is done at allocation time at the
places where checks for __GFP_ZERO are performed.

init_on_free=1 makes the kernel initialize freed pages and heap objects
with zeroes upon their deletion.  This helps to ensure sensitive data
doesn't leak via use-after-free accesses.

Both init_on_alloc=1 and init_on_free=1 guarantee that the allocator
returns zeroed memory.  The two exceptions are slab caches with
constructors and SLAB_TYPESAFE_BY_RCU flag.  Those are never
zero-initialized to preserve their semantics.

Both init_on_alloc and init_on_free default to zero, but those defaults
can be overridden with CONFIG_INIT_ON_ALLOC_DEFAULT_ON and
CONFIG_INIT_ON_FREE_DEFAULT_ON.

If either SLUB poisoning or page poisoning is enabled, those options take
precedence over init_on_alloc and init_on_free: initialization is only
applied to unpoisoned allocations.

Slowdown for the new features compared to init_on_free=0, init_on_alloc=0:

hackbench, init_on_free=1:  +7.62% sys time (st.err 0.74%)
hackbench, init_on_alloc=1: +7.75% sys time (st.err 2.14%)

Linux build with -j12, init_on_free=1:  +8.38% wall time (st.err 0.39%)
Linux build with -j12, init_on_free=1:  +24.42% sys time (st.err 0.52%)
Linux build with -j12, init_on_alloc=1: -0.13% wall time (st.err 0.42%)
Linux build with -j12, init_on_alloc=1: +0.57% sys time (st.err 0.40%)

The slowdown for init_on_free=0, init_on_alloc=0 compared to the baseline
is within the standard error.

The new features are also going to pave the way for hardware memory
tagging (e.g.  arm64's MTE), which will require both on_alloc and on_free
hooks to set the tags for heap objects.  With MTE, tagging will have the
same cost as memory initialization.

Although init_on_free is rather costly, there are paranoid use-cases where
in-memory data lifetime is desired to be minimized.  There are various
arguments for/against the realism of the associated threat models, but
given that we'll need the infrastructure for MTE anyway, and there are
people who want wipe-on-free behavior no matter what the performance cost,
it seems reasonable to include it in this series.

[glider@google.com: v8]
  Link: http://lkml.kernel.org/r/20190626121943.131390-2-glider@google.com
[glider@google.com: v9]
  Link: http://lkml.kernel.org/r/20190627130316.254309-2-glider@google.com
[glider@google.com: v10]
  Link: http://lkml.kernel.org/r/20190628093131.199499-2-glider@google.com
Link: http://lkml.kernel.org/r/20190617151050.92663-2-glider@google.com
Signed-off-by: Alexander Potapenko <glider@google.com>
Acked-by: Kees Cook <keescook@chromium.org>
Acked-by: Michal Hocko <mhocko@suse.cz>		[page and dmapool parts
Acked-by: James Morris <jamorris@linux.microsoft.com>]
Cc: Christoph Lameter <cl@linux.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
Cc: "Serge E. Hallyn" <serge@hallyn.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Sandeep Patil <sspatil@android.com>
Cc: Laura Abbott <labbott@redhat.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Jann Horn <jannh@google.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-07-12 11:05:46 -07:00
..
ABI Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-07-11 10:55:49 -07:00
accelerators docs: mark orphan documents as such 2019-06-08 13:42:11 -06:00
accounting psi: introduce psi monitor 2019-05-14 19:52:48 -07:00
acpi/dsd docs: fix broken documentation links 2019-06-08 13:42:13 -06:00
admin-guide mm: security: introduce init_on_alloc=1 and init_on_free=1 boot options 2019-07-12 11:05:46 -07:00
aoe docs: aoe: convert docs to ReST and rename to *.rst 2019-06-14 14:20:22 -06:00
arm docs: mark orphan documents as such 2019-06-08 13:42:11 -06:00
arm64 It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
auxdisplay
backlight
block for-5.3/block-20190708 2019-07-09 10:45:06 -07:00
blockdev zram: idle writeback fixes and cleanup 2019-01-08 17:15:10 -08:00
bpf Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-07-11 10:55:49 -07:00
bus-devices
cdrom docs: ide: convert docs to ReST and rename to *.rst 2019-06-14 14:21:18 -06:00
cgroup-v1 for-5.3/block-20190708 2019-07-09 10:45:06 -07:00
cma
connector
console
core-api asm-generic, x86: add bitops instrumentation for KASAN 2019-07-12 11:05:42 -07:00
cpu-freq Documentation: cpu-freq: Frequencies aren't always sorted 2018-11-07 13:29:04 +01:00
crypto crypto: doc - Fix formatting of new crypto engine content 2019-07-03 22:13:12 +08:00
dev-tools docs: kmemleak: add more documentation details 2019-07-12 11:05:42 -07:00
device-mapper docs: convert docs to ReST and rename to *.rst 2019-06-14 14:21:04 -06:00
devicetree Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-07-11 10:55:49 -07:00
doc-guide Doc : doc-guide : Fix a typo 2019-06-28 09:04:14 -06:00
driver-api Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-07-11 10:55:49 -07:00
driver-model i2c: core: add device-managed version of i2c_new_dummy 2019-05-17 19:29:40 +02:00
early-userspace Correct gen_init_cpio tool's documentation 2018-11-25 12:25:53 -07:00
EDID docs: EDID/HOWTO.txt: convert it and rename to howto.rst 2019-06-14 14:32:29 -06:00
fault-injection It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
fb docs: fb: Add TER16x32 to the available font names 2019-06-20 13:55:20 -06:00
features Documentation/stackprotector: powerpc supports stack protector 2019-06-14 14:44:43 -06:00
filesystems Highlights: 2019-07-10 21:22:43 -07:00
firmware_class
firmware-guide It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
fpga docs: fpga: convert docs to ReST and rename to *.rst 2019-06-14 14:21:15 -06:00
gpio docs: gpio: convert docs to ReST and rename to *.rst 2019-04-23 23:30:07 +02:00
gpu docs: mark orphan documents as such 2019-06-08 13:42:11 -06:00
hid docs: stop suggesting strlcpy 2019-06-20 14:08:49 -06:00
hwmon hwmon: (lm75) Add support for TMP75B 2019-05-03 13:16:18 -07:00
i2c docs: stop suggesting strlcpy 2019-06-20 14:08:49 -06:00
ia64
ide docs: ide: convert docs to ReST and rename to *.rst 2019-06-14 14:21:18 -06:00
iio
infiniband Documentation/infiniband: update from locked to pinned_vm 2019-02-07 12:56:23 -07:00
input doc: Change LXR references to elixir.bootlin.com 2019-02-01 16:05:03 -07:00
interconnect docs: mark orphan documents as such 2019-06-08 13:42:11 -06:00
ioctl seccomp: add a return code to trap to userspace 2018-12-11 16:28:41 -08:00
isdn isdn: remove isdn4linux 2019-05-31 11:13:10 +02:00
kbuild docs: kbuild: convert docs to ReST and rename to *.rst 2019-06-14 14:21:21 -06:00
kdump docs: kdump: convert docs to ReST and rename to *.rst 2019-06-14 14:21:24 -06:00
kernel-hacking docs: stop suggesting strlcpy 2019-06-20 14:08:49 -06:00
laptops It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
leds docs: leds: convert to ReST 2019-06-28 20:57:31 +02:00
lightnvm
livepatch docs/livepatch: Unify style of livepatch documentation in the ReST format 2019-05-07 16:06:28 -06:00
locking locking/lockdep: Add explanation to lock usage rules in lockdep design doc 2019-06-03 11:55:48 +02:00
m68k
maintainer docs: Add a document on repository management 2019-06-18 09:33:16 -06:00
md
media media: doc-rst: Fix typos 2019-06-27 07:35:47 -04:00
memory-devices
mic docs: mic: convert docs to ReST and rename to *.rst 2019-06-14 14:23:26 -06:00
mips
misc-devices Documentation: add ibmvmc to toctree(index) and fix warnings 2019-01-14 08:37:17 -07:00
mmc
mtd
namespaces
netlabel docs: netlabel: convert docs to ReST and rename to *.rst 2019-06-14 14:23:30 -06:00
networking Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-07-11 10:55:49 -07:00
nfc
nios2
nvdimm Documentation: nvdimm: Fix typo 2019-06-07 11:39:04 -06:00
nvmem
openrisc
parisc
PCI
pcmcia docs: pcmcia: convert docs to ReST and rename to *.rst 2019-06-14 14:23:35 -06:00
perf Documentation: perf: Add documentation for ThunderX2 PMU uncore driver 2018-12-06 12:29:47 +00:00
phy
power PM/EM: Document the Energy Model framework 2019-01-27 12:29:37 +01:00
powerpc docs: kdump: convert docs to ReST and rename to *.rst 2019-06-14 14:21:24 -06:00
process Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next 2019-07-11 10:55:49 -07:00
pti
rapidio
RCU It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
riscv docs: riscv: convert docs to ReST and rename to *.rst 2019-06-14 14:31:32 -06:00
s390 docs: s390: s390dbf: typos and formatting, update crash command 2019-07-05 13:42:24 +02:00
scheduler It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
scsi scsi: ufs-bsg: Allow reading descriptors 2019-02-27 09:00:02 -05:00
security Revert "Merge tag 'keys-acl-20190703' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs" 2019-07-10 18:43:43 -07:00
serial docs: serial: convert docs to ReST and rename to *.rst 2019-04-25 11:37:42 +02:00
sh sh: remove board_time_init() callback 2018-12-18 16:13:04 +01:00
sound ALSA: doc: my_chip has no element ioport 2019-04-03 11:55:47 +02:00
sparc docs: sparc: convert to ReST 2019-05-08 17:13:35 -07:00
sphinx docs: automarkup.py: ignore exceptions when seeking for xrefs 2019-07-08 14:35:47 -06:00
sphinx-static
spi spi-summary: document set_cs_timing 2019-04-08 14:13:43 +07:00
sysctl It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
target docs: target: convert docs to ReST and rename to *.rst 2019-06-14 14:31:36 -06:00
thermal docs: hwmon: Add an index file and rename docs to *.rst 2019-04-17 10:37:23 -07:00
timers docs: timers: convert docs to ReST and rename to *.rst 2019-06-14 14:31:48 -06:00
trace docs: trace: add a missing blank line 2019-06-20 14:05:46 -06:00
translations It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
usb USB: rio500: update Documentation 2019-05-21 10:11:19 +02:00
userspace-api Documentation: Add section about CPU vulnerabilities for Spectre 2019-06-26 11:42:41 -06:00
virtual It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
vm It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
w1
watchdog docs: watchdog: convert docs to ReST and rename to *.rst 2019-06-14 14:32:05 -06:00
wimax
x86 It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
xilinx docs: xilinx: convert eemi.txt to eemi.rst 2019-06-14 14:32:10 -06:00
xtensa xtensa: document boot parameter passing 2019-02-03 18:06:19 -08:00
.gitignore
atomic_bitops.txt docs: atomic_bitops.txt: add a title for this document 2019-04-11 12:37:02 -06:00
atomic_t.txt Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-07-08 16:12:03 -07:00
bt8xxgpio.txt
btmrvl.txt
bus-virt-phys-mapping.txt
Changes
clearing-warn-once.txt A reasonably busy cycle for docs, including: 2019-05-08 12:42:50 -07:00
CodingStyle
conf.py Disable Sphinx SmartyPants in HTML output 2019-06-30 15:30:34 -06:00
cpu-load.txt
cputopology.txt topology: Create core_cpus and die_cpus sysfs attributes 2019-05-23 10:08:34 +02:00
crc32.txt
dcdbas.txt
debugging-modules.txt
debugging-via-ohci1394.txt
dell_rbu.txt
digsig.txt
DMA-API-HOWTO.txt DMA mapping updates for 5.2 2019-05-09 08:40:55 -07:00
DMA-API.txt Documentation: DMA-API: fix a function name of max_mapping_size 2019-06-07 11:10:33 -06:00
DMA-attributes.txt
DMA-ISA-LPC.txt Documentation/DMA-ISA-LPC: fix an incorrect reference 2019-02-11 08:23:07 -07:00
docutils.conf doc-rst: Add missing newline at end of file 2019-06-20 14:16:56 -06:00
dontdiff A reasonably busy cycle for docs, including: 2019-05-08 12:42:50 -07:00
efi-stub.txt
eisa.txt
futex-requeue-pi.txt
gcc-plugins.txt
highuid.txt
hw_random.txt
hwspinlock.txt
index.rst Documentation: Remove duplicate x86 index entry 2019-06-14 11:02:13 -06:00
intel_txt.txt
Intel-IOMMU.txt
io_ordering.txt
io-mapping.txt
iostats.txt block: document iostat changes for disk busy time accounting 2019-06-14 14:46:43 -06:00
IPMI.txt
IRQ-affinity.txt
IRQ-domain.txt
IRQ.txt
irqflags-tracing.txt
isa.txt
isapnp.txt
Kconfig docs: Kbuild/Makefile: allow check for missing docs at build time 2019-06-07 11:33:16 -06:00
kernel-per-CPU-kthreads.txt docs: watchdog: convert docs to ReST and rename to *.rst 2019-06-14 14:32:05 -06:00
kobject.txt kref/kobject: Improve documentation 2018-12-06 13:57:03 +01:00
kprobes.txt Merge branch 'parisc-5.2-1' of git://git.kernel.org/pub/scm/linux/kernel/git/deller/parisc-linux 2019-05-07 19:34:17 -07:00
kref.txt
ldm.txt
lockup-watchdogs.txt
logo.gif
logo.txt
lsm.txt
lzo.txt lib/lzo: fix bugs for very short or empty input 2019-04-05 16:02:30 -10:00
mailbox.txt
Makefile docs: Kbuild/Makefile: allow check for missing docs at build time 2019-06-07 11:33:16 -06:00
memory-barriers.txt It's been a relatively busy cycle for docs: 2019-07-09 12:34:26 -07:00
men-chameleon-bus.txt
nommu-mmap.txt
ntb.txt docs: ntb.txt: add blank lines to clean up some Sphinx warnings 2019-04-11 12:37:03 -06:00
numastat.txt
packing.txt lib: Add support for generic packing operations 2019-05-03 10:49:17 -04:00
padata.txt
parport-lowlevel.txt
percpu-rw-semaphore.txt
phy.txt
pi-futex.txt
pnp.txt
preempt-locking.txt x86/fpu: Remove fpu__restore() 2019-04-09 19:27:42 +02:00
pwm.txt pwm: Add power management descriptions 2019-06-26 11:39:11 +02:00
rbtree.txt
remoteproc.txt
rfkill.txt
robust-futex-ABI.txt
robust-futexes.txt futex: Update comments and docs about return values of arch futex code 2019-04-26 13:57:55 +01:00
rpmsg.txt
rtc.txt Documentation: rtc: Correct location of rtctest.c 2019-03-25 10:34:55 -06:00
SAK.txt
sgi-ioc4.txt
siphash.txt
SM501.txt
smsc_ece1099.txt
speculation.txt docs: speculation.txt: mark example blocks as such 2019-04-11 12:37:03 -06:00
static-keys.txt static_keys.txt: Fix trivial spelling mistake 2019-02-06 16:44:16 -07:00
SubmittingPatches
svga.txt
switchtec.txt
sync_file.txt
tee.txt Documentation: tee: Grammar s/the its/its/ 2019-06-07 11:23:38 -06:00
this_cpu_ops.txt
unaligned-memory-access.txt docs: unaligned-memory-access.txt: use a lowercase title 2019-04-11 12:37:03 -06:00
vfio-mediated-device.txt
vfio.txt
video-output.txt docs: video-output.txt: convert it to ReST format 2019-04-11 12:37:03 -06:00
xillybus.txt
xz.txt
zorro.txt