Skip to content

Commit 8dafa9f

Browse files
hygoniVlastimil Babka (SUSE)
authored andcommitted
mm/slab: fix an incorrect check in obj_exts_alloc_size()
obj_exts_alloc_size() prevents recursive allocation of slabobj_ext array from the same cache, to avoid creating slabs that are never freed. There is one mistake that returns the original size when memory allocation profiling is disabled. The assumption was that memcg-triggered slabobj_ext allocation is always served from KMALLOC_CGROUP type. But this is wrong [1]: when the caller specifies both __GFP_RECLAIMABLE and __GFP_ACCOUNT with SLUB_TINY enabled, the allocation is served from normal kmalloc. This is because kmalloc_type() prioritizes __GFP_RECLAIMABLE over __GFP_ACCOUNT, and SLUB_TINY aliases KMALLOC_RECLAIM with KMALLOC_NORMAL. As a result, the recursion guard is bypassed and the problematic slabs can be created. Fix this by removing the mem_alloc_profiling_enabled() check entirely. The remaining is_kmalloc_normal() check is still sufficient to detect whether the cache is of KMALLOC_NORMAL type and avoid bumping the size if it's not. Without SLUB_TINY, no functional change intended. With SLUB_TINY, allocations with __GFP_ACCOUNT|__GFP_RECLAIMABLE now allocate a larger array if the sizes equal. Reported-by: Zw Tang <shicenci@gmail.com> Fixes: 280ea9c ("mm/slab: avoid allocating slabobj_ext array from its own slab") Closes: https://lore.kernel.org/linux-mm/CAPHJ_VKuMKSke8b11AZQw1PTSFN4n2C0gFxC6xGOG0ZLHgPmnA@mail.gmail.com [1] Cc: stable@vger.kernel.org Signed-off-by: Harry Yoo <harry.yoo@oracle.com> Link: https://patch.msgid.link/20260309072219.22653-1-harry.yoo@oracle.com Tested-by: Zw Tang <shicenci@gmail.com> Signed-off-by: Vlastimil Babka (SUSE) <vbabka@kernel.org>
1 parent 6432f15 commit 8dafa9f

1 file changed

Lines changed: 0 additions & 7 deletions

File tree

mm/slub.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,13 +2119,6 @@ static inline size_t obj_exts_alloc_size(struct kmem_cache *s,
21192119
size_t sz = sizeof(struct slabobj_ext) * slab->objects;
21202120
struct kmem_cache *obj_exts_cache;
21212121

2122-
/*
2123-
* slabobj_ext array for KMALLOC_CGROUP allocations
2124-
* are served from KMALLOC_NORMAL caches.
2125-
*/
2126-
if (!mem_alloc_profiling_enabled())
2127-
return sz;
2128-
21292122
if (sz > KMALLOC_MAX_CACHE_SIZE)
21302123
return sz;
21312124

0 commit comments

Comments
 (0)