Skip to content

Commit 7660a6f

Browse files
keestorvalds
authored andcommitted
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 <keescook@chromium.org> Cc: Daniel Micay <danielmicay@gmail.com> Cc: David Windsor <dave@nullcore.net> Cc: Eric Biggers <ebiggers3@gmail.com> Cc: Christoph Lameter <cl@linux.com> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Daniel Micay <danielmicay@gmail.com> Cc: David Windsor <dave@nullcore.net> Cc: Eric Biggers <ebiggers3@gmail.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: David Rientjes <rientjes@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Mauro Carvalho Chehab <mchehab@kernel.org> Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Andy Lutomirski <luto@kernel.org> Cc: Nicolas Pitre <nicolas.pitre@linaro.org> Cc: Tejun Heo <tj@kernel.org> Cc: Daniel Mack <daniel@zonque.org> Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Helge Deller <deller@gmx.de> Cc: Rik van Riel <riel@redhat.com> Cc: Randy Dunlap <rdunlap@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e077195 commit 7660a6f

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎Documentation/admin-guide/kernel-parameters.txt‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,8 +3760,14 @@
37603760
slab_nomerge [MM]
37613761
Disable merging of slabs with similar size. May be
37623762
necessary if there is some reason to distinguish
3763-
allocs to different slabs. Debug options disable
3764-
merging on their own.
3763+
allocs to different slabs, especially in hardened
3764+
environments where the risk of heap overflows and
3765+
layout control by attackers can usually be
3766+
frustrated by disabling merging. This will reduce
3767+
most of the exposure of a heap attack to a single
3768+
cache (risks via metadata attacks are mostly
3769+
unchanged). Debug options disable merging on their
3770+
own.
37653771
For more information see Documentation/vm/slub.txt.
37663772

37673773
slab_max_order= [MM, SLAB]

‎init/Kconfig‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,20 @@ config SLOB
15481548

15491549
endchoice
15501550

1551+
config SLAB_MERGE_DEFAULT
1552+
bool "Allow slab caches to be merged"
1553+
default y
1554+
help
1555+
For reduced kernel memory fragmentation, slab caches can be
1556+
merged when they share the same size and other characteristics.
1557+
This carries a risk of kernel heap overflows being able to
1558+
overwrite objects from merged caches (and more easily control
1559+
cache layout), which makes such heap attacks easier to exploit
1560+
by attackers. By keeping caches unmerged, these kinds of exploits
1561+
can usually only damage objects in the same cache. To disable
1562+
merging at runtime, "slab_nomerge" can be passed on the kernel
1563+
command line.
1564+
15511565
config SLAB_FREELIST_RANDOM
15521566
default n
15531567
depends on SLAB || SLUB

‎mm/slab_common.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,12 @@ static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
4747

4848
/*
4949
* Merge control. If this is set then no merging of slab caches will occur.
50-
* (Could be removed. This was introduced to pacify the merge skeptics.)
5150
*/
52-
static int slab_nomerge;
51+
static bool slab_nomerge = !IS_ENABLED(CONFIG_SLAB_MERGE_DEFAULT);
5352

5453
static int __init setup_slab_nomerge(char *str)
5554
{
56-
slab_nomerge = 1;
55+
slab_nomerge = true;
5756
return 1;
5857
}
5958

0 commit comments

Comments
 (0)