From: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
To: linusw@kernel.org
Cc: sboyd@kernel.org, bmasney+clk@redhat.com,
jbrunet+clk@baylibre.com, linux-arm-kernel@lists.infradead.org,
linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
wanghr2026@mail.zgclab.edu.cn
Subject: [PATCH] clk: versatile-icst: release regmap on registration failure
Date: Thu, 19 Nov 2026 16:14:53 +0800 [thread overview]
Message-ID: <1795076093787-3-ba1f065a@mail.zgclab.edu.cn> (raw)
icst_clk_register() creates a non-devm regmap with regmap_init_mmio() and
hands it to icst_clk_setup(), which on clk_register() failure only frees
its own structs and drops the regmap pointer, so the regmap and its
debugfs entry leak permanently. A name clash is a natural trigger: a DT
with N same-named auxosc children registers "osc" once and then fails
-EEXIST on every subsequent registration, leaking N-1 regmaps per boot.
Release the regmap with regmap_exit() when icst_clk_setup() fails.
Signed-off-by: Wang Haoran <wanghr2026@mail.zgclab.edu.cn>
Fixes: 179c8fb3c2a6 ("clk: versatile-icst: convert to use regmap")
---
diff --git a/drivers/clk/versatile/clk-icst.c b/drivers/clk/versatile/clk-icst.c
index 37334afee040..e9c7353aa5d5 100644
--- a/drivers/clk/versatile/clk-icst.c
+++ b/drivers/clk/versatile/clk-icst.c
@@ -407,14 +407,18 @@ struct clk *icst_clk_register(struct device *dev,
.reg_stride = 4,
};
struct regmap *map;
+ struct clk *clk;
map = regmap_init_mmio(dev, base, &icst_regmap_conf);
if (IS_ERR(map)) {
pr_err("could not initialize ICST regmap\n");
return ERR_CAST(map);
}
- return icst_clk_setup(dev, desc, name, parent_name, map,
- ICST_VERSATILE);
+ clk = icst_clk_setup(dev, desc, name, parent_name, map, ICST_VERSATILE);
+ if (IS_ERR(clk))
+ regmap_exit(map);
+
+ return clk;
}
EXPORT_SYMBOL_GPL(icst_clk_register);
---
PoC reproduction (7.4.0-rc2, arm64 QEMU virt, unmodified kernel):
Device tree injection, spliced into the QEMU virt machine DT:
reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges;
icst-regs@7f200000 { no-map; reg = <0x0 0x7f200000 0x0 0x1000>; }; };
syscon@7f200000 { compatible = "syscon"; reg = <0x0 0x7f200000 0x0 0x1000>;
osc@0 { compatible = "arm,versatile-cm-auxosc"; #clock-cells = <0>; };
osc@1 { compatible = "arm,versatile-cm-auxosc"; #clock-cells = <0>; }; };
Two same-compatible auxosc children make cm_osc_setup() run twice at boot
via CLK_OF_DECLARE: the first clk_register("osc") succeeds, the second hits
-EEXIST and its regmap is leaked. No trigger action is needed.
Result:
(null): error -EEXIST: failed to register clk 'osc' (0xffff000003407600)
===== LIVE REGMAP INSTANCES =====
drwxr-xr-x dummy0
drwxr-xr-x dummy1
dummy1 is the regmap leaked on the failed registration (dummy0 belongs to
the successfully registered clock). N duplicate nodes leak N-1 regmaps.
Note: the PoC was generated with AI assistance and the vulnerability was
found by static analysis. The device tree is trusted input (a bad DT
requires root or physical access), so this is not a security fix, but it
prevents a potential resource leak or system failure on a failed probe or
an old or malformed DT.
next reply other threads:[~2026-11-19 8:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 8:14 Wang Haoran [this message]
2026-11-19 14:52 ` Brian Masney
2026-11-22 9:29 ` 王浩然
2026-11-24 16:35 ` Brian Masney
2026-11-24 16:32 ` Brian Masney
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=1795076093787-3-ba1f065a@mail.zgclab.edu.cn \
--to=wanghr2026@mail.zgclab.edu.cn \
--cc=bmasney+clk@redhat.com \
--cc=jbrunet+clk@baylibre.com \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sboyd@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®