Skip to content

Commit 85a5830

Browse files
Reodusaxboe
authored andcommitted
io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP
io_async_cancel_prep() reads the opcode selector from sqe->len and stores it in cancel->opcode, which is an 8-bit field. Since sqe->len is a 32-bit value, values larger than U8_MAX are implicitly truncated. This can cause unintended opcode matches when the truncated value corresponds to a valid io_uring opcode. For example, submitting a value such as 0x10b will be truncated to 0x0b (IORING_OP_TIMEOUT), allowing a cancel request to match operations it did not intend to target. Validate the opcode value before assigning it to the 8-bit field and reject values outside the valid io_uring opcode range. Signed-off-by: Amir Mohammad Jahangirzad <a.jahangirzad@gmail.com> Link: https://patch.msgid.link/20260331232113.615972-1-a.jahangirzad@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 19a8cc6 commit 85a5830

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

io_uring/cancel.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,16 @@ int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
156156
cancel->fd = READ_ONCE(sqe->fd);
157157
}
158158
if (cancel->flags & IORING_ASYNC_CANCEL_OP) {
159+
u32 op;
160+
159161
if (cancel->flags & IORING_ASYNC_CANCEL_ANY)
160162
return -EINVAL;
161-
cancel->opcode = READ_ONCE(sqe->len);
163+
164+
op = READ_ONCE(sqe->len);
165+
if (op >= IORING_OP_LAST)
166+
return -EINVAL;
167+
168+
cancel->opcode = op;
162169
}
163170

164171
return 0;

0 commit comments

Comments
 (0)