Skip to content

Commit 3404be6

Browse files
keestorvalds
authored andcommitted
mm/slab: expand CONFIG_SLAB_FREELIST_HARDENED to include SLAB
Patch series "mm: Expand CONFIG_SLAB_FREELIST_HARDENED to include SLAB" In reviewing Vlastimil Babka's latest slub debug series, I realized[1] that several checks under CONFIG_SLAB_FREELIST_HARDENED weren't being applied to SLAB. Fix this by expanding the Kconfig coverage, and adding a simple double-free test for SLAB. This patch (of 2): Include SLAB caches when performing kmem_cache pointer verification. A defense against such corruption[1] should be applied to all the allocators. With this added, the "SLAB_FREE_CROSS" and "SLAB_FREE_PAGE" LKDTM tests now pass on SLAB: lkdtm: Performing direct entry SLAB_FREE_CROSS lkdtm: Attempting cross-cache slab free ... ------------[ cut here ]------------ cache_from_obj: Wrong slab cache. lkdtm-heap-b but object is from lkdtm-heap-a WARNING: CPU: 2 PID: 2195 at mm/slab.h:530 kmem_cache_free+0x8d/0x1d0 ... lkdtm: Performing direct entry SLAB_FREE_PAGE lkdtm: Attempting non-Slab slab free ... ------------[ cut here ]------------ virt_to_cache: Object is not a Slab page! WARNING: CPU: 1 PID: 2202 at mm/slab.h:489 kmem_cache_free+0x196/0x1d0 Additionally clean up neighboring Kconfig entries for clarity, readability, and redundant option removal. [1] https://github.com/ThomasKing2014/slides/raw/master/Building%20universal%20Android%20rooting%20with%20a%20type%20confusion%20vulnerability.pdf Fixes: 598a071 ("mm/slab: validate cache membership under freelist hardening") Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Alexander Popov <alex.popov@linux.com> Cc: Christoph Lameter <cl@linux.com> Cc: David Rientjes <rientjes@google.com> Cc: Jann Horn <jannh@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Matthew Garrett <mjg59@google.com> Cc: Pekka Enberg <penberg@kernel.org> Cc: Roman Gushchin <guro@fb.com> Cc: Vijayanand Jitta <vjitta@codeaurora.org> Cc: Vinayak Menon <vinmenon@codeaurora.org> Link: http://lkml.kernel.org/r/20200625215548.389774-1-keescook@chromium.org Link: http://lkml.kernel.org/r/20200625215548.389774-2-keescook@chromium.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fa9ba3a commit 3404be6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎init/Kconfig‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,22 +1913,23 @@ config SLAB_MERGE_DEFAULT
19131913
command line.
19141914

19151915
config SLAB_FREELIST_RANDOM
1916-
default n
1916+
bool "Randomize slab freelist"
19171917
depends on SLAB || SLUB
1918-
bool "SLAB freelist randomization"
19191918
help
19201919
Randomizes the freelist order used on creating new pages. This
19211920
security feature reduces the predictability of the kernel slab
19221921
allocator against heap overflows.
19231922

19241923
config SLAB_FREELIST_HARDENED
19251924
bool "Harden slab freelist metadata"
1926-
depends on SLUB
1925+
depends on SLAB || SLUB
19271926
help
19281927
Many kernel heap attacks try to target slab cache metadata and
19291928
other infrastructure. This options makes minor performance
19301929
sacrifices to harden the kernel slab allocator against common
1931-
freelist exploit methods.
1930+
freelist exploit methods. Some slab implementations have more
1931+
sanity-checking than others. This option is most effective with
1932+
CONFIG_SLUB.
19321933

19331934
config SHUFFLE_PAGE_ALLOCATOR
19341935
bool "Page allocator randomization"

0 commit comments

Comments
 (0)