All of lore.kernel.org
 help / color / mirror / Atom feed
From: Muchun Song <smuchun@gmail.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael@kernel.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Prateek Sood <prsood@codeaurora.org>,
	Mukesh Ojha <mojha@codeaurora.org>,
	gkohli@codeaurora.org,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-arm-msm <linux-arm-msm@vger.kernel.org>,
	zhaowuyun@wingtech.com
Subject: Re: [PATCH v4] driver core: Fix use-after-free and double free on glue directory
Date: Tue, 18 Jun 2019 21:40:13 +0800	[thread overview]
Message-ID: <CAPSr9jFG17YnQC3UZrTZjqytB5wpTMeqqqOcJ7Sf6gAr8o5Uhg@mail.gmail.com> (raw)
In-Reply-To: <CAPSr9jH3sowszuNtBaTM1Wdi9vW+iakYX1G3arj+2_r5r7bYwQ@mail.gmail.com>

Ping guys ? I think this is worth fixing.

Muchun Song <smuchun@gmail.com> 于2019年5月25日周六 下午8:15写道:

>
> Hi greg k-h,
>
> Greg KH <gregkh@linuxfoundation.org> 于2019年5月25日周六 上午3:04写道:
> >
> > On Thu, May 16, 2019 at 10:23:42PM +0800, Muchun Song wrote:
> > > There is a race condition between removing glue directory and adding a new
> > > device under the glue directory. It can be reproduced in following test:
> >
> > <snip>
> >
> > Is this related to:
> >         Subject: [PATCH v3] drivers: core: Remove glue dirs early only when refcount is 1
> >
> > ?
> >
> > If so, why is the solution so different?
>
> In the v1 patch, the solution is that remove glue dirs early only when
> refcount is 1. So
> the v1 patch like below:
>
> @@ -1825,7 +1825,7 @@ static void cleanup_glue_dir(struct device *dev,
> struct kobject *glue_dir)
>                 return;
>
>         mutex_lock(&gdp_mutex);
> -       if (!kobject_has_children(glue_dir))
> +       if (!kobject_has_children(glue_dir) && kref_read(&glue_dir->kref) == 1)
>                 kobject_del(glue_dir);
>         kobject_put(glue_dir);
>         mutex_unlock(&gdp_mutex);
> -----------------------------------------------------------------------
>
> But from Ben's suggestion as below:
>
> I find relying on the object count for such decisions rather fragile as
> it could be taken temporarily for other reasons, couldn't it ? In which
> case we would just fail...
>
> Ideally, the looking up of the glue dir and creation of its child
> should be protected by the same lock instance (the gdp_mutex in that
> case).
> -----------------------------------------------------------------------
>
> So another solution is used from Ben's suggestion in the v2 patch. But
> I forgot to update the commit message until the v4 patch. Thanks.
>
> Yours,
> Muchun

  reply	other threads:[~2019-06-18 13:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 14:23 [PATCH v4] driver core: Fix use-after-free and double free on glue directory Muchun Song
2019-05-24 19:04 ` Greg KH
2019-05-25 12:15   ` Muchun Song
2019-06-18 13:40     ` Muchun Song [this message]
2019-06-18 14:11       ` Benjamin Herrenschmidt
2019-06-18 15:28       ` Greg KH
2019-06-18 16:09         ` Muchun Song
2019-06-18 16:13           ` Greg KH
2019-06-18 21:51             ` Benjamin Herrenschmidt
2019-06-25 15:06               ` Muchun Song
2019-06-25 22:56                 ` Benjamin Herrenschmidt
2019-06-26  0:55                   ` Greg KH

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=CAPSr9jFG17YnQC3UZrTZjqytB5wpTMeqqqOcJ7Sf6gAr8o5Uhg@mail.gmail.com \
    --to=smuchun@gmail.com \
    --cc=benh@kernel.crashing.org \
    --cc=gkohli@codeaurora.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mojha@codeaurora.org \
    --cc=prsood@codeaurora.org \
    --cc=rafael@kernel.org \
    --cc=zhaowuyun@wingtech.com \
    /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.