]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
slab: validate slab before using it in alloc_single_from_partial()
authorVlastimil Babka <vbabka@suse.cz>
Mon, 15 Sep 2025 13:55:12 +0000 (15:55 +0200)
committerVlastimil Babka <vbabka@suse.cz>
Mon, 15 Sep 2025 14:47:36 +0000 (16:47 +0200)
commita21fe7b010e32c51c62a86dcba02f9404ed77cac
treeb9467a021d7ca066352aea73b8bb1af16f176308
parent40522db59b5bd36dd63d215bfb7fa83d64bce05a
slab: validate slab before using it in alloc_single_from_partial()

We touch slab->freelist and slab->inuse before checking the slab pointer
is actually sane. Do that validation first, which will be safer. We can
thus also remove the check from alloc_debug_processing().

This adds a new "s->flags & SLAB_CONSISTENCY_CHECKS" test but
alloc_single_from_partial() is only called for caches with debugging
enabled so it's acceptable.

In alloc_single_from_new_slab() we just created the struct slab and call
alloc_debug_processing() to mainly set up redzones, tracking etc, while
not really expecting the consistency checks to fail. Thus don't validate
it there.

Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
mm/slub.c