Re: [PATCH for-next v3 3/7] mm/slab: handle SLAB_FREE_NOLOCK in slab_free_hook() instead of open coding
From: sashiko-bot
Date: Mon Nov 16 2026 - 03:26:42 EST
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] mm/slab: kfree_nolock() leaves KASAN free_meta in init_on_free
objects
--
commit f5f03c7c446bcbe50fa191f0cf60accc8ad01ac9
Author: Harry Yoo (Meta) <harry@xxxxxxxxxx>
mm/slab: handle SLAB_FREE_NOLOCK in slab_free_hook() instead of open coding
This commit moves SLAB_FREE_NOLOCK handling into slab_free_hook() and replaces
the open-coded free hooks in kfree_nolock() with a call to slab_free_hook(),
enabling SLAB_FREE_INIT when slab_want_init_on_free() is true.
> diff --git a/mm/slub.c b/mm/slub.c
> index 761dc2affea27..7c0adc1049880 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
[ ... ]
> @@ -2775,8 +2790,11 @@ bool slab_free_hook(struct kmem_cache *s, void *x, unsigned int free_flags)
> set_orig_size(s, x, orig_size);
>
> }
> - /* KASAN might put x into memory quarantine, delaying its reuse. */
> - return !kasan_slab_free(s, x, init, still_accessible, false);
> + /*
> + * KASAN might put x into memory quarantine, delaying its reuse.
> + * Skip quarantine when spinning is not allowed as it uses a spinlock.
> + */
> + return !kasan_slab_free(s, x, init, still_accessible, !allow_spin);
> }
[ ... ]
> @@ -6949,33 +6968,12 @@ void kfree_nolock(const void *object)
>
> memcg_slab_free_hook(s, slab, &x, 1);
> alloc_tagging_slab_free_hook(s, slab, &x, 1);
[ ... ]
> +
> + if (slab_want_init_on_free(s))
> + free_flags |= SLAB_FREE_INIT;
> +
> + if (unlikely(!slab_free_hook(s, x, free_flags)))
> return;
[Severity: Low]
When CONFIG_KASAN_GENERIC and init_on_free are enabled, does kfree_nolock()
leave non-zero KASAN free_meta in the object after slab_free_hook() zeroes it?
After slab_free_hook() zeroes the object for SLAB_FREE_INIT, it calls
kasan_slab_free() with no_quarantine set to true (!allow_spin):
mm/kasan/common.c:__kasan_slab_free() {
...
poison_slab_object(cache, object, init);
if (no_quarantine)
return false;
...
}
In Generic KASAN, poison_slab_object() -> kasan_save_free_info() writes
struct kasan_free_meta at offset 0 of the object when free_meta_offset == 0.
Normal frees clear this in-object metadata upon quarantine eviction in
qlink_free(), but returning early for no_quarantine skips quarantine and
never zeroes free_meta before the object is reused.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261115-kmalloc-nolock-fixes-v3-0-9034dd4ecaab@xxxxxxxxxx?part=3