Re: [PATCH] io_uring: Replace 0-length array with flexible array

From: Kees Cook
Date: Thu Jan 05 2023 - 15:01:46 EST


[resend -- I failed to CC the thread]

On Thu, Jan 05, 2023 at 08:38:01PM +0100, Greg KH wrote:
> On Thu, Jan 05, 2023 at 10:04:19AM -0800, Kees Cook wrote:
> > On Thu, Jan 05, 2023 at 08:39:48AM +0100, Greg KH wrote:
> > > On Wed, Jan 04, 2023 at 07:37:48PM -0800, Kees Cook wrote:
> > > > Zero-length arrays are deprecated[1]. Replace struct io_uring_buf_ring's
> > > > "bufs" with a flexible array member. (How is the size of this array
> > > > verified?) Detected with GCC 13, using -fstrict-flex-arrays=3:
> > > >
> > > > In function 'io_ring_buffer_select',
> > > > inlined from 'io_buffer_select' at io_uring/kbuf.c:183:10:
> > > > io_uring/kbuf.c:141:23: warning: array subscript 255 is outside the bounds of an interior zero-length array 'struct io_uring_buf[0]' [-Wzero-length-bounds]
> > > > 141 | buf = &br->bufs[head];
> > > > | ^~~~~~~~~~~~~~~
> > > > In file included from include/linux/io_uring.h:7,
> > > > from io_uring/kbuf.c:10:
> > > > include/uapi/linux/io_uring.h: In function 'io_buffer_select':
> > > > include/uapi/linux/io_uring.h:628:41: note: while referencing 'bufs'
> > > > 628 | struct io_uring_buf bufs[0];
> > > > | ^~~~
> > > >
> > > > [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#zero-length-and-one-element-arrays
> > > >
> > > > Fixes: c7fb19428d67 ("io_uring: add support for ring mapped supplied buffers")
> > > > Cc: Jens Axboe <axboe@xxxxxxxxx>
> > > > Cc: Pavel Begunkov <asml.silence@xxxxxxxxx>
> > > > Cc: "Gustavo A. R. Silva" <gustavoars@xxxxxxxxxx>
> > > > Cc: stable@xxxxxxxxxxxxxxx
> > >
> > > Build problem aside, why is this a stable kernel issue?
> >
> > My thinking was that since this is technically a UAPI change, it'd be
> > best to get it changed as widely as possible.
>
> You can't break the uapi, so it should be the same with or without your
> change right?
>
> confused,

Correct -- but we've had a hard time finding breakages (with extremely
weird stuff like non-C .h file scrapers) due to the lag between making
UAPI changes like this.

Anyway, I can drop the CC stable if it's more sensible.

--
Kees Cook