[PATCH v2 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind
From: Lee Jones
Date: Wed Dec 02 2026 - 15:23:18 EST
nct3018y_clkout_register_clk() registers the CLKOUT clock via
devm_clk_register() but adds the OF clock provider with unmanaged
of_clk_add_provider() and never removes it. When the driver unbinds or
devm_rtc_register_device() fails, devres unregisters and frees struct
clk and nct3018y state while leaving a dangling pointer on the global
of_clk_providers list, leaking the provider entry and OF node reference
and causing a use-after-free on subsequent clock lookups.
Use devm_of_clk_add_hw_provider() so the OF clock provider is removed
automatically before the clock and driver state are released.
Fixes: 5adbaed16cc6 ("rtc: Add NCT3018Y real time clock driver")
Closes: https://sashiko.dev/#/bug/linux-9509654b-12c7-4bd1-b189-f52692af9457
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
v1 => v2:
- No changes
Cc: Alexandre Belloni <alexandre.belloni@xxxxxxxxxxx>
Cc: Andrew Jeffery <andrew@xxxxxxxxxxxxxxxxxxxx>
Cc: Avi Fishman <avifishman70@xxxxxxxxx>
Cc: Benjamin Fair <benjaminfair@xxxxxxxxxx>
Cc: Eric Liu <liuer@xxxxxxxxxx>
Cc: linux-rtc@xxxxxxxxxxxxxxx
Cc: Medad CChien <ctcchien@xxxxxxxxxxx>
Cc: Mia Lin <mimi05633@xxxxxxxxx>
Cc: Nancy Yuen <yuenn@xxxxxxxxxx>
Cc: openbmc@xxxxxxxxxxxxxxxx
Cc: Patrick Venture <venture@xxxxxxxxxx>
Cc: Tali Perry <tali.perry1@xxxxxxxxx>
Cc: Tomer Maimon <tmaimon77@xxxxxxxxx>
drivers/rtc/rtc-nct3018y.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-nct3018y.c b/drivers/rtc/rtc-nct3018y.c
index 194ba077363a..caa2b21f4002 100644
--- a/drivers/rtc/rtc-nct3018y.c
+++ b/drivers/rtc/rtc-nct3018y.c
@@ -479,7 +479,8 @@ static struct clk *nct3018y_clkout_register_clk(struct nct3018y *nct3018y)
clk = devm_clk_register(&client->dev, &nct3018y->clkout_hw);
if (!IS_ERR(clk))
- of_clk_add_provider(node, of_clk_src_simple_get, clk);
+ devm_of_clk_add_hw_provider(&client->dev, of_clk_hw_simple_get,
+ &nct3018y->clkout_hw);
return clk;
}
--
2.56.1.911.g883d8bcb20-goog