Linux Tegra architecture development
 help / color / mirror / Atom feed
* [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2)
@ 2026-11-27 19:25 Lee Jones
  2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-27 19:25 UTC (permalink / raw)
  To: lee, Heiko Stuebner, linux-arm-kernel, linux-rockchip
  Cc: linux-kernel, Thomas Richard (TI), Andrea della Porta,
	Brian Masney, Conor Dooley, Dominique Belhachemi, Doug Anderson,
	Emil Renner Berthing, Florian Fainelli, Hal Feng, Jerome Brunet,
	Jonathan Hunter, Joshua Peisach, Linus Walleij, linux-clk,
	linux-omap, linux-tegra, Michael Turquette, Michal Wilczynski,
	Naushir Patuck, Nishanth Menon, Palmer Dabbelt, Prashant Gaikwad,
	Rob Herring, Rosen Penev, Santosh Shilimkar, Stephen Boyd,
	Tero Kristo, Thierry Reding, Thomas Abraham, Timo Alho,
	Tony Lindgren, Wentao Liang, Xingyu Wu

These issues were reported by Sashiko.

This is batch 2 of Common Clock Framework fixes, based on clk/clk-next.
It addresses output array OOB writes in ti/fapll, ERR_PTR dereferences
and double-unregister in tegra/bpmp, notifier UAFs and global array
mutation in starfive/jh7110 and rockchip/cpu, rate and parent lookup
bugs in rp1, and allocation error handling in sci-clk and icst.

Cc: "Thomas Richard (TI)" <thomas.richard@bootlin.com>
Cc: Andrea della Porta <andrea.porta@suse.com>
Cc: Brian Masney <bmasney+clk@redhat.com>
Cc: Conor Dooley <conor.dooley@microchip.com>
Cc: Dominique Belhachemi <db@domibel.de>
Cc: Doug Anderson <dianders@chromium.org>
Cc: Emil Renner Berthing <kernel@esmil.dk>
Cc: Florian Fainelli <florian.fainelli@broadcom.com>
Cc: Hal Feng <hal.feng@starfivetech.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: Jerome Brunet <jbrunet+clk@baylibre.com>
Cc: Jonathan Hunter <jonathanh@nvidia.com>
Cc: Joshua Peisach <jpeisach@ubuntu.com>
Cc: Linus Walleij <linusw@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-clk@vger.kernel.org
Cc: linux-omap@vger.kernel.org
Cc: linux-rockchip@lists.infradead.org
Cc: linux-tegra@vger.kernel.org
Cc: Michael Turquette <mturquette@linaro.org>
Cc: Michal Wilczynski <m.wilczynski@samsung.com>
Cc: Naushir Patuck <naush@raspberrypi.com>
Cc: Nishanth Menon <nm@ti.com>
Cc: Palmer Dabbelt <palmer@rivosinc.com>
Cc: Prashant Gaikwad <pgaikwad@nvidia.com>
Cc: Rob Herring <robh@kernel.org>
Cc: Rosen Penev <rosenp@gmail.com>
Cc: Santosh Shilimkar <ssantosh@kernel.org>
Cc: Stephen Boyd <sboyd@kernel.org>
Cc: Tero Kristo <kristo@kernel.org>
Cc: Thierry Reding <thierry.reding@kernel.org>
Cc: Thomas Abraham <thomas.ab@samsung.com>
Cc: Timo Alho <talho@nvidia.com>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Wentao Liang <vulab@iscas.ac.cn>
Cc: Xingyu Wu <xingyu.wu@starfivetech.com>

Lee Jones (10):
  clk: ti: fapll: Fix output clock array allocation and bounds check
  clk: tegra: bpmp: Drop manual clock unregister on provider failure
  clk: starfive: jh7110-sys: Use devres for PLL0 clock and notifier
  clk: starfive: jh7110: Duplicate top clock bulk arrays per device
  clk: rockchip: cpu: Allocate rate_table before registering notifier
  clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate()
  clk: rp1: Propagate determine_rate() return value for PLL dividers
  clk: rp1: Reference secondary PLL divider clk_hw in parent tables
  clk: keystone: sci-clk: Check allocation failure before copying clock
    array
  clk: versatile: icst: Check kasprintf() and put parent node on error

 drivers/clk/clk-rp1.c                         | 32 +++++++++----------
 drivers/clk/keystone/sci-clk.c                |  8 +++--
 drivers/clk/rockchip/clk-cpu.c                | 26 +++++++--------
 .../clk/starfive/clk-starfive-jh7110-isp.c    |  9 ++++--
 .../clk/starfive/clk-starfive-jh7110-sys.c    |  5 +--
 .../clk/starfive/clk-starfive-jh7110-vout.c   |  9 ++++--
 drivers/clk/tegra/clk-bpmp.c                  | 14 +-------
 drivers/clk/ti/fapll.c                        | 13 +++++---
 drivers/clk/versatile/clk-icst.c              |  5 +++
 9 files changed, 66 insertions(+), 55 deletions(-)

-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure
  2026-11-27 19:25 [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Lee Jones
@ 2026-11-27 19:25 ` Lee Jones
  2026-12-04 12:41   ` Thierry Reding
  2026-11-27 19:25 ` [PATCH 06/10] clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate() Lee Jones
  2026-12-04  9:24 ` (subset) [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Jerome Brunet
  2 siblings, 1 reply; 7+ messages in thread
From: Lee Jones @ 2026-11-27 19:25 UTC (permalink / raw)
  To: lee, Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
	Thierry Reding, Jonathan Hunter, Rosen Penev, linux-clk,
	linux-tegra, linux-kernel
  Cc: stable

tegra_bpmp_clk_register() registers every clock with
devm_clk_hw_register(), and tegra_bpmp_register_clocks_one() records
ERR_PTR values in bpmp->clocks[i] whenever an individual clock fails to
register.  If of_clk_add_hw_provider() fails,
tegra_bpmp_unregister_clocks() unconditionally dereferences
bpmp->clocks[i] and calls clk_hw_unregister(), crashing on any error
pointer and double-unregistering clocks when devres subsequently unwinds
on probe failure.

Remove tegra_bpmp_unregister_clocks() and rely on devres to unregister
the clocks cleanly.

Fixes: ca6f2796eef7 ("clk: tegra: Add BPMP clock driver")
Closes: https://sashiko.dev/#/bug/linux-e3e9ccfe-87c7-4de5-b6bb-9b6968df7cc4
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/clk/tegra/clk-bpmp.c | 12 ------------
 1 file changed, 12 deletions(-)

diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index 3649324e2e1f..e4b4f3eec777 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -648,14 +648,6 @@ static int tegra_bpmp_register_clocks(struct tegra_bpmp *bpmp,
 	return 0;
 }
 
-static void tegra_bpmp_unregister_clocks(struct tegra_bpmp *bpmp)
-{
-	unsigned int i;
-
-	for (i = 0; i < bpmp->num_clocks; i++)
-		clk_hw_unregister(&bpmp->clocks[i]->hw);
-}
-
 static struct clk_hw *tegra_bpmp_clk_of_xlate(struct of_phandle_args *clkspec,
 					      void *data)
 {
@@ -696,10 +688,6 @@ int tegra_bpmp_init_clocks(struct tegra_bpmp *bpmp)
 	err = of_clk_add_hw_provider(bpmp->dev->of_node,
 				     tegra_bpmp_clk_of_xlate,
 				     bpmp);
-	if (err < 0) {
-		tegra_bpmp_unregister_clocks(bpmp);
-		goto free;
-	}
 
 free:
 	kfree(clocks);
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 06/10] clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate()
  2026-11-27 19:25 [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Lee Jones
  2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
@ 2026-11-27 19:25 ` Lee Jones
  2026-12-04  9:24 ` (subset) [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Jerome Brunet
  2 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2026-11-27 19:25 UTC (permalink / raw)
  To: lee, Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
	Thierry Reding, Jonathan Hunter, Rosen Penev, Timo Alho,
	linux-clk, linux-tegra, linux-kernel
  Cc: stable

tegra_bpmp_register_clocks_one() intentionally stores ERR_PTR values in
bpmp->clocks[i] when registering a clock fails.  However,
tegra_bpmp_clk_of_xlate() only checks for NULL before dereferencing
clk->id, crashing on any failed clock slot.

Use IS_ERR_OR_NULL() when skipping unpopulated clock entries.

Fixes: 2db12b15c6f3 ("clk: tegra: Register clocks from root to leaf")
Closes: https://sashiko.dev/#/bug/linux-3d54138a-c3d2-4466-952a-f7e44259adfe
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/clk/tegra/clk-bpmp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index e4b4f3eec777..7cbdd7797623 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -657,7 +657,7 @@ static struct clk_hw *tegra_bpmp_clk_of_xlate(struct of_phandle_args *clkspec,
 	for (i = 0; i < bpmp->num_clocks; i++) {
 		struct tegra_bpmp_clk *clk = bpmp->clocks[i];
 
-		if (!clk)
+		if (IS_ERR_OR_NULL(clk))
 			continue;
 
 		if (clk->id == id)
-- 
2.56.1.839.g22a8290db9-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: (subset) [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2)
  2026-11-27 19:25 [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Lee Jones
  2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
  2026-11-27 19:25 ` [PATCH 06/10] clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate() Lee Jones
@ 2026-12-04  9:24 ` Jerome Brunet
  2 siblings, 0 replies; 7+ messages in thread
From: Jerome Brunet @ 2026-12-04  9:24 UTC (permalink / raw)
  To: Heiko Stuebner, linux-arm-kernel, linux-rockchip, Lee Jones
  Cc: linux-kernel, Thomas Richard (TI), Andrea della Porta,
	Brian Masney, Conor Dooley, Dominique Belhachemi, Doug Anderson,
	Emil Renner Berthing, Florian Fainelli, Hal Feng, Jerome Brunet,
	Jonathan Hunter, Joshua Peisach, Linus Walleij, linux-clk,
	linux-omap, linux-tegra, Michael Turquette, Michal Wilczynski,
	Naushir Patuck, Nishanth Menon, Palmer Dabbelt, Prashant Gaikwad,
	Rob Herring, Rosen Penev, Santosh Shilimkar, Stephen Boyd,
	Tero Kristo, Thierry Reding, Thomas Abraham, Timo Alho,
	Tony Lindgren, Wentao Liang, Xingyu Wu

Applied to clk/linux.git (clk-pile), thanks!

[01/10] clk: ti: fapll: Fix output clock array allocation and bounds check
        https://git.kernel.org/clk/linux/c/2a866acf9b7f
[02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure
        https://git.kernel.org/clk/linux/c/b473edca8fe5
[03/10] clk: starfive: jh7110-sys: Use devres for PLL0 clock and notifier
        https://git.kernel.org/clk/linux/c/e625469a8c8a
[04/10] clk: starfive: jh7110: Duplicate top clock bulk arrays per device
        https://git.kernel.org/clk/linux/c/cd2dd80440c1
[05/10] clk: rockchip: cpu: Allocate rate_table before registering notifier
        https://git.kernel.org/clk/linux/c/039aa70776a7
[06/10] clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate()
        https://git.kernel.org/clk/linux/c/f7f4c102cfda
[07/10] clk: rp1: Propagate determine_rate() return value for PLL dividers
        https://git.kernel.org/clk/linux/c/9d15232e8d44
[08/10] clk: rp1: Reference secondary PLL divider clk_hw in parent tables
        https://git.kernel.org/clk/linux/c/f94ba5db0590
[10/10] clk: versatile: icst: Check kasprintf() and put parent node on error
        https://git.kernel.org/clk/linux/c/443452dcbcc9

Best regards,
--
Jerome


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure
  2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
@ 2026-12-04 12:41   ` Thierry Reding
  2026-12-04 14:30     ` Jerome Brunet
  0 siblings, 1 reply; 7+ messages in thread
From: Thierry Reding @ 2026-12-04 12:41 UTC (permalink / raw)
  To: Lee Jones
  Cc: Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
	Jonathan Hunter, Rosen Penev, linux-clk, linux-tegra,
	linux-kernel, stable

[-- Attachment #1: Type: text/plain, Size: 1192 bytes --]

On Fri, Nov 27, 2026 at 07:25:26PM +0000, Lee Jones wrote:
> tegra_bpmp_clk_register() registers every clock with
> devm_clk_hw_register(), and tegra_bpmp_register_clocks_one() records
> ERR_PTR values in bpmp->clocks[i] whenever an individual clock fails to
> register.  If of_clk_add_hw_provider() fails,
> tegra_bpmp_unregister_clocks() unconditionally dereferences
> bpmp->clocks[i] and calls clk_hw_unregister(), crashing on any error
> pointer and double-unregistering clocks when devres subsequently unwinds
> on probe failure.
> 
> Remove tegra_bpmp_unregister_clocks() and rely on devres to unregister
> the clocks cleanly.
> 
> Fixes: ca6f2796eef7 ("clk: tegra: Add BPMP clock driver")

Not sure it's really worth porting this back to 10 years worth of stable
trees since there's not been a single report of this ever happening. But
it's also not a very big patch, so might as well leave it here.

Brian, do you want me to take this via the Tegra tree? I already have
that "clk: tegra: bpmp: Do not cache the EMC clock rate" patch in that
tree, and while I don't think it's going to cause any conflicts, seems
reasonable to keep them all together.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure
  2026-12-04 12:41   ` Thierry Reding
@ 2026-12-04 14:30     ` Jerome Brunet
  2026-12-04 21:35       ` Thierry Reding
  0 siblings, 1 reply; 7+ messages in thread
From: Jerome Brunet @ 2026-12-04 14:30 UTC (permalink / raw)
  To: Thierry Reding
  Cc: Lee Jones, Prashant Gaikwad, Stephen Boyd, Brian Masney,
	Jerome Brunet, Jonathan Hunter, Rosen Penev, linux-clk,
	linux-tegra, linux-kernel, stable, Jerome Brunet

On 2026-12-04 13:41 +0100, Thierry Reding wrote:
> On Fri, Nov 27, 2026 at 07:25:26PM +0000, Lee Jones wrote:
> > tegra_bpmp_clk_register() registers every clock with
> > devm_clk_hw_register(), and tegra_bpmp_register_clocks_one() records
> > ERR_PTR values in bpmp->clocks[i] whenever an individual clock fails to
> > register.  If of_clk_add_hw_provider() fails,
> > tegra_bpmp_unregister_clocks() unconditionally dereferences
> > bpmp->clocks[i] and calls clk_hw_unregister(), crashing on any error
> > pointer and double-unregistering clocks when devres subsequently unwinds
> > on probe failure.
> > 
> > Remove tegra_bpmp_unregister_clocks() and rely on devres to unregister
> > the clocks cleanly.
> > 
> > Fixes: ca6f2796eef7 ("clk: tegra: Add BPMP clock driver")
> 
> Not sure it's really worth porting this back to 10 years worth of stable
> trees since there's not been a single report of this ever happening. But
> it's also not a very big patch, so might as well leave it here.
> 
> Brian, do you want me to take this via the Tegra tree? I already have
> that "clk: tegra: bpmp: Do not cache the EMC clock rate" patch in that
> tree, and while I don't think it's going to cause any conflicts, seems
> reasonable to keep them all together.

Hi Thierry,

I already applied it. Send what you have. I'd deal with the conflict if
there is one.

-- 
Jerome


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure
  2026-12-04 14:30     ` Jerome Brunet
@ 2026-12-04 21:35       ` Thierry Reding
  0 siblings, 0 replies; 7+ messages in thread
From: Thierry Reding @ 2026-12-04 21:35 UTC (permalink / raw)
  To: Jerome Brunet
  Cc: Lee Jones, Prashant Gaikwad, Stephen Boyd, Brian Masney,
	Jerome Brunet, Jonathan Hunter, Rosen Penev, linux-clk,
	linux-tegra, linux-kernel, stable

[-- Attachment #1: Type: text/plain, Size: 1538 bytes --]

On Fri, Dec 04, 2026 at 03:30:34PM +0100, Jerome Brunet wrote:
> On 2026-12-04 13:41 +0100, Thierry Reding wrote:
> > On Fri, Nov 27, 2026 at 07:25:26PM +0000, Lee Jones wrote:
> > > tegra_bpmp_clk_register() registers every clock with
> > > devm_clk_hw_register(), and tegra_bpmp_register_clocks_one() records
> > > ERR_PTR values in bpmp->clocks[i] whenever an individual clock fails to
> > > register.  If of_clk_add_hw_provider() fails,
> > > tegra_bpmp_unregister_clocks() unconditionally dereferences
> > > bpmp->clocks[i] and calls clk_hw_unregister(), crashing on any error
> > > pointer and double-unregistering clocks when devres subsequently unwinds
> > > on probe failure.
> > > 
> > > Remove tegra_bpmp_unregister_clocks() and rely on devres to unregister
> > > the clocks cleanly.
> > > 
> > > Fixes: ca6f2796eef7 ("clk: tegra: Add BPMP clock driver")
> > 
> > Not sure it's really worth porting this back to 10 years worth of stable
> > trees since there's not been a single report of this ever happening. But
> > it's also not a very big patch, so might as well leave it here.
> > 
> > Brian, do you want me to take this via the Tegra tree? I already have
> > that "clk: tegra: bpmp: Do not cache the EMC clock rate" patch in that
> > tree, and while I don't think it's going to cause any conflicts, seems
> > reasonable to keep them all together.
> 
> Hi Thierry,
> 
> I already applied it. Send what you have. I'd deal with the conflict if
> there is one.

No problem, thanks.

Thierry

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-04 21:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 19:25 [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Lee Jones
2026-11-27 19:25 ` [PATCH 02/10] clk: tegra: bpmp: Drop manual clock unregister on provider failure Lee Jones
2026-12-04 12:41   ` Thierry Reding
2026-12-04 14:30     ` Jerome Brunet
2026-12-04 21:35       ` Thierry Reding
2026-11-27 19:25 ` [PATCH 06/10] clk: tegra: bpmp: Skip ERR_PTR entries in tegra_bpmp_clk_of_xlate() Lee Jones
2026-12-04  9:24 ` (subset) [PATCH 00/10] clk: Fix OOB writes, UAFs, ERR_PTR dereferences, and rate-calc bugs (batch 2) Jerome Brunet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox