lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 2 Aug 2022 09:59:00 +0200
From:   Dmitry Vyukov <dvyukov@...gle.com>
To:     Feng Tang <feng.tang@...el.com>
Cc:     Vlastimil Babka <vbabka@...e.cz>,
        "Sang, Oliver" <oliver.sang@...el.com>, lkp <lkp@...el.com>,
        LKML <linux-kernel@...r.kernel.org>,
        "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "lkp@...ts.01.org" <lkp@...ts.01.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Christoph Lameter <cl@...ux.com>,
        Pekka Enberg <penberg@...nel.org>,
        David Rientjes <rientjes@...gle.com>,
        Joonsoo Kim <iamjoonsoo.kim@....com>,
        Roman Gushchin <roman.gushchin@...ux.dev>,
        Hyeonggon Yoo <42.hyeyoo@...il.com>,
        "Hansen, Dave" <dave.hansen@...el.com>,
        Robin Murphy <robin.murphy@....com>,
        John Garry <john.garry@...wei.com>,
        Kefeng Wang <wangkefeng.wang@...wei.com>,
        Andrey Konovalov <andreyknvl@...il.com>,
        Andrey Ryabinin <ryabinin.a.a@...il.com>,
        Alexander Potapenko <glider@...gle.com>,
        "kasan-dev@...glegroups.com" <kasan-dev@...glegroups.com>
Subject: Re: [mm/slub] 3616799128: BUG_kmalloc-#(Not_tainted):kmalloc_Redzone_overwritten

On Tue, 2 Aug 2022 at 09:47, Feng Tang <feng.tang@...el.com> wrote:
> > > On Mon, Aug 01, 2022 at 10:23:23PM +0800, Vlastimil Babka wrote:
> > > > On 8/1/22 08:21, Feng Tang wrote:
> > > [snip]
> > > > > Cc kansan  mail list.
> > > > >
> > > > > This is really related with KASAN debug, that in free path, some
> > > > > kmalloc redzone ([orig_size+1, object_size]) area is written by
> > > > > kasan to save free meta info.
> > > > >
> > > > > The callstack is:
> > > > >
> > > > >   kfree
> > > > >     slab_free
> > > > >       slab_free_freelist_hook
> > > > >           slab_free_hook
> > > > >             __kasan_slab_free
> > > > >               ____kasan_slab_free
> > > > >                 kasan_set_free_info
> > > > >                   kasan_set_track
> > > > >
> > > > > And this issue only happens with "kmalloc-16" slab. Kasan has 2
> > > > > tracks: alloc_track and free_track, for x86_64 test platform, most
> > > > > of the slabs will reserve space for alloc_track, and reuse the
> > > > > 'object' area for free_track.  The kasan free_track is 16 bytes
> > > > > large, that it will occupy the whole 'kmalloc-16's object area,
> > > > > so when kmalloc-redzone is enabled by this patch, the 'overwritten'
> > > > > error is triggered.
> > > > >
> > > > > But it won't hurt other kmalloc slabs, as kasan's free meta won't
> > > > > conflict with kmalloc-redzone which stay in the latter part of
> > > > > kmalloc area.
> > > > >
> > > > > So the solution I can think of is:
> > > > > * skip the kmalloc-redzone for kmalloc-16 only, or
> > > > > * skip kmalloc-redzone if kasan is enabled, or
> > > > > * let kasan reserve the free meta (16 bytes) outside of object
> > > > >   just like for alloc meta
> > > >
> > > > Maybe we could add some hack that if both kasan and SLAB_STORE_USER is
> > > > enabled, we bump the stored orig_size from <16 to 16? Similar to what
> > > > __ksize() does.
> > >
> > > How about the following patch:
> > >
> > > ---
> > > diff --git a/mm/slub.c b/mm/slub.c
> > > index added2653bb0..33bbac2afaef 100644
> > > --- a/mm/slub.c
> > > +++ b/mm/slub.c
> > > @@ -830,6 +830,16 @@ static inline void set_orig_size(struct kmem_cache *s,
> > >         if (!slub_debug_orig_size(s))
> > >                 return;
> > >
> > > +#ifdef CONFIG_KASAN
> > > +       /*
> > > +        * When kasan is enabled, it could save its free meta data in the
> > > +        * start part of object area, so skip the kmalloc redzone check
> > > +        * for small kmalloc slabs to avoid the data conflict.
> > > +        */
> > > +       if (s->object_size <= 32)
> > > +               orig_size = s->object_size;
> > > +#endif

I think this can be done only when CONFIG_KASAN_GENERIC.
Only CONFIG_KASAN_GENERIC stores free meta info in objects:
https://elixir.bootlin.com/linux/latest/source/mm/kasan/common.c#L176

And KASAN_HW_TAGS has chances of being enabled with DEBUG_SLUB in
real-world uses (with Arm MTE).


> > > +
> > >         p += get_info_end(s);
> > >         p += sizeof(struct track) * 2;
> > >
> > > I extend the size to 32 for potential's kasan meta data size increase.
> > > This is tested locally, if people are OK with it, I can ask for 0Day's
> > > help to verify this.
> >
> > Where is set_orig_size() function defined? Don't see it upstream nor
> > in linux-next.
> > This looks fine but my only concern is that this should not increase
> > memory consumption when slub debug tracking is not enabled, which
> > should be the main operation mode when KASAN is enabled. But I can't
> > figure this out w/o context.
>
> Yes, the patchset was only posted on LKML, and not in any tree now.
> The link to the original patches is:
>
> https://lore.kernel.org/lkml/20220727071042.8796-1-feng.tang@intel.com/t/

Lots of code...

This SLAB_STORE_USER seems to be set on all kmalloc slabs by default
when CONFIG_SLUB_DEBUG is enabled, right?
And KASAN enables CONFIG_SLUB_DEBUG, this means that this is stored
always when KASAN is enabled? Looks wrong.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ