Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

io_uring/query: buffer size calculations with a union

Instead of having an array of a calculated size as a buffer, put all
query uapi structures into a union and pass that around. That way
everything is well typed, and the compiler will prevent opcode handling
using a structure not accounted into the buffer size.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Pavel Begunkov and committed by
Jens Axboe
21bd7b14 b6c5f945

+11 -9
+11 -9
io_uring/query.c
··· 5 5 #include "query.h" 6 6 #include "io_uring.h" 7 7 8 - #define IO_MAX_QUERY_SIZE (sizeof(struct io_uring_query_opcode)) 8 + union io_query_data { 9 + struct io_uring_query_opcode opcodes; 10 + }; 11 + 12 + #define IO_MAX_QUERY_SIZE sizeof(union io_query_data) 9 13 #define IO_MAX_QUERY_ENTRIES 1000 10 14 11 - static ssize_t io_query_ops(void *data) 15 + static ssize_t io_query_ops(union io_query_data *data) 12 16 { 13 - struct io_uring_query_opcode *e = data; 14 - 15 - BUILD_BUG_ON(sizeof(*e) > IO_MAX_QUERY_SIZE); 17 + struct io_uring_query_opcode *e = &data->opcodes; 16 18 17 19 e->nr_request_opcodes = IORING_OP_LAST; 18 20 e->nr_register_opcodes = IORING_REGISTER_LAST; ··· 26 24 } 27 25 28 26 static int io_handle_query_entry(struct io_ring_ctx *ctx, 29 - void *data, void __user *uhdr, 27 + union io_query_data *data, void __user *uhdr, 30 28 u64 *next_entry) 31 29 { 32 30 struct io_uring_query_hdr hdr; ··· 75 73 76 74 int io_query(struct io_ring_ctx *ctx, void __user *arg, unsigned nr_args) 77 75 { 78 - char entry_buffer[IO_MAX_QUERY_SIZE]; 76 + union io_query_data entry_buffer; 79 77 void __user *uhdr = arg; 80 78 int ret, nr = 0; 81 79 82 - memset(entry_buffer, 0, sizeof(entry_buffer)); 80 + memset(&entry_buffer, 0, sizeof(entry_buffer)); 83 81 84 82 if (nr_args) 85 83 return -EINVAL; ··· 87 85 while (uhdr) { 88 86 u64 next_hdr; 89 87 90 - ret = io_handle_query_entry(ctx, entry_buffer, uhdr, &next_hdr); 88 + ret = io_handle_query_entry(ctx, &entry_buffer, uhdr, &next_hdr); 91 89 if (ret) 92 90 return ret; 93 91 uhdr = u64_to_user_ptr(next_hdr);