linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Jacek Anaszewski <jacek.anaszewski@gmail.com>,
	Pavel Machek <pavel@ucw.cz>
Cc: Dan Murphy <dmurphy@ti.com>,
	Amitoj Kaur Chawla <amitoj1606@gmail.com>,
	linux-leds@vger.kernel.org, linux-kernel@vger.kernel.org,
	Johan Hovold <johan@kernel.org>, stable <stable@vger.kernel.org>
Subject: [PATCH 4/6] leds: lm36274: fix use-after-free on unbind
Date: Mon,  1 Jun 2020 15:39:48 +0200	[thread overview]
Message-ID: <20200601133950.12420-5-johan@kernel.org> (raw)
In-Reply-To: <20200601133950.12420-1-johan@kernel.org>

Several MFD child drivers register their class devices directly under
the parent device. This means you cannot use devres 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.

Fixes: 11e1bbc116a7 ("leds: lm36274: Introduce the TI LM36274 LED driver")
Cc: stable <stable@vger.kernel.org>     # 5.3
Cc: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/leds/leds-lm36274.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/leds-lm36274.c b/drivers/leds/leds-lm36274.c
index 836b60c9a2b8..db842eeb7ca2 100644
--- a/drivers/leds/leds-lm36274.c
+++ b/drivers/leds/leds-lm36274.c
@@ -133,7 +133,7 @@ static int lm36274_probe(struct platform_device *pdev)
 	lm36274_data->pdev = pdev;
 	lm36274_data->dev = lmu->dev;
 	lm36274_data->regmap = lmu->regmap;
-	dev_set_drvdata(&pdev->dev, lm36274_data);
+	platform_set_drvdata(pdev, lm36274_data);
 
 	ret = lm36274_parse_dt(lm36274_data);
 	if (ret) {
@@ -147,8 +147,16 @@ static int lm36274_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return devm_led_classdev_register(lm36274_data->dev,
-					 &lm36274_data->led_dev);
+	return led_classdev_register(lm36274_data->dev, &lm36274_data->led_dev);
+}
+
+static int lm36274_remove(struct platform_device *pdev)
+{
+	struct lm36274 *lm36274_data = platform_get_drvdata(pdev);
+
+	led_classdev_unregister(&lm36274_data->led_dev);
+
+	return 0;
 }
 
 static const struct of_device_id of_lm36274_leds_match[] = {
@@ -159,6 +167,7 @@ MODULE_DEVICE_TABLE(of, of_lm36274_leds_match);
 
 static struct platform_driver lm36274_driver = {
 	.probe  = lm36274_probe,
+	.remove = lm36274_remove,
 	.driver = {
 		.name = "lm36274-leds",
 	},
-- 
2.26.2


  parent reply	other threads:[~2020-06-01 13:40 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 ` Johan Hovold [this message]
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
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=20200601133950.12420-5-johan@kernel.org \
    --to=johan@kernel.org \
    --cc=amitoj1606@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 \
    --cc=stable@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).