Re: [PATCH 01/10] clk: imx: imx8qxp-lpcg: Prevent stack overflow when parsing clocks

From: Peng Fan

Date: Tue Nov 24 2026 - 19:14:31 EST


On Mon, Nov 23, 2026 at 04:47:34PM +0000, Lee Jones wrote:
>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@xxxxxxxxxxxxxxx
>Signed-off-by: Lee Jones <lee@xxxxxxxxxx>

There was already a fix from Abel.

https://lore.kernel.org/linux-clk/20261102-imx8qxp-lpcg-duplicate-clock-indices-v1-2-1c3fc3fe727c@xxxxxxxxxxxxxxxx/

Regards,
Peng

>---
> 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
>
>