Re: [PATCH slab/for-next-fixes v3 4/4] mm/slab: prevent unbounded recursion in free path with new kmalloc type
From: Vlastimil Babka (SUSE)
Date: Tue Jul 14 2026 - 11:33:58 EST
On 7/13/26 16:28, Harry Yoo (Oracle) wrote:
> @@ -2168,14 +2132,20 @@ int alloc_slab_obj_exts(struct slab *slab, struct kmem_cache *s,
> unsigned long new_exts;
> unsigned long old_exts;
> struct slabobj_ext *vec;
> - size_t sz;
> + size_t sz = sizeof(struct slabobj_ext) * slab->objects;
>
> gfp &= ~OBJCGS_CLEAR_MASK;
> - /* Prevent recursive extension vector allocation */
> - alloc_flags |= SLAB_ALLOC_NO_RECURSE;
> - alloc_flags &= ~SLAB_ALLOC_NEW_SLAB;
> + /*
> + * In most cases, obj_exts arrays are allocated from normal kmalloc.
> + * However, normal kmalloc caches must allocate them from
> + * KMALLOC_NO_OBJ_EXT caches to prevent recursion.
> + */
> + if (is_kmalloc_normal(s)) {
> + VM_WARN_ON_ONCE(!need_kmalloc_no_objext());
As discussed off-list, this can false positively trigger due to a race with
shutdown_mem_profiling() so I'll remove it.
> + alloc_flags |= SLAB_ALLOC_NO_OBJ_EXT;
> + }
>
> - sz = obj_exts_alloc_size(s, slab, gfp);
> + alloc_flags &= ~SLAB_ALLOC_NEW_SLAB;
>
> /* This will use kmalloc_nolock() if alloc_flags say so */
> vec = kmalloc_flags(sz, gfp | __GFP_ZERO, alloc_flags, slab_nid(slab));