* [PATCH 0/2] clk: bcm: Move a couple of __counted_by initializations
@ 2024-04-25 16:55 ` Nathan Chancellor
0 siblings, 0 replies; 18+ messages in thread
From: Nathan Chancellor @ 2024-04-25 16:55 UTC (permalink / raw)
To: Michael Turquette, Stephen Boyd, Florian Fainelli
Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list,
linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening,
patches, llvm, stable, Nathan Chancellor
Hi all,
This series addresses two UBSAN warnings I see on my Raspberry Pi 4 with
recent releases of clang that support __counted_by by moving the
initializations of the element count member before any accesses of the
flexible array member.
I marked these for stable because more distributions are enabling the
bounds sanitizer [1][2], so the warnings will show up when the kernel is
built with a compiler that supports __counted_by, so it seems worth
fixing this for future users.
[1]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1914685
[2]: https://src.fedoraproject.org/rpms/kernel/c/79a2207963b8fea452acfc5dea13ed54bd36c7e1
---
Nathan Chancellor (2):
clk: bcm: dvp: Assign ->num before accessing ->hws
clk: bcm: rpi: Assign ->num before accessing ->hws
drivers/clk/bcm/clk-bcm2711-dvp.c | 3 ++-
drivers/clk/bcm/clk-raspberrypi.c | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
---
base-commit: ed30a4a51bb196781c8058073ea720133a65596f
change-id: 20240424-cbl-bcm-assign-counted-by-val-before-access-cf19d630f2b4
Best regards,
--
Nathan Chancellor <nathan@kernel.org>
^ permalink raw reply [flat|nested] 18+ messages in thread* [PATCH 0/2] clk: bcm: Move a couple of __counted_by initializations @ 2024-04-25 16:55 ` Nathan Chancellor 0 siblings, 0 replies; 18+ messages in thread From: Nathan Chancellor @ 2024-04-25 16:55 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Florian Fainelli Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Hi all, This series addresses two UBSAN warnings I see on my Raspberry Pi 4 with recent releases of clang that support __counted_by by moving the initializations of the element count member before any accesses of the flexible array member. I marked these for stable because more distributions are enabling the bounds sanitizer [1][2], so the warnings will show up when the kernel is built with a compiler that supports __counted_by, so it seems worth fixing this for future users. [1]: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1914685 [2]: https://src.fedoraproject.org/rpms/kernel/c/79a2207963b8fea452acfc5dea13ed54bd36c7e1 --- Nathan Chancellor (2): clk: bcm: dvp: Assign ->num before accessing ->hws clk: bcm: rpi: Assign ->num before accessing ->hws drivers/clk/bcm/clk-bcm2711-dvp.c | 3 ++- drivers/clk/bcm/clk-raspberrypi.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) --- base-commit: ed30a4a51bb196781c8058073ea720133a65596f change-id: 20240424-cbl-bcm-assign-counted-by-val-before-access-cf19d630f2b4 Best regards, -- Nathan Chancellor <nathan@kernel.org> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-25 16:55 ` Nathan Chancellor -1 siblings, 0 replies; 18+ messages in thread From: Nathan Chancellor @ 2024-04-25 16:55 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Florian Fainelli Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' 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 initialized with the number of elements before the first array access happens, otherwise there will be a warning from each access prior to the initialization because the number of elements is zero. This occurs in clk_dvp_probe() due to ->num being assigned after ->hws has been accessed: UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') Move the ->num initialization to before the first access of ->hws, which clears up the warning. Cc: stable@vger.kernel.org Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") Signed-off-by: Nathan Chancellor <nathan@kernel.org> --- drivers/clk/bcm/clk-bcm2711-dvp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-bcm2711-dvp.c b/drivers/clk/bcm/clk-bcm2711-dvp.c index e4fbbf3c40fe..3cb235df9d37 100644 --- a/drivers/clk/bcm/clk-bcm2711-dvp.c +++ b/drivers/clk/bcm/clk-bcm2711-dvp.c @@ -56,6 +56,8 @@ static int clk_dvp_probe(struct platform_device *pdev) if (ret) return ret; + data->num = NR_CLOCKS; + data->hws[0] = clk_hw_register_gate_parent_data(&pdev->dev, "hdmi0-108MHz", &clk_dvp_parent, 0, @@ -76,7 +78,6 @@ static int clk_dvp_probe(struct platform_device *pdev) goto unregister_clk0; } - data->num = NR_CLOCKS; ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get, data); if (ret) -- 2.44.0 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws @ 2024-04-25 16:55 ` Nathan Chancellor 0 siblings, 0 replies; 18+ messages in thread From: Nathan Chancellor @ 2024-04-25 16:55 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Florian Fainelli Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' 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 initialized with the number of elements before the first array access happens, otherwise there will be a warning from each access prior to the initialization because the number of elements is zero. This occurs in clk_dvp_probe() due to ->num being assigned after ->hws has been accessed: UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') Move the ->num initialization to before the first access of ->hws, which clears up the warning. Cc: stable@vger.kernel.org Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") Signed-off-by: Nathan Chancellor <nathan@kernel.org> --- drivers/clk/bcm/clk-bcm2711-dvp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-bcm2711-dvp.c b/drivers/clk/bcm/clk-bcm2711-dvp.c index e4fbbf3c40fe..3cb235df9d37 100644 --- a/drivers/clk/bcm/clk-bcm2711-dvp.c +++ b/drivers/clk/bcm/clk-bcm2711-dvp.c @@ -56,6 +56,8 @@ static int clk_dvp_probe(struct platform_device *pdev) if (ret) return ret; + data->num = NR_CLOCKS; + data->hws[0] = clk_hw_register_gate_parent_data(&pdev->dev, "hdmi0-108MHz", &clk_dvp_parent, 0, @@ -76,7 +78,6 @@ static int clk_dvp_probe(struct platform_device *pdev) goto unregister_clk0; } - data->num = NR_CLOCKS; ret = of_clk_add_hw_provider(pdev->dev.of_node, of_clk_hw_onecell_get, data); if (ret) -- 2.44.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-25 17:15 ` Kees Cook -1 siblings, 0 replies; 18+ messages in thread From: Kees Cook @ 2024-04-25 17:15 UTC (permalink / raw) To: Nathan Chancellor Cc: Michael Turquette, Stephen Boyd, Florian Fainelli, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable On Thu, Apr 25, 2024 at 09:55:51AM -0700, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > clk_dvp_probe() due to ->num being assigned after ->hws has been > accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 > index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Thanks for finding this! Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws @ 2024-04-25 17:15 ` Kees Cook 0 siblings, 0 replies; 18+ messages in thread From: Kees Cook @ 2024-04-25 17:15 UTC (permalink / raw) To: Nathan Chancellor Cc: Michael Turquette, Stephen Boyd, Florian Fainelli, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable On Thu, Apr 25, 2024 at 09:55:51AM -0700, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > clk_dvp_probe() due to ->num being assigned after ->hws has been > accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 > index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Thanks for finding this! Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-25 21:26 ` Florian Fainelli -1 siblings, 0 replies; 18+ messages in thread From: Florian Fainelli @ 2024-04-25 21:26 UTC (permalink / raw) To: Nathan Chancellor, Michael Turquette, Stephen Boyd Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable [-- Attachment #1: Type: text/plain, Size: 1231 bytes --] On 4/25/24 09:55, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > clk_dvp_probe() due to ->num being assigned after ->hws has been > accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 > index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> -- Florian [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 4221 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws @ 2024-04-25 21:26 ` Florian Fainelli 0 siblings, 0 replies; 18+ messages in thread From: Florian Fainelli @ 2024-04-25 21:26 UTC (permalink / raw) To: Nathan Chancellor, Michael Turquette, Stephen Boyd Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable [-- Attachment #1.1: Type: text/plain, Size: 1231 bytes --] On 4/25/24 09:55, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > clk_dvp_probe() due to ->num being assigned after ->hws has been > accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 > index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> -- Florian [-- Attachment #1.2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 4221 bytes --] [-- Attachment #2: Type: text/plain, Size: 176 bytes --] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-30 0:04 ` Stephen Boyd -1 siblings, 0 replies; 18+ messages in thread From: Stephen Boyd @ 2024-04-30 0:04 UTC (permalink / raw) To: Florian Fainelli, Michael Turquette, Nathan Chancellor Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Quoting Nathan Chancellor (2024-04-25 09:55:51) > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > clk_dvp_probe() due to ->num being assigned after ->hws has been > accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 > index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > --- Applied to clk-next ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws @ 2024-04-30 0:04 ` Stephen Boyd 0 siblings, 0 replies; 18+ messages in thread From: Stephen Boyd @ 2024-04-30 0:04 UTC (permalink / raw) To: Florian Fainelli, Michael Turquette, Nathan Chancellor Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Quoting Nathan Chancellor (2024-04-25 09:55:51) > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > clk_dvp_probe() due to ->num being assigned after ->hws has been > accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-bcm2711-dvp.c:59:2 > index 0 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > --- Applied to clk-next _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
* [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-25 16:55 ` Nathan Chancellor -1 siblings, 0 replies; 18+ messages in thread From: Nathan Chancellor @ 2024-04-25 16:55 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Florian Fainelli Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' 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 initialized with the number of elements before the first array access happens, otherwise there will be a warning from each access prior to the initialization because the number of elements is zero. This occurs in raspberrypi_discover_clocks() due to ->num being assigned after ->hws has been accessed: UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') Move the ->num initialization to before the first access of ->hws, which clears up the warning. Cc: stable@vger.kernel.org Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") Signed-off-by: Nathan Chancellor <nathan@kernel.org> --- drivers/clk/bcm/clk-raspberrypi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index 829406dc44a2..4d411408e4af 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -371,8 +371,8 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi, if (IS_ERR(hw)) return PTR_ERR(hw); - data->hws[clks->id] = hw; data->num = clks->id + 1; + data->hws[clks->id] = hw; } clks++; -- 2.44.0 ^ permalink raw reply related [flat|nested] 18+ messages in thread
* [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws @ 2024-04-25 16:55 ` Nathan Chancellor 0 siblings, 0 replies; 18+ messages in thread From: Nathan Chancellor @ 2024-04-25 16:55 UTC (permalink / raw) To: Michael Turquette, Stephen Boyd, Florian Fainelli Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' 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 initialized with the number of elements before the first array access happens, otherwise there will be a warning from each access prior to the initialization because the number of elements is zero. This occurs in raspberrypi_discover_clocks() due to ->num being assigned after ->hws has been accessed: UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') Move the ->num initialization to before the first access of ->hws, which clears up the warning. Cc: stable@vger.kernel.org Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") Signed-off-by: Nathan Chancellor <nathan@kernel.org> --- drivers/clk/bcm/clk-raspberrypi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/bcm/clk-raspberrypi.c b/drivers/clk/bcm/clk-raspberrypi.c index 829406dc44a2..4d411408e4af 100644 --- a/drivers/clk/bcm/clk-raspberrypi.c +++ b/drivers/clk/bcm/clk-raspberrypi.c @@ -371,8 +371,8 @@ static int raspberrypi_discover_clocks(struct raspberrypi_clk *rpi, if (IS_ERR(hw)) return PTR_ERR(hw); - data->hws[clks->id] = hw; data->num = clks->id + 1; + data->hws[clks->id] = hw; } clks++; -- 2.44.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-25 17:15 ` Kees Cook -1 siblings, 0 replies; 18+ messages in thread From: Kees Cook @ 2024-04-25 17:15 UTC (permalink / raw) To: Nathan Chancellor Cc: Michael Turquette, Stephen Boyd, Florian Fainelli, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable On Thu, Apr 25, 2024 at 09:55:52AM -0700, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > raspberrypi_discover_clocks() due to ->num being assigned after ->hws > has been accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 > index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Looks good; thanks! Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws @ 2024-04-25 17:15 ` Kees Cook 0 siblings, 0 replies; 18+ messages in thread From: Kees Cook @ 2024-04-25 17:15 UTC (permalink / raw) To: Nathan Chancellor Cc: Michael Turquette, Stephen Boyd, Florian Fainelli, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable On Thu, Apr 25, 2024 at 09:55:52AM -0700, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > raspberrypi_discover_clocks() due to ->num being assigned after ->hws > has been accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 > index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Looks good; thanks! Reviewed-by: Kees Cook <keescook@chromium.org> -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-25 21:26 ` Florian Fainelli -1 siblings, 0 replies; 18+ messages in thread From: Florian Fainelli @ 2024-04-25 21:26 UTC (permalink / raw) To: Nathan Chancellor, Michael Turquette, Stephen Boyd Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable [-- Attachment #1: Type: text/plain, Size: 1246 bytes --] On 4/25/24 09:55, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > raspberrypi_discover_clocks() due to ->num being assigned after ->hws > has been accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 > index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> -- Florian [-- Attachment #2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 4221 bytes --] ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws @ 2024-04-25 21:26 ` Florian Fainelli 0 siblings, 0 replies; 18+ messages in thread From: Florian Fainelli @ 2024-04-25 21:26 UTC (permalink / raw) To: Nathan Chancellor, Michael Turquette, Stephen Boyd Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable [-- Attachment #1.1: Type: text/plain, Size: 1246 bytes --] On 4/25/24 09:55, Nathan Chancellor wrote: > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > raspberrypi_discover_clocks() due to ->num being assigned after ->hws > has been accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 > index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com> -- Florian [-- Attachment #1.2: S/MIME Cryptographic Signature --] [-- Type: application/pkcs7-signature, Size: 4221 bytes --] [-- Attachment #2: Type: text/plain, Size: 176 bytes --] _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws 2024-04-25 16:55 ` Nathan Chancellor @ 2024-04-30 0:04 ` Stephen Boyd -1 siblings, 0 replies; 18+ messages in thread From: Stephen Boyd @ 2024-04-30 0:04 UTC (permalink / raw) To: Florian Fainelli, Michael Turquette, Nathan Chancellor Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Quoting Nathan Chancellor (2024-04-25 09:55:52) > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > raspberrypi_discover_clocks() due to ->num being assigned after ->hws > has been accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 > index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > --- Applied to clk-next ^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [PATCH 2/2] clk: bcm: rpi: Assign ->num before accessing ->hws @ 2024-04-30 0:04 ` Stephen Boyd 0 siblings, 0 replies; 18+ messages in thread From: Stephen Boyd @ 2024-04-30 0:04 UTC (permalink / raw) To: Florian Fainelli, Michael Turquette, Nathan Chancellor Cc: Kees Cook, Gustavo A. R. Silva, bcm-kernel-feedback-list, linux-clk, linux-rpi-kernel, linux-arm-kernel, linux-hardening, patches, llvm, stable, Nathan Chancellor Quoting Nathan Chancellor (2024-04-25 09:55:52) > Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with > __counted_by") annotated the hws member of 'struct clk_hw_onecell_data' > 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 > initialized with the number of elements before the first array access > happens, otherwise there will be a warning from each access prior to the > initialization because the number of elements is zero. This occurs in > raspberrypi_discover_clocks() due to ->num being assigned after ->hws > has been accessed: > > UBSAN: array-index-out-of-bounds in drivers/clk/bcm/clk-raspberrypi.c:374:4 > index 3 is out of range for type 'struct clk_hw *[] __counted_by(num)' (aka 'struct clk_hw *[]') > > Move the ->num initialization to before the first access of ->hws, which > clears up the warning. > > Cc: stable@vger.kernel.org > Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by") > Signed-off-by: Nathan Chancellor <nathan@kernel.org> > --- Applied to clk-next _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2024-04-30 0:05 UTC | newest] Thread overview: 18+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-04-25 16:55 [PATCH 0/2] clk: bcm: Move a couple of __counted_by initializations Nathan Chancellor 2024-04-25 16:55 ` Nathan Chancellor 2024-04-25 16:55 ` [PATCH 1/2] clk: bcm: dvp: Assign ->num before accessing ->hws Nathan Chancellor 2024-04-25 16:55 ` Nathan Chancellor 2024-04-25 17:15 ` Kees Cook 2024-04-25 17:15 ` Kees Cook 2024-04-25 21:26 ` Florian Fainelli 2024-04-25 21:26 ` Florian Fainelli 2024-04-30 0:04 ` Stephen Boyd 2024-04-30 0:04 ` Stephen Boyd 2024-04-25 16:55 ` [PATCH 2/2] clk: bcm: rpi: " Nathan Chancellor 2024-04-25 16:55 ` Nathan Chancellor 2024-04-25 17:15 ` Kees Cook 2024-04-25 17:15 ` Kees Cook 2024-04-25 21:26 ` Florian Fainelli 2024-04-25 21:26 ` Florian Fainelli 2024-04-30 0:04 ` Stephen Boyd 2024-04-30 0:04 ` Stephen Boyd
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.