linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: KASAN: invalid-free in p9_client_create (2)
       [not found] <000000000000672eda05b9e291ff@google.com>
@ 2021-01-27 19:31 ` Linus Torvalds
  2021-01-28 11:39   ` wanghai (M)
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Torvalds @ 2021-01-27 19:31 UTC (permalink / raw)
  To: syzbot, Pekka Enberg, David Rientjes, Joonsoo Kim, Andrew Morton
  Cc: Dominique Martinet, David Miller, ericvh, Jakub Kicinski,
	Linux Kernel Mailing List, lucho, Netdev, syzkaller-bugs,
	v9fs-developer, wanghai38, Linux-MM

[ Participants list changed - syzbot thought this was networking and
p9, but it really looks entirely like a slub internal bug. I left the
innocent people on the list just to let them know they are innocent ]

On Wed, Jan 27, 2021 at 6:27 AM syzbot
<syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com> wrote:
>
> The issue was bisected to:
>
> commit dde3c6b72a16c2db826f54b2d49bdea26c3534a2
> Author: Wang Hai <wanghai38@huawei.com>
> Date:   Wed Jun 3 22:56:21 2020 +0000
>
>     mm/slub: fix a memory leak in sysfs_slab_add()
>
> BUG: KASAN: double-free or invalid-free in slab_free mm/slub.c:3142 [inline]
> BUG: KASAN: double-free or invalid-free in kmem_cache_free+0x82/0x350 mm/slub.c:3158

The p9 part of this bug report seems to be a red herring.

The problem looks like it's simply the kmem_cache failure case, ie:

 - mm/slab_common.c: create_cache(): if the __kmem_cache_create()
fails, it does:

        out_free_cache:
                kmem_cache_free(kmem_cache, s);

 - but __kmem_cache_create() - at least for slub() - will have done

        sysfs_slab_add(s) .. fails ..
            -> kobject_del(&s->kobj); .. which frees s ...

so the networking and p9 are fine, and the only reason p9 shows up in
the trace is that apparently it causes that failure in
kobject_init_and_add() for whatever reason, and that then exposes the
problem.

So the added kobject_put() really looks buggy in this situation, and
the memory leak that that commit dde3c6b72a16 ("mm/slub: fix a memory
leak in sysfs_slab_add()") fixes is now a double free.

And no, I don't think you can just remove the kmem_cache_free() in
create_cache(), because _other_ error cases of __kmem_cache_create()
do not free this.

Wang Hai - comments? I'm inclined to revert that commit for now unless
somebody can come up with a proper fix..

              Linus


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: KASAN: invalid-free in p9_client_create (2)
  2021-01-27 19:31 ` KASAN: invalid-free in p9_client_create (2) Linus Torvalds
@ 2021-01-28 11:39   ` wanghai (M)
  0 siblings, 0 replies; 2+ messages in thread
From: wanghai (M) @ 2021-01-28 11:39 UTC (permalink / raw)
  To: Linus Torvalds, syzbot, Pekka Enberg, David Rientjes,
	Joonsoo Kim, Andrew Morton
  Cc: Dominique Martinet, David Miller, ericvh, Jakub Kicinski,
	Linux Kernel Mailing List, lucho, Netdev, syzkaller-bugs,
	v9fs-developer, Linux-MM


在 2021/1/28 3:31, Linus Torvalds 写道:
> [ Participants list changed - syzbot thought this was networking and
> p9, but it really looks entirely like a slub internal bug. I left the
> innocent people on the list just to let them know they are innocent ]
>
> On Wed, Jan 27, 2021 at 6:27 AM syzbot
> <syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com> wrote:
>> The issue was bisected to:
>>
>> commit dde3c6b72a16c2db826f54b2d49bdea26c3534a2
>> Author: Wang Hai <wanghai38@huawei.com>
>> Date:   Wed Jun 3 22:56:21 2020 +0000
>>
>>      mm/slub: fix a memory leak in sysfs_slab_add()
>>
>> BUG: KASAN: double-free or invalid-free in slab_free mm/slub.c:3142 [inline]
>> BUG: KASAN: double-free or invalid-free in kmem_cache_free+0x82/0x350 mm/slub.c:3158
> The p9 part of this bug report seems to be a red herring.
>
> The problem looks like it's simply the kmem_cache failure case, ie:
>
>   - mm/slab_common.c: create_cache(): if the __kmem_cache_create()
> fails, it does:
>
>          out_free_cache:
>                  kmem_cache_free(kmem_cache, s);
>
>   - but __kmem_cache_create() - at least for slub() - will have done
>
>          sysfs_slab_add(s) .. fails ..
>              -> kobject_del(&s->kobj); .. which frees s ...
>
> so the networking and p9 are fine, and the only reason p9 shows up in
> the trace is that apparently it causes that failure in
> kobject_init_and_add() for whatever reason, and that then exposes the
> problem.
>
> So the added kobject_put() really looks buggy in this situation, and
> the memory leak that that commit dde3c6b72a16 ("mm/slub: fix a memory
> leak in sysfs_slab_add()") fixes is now a double free.
>
> And no, I don't think you can just remove the kmem_cache_free() in
> create_cache(), because _other_ error cases of __kmem_cache_create()
> do not free this.
>
> Wang Hai - comments? I'm inclined to revert that commit for now unless
> somebody can come up with a proper fix..
>
>                Linus
> .
Hi, Linus.
I'm sorry for introducing this bug, and I agree to revert it.
I've just sent the revert patch.
https://lore.kernel.org/patchwork/patch/1372475/

Thanks,
Wang Hai


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-28 11:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <000000000000672eda05b9e291ff@google.com>
2021-01-27 19:31 ` KASAN: invalid-free in p9_client_create (2) Linus Torvalds
2021-01-28 11:39   ` wanghai (M)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox