From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Joel Stanley <joel@jms.id.au>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/2] drivers: core: Don't try to use a dead glue_dir
Date: Sat, 7 Jul 2018 18:51:00 +0200 [thread overview]
Message-ID: <20180707165100.GD16279@kroah.com> (raw)
In-Reply-To: <828fb935c0cd04e74a09b8ed2b78aca405d7c5b2.camel@kernel.crashing.org>
On Fri, Jun 29, 2018 at 12:21:51PM +1000, Benjamin Herrenschmidt wrote:
> Under some circumstances (such as when using kobject debugging)
> a gluedir whose kref is 0 might remain in the class kset for
> a long time. The reason is that we don't actively remove glue
> dirs when they become empty, but instead rely on the implicit
> removal done by kobject_release(), which can happen some amount
> of time after the last kobject_put().
>
> Using such a dead object is a bad idea and will lead to warnings
> and crashes.
>
> Unfortunately that can happen in get_device_parent() if the
> last child of a glue dir was removed and a new one added
> before the glue dir gets fully released().
>
> This prevents this by making get_device_parent() only "find"
> a glue dir whose refcount is non-0.
>
> While this fixes the crash, it doesn't fully fix the problem,
> instead the race will now result in an error attempting to
> use a duplicate file name in sysfs. A fix for that will come
> separately.
>
> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> ---
>
> (Adding lkml, I just realized I completely forgot to CC it in
> the first place on this whole conversation, blame the 1am debugging
> session)
>
> drivers/base/core.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/base/core.c b/drivers/base/core.c
> index b610816eb887..e9eff2099896 100644
> --- a/drivers/base/core.c
> +++ b/drivers/base/core.c
> @@ -1517,11 +1517,13 @@ static struct kobject *get_device_parent(struct device *dev,
>
> /* find our class-directory at the parent and reference it */
> spin_lock(&dev->class->p->glue_dirs.list_lock);
> - list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry)
> + list_for_each_entry(k, &dev->class->p->glue_dirs.list, entry) {
> if (k->parent == parent_kobj) {
> - kobj = kobject_get(k);
> - break;
> + kobj = kobject_get_unless_zero(k);
> + if (kobj)
> + break;
A parent directory _should_ not ever be able to be removed before the
object being removed was, as we should have had a reference to it,
right? So I don't see how this can get hit "in real life".
Yes, enabling kobject debugging does keep objects around for a long time
in order to try to help figure out where people are messing up their
usage of them. What subsystem is doing this in a way that causes
problems here? Shouldn't we fix that up instead?
thanks,
greg k-h
next prev parent reply other threads:[~2018-07-07 16:51 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <c40fe912fe008b1b531a3867e8784ed79d68023e.camel@kernel.crashing.org>
[not found] ` <CA+55aFxR0qg0yY-NWnH0DDruVWw8qRqp8=CRLq13p=TyxosJKw@mail.gmail.com>
2018-06-29 2:21 ` [PATCH 1/2] drivers: core: Don't try to use a dead glue_dir Benjamin Herrenschmidt
2018-06-30 19:45 ` Linus Torvalds
2018-07-07 16:48 ` Greg Kroah-Hartman
2018-07-09 23:44 ` Benjamin Herrenschmidt
2018-07-10 14:55 ` Greg Kroah-Hartman
2018-07-10 23:32 ` Benjamin Herrenschmidt
2018-07-10 23:55 ` Linus Torvalds
2018-07-11 0:07 ` Benjamin Herrenschmidt
2018-07-21 7:53 ` Greg Kroah-Hartman
2018-07-23 0:35 ` Benjamin Herrenschmidt
2018-07-07 16:51 ` Greg Kroah-Hartman [this message]
2018-07-09 23:50 ` Benjamin Herrenschmidt
2018-06-29 2:21 ` [PATCH 2/2] drivers: core: Remove glue dirs from sysfs earlier Benjamin Herrenschmidt
2018-06-29 13:56 ` Linus Torvalds
2018-06-29 13:57 ` Linus Torvalds
2018-06-30 1:04 ` Benjamin Herrenschmidt
2018-06-30 3:51 ` Benjamin Herrenschmidt
[not found] ` <edc7b03b9550ddcf1291ebf5a6dafd24f4455c23.camel@kernel.crashing.org>
[not found] ` <CA+55aFxS7OVEN5XrxceC5ibz780mhn-qRa50w1gVFjsz2JjMbw@mail.gmail.com>
[not found] ` <7eb06b499f2be366cf68c6b6588b16c603e6a567.camel@kernel.crashing.org>
2018-07-01 2:07 ` Linus Torvalds
2018-07-01 2:18 ` Linus Torvalds
2018-07-01 3:49 ` Benjamin Herrenschmidt
2018-07-01 3:42 ` Benjamin Herrenschmidt
2018-07-01 3:57 ` Linus Torvalds
2018-07-01 7:16 ` Benjamin Herrenschmidt
2018-07-01 17:04 ` Linus Torvalds
2018-07-01 23:36 ` Benjamin Herrenschmidt
2018-07-02 10:23 ` Benjamin Herrenschmidt
2018-07-02 19:24 ` Linus Torvalds
2018-07-03 0:57 ` Benjamin Herrenschmidt
2018-07-03 2:15 ` Linus Torvalds
2018-07-03 2:26 ` Linus Torvalds
2018-07-03 2:39 ` Benjamin Herrenschmidt
2018-07-03 5:22 ` Benjamin Herrenschmidt
2018-07-03 15:46 ` Tejun Heo
2018-07-04 1:10 ` Benjamin Herrenschmidt
[not found] ` <CA+55aFzKmzC-2_6+RsRRu9KfK_r=UGgLN2Q0hSNBV=ScGR7=8g@mail.gmail.com>
[not found] ` <6e3ca577f8dd5f3621d1054447d3f928a73dfcf9.camel@kernel.crashing.org>
[not found] ` <CA+55aFy+ZSu5cPzk887N-ZgXqvTB=Bp1JQYMWT1SZY81MqLH6Q@mail.gmail.com>
[not found] ` <1bc873980e7f63291fbe19dbc7e1607b8e126241.camel@kernel.crashing.org>
[not found] ` <20180707164241.GB16279@kroah.com>
[not found] ` <CA+55aFx-UX8nxewRFFWdBgYfPqfipnxaqJuJCUni9h4JvhoPFw@mail.gmail.com>
2018-07-10 0:29 ` [PATCH v2 " Benjamin Herrenschmidt
2018-07-10 0:33 ` Linus Torvalds
2018-07-10 1:37 ` Benjamin Herrenschmidt
2018-07-10 14:55 ` Greg Kroah-Hartman
2018-07-10 23:31 ` Benjamin Herrenschmidt
2018-07-03 2:37 ` [PATCH " Benjamin Herrenschmidt
2018-07-02 10:22 ` Benjamin Herrenschmidt
2018-07-01 3:52 ` Benjamin Herrenschmidt
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=20180707165100.GD16279@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=benh@kernel.crashing.org \
--cc=ebiederm@xmission.com \
--cc=joel@jms.id.au \
--cc=linux-kernel@vger.kernel.org \
--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