Skip to content

RFC Prevent cross-cache attacks in the SLUB allocator

Matteo Rizzo linux-doc linux-hardening linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest14 patches 33 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/14mm/slub: don't try to dereference invalid freepointersmm/slub.c+3 -12 replies
2/14mm/slub: add is_slab_addr/is_slab_page helpersinclude/linux/slab.h kernel/resource.c mm/slab.h +2 more+16 -71 reply
3/14mm/slub: move kmem_cache_order_objects to slab.hinclude/linux/slub_def.h mm/slab.h mm/slub.c+22 -211 reply
4/14mm: use virt_to_slab instead of folio_slabmm/memcontrol.c mm/slab_common.c mm/slub.c+14 -141 reply
5/14mm/slub: create folio_set/clear_slab helpersmm/slub.c+22 -101 reply
6/14mm/slub: pass additional args to alloc_slab_pagemm/slub.c+4 -31 reply
7/14mm/slub: pass slab pointer to the freeptr decode helpermm/slub.c+23 -201 reply
8/14security: introduce CONFIG_SLAB_VIRTUALsecurity/Kconfig.hardening+14 -01 reply
9/14mm/slub: add the slab freelists to kmem_cacheinclude/linux/slub_def.h mm/slub.c+39 -01 reply
10/14x86: Create virtual memory region for SLUBDocumentation/arch/x86/x86_64/mm.rst arch/x86/include/asm/pgtable_64_types.h arch/x86/mm/init_64.c +4 more+52 -63 replies
11/14mm/slub: allocate slabs from virtual memoryarch/x86/include/asm/page_64.h arch/x86/include/asm/pgtable_64_types.h arch/x86/mm/physaddr.c +6 more+587 -73 replies
12/14mm/slub: introduce the deallocated_pages sysfs attributeinclude/linux/slub_def.h mm/slub.c+21 -11 reply
13/14mm/slub: sanity-check freepointerslib/slub_kunit.c mm/slab.h mm/slub.c+69 -01 reply
14/14security: add documentation for SLAB_VIRTUALDocumentation/security/self-protection.rst+102 -02 replies

Reviews trailers per patch

11 of 14 patches have a Reviewed-by or Acked-by.

PatchKees CookHyeonggon Yoo
1/14R-b R-b
2/14R-b
3/14R-b
4/14R-b
5/14R-b
6/14R-b
7/14
8/14R-b
9/14R-b
10/14R-b
11/14
12/14R-b
13/14R-b
14/14

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 00/14] Prevent cross-cache attacks in the SLUB allocator

The goal of this patch series is to deterministically prevent cross-cache attacks in the SLUB allocator.

Use-after-free bugs are normally exploited by making the memory allocator reuse the victim object's memory for an object with a different type. This creates a type confusion which is a very powerful attack primitive.

There are generally two ways to create such type confusions in the kernel:
one way is to make SLUB reuse the freed object's address for another object of a different type which lives in the same slab cache. This only works in slab caches that can contain objects of different types (i.e. the kmalloc caches) and the attacker is limited to objects that belong to the same size class as the victim object.

The other way is to use a "cross-cache attack": make SLUB return the page containing the victim object to the page allocator and then make it use the same page for a different slab cache or other objects that contain attacker-controlled data. This gives attackers access to all objects rather than just the ones in the same size class as the target and lets attackers target objects allocated from dedicated caches such as struct file.

This patch prevents cross-cache attacks by making sure that once a virtual address is used for a slab cache it's never reused for anything except for other slabs in that cache.

Jann Horn (13):
mm/slub: add is_slab_addr/is_slab_page helpers mm/slub: move kmem_cache_order_objects to slab.h
mm: use virt_to_slab instead of folio_slab mm/slub: create folio_set/clear_slab helpers mm/slub: pass additional args to alloc_slab_page mm/slub: pass slab pointer to the freeptr decode helper
security: introduce CONFIG_SLAB_VIRTUAL mm/slub: add the slab freelists to kmem_cache
x86: Create virtual memory region for SLUB mm/slub: allocate slabs from virtual memory mm/slub: introduce the deallocated_pages sysfs attribute mm/slub: sanity-check freepointers
security: add documentation for SLAB_VIRTUAL

Matteo Rizzo (1):
mm/slub: don't try to dereference invalid freepointers

 Documentation/arch/x86/x86_64/mm.rst       |   4 +-
 Documentation/security/self-protection.rst | 102 ++++
 arch/x86/include/asm/page_64.h             |  10 +
 arch/x86/include/asm/pgtable_64_types.h    |  21 +
 arch/x86/mm/init_64.c                      |  19 +-
 arch/x86/mm/kaslr.c                        |   9 +
 arch/x86/mm/mm_internal.h                  |   4 +
 arch/x86/mm/physaddr.c                     |  10 +
 include/linux/slab.h                       |   8 +
 include/linux/slub_def.h                   |  25 +-
 init/main.c                                |   1 +
 kernel/resource.c                          |   2 +-
 lib/slub_kunit.c                           |   4 +
 mm/memcontrol.c                            |   2 +-
 mm/slab.h                                  | 145 +++++
 mm/slab_common.c                           |  21 +-
 mm/slub.c                                  | 641 +++++++++++++++++++--
 mm/usercopy.c                              |  12 +-
 security/Kconfig.hardening                 |  16 +
 19 files changed, 977 insertions(+), 79 deletions(-)

base-commit: 46a9ea6681907a3be6b6b0d43776dccc62cad6cf

Signature · 1 line
2.42.0.459.ge4e396fd5e-goog