All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Andrew Jeffery <andrew@codeconstruct.com.au>,
	Avi Fishman <avifishman70@gmail.com>,
	Tomer Maimon <tmaimon77@gmail.com>,
	Tali Perry <tali.perry1@gmail.com>,
	Patrick Venture <venture@google.com>,
	Nancy Yuen <yuenn@google.com>,
	Benjamin Fair <benjaminfair@google.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Eric Liu <liuer@nvidia.com>, Medad CChien <ctcchien@nuvoton.com>,
	Mia Lin <mimi05633@gmail.com>,
	openbmc@lists.ozlabs.org, linux-rtc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 06/10] rtc: nct3018y: fix clock provider use-after-free and leak on unbind
Date: Mon, 23 Nov 2026 19:59:17 +0000	[thread overview]
Message-ID: <20261123200012.502284-7-lee@kernel.org> (raw)
In-Reply-To: <20261123200012.502284-1-lee@kernel.org>

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@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 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 c770450e48b4..8349ddd1a9d6 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.750.gf70dc682cf-goog


  parent reply	other threads:[~2026-11-23 20:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 19:59 [PATCH 00/10] rtc: assorted bug fixes across RTC drivers Lee Jones
2026-11-23 19:59 ` [PATCH 01/10] rtc: rx8025: pass parent I2C device in clock_adjust_ppb sysfs callbacks Lee Jones
2026-11-23 19:59 ` [PATCH 02/10] rtc: mt6397: handle non-DT platform device matching in probe Lee Jones
2026-11-23 19:59 ` [PATCH 03/10] rtc: ma35d1: allocate RTC device before requesting interrupt Lee Jones
2026-11-23 19:59 ` [PATCH 04/10] rtc: mpc5121: get interrupts via platform_get_irq() Lee Jones
2026-11-23 19:59 ` [PATCH 05/10] rtc: m41t80: use devm helpers for square-wave clock registration Lee Jones
2026-11-23 19:59 ` Lee Jones [this message]
2026-11-23 19:59 ` [PATCH 07/10] rtc: stmp3xxx: unregister child watchdog platform device on unbind Lee Jones
2026-11-23 19:59 ` [PATCH 08/10] rtc: ds1685: check driver data for NULL in ds1685_rtc_poweroff() Lee Jones
2026-11-29 16:08   ` Imre Kaloz
2026-11-23 19:59 ` [PATCH 09/10] rtc: omap: prevent NULL and dangling pointer dereferences in power-off path Lee Jones
2026-11-24  7:59   ` Johan Hovold
2026-11-23 19:59 ` [PATCH 10/10] rtc: bq32k: use u8 register buffer in trickle_charge_bypass sysfs Lee Jones
2026-11-23 20:16 ` [PATCH 00/10] rtc: assorted bug fixes across RTC drivers sashiko-bot

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=20261123200012.502284-7-lee@kernel.org \
    --to=lee@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=avifishman70@gmail.com \
    --cc=benjaminfair@google.com \
    --cc=ctcchien@nuvoton.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rtc@vger.kernel.org \
    --cc=liuer@nvidia.com \
    --cc=mimi05633@gmail.com \
    --cc=openbmc@lists.ozlabs.org \
    --cc=stable@vger.kernel.org \
    --cc=tali.perry1@gmail.com \
    --cc=tmaimon77@gmail.com \
    --cc=venture@google.com \
    --cc=yuenn@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.