2023-09-18 21:49:24

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1 1/1] gpiolib: cdev: Annotate struct linereq 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 checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/gpio/gpiolib-cdev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c
index a5bbbd44531f..e23f06f58234 100644
--- a/drivers/gpio/gpiolib-cdev.c
+++ b/drivers/gpio/gpiolib-cdev.c
@@ -572,7 +572,7 @@ struct linereq {
DECLARE_KFIFO_PTR(events, struct gpio_v2_line_event);
atomic_t seqno;
struct mutex config_mutex;
- struct line lines[];
+ struct line lines[] __counted_by(num_lines);
};

#define GPIO_V2_LINE_BIAS_FLAGS \
--
2.40.0.1.gaa8946217a0b


2023-09-25 07:10:50

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] gpiolib: cdev: Annotate struct linereq with __counted_by()

On Mon, Sep 18, 2023 at 12:15:53PM +0300, Andy Shevchenko 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 checking via CONFIG_UBSAN_BOUNDS
> (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).

Kees' patch is better, please ignore this one.

--
With Best Regards,
Andy Shevchenko


2023-09-25 21:03:46

by Kees Cook

[permalink] [raw]
Subject: Re: [PATCH v1 1/1] gpiolib: cdev: Annotate struct linereq with __counted_by()

On Mon, Sep 25, 2023 at 09:54:34AM +0300, Andy Shevchenko wrote:
> On Mon, Sep 18, 2023 at 12:15:53PM +0300, Andy Shevchenko 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 checking via CONFIG_UBSAN_BOUNDS
> > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions).
>
> Kees' patch is better, please ignore this one.

Oh! I didn't get CCed so I didn't know you'd sent this. :)

Thanks for taking the initiative on this, though! (But, yes,
initialization order matters.)

--
Kees Cook