Skip to content

Commit 3232dd0

Browse files
isilenceaxboe
authored andcommitted
io_uring: fix {SQ,IO}POLL with unsupported opcodes
IORING_SETUP_IOPOLL is defined only for read/write, other opcodes should be disallowed, otherwise it'll get an error as below. Also refuse open/close with SQPOLL, as the polling thread wouldn't know which file table to use. RIP: 0010:io_iopoll_getevents+0x111/0x5a0 Call Trace: ? _raw_spin_unlock_irqrestore+0x24/0x40 ? do_send_sig_info+0x64/0x90 io_iopoll_reap_events.part.0+0x5e/0xa0 io_ring_ctx_wait_and_kill+0x132/0x1c0 io_uring_release+0x20/0x30 __fput+0xcd/0x230 ____fput+0xe/0x10 task_work_run+0x67/0xa0 do_exit+0x353/0xb10 ? handle_mm_fault+0xd4/0x200 ? syscall_trace_enter+0x18c/0x2c0 do_group_exit+0x43/0xa0 __x64_sys_exit_group+0x18/0x20 do_syscall_64+0x60/0x1e0 entry_SYSCALL_64_after_hwframe+0x44/0xa9 Signed-off-by: Pavel Begunkov <[email protected]> [axboe: allow provide/remove buffers and files update] Signed-off-by: Jens Axboe <[email protected]>
1 parent fd2206e commit 3232dd0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

fs/io_uring.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2766,6 +2766,8 @@ static int __io_splice_prep(struct io_kiocb *req,
27662766

27672767
if (req->flags & REQ_F_NEED_CLEANUP)
27682768
return 0;
2769+
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
2770+
return -EINVAL;
27692771

27702772
sp->file_in = NULL;
27712773
sp->len = READ_ONCE(sqe->len);
@@ -2966,6 +2968,8 @@ static int io_fallocate_prep(struct io_kiocb *req,
29662968
{
29672969
if (sqe->ioprio || sqe->buf_index || sqe->rw_flags)
29682970
return -EINVAL;
2971+
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
2972+
return -EINVAL;
29692973

29702974
req->sync.off = READ_ONCE(sqe->off);
29712975
req->sync.len = READ_ONCE(sqe->addr);
@@ -2991,6 +2995,8 @@ static int io_openat_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
29912995
const char __user *fname;
29922996
int ret;
29932997

2998+
if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
2999+
return -EINVAL;
29943000
if (sqe->ioprio || sqe->buf_index)
29953001
return -EINVAL;
29963002
if (req->flags & REQ_F_FIXED_FILE)
@@ -3024,6 +3030,8 @@ static int io_openat2_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
30243030
size_t len;
30253031
int ret;
30263032

3033+
if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
3034+
return -EINVAL;
30273035
if (sqe->ioprio || sqe->buf_index)
30283036
return -EINVAL;
30293037
if (req->flags & REQ_F_FIXED_FILE)
@@ -3263,6 +3271,8 @@ static int io_epoll_ctl_prep(struct io_kiocb *req,
32633271
#if defined(CONFIG_EPOLL)
32643272
if (sqe->ioprio || sqe->buf_index)
32653273
return -EINVAL;
3274+
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
3275+
return -EINVAL;
32663276

32673277
req->epoll.epfd = READ_ONCE(sqe->fd);
32683278
req->epoll.op = READ_ONCE(sqe->len);
@@ -3307,6 +3317,8 @@ static int io_madvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
33073317
#if defined(CONFIG_ADVISE_SYSCALLS) && defined(CONFIG_MMU)
33083318
if (sqe->ioprio || sqe->buf_index || sqe->off)
33093319
return -EINVAL;
3320+
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
3321+
return -EINVAL;
33103322

33113323
req->madvise.addr = READ_ONCE(sqe->addr);
33123324
req->madvise.len = READ_ONCE(sqe->len);
@@ -3341,6 +3353,8 @@ static int io_fadvise_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
33413353
{
33423354
if (sqe->ioprio || sqe->buf_index || sqe->addr)
33433355
return -EINVAL;
3356+
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
3357+
return -EINVAL;
33443358

33453359
req->fadvise.offset = READ_ONCE(sqe->off);
33463360
req->fadvise.len = READ_ONCE(sqe->len);
@@ -3374,6 +3388,8 @@ static int io_fadvise(struct io_kiocb *req, bool force_nonblock)
33743388

33753389
static int io_statx_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
33763390
{
3391+
if (unlikely(req->ctx->flags & IORING_SETUP_IOPOLL))
3392+
return -EINVAL;
33773393
if (sqe->ioprio || sqe->buf_index)
33783394
return -EINVAL;
33793395
if (req->flags & REQ_F_FIXED_FILE)
@@ -3418,6 +3434,8 @@ static int io_close_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
34183434
*/
34193435
req->work.flags |= IO_WQ_WORK_NO_CANCEL;
34203436

3437+
if (unlikely(req->ctx->flags & (IORING_SETUP_IOPOLL|IORING_SETUP_SQPOLL)))
3438+
return -EINVAL;
34213439
if (sqe->ioprio || sqe->off || sqe->addr || sqe->len ||
34223440
sqe->rw_flags || sqe->buf_index)
34233441
return -EINVAL;

0 commit comments

Comments
 (0)