linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Christoph Lameter <cl@linux.com>
Cc: Sasha Levin <levinsasha928@gmail.com>,
	Dave Jones <davej@redhat.com>, davem <davem@davemloft.net>,
	Pekka Enberg <penberg@kernel.org>, Matt Mackall <mpm@selenic.com>,
	kaber@trash.net, pablo@netfilter.org,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	netfilter-devel@vger.kernel.org, netdev <netdev@vger.kernel.org>
Subject: Re: Hung task when calling clone() due to netfilter/slab
Date: Tue, 17 Jan 2012 16:20:30 +0100	[thread overview]
Message-ID: <1326813630.2259.19.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> (raw)
In-Reply-To: <alpine.DEB.2.00.1201170910130.4800@router.home>

Le mardi 17 janvier 2012 à 09:12 -0600, Christoph Lameter a écrit :
> On Sun, 15 Jan 2012, Eric Dumazet wrote:
> 
> > As soon as the slub_lock is released, another thread can come and find
> > the new kmem_cache.
> 
> Slabs are not looked up by name. A pointer to kmem_cache is passed to slab
> functions and that pointer is returned from kmem_cache_create(). The risk
> is someone traversing the kmem_cach list which is only done from within slub.
> 
> 
> Subject: slub: Do not hold slub_lock when calling sysfs_slab_add()
> 
> sysfs_slab_add() calls various sysfs functions that actually may
> end up in userspace doing all sorts of things.
> 
> Release the slub_lock after adding the kmem_cache structure to the list.
> At that point the address of the kmem_cache is not known so we are
> guaranteed exlusive access to the following modifications to the
> kmem_cache structure.
> 
> If the sysfs_slab_add fails then reacquire the slub_lock to
> remove the kmem_cache structure from the list.
> 
> Signed-off-by: Christoph Lameter <cl@linux.com>
> 
> ---
>  mm/slub.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Index: linux-2.6/mm/slub.c
> ===================================================================
> --- linux-2.6.orig/mm/slub.c	2012-01-17 03:07:11.140010438 -0600
> +++ linux-2.6/mm/slub.c	2012-01-17 03:07:19.532010264 -0600
> @@ -3929,13 +3929,15 @@ struct kmem_cache *kmem_cache_create(con
>  		if (kmem_cache_open(s, n,
>  				size, align, flags, ctor)) {
>  			list_add(&s->list, &slab_caches);
> +			up_write(&slub_lock);
>  			if (sysfs_slab_add(s)) {
> +				down_write(&slub_lock);
>  				list_del(&s->list);
> +				up_write(&slub_lock);
>  				kfree(n);
>  				kfree(s);
>  				goto err;
>  			}
> -			up_write(&slub_lock);
>  			return s;
>  		}
>  		kfree(n);



Buggy patch, since "goto err;" is going to up_write(&slub_lock) again.

Also Christoph, you forgot to add the very much needed :

Reported-by: Sasha Levin <levinsasha928@gmail.com>




  reply	other threads:[~2012-01-17 15:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-14 16:30 Hung task when calling clone() due to netfilter/slab Sasha Levin
2012-01-14 17:10 ` Eric Dumazet
2012-01-14 17:18   ` Eric Dumazet
2012-01-15 12:59   ` Sasha Levin
2012-01-15 17:25     ` Eric Dumazet
2012-01-17 15:12       ` Christoph Lameter
2012-01-17 15:20         ` Eric Dumazet [this message]
2012-01-17 15:27           ` Christoph Lameter
2012-01-17 15:30             ` Eric Dumazet
2012-01-17 16:04               ` Christoph Lameter
2012-01-17 22:22                 ` Christoph Lameter
2012-01-19 21:43                   ` Eric W. Biederman
2012-01-19 22:15                     ` Eric W. Biederman
2012-01-20  2:03                       ` Christoph Lameter
2012-01-20  2:31                         ` Eric W. Biederman
2012-01-20 14:49                           ` Christoph Lameter
2012-01-20 20:40                             ` Eric W. Biederman
2012-02-01  8:05                             ` Pekka Enberg
2012-02-01 17:32                               ` Eric W. Biederman
2012-02-01  8:07               ` Pekka Enberg

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=1326813630.2259.19.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC \
    --to=eric.dumazet@gmail.com \
    --cc=cl@linux.com \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=kaber@trash.net \
    --cc=levinsasha928@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mpm@selenic.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=penberg@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).