linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Wang Hai <wanghai38@huawei.com>,
	torvalds@linux-foundation.org, cl@linux.com, penberg@kernel.org,
	rientjes@google.com, iamjoonsoo.kim@lge.com,
	akpm@linux-foundation.org
Cc: asmadeus@codewreck.org, davem@davemloft.net, ericvh@gmail.com,
	kuba@kernel.org, lucho@ionkov.net, netdev@vger.kernel.org,
	syzkaller-bugs@googlegroups.com,
	v9fs-developer@lists.sourceforge.net, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org,
	syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com
Subject: Re: [PATCH] Revert "mm/slub: fix a memory leak in sysfs_slab_add()"
Date: Thu, 28 Jan 2021 13:03:53 +0100	[thread overview]
Message-ID: <1f4afc98-f5de-3992-1f49-f041d3783ea2@suse.cz> (raw)
In-Reply-To: <20210128113250.60078-1-wanghai38@huawei.com>

On 1/28/21 12:32 PM, Wang Hai wrote:
> This reverts commit dde3c6b72a16c2db826f54b2d49bdea26c3534a2.
> 
> syzbot report a double-free bug. The following case can cause this bug.
>  - 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)
> 		-> sysfs_create_group() .. fails ..
> 		-> kobject_del(&s->kobj); .. which frees s ...
> 
> We can't remove the kmem_cache_free() in create_cache(), because
> other error cases of __kmem_cache_create() do not free this.
> 
> So, revert the commit dde3c6b72a16 ("mm/slub: fix a memory leak in
> sysfs_slab_add()") to fix this.
> 
> Reported-by: syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com
> Fixes: dde3c6b72a16 ("mm/slub: fix a memory leak in sysfs_slab_add()")
> Signed-off-by: Wang Hai <wanghai38@huawei.com>

Cc: <stable@vger.kernel.org>
Acked-by: Vlastimil Babka <vbabka@suse.cz>

Double-free is worse than a rare small memory leak. Which would still be nice to
fix, but I'm afraid it will be more complicated, so start with preventing the
worse issue, including stable.

> ---
>  mm/slub.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index 69742ab9a21d..7ecbbbe5bc0c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -5625,10 +5625,8 @@ static int sysfs_slab_add(struct kmem_cache *s)
>  
>  	s->kobj.kset = kset;
>  	err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
> -	if (err) {
> -		kobject_put(&s->kobj);
> +	if (err)
>  		goto out;
> -	}
>  
>  	err = sysfs_create_group(&s->kobj, &slab_attr_group);
>  	if (err)
> 



      reply	other threads:[~2021-01-28 12:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 11:32 Wang Hai
2021-01-28 12:03 ` Vlastimil Babka [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f4afc98-f5de-3992-1f49-f041d3783ea2@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=asmadeus@codewreck.org \
    --cc=cl@linux.com \
    --cc=davem@davemloft.net \
    --cc=ericvh@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lucho@ionkov.net \
    --cc=netdev@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=rientjes@google.com \
    --cc=syzbot+d0bd96b4696c1ef67991@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=torvalds@linux-foundation.org \
    --cc=v9fs-developer@lists.sourceforge.net \
    --cc=wanghai38@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox