From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Lee Jones <lee@kernel.org>, Arnd Bergmann <arnd@arndb.de>
Cc: Fabrice Gasnier <fabrice.gasnier@foss.st.com>,
Jeremy Kerr <jk@codeconstruct.com.au>,
mfd@lists.linux.dev, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH] mfd: syscon: Put the clock after regmap_exit()
Date: Thu, 19 Nov 2026 16:49:56 +0000 [thread overview]
Message-ID: <20261119-syscon-clk-uaf-v1-1-dc4a4c1be353@gmail.com> (raw)
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>
reply other threads:[~2026-11-19 16:49 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261119-syscon-clk-uaf-v1-1-dc4a4c1be353@gmail.com \
--to=devnull+aiyengar1990.gmail.com@kernel.org \
--cc=aiyengar1990@gmail.com \
--cc=arnd@arndb.de \
--cc=fabrice.gasnier@foss.st.com \
--cc=jk@codeconstruct.com.au \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--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
all inboxes | Powered by JetHome®