pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
Subsystems (4)
PATCH 1/1 pinctrl: samsung: Annotate struct exynos_muxed_weint_data with __counted_by
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.
--- drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +- drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/samsung/pinctrl-exynos.c +1 -1
@@ -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 ; }
drivers/pinctrl/samsung/pinctrl-exynos.h +1 -1
@@ -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);
Signature · 1 line
2.34.1
Quoted 11 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).As found with Coccinelle[1], add
__counted_byfor structexynos_muxed_weint_data. Additionally, since the element count member must be set before accessing the annotated flexible array member, move its initialization earlier.
Quoted 12 lines
Cc Tomasz Figa <[email protected]>Cc Krzysztof Kozlowski <[email protected]>Cc Sylwester Nawrocki <[email protected]>Cc Alim Akhtar <[email protected]>Cc Linus Walleij <[email protected]>Cc "Gustavo A. R. Silva" <[email protected]>Signed-off-by Kees Cook <[email protected]>
Thanks!
Signature · 1 line
Gustavo
Quoted 38 lines
--- drivers/pinctrl/samsung/pinctrl-exynos.c | 2 +- drivers/pinctrl/samsung/pinctrl-exynos.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/pinctrl/samsung/pinctrl-exynos.c +1
-1@@ -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 ; }drivers/pinctrl/samsung/pinctrl-exynos.h +1
-1@@ -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);
Krzysztof Kozlowski
AppliedQuoted 6 lines · Kees Cook
Prepare for the coming implementation by GCC and Clang of the
__counted_byattribute. Flexible array members annotated with__counted_bycan have their accesses bounds-checked at run-time viaCONFIG_UBSAN_BOUNDS(for array indexing) andCONFIG_FORTIFY_SOURCE(for strcpy/memcpy-family functions).
Quoted 6 lines
As found with Coccinelle[1], add
__counted_byfor structexynos_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,
Signature · 1 line
Krzysztof Kozlowski <[email protected]>