On 6/11/26 12:40 AM, Vlastimil Babka (SUSE) wrote: > When init (zeroing) on allocation is requested, for kmalloc() we > generally have to zero the full object size even if a smaller size is > requested, in order to provide krealloc()'s __GFP_ZERO guarantees. > > But if we track the requested size, krealloc() uses that information to > do the right thing. With red zoning also enabled, any unused size > became part of the red zone, so it must not be zeroed. > > However the check is imprecise, and will trigger also when only > SLAB_RED_ZONE is enabled without SLAB_STORE_USER. This means enabling > red zoning alone can compromise krealloc()'s __GFP_ZERO contract. > > Fix this by using slub_debug_orig_size() instead, which is the exact > check for whether the requested size is tracked. We don't need to care > if red zoning is also enabled or not. Also update and expand the > comment accordingly. > > Fixes: 9ce67395f5a0 ("mm/slub: only zero requested size of buffer for kzalloc when debug enabled") > Cc: > Signed-off-by: Vlastimil Babka (SUSE) > --- Reviewed-by: Harry Yoo (Oracle) -- Cheers, Harry / Hyeonggon