Re: [PATCH v7 1/3] mm/slub: only zero requested size of buffer for kzalloc when debug enabled

From: Feng Tang
Date: Thu Nov 10 2022 - 08:00:54 EST


On Thu, Nov 10, 2022 at 11:20:34AM +0800, Tang, Feng wrote:
> On Wed, Nov 09, 2022 at 03:28:19PM +0100, Vlastimil Babka wrote:
[...]
> > > + /*
> > > + * 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.
> > > + */
> > > + if (kmem_cache_debug_flags(s, SLAB_STORE_USER) &&
> >
> > Shouldn't we check SLAB_RED_ZONE instead? Otherwise a debugging could be
> > specified so that SLAB_RED_ZONE is set but SLAB_STORE_USER?
>
> Thanks for the catch!
>
> I will add check for SLAB_RED_ZONE. The SLAB_STORE_USER is for
> checking whether 'orig_size' field exists. In earlier discussion,
> we make 'orig_size' depend on STORE_USER, https://lore.kernel.org/lkml/1b0fa66c-f855-1c00-e024-b2b823b18678@xxxxxxx/

Below is the updated patch, please review, thanks!

- Feng

-----8>----