[PATCH 01/10] clk: ti: fapll: Fix output clock array allocation and bounds check
From: Lee Jones
Date: Fri Nov 27 2026 - 14:26:40 EST
ti_fapll_setup() allocates fd->outputs.clks as
sizeof(struct clk *) * MAX_FAPLL_OUTPUTS + 1, adding a single byte
rather than an extra pointer slot for the 1-based child synthesisers
stored at indices 1..MAX_FAPLL_OUTPUTS. It also reads output_instance
into a signed int via of_property_read_u32_index() and indexes
fd->outputs.clks[output_instance] without bounds validation, allowing
out-of-bounds heap writes.
Allocate MAX_FAPLL_OUTPUTS + 1 pointer slots with kzalloc_objs(), store
output_instance as u32, and skip entries exceeding MAX_FAPLL_OUTPUTS.
Fixes: 163152cbbe32 ("clk: ti: Add support for FAPLL on dm816x")
Closes: https://sashiko.dev/#/bug/linux-48a97add-8ee5-49f5-b05c-925006d9ec42
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Lee Jones <lee@xxxxxxxxxx>
---
drivers/clk/ti/fapll.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/ti/fapll.c b/drivers/clk/ti/fapll.c
index 7d6a4dd4fc8c..d5e95e6489cd 100644
--- a/drivers/clk/ti/fapll.c
+++ b/drivers/clk/ti/fapll.c
@@ -549,9 +549,8 @@ static void __init ti_fapll_setup(struct device_node *node)
if (!fd)
return;
- fd->outputs.clks = kzalloc(sizeof(struct clk *) *
- MAX_FAPLL_OUTPUTS + 1,
- GFP_KERNEL);
+ fd->outputs.clks = kzalloc_objs(*fd->outputs.clks,
+ MAX_FAPLL_OUTPUTS + 1);
if (!fd->outputs.clks)
goto free;
@@ -614,7 +613,7 @@ static void __init ti_fapll_setup(struct device_node *node)
const char *output_name;
void __iomem *freq, *div;
struct clk *synth_clk;
- int output_instance;
+ u32 output_instance;
u32 v;
if (of_property_read_string_index(node, "clock-output-names",
@@ -625,6 +624,12 @@ static void __init ti_fapll_setup(struct device_node *node)
&output_instance))
output_instance = i;
+ if (output_instance > MAX_FAPLL_OUTPUTS) {
+ pr_err("%pOFn invalid output_instance %u\n",
+ node, output_instance);
+ continue;
+ }
+
freq = fd->base + (output_instance * 8);
div = freq + 4;
--
2.56.1.839.g22a8290db9-goog