FAILED: patch "[PATCH] mm/slab: do not limit zeroing to orig_size when only red" failed to apply to 6.6-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 648927ceb84021a25a0fbd5673740956f318d534
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026071403-afar-policy-60a2@gregkh' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 648927ceb84021a25a0fbd5673740956f318d534 Mon Sep 17 00:00:00 2001
From: "Vlastimil Babka (SUSE)" <[email protected]>
Date: Wed, 10 Jun 2026 17:40:03 +0200
Subject: [PATCH] mm/slab: do not limit zeroing to orig_size when only red
zoning is enabled
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, so we can zero only the requested size. With red zoning also enabled, any extra size became part of the red zone, so it must not be zeroed and thus we must zero only the requested size.
However the current check is imprecise, and will trigger also when only SLAB_RED_ZONE is enabled without SLAB_STORE_USER (which enables tracking the requested size). 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.
mm/slub.c +10 -8
@@ -4574,15 +4574,17 @@ bool slab_post_alloc_hook(struct kmem_cache *s, struct list_lru *lru,gfp_t init_flags = flags & gfp_allowed_mask;/* -* For kmalloc object, the allocated memory size(object_size) is likely -* larger than the requested size(orig_size). If redzone check is -* enabled for the extra space, don't zero it, as it will be redzoned -* soon. The redzone operation for this extra space could be seen as a -* replacement of current poisoning under certain debug option, and -* won't break other sanity checks. +* For kmalloc object, the allocated size (object_size) can be larger +* than the requested size (orig_size). We however need to zero the +* whole object_size to handle possible later krealloc() with +*__GFP_ZERO properly. +* +* But if we keep track of the requested size, krealloc() uses that +* information. Additionally if red zoning is enabled, the extra space +* is also red zone, so we should not overwrite it. So limit zeroing to +* orig_size if we track it. */ -if (kmem_cache_debug_flags (s,SLAB_STORE_USER |SLAB_RED_ZONE ) && - (s->flags &SLAB_KMALLOC )) +if (slub_debug_orig_size (s)) zero_size = orig_size;/*
Sasha Levin
maintainerPATCH 1/1 mm/slab: do not limit zeroing to orig_size when only red zoning is enabled
From: "Vlastimil Babka (SUSE)" <[email protected]>
[ Upstream commit 648927ceb84021a25a0fbd5673740956f318d534 ]
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, so we can zero only the requested size. With red zoning also enabled, any extra size became part of the red zone, so it must not be zeroed and thus we must zero only the requested size.
However the current check is imprecise, and will trigger also when only SLAB_RED_ZONE is enabled without SLAB_STORE_USER (which enables tracking the requested size). 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.
--- mm/slab.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
mm/slab.h +10 -7
@@ -734,14 +734,17 @@ static inline void slab_post_alloc_hook(struct kmem_cache *s, flags &= gfp_allowed_mask;/* -* For kmalloc object, the allocated memory size(object_size) is likely -* larger than the requested size(orig_size). If redzone check is -* enabled for the extra space, don't zero it, as it will be redzoned -* soon. The redzone operation for this extra space could be seen as a -* replacement of current poisoning under certain debug option, and -* won't break other sanity checks. +* For kmalloc object, the allocated size (object_size) can be larger +* than the requested size (orig_size). We however need to zero the +* whole object_size to handle possible later krealloc() with +*__GFP_ZERO properly. +* +* But if we keep track of the requested size, krealloc() uses that +* information. Additionally if red zoning is enabled, the extra space +* is also red zone, so we should not overwrite it. So limit zeroing to +* orig_size if we track it. */ -if (kmem_cache_debug_flags (s,SLAB_STORE_USER |SLAB_RED_ZONE ) && +if (kmem_cache_debug_flags (s,SLAB_STORE_USER ) && (s->flags &SLAB_KMALLOC )) zero_size = orig_size;
Signature · 1 line
2.53.0