public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Anatol Pomozov <anatol.pomozov@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Salman Qazi <sqazi@google.com>,
	Rusty Russell <rusty@rustcorp.com.au>
Subject: Re: [PATCH] module: Fix race condition between load and unload module
Date: Sun, 14 Apr 2013 04:35:39 +0100	[thread overview]
Message-ID: <20130414033539.GE4068@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CA+55aFzxxGBU3AOeNg3UEicHrx3nzWRyo5DOd=hh6SHJfYvB3g@mail.gmail.com>

On Fri, Apr 12, 2013 at 04:47:50PM -0700, Linus Torvalds wrote:
> This is a much more generic bug in kobjects, and I would hate to add
> some random workaround for just one case of this bug like you do. The
> more fundamental bug needs to be fixed too.
> 
> I think the more fundamental bugfix is to just fix kobject_get() to
> return NULL if the refcount was zero, because in that case the kobject
> no longer really exists.
> 
> So instead of having
> 
>     kref_get(&kobj->kref);
> 
> it should do
> 
>     if (!atomic_inc_not_zero(&kobj->kref.refcount))
>         kobj = NULL;
> 
> and I think that should fix your race automatically, no? Proper patch
> attached (but TOTALLY UNTESTED - it seems to compile, though).
> 
> The problem is that we lose the warning for when the refcount is zero
> and somebody does a kobject_get(), but that is ok *assuming* that
> people actually check the return value of kobject_get() rather than
> just "know" that if they passed in a non-NULL kobj, they'll get it
> right back.
> 
> Greg - please take a look... I'm adding Al to the discussion too,
> because Al just *loooves* these kinds of races ;)

Unless I'm misreading what's going on, we have the following to thank for that:
        /* remove from sysfs if the caller did not do it */
        if (kobj->state_in_sysfs) {
                pr_debug("kobject: '%s' (%p): auto cleanup kobject_del\n",
                         kobject_name(kobj), kobj);
                kobject_del(kobj);
        }
in kobject_cleanup().  Why don't we require kobject_del() before the final
kobject_put(), if the sucker had been added?  FWIW, I thought it *was*
required all along...

  parent reply	other threads:[~2013-04-14  3:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 22:32 [PATCH] module: Fix race condition between load and unload module Anatol Pomozov
2013-04-12 23:47 ` Linus Torvalds
2013-04-12 23:53   ` Greg Kroah-Hartman
2013-04-13  0:04     ` Anatol Pomozov
2013-04-13  0:11     ` Linus Torvalds
2013-04-13  0:48       ` Anatol Pomozov
2013-04-13 15:41   ` Anatol Pomozov
2013-04-13 17:53     ` Linus Torvalds
2013-04-13 21:10       ` Anatol Pomozov
2013-04-14  3:35   ` Al Viro [this message]
2013-04-14  4:42     ` Anatol Pomozov
2013-04-14  4:56       ` Al Viro

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=20130414033539.GE4068@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=anatol.pomozov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rusty@rustcorp.com.au \
    --cc=sqazi@google.com \
    --cc=torvalds@linux-foundation.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