mm: SLAB freelist randomization
PATCH v2 1/1 mm: SLAB freelist randomization
Provides an optional config (CONFIG_FREELIST_RANDOM) to randomize the SLAB freelist. The list is randomized during initialization of a new set of pages. The order on different freelist sizes is pre-computed at boot for performance. This security feature reduces the predictability of the kernel SLAB allocator against heap overflows rendering attacks much less stable.
For example this attack against SLUB (also applicable against SLAB) would be affected:
https://jon.oberheide.org/blog/2010/09/10/linux-kernel-can-slub-overflow/
Also, since v4.6 the freelist was moved at the end of the SLAB. It means a controllable heap is opened to new attacks not yet publicly discussed. A kernel heap overflow can be transformed to multiple use-after-free. This feature makes this type of attack harder too.
To generate entropy, we use get_random_bytes_arch because 0 bits of entropy is available at that boot stage. In the worse case this function will fallback to the get_random_bytes sub API.
The config option name is not specific to the SLAB as this approach will be extended to other allocators like SLUB.
Performance results highlighted no major changes:
Netperf average on 10 runs:
threads,base,change
16,576943.10,585905.90 (101.55%)
32,564082.00,569741.20 (101.00%)
48,558334.30,561851.20 (100.63%)
64,552025.20,556448.30 (100.80%)
80,552294.40,551743.10 (99.90%)
96,552435.30,547529.20 (99.11%)
112,551320.60,550183.20 (99.79%)
128,549138.30,550542.70 (100.26%)
144,549344.50,544529.10 (99.12%)
160,550360.80,539929.30 (98.10%)
slab_test 1 run on boot. After is faster except for odd result on size 2048.
Before:
Single thread testing
=====================
1. Kmalloc: Repeatedly allocate then free test 10000 times kmalloc(8) -> 137 cycles kfree -> 126 cycles 10000 times kmalloc(16) -> 118 cycles kfree -> 119 cycles 10000 times kmalloc(32) -> 112 cycles kfree -> 119 cycles 10000 times kmalloc(64) -> 126 cycles kfree -> 123 cycles 10000 times kmalloc(128) -> 135 cycles kfree -> 131 cycles 10000 times kmalloc(256) -> 165 cycles kfree -> 104 cycles 10000 times kmalloc(512) -> 174 cycles kfree -> 126 cycles 10000 times kmalloc(1024) -> 242 cycles kfree -> 160 cycles 10000 times kmalloc(2048) -> 478 cycles kfree -> 239 cycles 10000 times kmalloc(4096) -> 747 cycles kfree -> 364 cycles 10000 times kmalloc(8192) -> 774 cycles kfree -> 404 cycles 10000 times kmalloc(16384) -> 849 cycles kfree -> 430 cycles
2. Kmalloc: alloc/free test
10000 times kmalloc(8)/kfree -> 118 cycles
10000 times kmalloc(16)/kfree -> 118 cycles
10000 times kmalloc(32)/kfree -> 118 cycles
10000 times kmalloc(64)/kfree -> 121 cycles
10000 times kmalloc(128)/kfree -> 118 cycles
10000 times kmalloc(256)/kfree -> 115 cycles
10000 times kmalloc(512)/kfree -> 115 cycles
10000 times kmalloc(1024)/kfree -> 115 cycles 10000 times kmalloc(2048)/kfree -> 115 cycles 10000 times kmalloc(4096)/kfree -> 115 cycles 10000 times kmalloc(8192)/kfree -> 115 cycles 10000 times kmalloc(16384)/kfree -> 115 cycles
After:
Single thread testing
=====================
1. Kmalloc: Repeatedly allocate then free test 10000 times kmalloc(8) -> 99 cycles kfree -> 84 cycles 10000 times kmalloc(16) -> 88 cycles kfree -> 83 cycles 10000 times kmalloc(32) -> 90 cycles kfree -> 81 cycles 10000 times kmalloc(64) -> 107 cycles kfree -> 97 cycles 10000 times kmalloc(128) -> 134 cycles kfree -> 89 cycles 10000 times kmalloc(256) -> 145 cycles kfree -> 97 cycles 10000 times kmalloc(512) -> 177 cycles kfree -> 116 cycles 10000 times kmalloc(1024) -> 223 cycles kfree -> 151 cycles 10000 times kmalloc(2048) -> 1429 cycles kfree -> 221 cycles 10000 times kmalloc(4096) -> 720 cycles kfree -> 348 cycles 10000 times kmalloc(8192) -> 788 cycles kfree -> 393 cycles 10000 times kmalloc(16384) -> 867 cycles kfree -> 433 cycles
2. Kmalloc: alloc/free test
10000 times kmalloc(8)/kfree -> 115 cycles
10000 times kmalloc(16)/kfree -> 115 cycles
10000 times kmalloc(32)/kfree -> 115 cycles
10000 times kmalloc(64)/kfree -> 120 cycles
10000 times kmalloc(128)/kfree -> 127 cycles
10000 times kmalloc(256)/kfree -> 119 cycles
10000 times kmalloc(512)/kfree -> 112 cycles
10000 times kmalloc(1024)/kfree -> 112 cycles 10000 times kmalloc(2048)/kfree -> 112 cycles 10000 times kmalloc(4096)/kfree -> 112 cycles 10000 times kmalloc(8192)/kfree -> 112 cycles 10000 times kmalloc(16384)/kfree -> 112 cycles
---
Based on next-20160418
--- init/Kconfig | 9 ++++ mm/slab.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 174 insertions(+), 1 deletion(-)
init/Kconfig +9 -0
@@ -1742,6 +1742,15 @@ config SLOB endchoice +config FREELIST_RANDOM + default n + depends on SLAB + bool "SLAB freelist randomization" + help + Randomizes the freelist order used on creating new SLABs. This + security feature reduces the predictability of the kernel slab + allocator against heap overflows. + config SLUB_CPU_PARTIAL default y depends on SLUB && SMP
mm/slab.c +165 -1
197 lines not on this page · raw message
Signature · 1 line
2.8.0.rc3.226.g39d4020