* [PATCH] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe()
@ 2025-03-26 12:08 André Draszik
2025-03-26 14:12 ` Krzysztof Kozlowski
2025-05-08 21:01 ` Stephen Boyd
0 siblings, 2 replies; 3+ messages in thread
From: André Draszik @ 2025-03-26 12:08 UTC (permalink / raw)
To: Krzysztof Kozlowski, Michael Turquette, Stephen Boyd, Kees Cook,
Gustavo A. R. Silva
Cc: linux-kernel, linux-samsung-soc, linux-clk, linux-hardening,
stable, André Draszik
With UBSAN enabled, we're getting the following trace:
UBSAN: array-index-out-of-bounds in .../drivers/clk/clk-s2mps11.c:186:3
index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]')
This is because commit f316cdff8d67 ("clk: Annotate struct
clk_hw_onecell_data with __counted_by") annotated the hws member of
that struct with __counted_by, which informs the bounds sanitizer about
the number of elements in hws, so that it can warn when hws is accessed
out of bounds.
As noted in that change, the __counted_by member must be initialised
with the number of elements before the first array access happens,
otherwise there will be a warning from each access prior to the
initialisation because the number of elements is zero. This occurs in
s2mps11_clk_probe() due to ::num being assigned after ::hws access.
Move the assignment to satisfy the requirement of assign-before-access.
Cc: stable@vger.kernel.org
Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/clk/clk-s2mps11.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/clk/clk-s2mps11.c b/drivers/clk/clk-s2mps11.c
index 014db6386624071e173b5b940466301d2596400a..8ddf3a9a53dfd5bb52a05a3e02788a357ea77ad3 100644
--- a/drivers/clk/clk-s2mps11.c
+++ b/drivers/clk/clk-s2mps11.c
@@ -137,6 +137,8 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
if (!clk_data)
return -ENOMEM;
+ clk_data->num = S2MPS11_CLKS_NUM;
+
switch (hwid) {
case S2MPS11X:
s2mps11_reg = S2MPS11_REG_RTC_CTRL;
@@ -186,7 +188,6 @@ static int s2mps11_clk_probe(struct platform_device *pdev)
clk_data->hws[i] = &s2mps11_clks[i].hw;
}
- clk_data->num = S2MPS11_CLKS_NUM;
of_clk_add_hw_provider(s2mps11_clks->clk_np, of_clk_hw_onecell_get,
clk_data);
---
base-commit: 9388ec571cb1adba59d1cded2300eeb11827679c
change-id: 20250326-s2mps11-ubsan-c90978e7bc04
Best regards,
--
André Draszik <andre.draszik@linaro.org>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe()
2025-03-26 12:08 [PATCH] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe() André Draszik
@ 2025-03-26 14:12 ` Krzysztof Kozlowski
2025-05-08 21:01 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2025-03-26 14:12 UTC (permalink / raw)
To: André Draszik, Michael Turquette, Stephen Boyd, Kees Cook,
Gustavo A. R. Silva
Cc: linux-kernel, linux-samsung-soc, linux-clk, linux-hardening,
stable
On 26/03/2025 13:08, André Draszik wrote:
> With UBSAN enabled, we're getting the following trace:
>
> UBSAN: array-index-out-of-bounds in .../drivers/clk/clk-s2mps11.c:186:3
> index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]')
>
> This is because commit f316cdff8d67 ("clk: Annotate struct
> clk_hw_onecell_data with __counted_by") annotated the hws member of
> that struct with __counted_by, which informs the bounds sanitizer about
> the number of elements in hws, so that it can warn when hws is accessed
> out of bounds.
>
> As noted in that change, the __counted_by member must be initialised
> with the number of elements before the first array access happens,
> otherwise there will be a warning from each access prior to the
> initialisation because the number of elements is zero. This occurs in
> s2mps11_clk_probe() due to ::num being assigned after ::hws access.
>
> Move the assignment to satisfy the requirement of assign-before-access.
>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe()
2025-03-26 12:08 [PATCH] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe() André Draszik
2025-03-26 14:12 ` Krzysztof Kozlowski
@ 2025-05-08 21:01 ` Stephen Boyd
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Boyd @ 2025-05-08 21:01 UTC (permalink / raw)
To: André Draszik, Gustavo A. R. Silva, Kees Cook,
Krzysztof Kozlowski, Michael Turquette
Cc: linux-kernel, linux-samsung-soc, linux-clk, linux-hardening,
stable, André Draszik
Quoting André Draszik (2025-03-26 05:08:00)
> With UBSAN enabled, we're getting the following trace:
>
> UBSAN: array-index-out-of-bounds in .../drivers/clk/clk-s2mps11.c:186:3
> index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]')
>
> This is because commit f316cdff8d67 ("clk: Annotate struct
> clk_hw_onecell_data with __counted_by") annotated the hws member of
> that struct with __counted_by, which informs the bounds sanitizer about
> the number of elements in hws, so that it can warn when hws is accessed
> out of bounds.
>
> As noted in that change, the __counted_by member must be initialised
> with the number of elements before the first array access happens,
> otherwise there will be a warning from each access prior to the
> initialisation because the number of elements is zero. This occurs in
> s2mps11_clk_probe() due to ::num being assigned after ::hws access.
>
> Move the assignment to satisfy the requirement of assign-before-access.
>
> Cc: stable@vger.kernel.org
> Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
> Signed-off-by: André Draszik <andre.draszik@linaro.org>
> ---
Applied to clk-fixes
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-05-08 21:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-26 12:08 [PATCH] clk: s2mps11: initialise clk_hw_onecell_data::num before accessing ::hws[] in probe() André Draszik
2025-03-26 14:12 ` Krzysztof Kozlowski
2025-05-08 21:01 ` Stephen Boyd
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox