Skip to content

Commit

Permalink
io_uring: Replace 0-length array with flexible array
Browse files Browse the repository at this point in the history
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: c7fb194 ("io_uring: add support for ring mapped supplied buffers")
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Pavel Begunkov <asml.silence@gmail.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: stable@vger.kernel.org
Cc: io-uring@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
kees authored and intel-lab-lkp committed Jan 5, 2023
1 parent 88603b6 commit 6239ffe
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion include/uapi/linux/io_uring.h
Expand Up @@ -625,7 +625,7 @@ struct io_uring_buf_ring {
__u16 resv3;
__u16 tail;
};
struct io_uring_buf bufs[0];
struct io_uring_buf bufs[];
};
};

Expand Down

0 comments on commit 6239ffe

Please sign in to comment.