All of lore.kernel.org
 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: Sat, 4 Jan 2014 10:16:20 -0800	[thread overview]
Message-ID: <20140104181620.GA2087@kroah.com> (raw)
In-Reply-To: <alpine.LRH.2.02.1401021733250.27775@file01.intranet.prod.int.rdu2.redhat.com>

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.

> I came up with a simpler patch to achieve the same purpose - this patch 
> makes fixing the drivers easy - the driver is fixed just by replacing 
> "kobject_put" with "kobject_put_wait" in the unload routine.

No, that's not ok at all.

> I'd like to ask if you could revert 
> eee031649707db3c9920d9498f8d03819b74fc23 (no code uses it) and replace it 
> with this patch.
> 
> See http://www.redhat.com/archives/dm-devel/2013-October/msg00141.html for 
> the bug that this patch fixes.
> 
> Mikulas
> 
> 
> 
> From: Mikulas Patocka <mpatocka@redhat.com>
> 
> This patch introduces a new function kobject_put_wait. It decrements the
> kobject reference count, waits until the count reaches zero. When this
> function returns, it is guaranteed that the kobject was freed.
> 
> A rationale for this function:
> 
> The kobject is keeps a reference count. The driver unload routine
> decrements the reference count, however, references to the kobject may
> still be held by other kernel subsystems. The driver must not free the
> memory that contains the kobject. Instead, the driver provides a "release"
> method. The "release" method is called by the kernel when the last kobject
> refernce is dropped. The "release" method should free the memory that
> contains the kobject.
> 
> However, this pattern is buggy with respect to modules. The release method
> is placed in the driver's module. When the driver exits, the module
> reference count is zero, thus the module may be freed. However, there may
> still be references to the kobject. If the module is unloaded and then the
> release method is called, a crash happens.

Yes, module unloading while a kobject is still "active" is not a good
thing, what modules do you have that cause this problem?  Why not just
grab the module reference in your kobject if you need this type of
protection?  It's not the kobject's code fault that this issue is there,
or that we now have a "delayed release" function to expose this type of
thing, it's the user of the kobject.

Please fix the broken users of the kobject first.

thanks,

greg k-h

  parent reply	other threads:[~2014-01-04 18:16 UTC|newest]

Thread overview: 31+ 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 [this message]
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
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 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=20140104181620.GA2087@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.