All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Van Asbroeck <thesven73@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Tejun Heo <tj@kernel.org>, Lai Jiangshan <jiangshanlai@gmail.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Sebastian Reichel <sre@kernel.org>,
	Kees Cook <keescook@chromium.org>
Subject: Re: [RFC v1 2/3] max17042_battery: fix potential user-after-free on module unload
Date: Tue, 5 Feb 2019 09:27:49 -0500	[thread overview]
Message-ID: <CAGngYiWJhja9bF5vL_4mwTjPMtzOwvsahHEpkntMPgMXdBNg9g@mail.gmail.com> (raw)
In-Reply-To: <20190205082727.GB118684@dtor-ws>

On Tue, Feb 5, 2019 at 3:27 AM Dmitry Torokhov
<dmitry.torokhov@gmail.com> wrote:
>
> Are there many more instances of this?

Unfortunately I think so.
A simple grep brings up a couple of candidates, but I'm sure there are more:

drivers/regulator/arizona-micsupp.c
drivers/nfc/port100.c
drivers/power/supply/max14656_charger_detector.c
drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c

> I am unsure if we need
> devm_init_work() when we can easily do the same in remove() call.

The devm_init_work() suggestion only addresses the problem for those modules
that use devm_. The others will need fixes in remove(). But this is not as
elegant and error-proof as using devm_init_work().

For example, take port100.c's disconnect function. It starts deallocating
resources, but the cmd_complete_work (scheduled by urb completion) may still
be in progress, and touch these resources after free.

At least, I _think_ that is the case. I'm not familiar enough with this driver
to be 100% sure, but it sounds likely.

static void port100_disconnect(struct usb_interface *interface)
{
    struct port100 *dev;

    dev = usb_get_intfdata(interface);
    usb_set_intfdata(interface, NULL);

    nfc_digital_unregister_device(dev->nfc_digital_dev);
    nfc_digital_free_device(dev->nfc_digital_dev);

    usb_kill_urb(dev->in_urb);
    usb_kill_urb(dev->out_urb);

    usb_free_urb(dev->in_urb);
    usb_free_urb(dev->out_urb);
    usb_put_dev(dev->udev);

    kfree(dev->cmd);

    nfc_info(&interface->dev, "Sony Port-100 NFC device disconnected\n");
}

  reply	other threads:[~2019-02-05 14:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 22:09 [RFC v1 0/3] Address potential user-after-free on module unload Sven Van Asbroeck
2019-02-04 22:09 ` [RFC v1 1/3] workqueue: Add resource-managed version of INIT_[DELAYED_]WORK() Sven Van Asbroeck
2019-02-08 17:06   ` Tejun Heo
2019-02-08 18:15     ` Sven Van Asbroeck
2019-02-04 22:09 ` [RFC v1 2/3] max17042_battery: fix potential user-after-free on module unload Sven Van Asbroeck
2019-02-05  8:27   ` Dmitry Torokhov
2019-02-05 14:27     ` Sven Van Asbroeck [this message]
2019-02-05 17:21       ` Sebastian Reichel
2019-02-04 22:09 ` [RFC v1 3/3] cap11xx: " Sven Van Asbroeck
2019-02-05  8:18   ` Dmitry Torokhov
2019-02-05  8:34     ` Dmitry Torokhov
2019-02-05 21:24     ` Jacek Anaszewski
2019-02-05 21:43       ` Dmitry Torokhov
2019-02-05 22:03         ` Sven Van Asbroeck
2019-02-05 14:57 ` [RFC v1 0/3] Address " Kees Cook
2019-02-05 15:22   ` Sven Van Asbroeck
2019-02-05 18:43     ` Greg KH
2019-02-05 19:12       ` Sven Van Asbroeck
2019-02-06 16:46         ` Greg KH
2019-02-06 17:30           ` Dmitry Torokhov
2019-02-06 17:49             ` Sven Van Asbroeck
2019-02-08  6:51             ` Greg KH
2019-02-05 18:42   ` Greg KH
2019-02-07 21:49   ` Sven Van Asbroeck
2019-02-07 22:20     ` Dmitry Torokhov
2019-02-07 22:27       ` Sven Van Asbroeck
2019-02-07 22:32       ` Sven Van Asbroeck
2019-02-07 22:48         ` Dmitry Torokhov
2019-02-08  4:30         ` Miguel Ojeda
2019-02-10 18:05           ` Sven Van Asbroeck
2019-02-14  1:11             ` Miguel Ojeda
2019-02-14 15:23               ` Sven Van Asbroeck
     [not found]     ` <CAGngYiXcogd69n-MvBD1n5ZJpBzqCau8UOfLMgXEXLnAev=srw@mail.gmail.com>
     [not found]       ` <alpine.DEB.2.21.1902080745480.4201@hadrien>
2019-02-14 17:52         ` Fwd: " Sven Van Asbroeck

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=CAGngYiWJhja9bF5vL_4mwTjPMtzOwvsahHEpkntMPgMXdBNg9g@mail.gmail.com \
    --to=thesven73@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=jiangshanlai@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sre@kernel.org \
    --cc=tj@kernel.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.