linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Mikulas Patocka <mpatocka@redhat.com>
Cc: Jeff Mahoney <jeffm@suse.com>,
	torvalds@linux-foundation.org, linux-kernel@vger.kernel.org,
	dm-devel@redhat.com, tglx@linutronix.de,
	paulmck@linux.vnet.ibm.com, mingo@kernel.org
Subject: Re: [PATCH] kobject: provide kobject_put_wait to fix module unload race
Date: Sun, 5 Jan 2014 14:23:56 -0800	[thread overview]
Message-ID: <20140105222356.GA22084@kroah.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1401051655430.18406@file01.intranet.prod.int.rdu2.redhat.com>

On Sun, Jan 05, 2014 at 05:04:31PM -0500, Mikulas Patocka wrote:
> 
> 
> On Sat, 4 Jan 2014, Greg Kroah-Hartman wrote:
> 
> > On Sat, Jan 04, 2014 at 03:35:39PM -0500, Mikulas Patocka wrote:
> > > 
> > > 
> > > On Sat, 4 Jan 2014, Greg Kroah-Hartman wrote:
> > > 
> > > > On Sat, Jan 04, 2014 at 01:06:01PM -0500, Mikulas Patocka wrote:
> > > > > Hi
> > > > > 
> > > > > I noticed that Jeff Mahoney added a new structure kobj_completion, defined 
> > > > > in include/linux/kobj_completion.h to the kernel 3.13-rc1 in the patch 
> > > > > eee031649707db3c9920d9498f8d03819b74fc23. In the current upstream kernel, 
> > > > > this interface is still unused.
> > > > 
> > > > There are pending btrfs patches to use this interface.
> > > > 
> > > > > However, converting the drivers to use kobj_completion is not trivial 
> > > > > (note that all users of the original kobject interface are buggy - so all 
> > > > > of them need to be converted).
> > > > 
> > > > Wait, what?  How are "all users" buggy?  Please explain this in detail.
> > > 
> > > 1) some code takes a reference to a kobject
> > > 2) the user unloads the device
> > > 3) the device driver unload routine calls kobject_put (but there is still 
> > >    reference, so the kobject is not destroyed)
> > 
> > A driver should never be messing around with "raw" kobjects, they should
> > be using a 'struct device' which is created/managed by the subsystem
> > they belong to.  See Dmitry's example of input and serio as ways to do
> > this, also USB and PCI do this properly.
> > 
> > Perhaps your sybsystem isn't doing this properly?  What code do you have
> > that creates raw kobjects and has this problem?
> > 
> > thanks,
> > 
> > greg k-h
> 
> So, are you saying that a module shouldn't ever be able to create a 
> kobject type?
> 
> Do "grep -rw kobj_type drivers/ fs/* net/bridge/" to see how much code 
> uses kobjects. There are 77 line. Majority of them may be compiled as 
> modules.
> 
> What do you want to do with all those kobject users? Hide them behind 
> another interface that doesn't exists yet?

Most of them should be using the driver/device interface to sysfs (the
drivers/* files, with the exception of the driver core code).  I'll look
at the others later.

And note, as module unloading can only happen by the root user, and
never happens "automatically", this is an issue, but a very minor one,
and can usually be solved by having a central "place" that handles the
kobject lifetimes.

thanks,

greg k-h

  reply	other threads:[~2014-01-05 22:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 18:06 [PATCH] kobject: provide kobject_put_wait to fix module unload race Mikulas Patocka
2014-01-04 18:14 ` Jeff Mahoney
2014-01-05  3:48   ` Greg Kroah-Hartman
2014-01-04 18:16 ` Greg Kroah-Hartman
2014-01-04 18:34   ` Al Viro
2014-01-04 22:42     ` Dmitry Torokhov
2014-01-05 22:11       ` Mikulas Patocka
2014-01-05 22:39         ` Dmitry Torokhov
2014-01-06 18:43           ` Mikulas Patocka
2014-01-04 20:35   ` Mikulas Patocka
2014-01-05  3:42     ` Greg Kroah-Hartman
2014-01-05  6:05       ` Dmitry Torokhov
2014-01-05 18:27         ` Greg Kroah-Hartman
2014-01-05 22:04       ` Mikulas Patocka
2014-01-05 22:23         ` Greg Kroah-Hartman [this message]
2014-01-05 16:43 ` [dm-devel] " Bart Van Assche
2014-01-05 18:26   ` Greg Kroah-Hartman
2014-01-06 18:55     ` Mikulas Patocka
2014-01-06 19:23       ` Greg Kroah-Hartman
2014-01-06 21:31       ` Mike Snitzer
2014-01-07  4:01         ` Mikulas Patocka
2014-01-07  5:25           ` Linus Torvalds
2014-01-07 18:00             ` Mikulas Patocka
2014-01-07 19:19               ` Mike Snitzer
2014-01-07 20:16                 ` Mikulas Patocka
2014-01-07 22:32                   ` Mike Snitzer
2014-01-07 14:16           ` Greg Kroah-Hartman
2014-01-07 18:16             ` Mikulas Patocka
2014-01-07 18:26             ` Dmitry Torokhov
2014-01-05 22:04   ` [dm-devel] [PATCH] " Mikulas Patocka

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=20140105222356.GA22084@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=dm-devel@redhat.com \
    --cc=jeffm@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mpatocka@redhat.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=tglx@linutronix.de \
    --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;
as well as URLs for NNTP newsgroup(s).