From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 6/6] regmap-mmio: fix use-after-free
Date: Mon, 12 Jun 2023 14:53:31 +0200 [thread overview]
Message-ID: <20230612125331.1085059-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230612125331.1085059-1-a.fatoum@pengutronix.de>
Once we free ctx, dereferencing it to return ERR_CAST(ctx->clk) is
verboten. Fix this by using an intermediary variable.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/base/regmap/regmap-mmio.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/drivers/base/regmap/regmap-mmio.c b/drivers/base/regmap/regmap-mmio.c
index 6e6ae5ed54d4..4c6389689cd6 100644
--- a/drivers/base/regmap/regmap-mmio.c
+++ b/drivers/base/regmap/regmap-mmio.c
@@ -289,11 +289,15 @@ struct regmap *regmap_init_mmio_clk(struct device *dev,
return ERR_CAST(ctx);
if (clk_id) {
- ctx->clk = clk_get(dev, clk_id);
- if (IS_ERR(ctx->clk)) {
+ struct clk *clk;
+
+ clk = clk_get(dev, clk_id);
+ if (IS_ERR(clk)) {
kfree(ctx);
- return ERR_CAST(ctx->clk);
+ return ERR_CAST(clk);
}
+
+ ctx->clk = clk;
}
return regmap_init(dev, ®map_mmio, ctx, config);
--
2.39.2
next prev parent reply other threads:[~2023-06-12 12:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-12 12:53 [PATCH master 1/6] net: smc1111: add missing drive's of_device_id array sentinel Ahmad Fatoum
2023-06-12 12:53 ` [PATCH master 2/6] scripts: remove openssl dependency in multi_v7_defconfig Ahmad Fatoum
2023-06-12 12:53 ` [PATCH master 3/6] clocksource: armv7m_systick: fix MMIO address Ahmad Fatoum
2023-06-12 12:53 ` [PATCH master 4/6] of: select OF_OVERLAY where appropriate Ahmad Fatoum
2023-06-12 12:53 ` [PATCH master 5/6] memory_display: don't skip va_end in error case Ahmad Fatoum
2023-06-12 12:53 ` Ahmad Fatoum [this message]
2023-06-13 7:11 ` [PATCH master 6/6] regmap-mmio: fix use-after-free Sascha Hauer
2023-06-13 7:17 ` Ahmad Fatoum
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=20230612125331.1085059-6-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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