mm: allow slab_nomerge to be set at build time

Some hardened environments want to build kernels with slab_nomerge
already set (so that they do not depend on remembering to set the kernel
command line option).  This is desired to reduce the risk of kernel heap
overflows being able to overwrite objects from merged caches and changes
the requirements for cache layout control, increasing the difficulty of
these attacks.  By keeping caches unmerged, these kinds of exploits can
usually only damage objects in the same cache (though the risk to
metadata exploitation is unchanged).

Link: http://lkml.kernel.org/r/20170620230911.GA25238@beast
Signed-off-by: Kees Cook <[email protected]>
Cc: Daniel Micay <[email protected]>
Cc: David Windsor <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Daniel Micay <[email protected]>
Cc: David Windsor <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: "Paul E. McKenney" <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Nicolas Pitre <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Daniel Mack <[email protected]>
Cc: Sebastian Andrzej Siewior <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Helge Deller <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Randy Dunlap <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
This commit is contained in:
Kees Cook 2017-07-06 15:36:40 -07:00 • committed by Linus Torvalds
commit 7660a6fddc
3 changed files with 24 additions and 5 deletions

View file

@ -1548,6 +1548,20 @@ config SLOB
endchoice
config SLAB_MERGE_DEFAULT
bool "Allow slab caches to be merged"
default y
help
For reduced kernel memory fragmentation, slab caches can be
merged when they share the same size and other characteristics.
This carries a risk of kernel heap overflows being able to
overwrite objects from merged caches (and more easily control
cache layout), which makes such heap attacks easier to exploit
by attackers. By keeping caches unmerged, these kinds of exploits
can usually only damage objects in the same cache. To disable
merging at runtime, "slab_nomerge" can be passed on the kernel
command line.
config SLAB_FREELIST_RANDOM
default n
depends on SLAB || SLUB