Skip to content

Commit 7ea2432

Browse files
isilenceaxboe
authored andcommitted
io_uring/query: cap number of queries
If a query chain forms a cycle, it'll be looping in the kernel until the process is killed. It might be fine as any such mistake can be easily uncovered during testing, but it's still nicer to let it break out of the syscall if it executed too many queries. Suggested-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2408d17 commit 7ea2432

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

io_uring/query.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "io_uring.h"
77

88
#define IO_MAX_QUERY_SIZE (sizeof(struct io_uring_query_opcode))
9+
#define IO_MAX_QUERY_ENTRIES 1000
910

1011
static ssize_t io_query_ops(void *data)
1112
{
@@ -74,7 +75,7 @@ int io_query(struct io_ring_ctx *ctx, void __user *arg, unsigned nr_args)
7475
{
7576
char entry_buffer[IO_MAX_QUERY_SIZE];
7677
void __user *uhdr = arg;
77-
int ret;
78+
int ret, nr = 0;
7879

7980
memset(entry_buffer, 0, sizeof(entry_buffer));
8081

@@ -89,6 +90,9 @@ int io_query(struct io_ring_ctx *ctx, void __user *arg, unsigned nr_args)
8990
return ret;
9091
uhdr = u64_to_user_ptr(next_hdr);
9192

93+
/* Have some limit to avoid a potential cycle */
94+
if (++nr >= IO_MAX_QUERY_ENTRIES)
95+
return -ERANGE;
9296
if (fatal_signal_pending(current))
9397
return -EINTR;
9498
cond_resched();

0 commit comments

Comments
 (0)