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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Nov 10, 2022 at 04:44:59PM +0100, Vlastimil Babka wrote:
> On 11/10/22 13:57, Feng Tang wrote:
> > 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! 
> 
> Thanks, grabbing it including Andrey's review, with a small change below:
> 
> > - Feng
> > 
> > -----8>----
> > From b2a92f0c2518ef80fcda340f1ad37b418ee32d85 Mon Sep 17 00:00:00 2001
> > From: Feng Tang <feng.tang@xxxxxxxxx>
> > Date: Thu, 20 Oct 2022 20:47:31 +0800
> > Subject: [PATCH 1/3] mm/slub: only zero requested size of buffer for kzalloc
> >  when debug enabled
[...]
> > +	/*
> > +	 * 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) &&
> > +	    (s->flags & SLAB_RED_ZONE) &&
> 
> Combined the two above to:
> 
>   if (kmem_cache_debug_flags(s, SLAB_STORE_USER | SLAB_RED_ZONE)

Yes, this is cleaner, thanks!

- Feng




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux