]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
clk: samsung: Fix UBSAN panic in samsung_clk_init()
authorWill McVicker <willmcvicker@google.com>
Wed, 12 Feb 2025 18:32:52 +0000 (10:32 -0800)
committerKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Sat, 15 Feb 2025 13:35:02 +0000 (14:35 +0100)
With UBSAN_ARRAY_BOUNDS=y, I'm hitting the below panic due to
dereferencing `ctx->clk_data.hws` before setting
`ctx->clk_data.num = nr_clks`. Move that up to fix the crash.

  UBSAN: array index out of bounds: 00000000f2005512 [#1] PREEMPT SMP
  <snip>
  Call trace:
   samsung_clk_init+0x110/0x124 (P)
   samsung_clk_init+0x48/0x124 (L)
   samsung_cmu_register_one+0x3c/0xa0
   exynos_arm64_register_cmu+0x54/0x64
   __gs101_cmu_top_of_clk_init_declare+0x28/0x60
   ...

Fixes: e620a1e061c4 ("drivers/clk: convert VL struct to struct_size")
Signed-off-by: Will McVicker <willmcvicker@google.com>
Link: https://lore.kernel.org/r/20250212183253.509771-1-willmcvicker@google.com
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
drivers/clk/samsung/clk.c

index 283c523763e6b6de041147c890c23af33e87852c..8d440cf56bd45970929bd556b739194ed7b80ce3 100644 (file)
@@ -74,12 +74,12 @@ struct samsung_clk_provider * __init samsung_clk_init(struct device *dev,
        if (!ctx)
                panic("could not allocate clock provider context.\n");
 
+       ctx->clk_data.num = nr_clks;
        for (i = 0; i < nr_clks; ++i)
                ctx->clk_data.hws[i] = ERR_PTR(-ENOENT);
 
        ctx->dev = dev;
        ctx->reg_base = base;
-       ctx->clk_data.num = nr_clks;
        spin_lock_init(&ctx->lock);
 
        return ctx;