* [PATCH] mfd: syscon: Put the clock after regmap_exit()
@ 2026-11-19 16:49 Arun Iyengar via B4 Relay
0 siblings, 0 replies; only message in thread
From: Arun Iyengar via B4 Relay @ 2026-11-19 16:49 UTC (permalink / raw)
To: Lee Jones, Arnd Bergmann
Cc: Fabrice Gasnier, Jeremy Kerr, mfd, linux-kernel, stable, Arun Iyengar
From: Arun Iyengar <aiyengar1990@gmail.com>
On the error path, of_syscon_register() puts the clock before
regmap_exit(), which then unprepares the freed clock. This happens
when the reset lookup fails, e.g. with -EPROBE_DEFER.
Put the clock after regmap_exit().
Fixes: a00406b71c5f ("mfd: syscon: Add optional clock support")
Fixes: 7d1e3bd94828 ("mfd: syscon: Allow reset control for syscon devices")
Cc: stable@vger.kernel.org
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/r/179493691305.3136.16311404541139130213@kernel.org
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
A related regmap patch ("regmap: mmio: Don't attach the clock if
clk_prepare() fails") is sent separately; neither depends on the other.
Tested on an Orange Pi 5 (RK3588S), 7.3 with KASAN, together with the
regmap patch: with a forced reset lookup failure, a use-after-free in
clk_unprepare() is reported without the two patches and nothing with both.
Developed with Claude (Anthropic), which wrote the code and the commit
message. I reviewed every change.
---
drivers/mfd/syscon.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 21a7fcdd2737..3ff4e024542b 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -132,13 +132,13 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
} else {
ret = regmap_mmio_attach_clk(regmap, clk);
if (ret)
- goto err_attach_clk;
+ goto err_clk;
}
reset = of_reset_control_get_optional_exclusive(np, NULL);
if (IS_ERR(reset)) {
ret = PTR_ERR(reset);
- goto err_attach_clk;
+ goto err_clk;
}
ret = reset_control_deassert(reset);
@@ -155,11 +155,10 @@ static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
err_reset:
reset_control_put(reset);
-err_attach_clk:
- if (!IS_ERR(clk))
- clk_put(clk);
err_clk:
regmap_exit(regmap);
+ if (!IS_ERR(clk))
+ clk_put(clk);
err_regmap:
iounmap(base);
return ERR_PTR(ret);
---
base-commit: e5bcc8e02e570e3eee46d4cebefd552cc7c9e843
change-id: 20261119-syscon-clk-uaf-5ff259e0fa15
Best regards,
--
Arun Iyengar <aiyengar1990@gmail.com>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 16:49 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 16:49 [PATCH] mfd: syscon: Put the clock after regmap_exit() Arun Iyengar via B4 Relay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®