Skip to contentSkip to conversation

mm/slub: initialize the free pointer of the bootstrap kmem_cache_node

PATCH Applied Karl Mehltretter 5 participants 6 messages Oct 10 – Oct 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slub: initialize the free pointer of the bootstrap kmem_cache_node

With slub_debug=FZPU, validating kmem_cache_node reports

BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a

and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.

early_kmem_cache_node_alloc() previously took this object from a freelist with an initialized pointer. It now takes it from the slab iterator and builds the freelist only for the remaining objects, leaving its pointer filled with POISON_INUSE.

Initialize the bootstrap object's free pointer to NULL.

Fixes dc795d4c0282 ("mm/slub: defer freelist construction until after bulk allocation from a new slab")
Assisted-by LLM

---
QEMU x86_64 and custom QEMU SH7785LCR model, slub_debug=FZPU:
validation reports "Freepointer corrupt" before the fix, clean after.

 mm/slub.c | 1 +
 1 file changed, 1 insertion(+)
mm/slub.c +1 -0
index 54ec125033571..9a20aa820bb0f 100644
@@ -7777,6 +7777,7 @@ static void early_kmem_cache_node_alloc(int node)
 
 	n = next_slab_obj(kmem_cache_node, &iter);
 	BUG_ON(!n);
+	set_freepointer(kmem_cache_node, n, NULL);
 
 	slab->inuse = 1;
 	build_slab_freelist(kmem_cache_node, slab, &iter);
Signature · 1 line
2.53.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Karl Mehltretter

With slub_debug=FZPU, validating kmem_cache_node reports

BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a

and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.

early_kmem_cache_node_alloc() previously took this object from a freelist with an initialized pointer. It now takes it from the slab iterator and builds the freelist only for the remaining objects, leaving its pointer filled with POISON_INUSE.

Quoted 6 lines

Initialize the bootstrap object's free pointer to NULL.

Fixes dc795d4c0282 ("mm/slub: defer freelist construction until after bulk allocation from a new slab")
Assisted-by LLM

---

Looks good to me,

Signature · 2 lines
Cheers,
Harry / Hyeonggon
maintainer Applied
#2 lore raw
In reply to Karl Mehltretter
Quoted 10 lines · Karl Mehltretter

With slub_debug=FZPU, validating kmem_cache_node reports

BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a

and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.

[...]

Applied to mm/slab.git slab/for-next, thanks!

[1/1] mm/slub: initialize the free pointer of the bootstrap kmem_cache_node

      commit: 10a5ff7555ae3042393d8a662a25dca9b38ea415

Note: I did not add Cc: stable because it only affects slab_debug users and requires writing to 'validate' field, which requires the root.

Signature · 2 lines
Cheers,
Harry / Hyeonggon
maintainer Reviewed-by on v1 1/1
#3 lore raw
In reply to Karl Mehltretter
Quoted 14 lines · Karl Mehltretter

With slub_debug=FZPU, validating kmem_cache_node reports

BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a

and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.

early_kmem_cache_node_alloc() previously took this object from a freelist with an initialized pointer. It now takes it from the slab iterator and builds the freelist only for the remaining objects, leaving its pointer filled with POISON_INUSE.

Quoted 5 lines

Initialize the bootstrap object's free pointer to NULL.

Fixes dc795d4c0282 ("mm/slub: defer freelist construction until after bulk allocation from a new slab")
Assisted-by LLM
Quoted 19 lines

---
QEMU x86_64 and custom QEMU SH7785LCR model, slub_debug=FZPU:
validation reports "Freepointer corrupt" before the fix, clean after.

 mm/slub.c | 1 +
 1 file changed, 1 insertion(+)
mm/slub.c +1 -0
index 54ec125033571..9a20aa820bb0f 100644
@@ -7777,6 +7777,7 @@ static void early_kmem_cache_node_alloc(int node)
 
 	n = next_slab_obj(kmem_cache_node, &iter);
 	BUG_ON(!n);
+	set_freepointer(kmem_cache_node, n, NULL);
 
 	slab->inuse = 1;
 	build_slab_freelist(kmem_cache_node, slab, &iter);
Reviewed-by on v1 1/1
#4 lore raw
In reply to Karl Mehltretter
Quoted 14 lines · [email protected] wrote:

With slub_debug=FZPU, validating kmem_cache_node reports

BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a

and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.

early_kmem_cache_node_alloc() previously took this object from a freelist with an initialized pointer. It now takes it from the slab iterator and builds the freelist only for the remaining objects, leaving its pointer filled with POISON_INUSE.

Quoted 5 lines

Initialize the bootstrap object's free pointer to NULL.

Fixes dc795d4c0282 ("mm/slub: defer freelist construction until after bulk allocation from a new slab")
Assisted-by LLM

Thanks for the patch, LGTM!

--
With Best Regards,
Shengming

Quoted 21 lines

---
QEMU x86_64 and custom QEMU SH7785LCR model, slub_debug=FZPU:
validation reports "Freepointer corrupt" before the fix, clean after.

 mm/slub.c | 1 +
 1 file changed, 1 insertion(+)
mm/slub.c +1 -0
index 54ec125033571..9a20aa820bb0f 100644
@@ -7777,6 +7777,7 @@ static void early_kmem_cache_node_alloc(int node)
 
     n = next_slab_obj(kmem_cache_node, &iter);
     BUG_ON(!n);
+    set_freepointer(kmem_cache_node, n, NULL);
 
     slab->inuse = 1;
     build_slab_freelist(kmem_cache_node, slab, &iter);
Signature · 1 line
2.53.0
reviewer Tested-by on v1 1/1
#5 lore raw
In reply to Karl Mehltretter
Quoted 14 lines · Karl Mehltretter

With slub_debug=FZPU, validating kmem_cache_node reports

BUG kmem_cache_node (Not tainted): Freepointer corrupt Object 0xffff888000140040 @offset=64 fp=0x5a5a5a5a5a5a5a5a

and taints the kernel. Poisoning places the bootstrap object's free pointer outside the object, where check_object() checks it even while allocated.

early_kmem_cache_node_alloc() previously took this object from a freelist with an initialized pointer. It now takes it from the slab iterator and builds the freelist only for the remaining objects, leaving its pointer filled with POISON_INUSE.

Quoted 5 lines

Initialize the bootstrap object's free pointer to NULL.

Fixes dc795d4c0282 ("mm/slub: defer freelist construction until after bulk allocation from a new slab")
Assisted-by LLM