Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/10] clk: imx: imx8qxp-lpcg: Prevent stack overflow when parsing clocks
       [not found] <20261123164834.3330320-1-lee@kernel.org>
@ 2026-11-23 16:47 ` Lee Jones
  0 siblings, 0 replies; only message in thread
From: Lee Jones @ 2026-11-23 16:47 UTC (permalink / raw)
  To: lee, Abel Vesa, Peng Fan, Stephen Boyd, Brian Masney,
	Jerome Brunet, Frank Li, Sascha Hauer, Pengutronix Kernel Team,
	Fabio Estevam, Pengpeng Hou, Dong Aisheng, Shawn Guo, linux-clk,
	imx, linux-arm-kernel, linux-kernel
  Cc: stable

imx_lpcg_parse_clks_from_dt() allocates output_names, parent_names, and
bit_offset on the stack with IMX_LPCG_MAX_CLKS (8) entries each to match
the hardware limit of eight clock outputs per LPCG block.  However, it
only checks whether of_property_count_u32_elems() returns a negative
error code and enforces no upper bound on count.

If a Device Tree node specifies more than IMX_LPCG_MAX_CLKS entries in
clock-indices, subsequent calls to of_property_read_u32_array(),
of_clk_parent_fill(), and of_property_read_string_array() write past the
end of these stack buffers.  Reject counts exceeding IMX_LPCG_MAX_CLKS.

Fixes: d5f1e6a2bb61 ("clk: imx: imx8qxp-lpcg: add parsing clocks from device tree")
Closes: https://sashiko.dev/#/bug/linux-22dfac78-f44b-42f8-985a-995308723fc4
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/clk/imx/clk-imx8qxp-lpcg.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/clk/imx/clk-imx8qxp-lpcg.c b/drivers/clk/imx/clk-imx8qxp-lpcg.c
index 9ad016106b1e..5eb4bdbaf7d8 100644
--- a/drivers/clk/imx/clk-imx8qxp-lpcg.c
+++ b/drivers/clk/imx/clk-imx8qxp-lpcg.c
@@ -199,6 +199,10 @@ static int imx_lpcg_parse_clks_from_dt(struct platform_device *pdev,
 		dev_err(&pdev->dev, "failed to count clocks\n");
 		return -EINVAL;
 	}
+	if (count > IMX_LPCG_MAX_CLKS) {
+		dev_err(&pdev->dev, "too many clocks: %d\n", count);
+		return -EINVAL;
+	}
 
 	/*
 	 * A trick here is that we set the num of clks to the MAX instead
-- 
2.56.1.750.gf70dc682cf-goog



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 16:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20261123164834.3330320-1-lee@kernel.org>
2026-11-23 16:47 ` [PATCH 01/10] clk: imx: imx8qxp-lpcg: Prevent stack overflow when parsing clocks Lee Jones

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