From: Johan Hovold <johan@kernel.org>
To: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Johan Hovold <johan@kernel.org>,
Jacek Anaszewski <jacek.anaszewski@gmail.com>,
Pavel Machek <pavel@ucw.cz>, Dan Murphy <dmurphy@ti.com>,
Amitoj Kaur Chawla <amitoj1606@gmail.com>,
Linux LED Subsystem <linux-leds@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 0/6] leds: fix broken devres usage
Date: Mon, 1 Jun 2020 16:29:47 +0200 [thread overview]
Message-ID: <20200601142947.GG19480@localhost> (raw)
In-Reply-To: <CAHp75VdSLb7bnd4v52wYD8KfqcDxjkirBgJVEYMWo=cwdeLzsg@mail.gmail.com>
On Mon, Jun 01, 2020 at 05:08:40PM +0300, Andy Shevchenko wrote:
> On Mon, Jun 1, 2020 at 5:01 PM Johan Hovold <johan@kernel.org> wrote:
> >
> > On Mon, Jun 01, 2020 at 04:51:01PM +0300, Andy Shevchenko wrote:
> > > On Mon, Jun 1, 2020 at 4:42 PM Johan Hovold <johan@kernel.org> wrote:
> > > >
> > > > Several MFD child drivers register their class devices directly under
> > > > the parent device (about half of the MFD LED drivers do so).
> > > >
> > > > This means you cannot blindly do devres conversions so that
> > > > deregistration ends up being tied to the parent device, something which
> > > > leads to use-after-free on driver unbind when the class device is
> > > > released while still being registered (and, for example, oopses on later
> > > > parent MFD driver unbind or LED class callbacks, or resource leaks and
> > > > name clashes on child driver reload).
> > >
> > > Shouldn't MFD take reference count for their children?
> >
> > That's not the issue here. The child driver is allocating memory for the
> > class device (for example using devres), and that will end up being
> > freed on unbind while said device is still registered. The child driver
> > may then even be unloaded. No extra reference can fix this.
>
> Okay, I didn't still get how dropping devres will help here.
>
> Say, we have
>
> ->probe()
> {
> return devm_foo_register();
> }
>
> and no ->remove()
>
> vs.
>
> ->probe()
> {
> return foo_register();
> }
>
> ->remove()
> {
> foo_unregister();
> }
>
> So, basically what you seem to workaround is that ->remove() is not
> getting called?
Any driver which frees a resource before making sure it's no longer used
it is just plain broken. Unfortunately, devres makes this harder to
reason about and people get it wrong. This is roughly the current
situation with these drivers:
drv->probe(dev)
foo = devm_kzalloc(dev);
devm_foo_register(dev->parent, foo); // NOTE: dev->parent
drv->remove(dev)
devres_release_all(dev)
kfree(foo); // foo still registered
but foo remains registered until the parent driver is unbound.
Johan
next prev parent reply other threads:[~2020-06-01 14:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-01 13:39 [PATCH 0/6] leds: fix broken devres usage Johan Hovold
2020-06-01 13:39 ` [PATCH 1/6] leds: 88pm860x: fix use-after-free on unbind Johan Hovold
2020-06-01 13:39 ` [PATCH 2/6] leds: da903x: " Johan Hovold
2020-06-01 13:39 ` [PATCH 3/6] leds: lm3533: " Johan Hovold
2020-06-01 13:39 ` [PATCH 4/6] leds: lm36274: " Johan Hovold
2020-06-01 13:39 ` [PATCH 5/6] leds: wm831x-status: " Johan Hovold
2020-06-01 13:39 ` [PATCH 6/6] leds: drop redundant struct-device pointer casts Johan Hovold
2020-06-01 13:51 ` [PATCH 0/6] leds: fix broken devres usage Andy Shevchenko
2020-06-01 14:01 ` Johan Hovold
2020-06-01 14:08 ` Andy Shevchenko
2020-06-01 14:29 ` Johan Hovold [this message]
2020-06-01 15:09 ` Andy Shevchenko
2020-06-01 15:31 ` Johan Hovold
2020-06-02 8:32 ` Andy Shevchenko
2020-06-04 13:31 ` Pavel Machek
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=20200601142947.GG19480@localhost \
--to=johan@kernel.org \
--cc=amitoj1606@gmail.com \
--cc=andy.shevchenko@gmail.com \
--cc=dmurphy@ti.com \
--cc=jacek.anaszewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
/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