* [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
@ 2023-10-06 20:17 ` Kees Cook
0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2023-10-06 20:17 UTC (permalink / raw)
To: Tomasz Figa
Cc: Kees Cook, Krzysztof Kozlowski, Sylwester Nawrocki, Alim Akhtar,
Linus Walleij, Gustavo A. R. Silva, linux-arm-kernel,
linux-samsung-soc, linux-gpio, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).
As found with Coccinelle[1], add __counted_by for struct
exynos_muxed_weint_data. Additionally, since the element count member
must be set before accessing the annotated flexible array member, move
its initialization earlier.
Cc: Tomasz Figa <tomasz.figa@gmail.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: linux-gpio@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +-
drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
index a8212fc126bf..6b58ec84e34b 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
@@ -616,6 +616,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
+ muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
if (!muxed_data)
return -ENOMEM;
+ muxed_data->nr_banks = muxed_banks;
irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31,
muxed_data);
@@ -628,7 +629,6 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
muxed_data->banks[idx++] = bank;
}
- muxed_data->nr_banks = muxed_banks;
return 0;
}
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.h b/drivers/pinctrl/samsung/pinctrl-exynos.h
index 7bd6d82c9f36..3ac52c2cf998 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos.h
+++ b/drivers/pinctrl/samsung/pinctrl-exynos.h
@@ -159,7 +159,7 @@ struct exynos_weint_data {
*/
struct exynos_muxed_weint_data {
unsigned int nr_banks;
- struct samsung_pin_bank *banks[];
+ struct samsung_pin_bank *banks[] __counted_by(nr_banks);
};
int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d);
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
@ 2023-10-06 20:17 ` Kees Cook
0 siblings, 0 replies; 6+ messages in thread
From: Kees Cook @ 2023-10-06 20:17 UTC (permalink / raw)
To: Tomasz Figa
Cc: Kees Cook, Krzysztof Kozlowski, Sylwester Nawrocki, Alim Akhtar,
Linus Walleij, Gustavo A. R. Silva, linux-arm-kernel,
linux-samsung-soc, linux-gpio, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).
As found with Coccinelle[1], add __counted_by for struct
exynos_muxed_weint_data. Additionally, since the element count member
must be set before accessing the annotated flexible array member, move
its initialization earlier.
Cc: Tomasz Figa <tomasz.figa@gmail.com>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-samsung-soc@vger.kernel.org
Cc: linux-gpio@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +-
drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
index a8212fc126bf..6b58ec84e34b 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos.c
+++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
@@ -616,6 +616,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
+ muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
if (!muxed_data)
return -ENOMEM;
+ muxed_data->nr_banks = muxed_banks;
irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31,
muxed_data);
@@ -628,7 +629,6 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
muxed_data->banks[idx++] = bank;
}
- muxed_data->nr_banks = muxed_banks;
return 0;
}
diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.h b/drivers/pinctrl/samsung/pinctrl-exynos.h
index 7bd6d82c9f36..3ac52c2cf998 100644
--- a/drivers/pinctrl/samsung/pinctrl-exynos.h
+++ b/drivers/pinctrl/samsung/pinctrl-exynos.h
@@ -159,7 +159,7 @@ struct exynos_weint_data {
*/
struct exynos_muxed_weint_data {
unsigned int nr_banks;
- struct samsung_pin_bank *banks[];
+ struct samsung_pin_bank *banks[] __counted_by(nr_banks);
};
int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d);
--
2.34.1
_______________________________________________
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] 6+ messages in thread
* Re: [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
2023-10-06 20:17 ` Kees Cook
@ 2023-10-06 20:50 ` Gustavo A. R. Silva
-1 siblings, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-06 20:50 UTC (permalink / raw)
To: Kees Cook, Tomasz Figa
Cc: Krzysztof Kozlowski, Sylwester Nawrocki, Alim Akhtar,
Linus Walleij, Gustavo A. R. Silva, linux-arm-kernel,
linux-samsung-soc, linux-gpio, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
On 10/6/23 22:17, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct
> exynos_muxed_weint_data. Additionally, since the element count member
> must be set before accessing the annotated flexible array member, move
> its initialization earlier.
>
> Cc: Tomasz Figa <tomasz.figa@gmail.com>
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Cc: Alim Akhtar <alim.akhtar@samsung.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-samsung-soc@vger.kernel.org
> Cc: linux-gpio@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks!
--
Gustavo
> ---
> drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +-
> drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
> index a8212fc126bf..6b58ec84e34b 100644
> --- a/drivers/pinctrl/samsung/pinctrl-exynos.c
> +++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
> @@ -616,6 +616,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
> + muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
> if (!muxed_data)
> return -ENOMEM;
> + muxed_data->nr_banks = muxed_banks;
>
> irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31,
> muxed_data);
> @@ -628,7 +629,6 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
>
> muxed_data->banks[idx++] = bank;
> }
> - muxed_data->nr_banks = muxed_banks;
>
> return 0;
> }
> diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.h b/drivers/pinctrl/samsung/pinctrl-exynos.h
> index 7bd6d82c9f36..3ac52c2cf998 100644
> --- a/drivers/pinctrl/samsung/pinctrl-exynos.h
> +++ b/drivers/pinctrl/samsung/pinctrl-exynos.h
> @@ -159,7 +159,7 @@ struct exynos_weint_data {
> */
> struct exynos_muxed_weint_data {
> unsigned int nr_banks;
> - struct samsung_pin_bank *banks[];
> + struct samsung_pin_bank *banks[] __counted_by(nr_banks);
> };
>
> int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
@ 2023-10-06 20:50 ` Gustavo A. R. Silva
0 siblings, 0 replies; 6+ messages in thread
From: Gustavo A. R. Silva @ 2023-10-06 20:50 UTC (permalink / raw)
To: Kees Cook, Tomasz Figa
Cc: Krzysztof Kozlowski, Sylwester Nawrocki, Alim Akhtar,
Linus Walleij, Gustavo A. R. Silva, linux-arm-kernel,
linux-samsung-soc, linux-gpio, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
On 10/6/23 22:17, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct
> exynos_muxed_weint_data. Additionally, since the element count member
> must be set before accessing the annotated flexible array member, move
> its initialization earlier.
>
> Cc: Tomasz Figa <tomasz.figa@gmail.com>
> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
> Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Cc: Alim Akhtar <alim.akhtar@samsung.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: linux-samsung-soc@vger.kernel.org
> Cc: linux-gpio@vger.kernel.org
> Cc: linux-hardening@vger.kernel.org
> Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thanks!
--
Gustavo
> ---
> drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +-
> drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +-
> 2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.c b/drivers/pinctrl/samsung/pinctrl-exynos.c
> index a8212fc126bf..6b58ec84e34b 100644
> --- a/drivers/pinctrl/samsung/pinctrl-exynos.c
> +++ b/drivers/pinctrl/samsung/pinctrl-exynos.c
> @@ -616,6 +616,7 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
> + muxed_banks*sizeof(struct samsung_pin_bank *), GFP_KERNEL);
> if (!muxed_data)
> return -ENOMEM;
> + muxed_data->nr_banks = muxed_banks;
>
> irq_set_chained_handler_and_data(irq, exynos_irq_demux_eint16_31,
> muxed_data);
> @@ -628,7 +629,6 @@ __init int exynos_eint_wkup_init(struct samsung_pinctrl_drv_data *d)
>
> muxed_data->banks[idx++] = bank;
> }
> - muxed_data->nr_banks = muxed_banks;
>
> return 0;
> }
> diff --git a/drivers/pinctrl/samsung/pinctrl-exynos.h b/drivers/pinctrl/samsung/pinctrl-exynos.h
> index 7bd6d82c9f36..3ac52c2cf998 100644
> --- a/drivers/pinctrl/samsung/pinctrl-exynos.h
> +++ b/drivers/pinctrl/samsung/pinctrl-exynos.h
> @@ -159,7 +159,7 @@ struct exynos_weint_data {
> */
> struct exynos_muxed_weint_data {
> unsigned int nr_banks;
> - struct samsung_pin_bank *banks[];
> + struct samsung_pin_bank *banks[] __counted_by(nr_banks);
> };
>
> int exynos_eint_gpio_init(struct samsung_pinctrl_drv_data *d);
_______________________________________________
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] 6+ messages in thread
* Re: [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
2023-10-06 20:17 ` Kees Cook
@ 2023-10-08 11:37 ` Krzysztof Kozlowski
-1 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2023-10-08 11:37 UTC (permalink / raw)
To: Tomasz Figa, Kees Cook
Cc: Krzysztof Kozlowski, Sylwester Nawrocki, Alim Akhtar,
Linus Walleij, Gustavo A. R. Silva, linux-arm-kernel,
linux-samsung-soc, linux-gpio, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
On Fri, 06 Oct 2023 13:17:07 -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct
> exynos_muxed_weint_data. Additionally, since the element count member
> must be set before accessing the annotated flexible array member, move
> its initialization earlier.
>
> [...]
Applied, thanks!
[1/1] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
https://git.kernel.org/pinctrl/samsung/c/4e1e21117e7e1275477ba80e634c769a511249bd
Best regards,
--
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
@ 2023-10-08 11:37 ` Krzysztof Kozlowski
0 siblings, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2023-10-08 11:37 UTC (permalink / raw)
To: Tomasz Figa, Kees Cook
Cc: Krzysztof Kozlowski, Sylwester Nawrocki, Alim Akhtar,
Linus Walleij, Gustavo A. R. Silva, linux-arm-kernel,
linux-samsung-soc, linux-gpio, linux-hardening,
Nathan Chancellor, Nick Desaulniers, Tom Rix, linux-kernel, llvm
On Fri, 06 Oct 2023 13:17:07 -0700, Kees Cook wrote:
> Prepare for the coming implementation by GCC and Clang of the __counted_by
> attribute. Flexible array members annotated with __counted_by can have
> their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for
> array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
> functions).
>
> As found with Coccinelle[1], add __counted_by for struct
> exynos_muxed_weint_data. Additionally, since the element count member
> must be set before accessing the annotated flexible array member, move
> its initialization earlier.
>
> [...]
Applied, thanks!
[1/1] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
https://git.kernel.org/pinctrl/samsung/c/4e1e21117e7e1275477ba80e634c769a511249bd
Best regards,
--
Krzysztof Kozlowski <krzysztof.kozlowski@linaro.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] 6+ messages in thread
end of thread, other threads:[~2023-10-08 11:38 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-06 20:17 [PATCH] pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by Kees Cook
2023-10-06 20:17 ` Kees Cook
2023-10-06 20:50 ` Gustavo A. R. Silva
2023-10-06 20:50 ` Gustavo A. R. Silva
2023-10-08 11:37 ` Krzysztof Kozlowski
2023-10-08 11:37 ` Krzysztof Kozlowski
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.