* [PATCH] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP
@ 2026-03-31 23:21 Amir Mohammad Jahangirzad
2026-04-01 13:31 ` Jens Axboe
2026-04-01 13:39 ` Jens Axboe
0 siblings, 2 replies; 3+ messages in thread
From: Amir Mohammad Jahangirzad @ 2026-03-31 23:21 UTC (permalink / raw)
To: axboe; +Cc: io-uring, linux-kernel, Amir Mohammad Jahangirzad
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>
---
io_uring/cancel.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/io_uring/cancel.c b/io_uring/cancel.c
index 65e04063e..5e5eb9cfc 100644
--- a/io_uring/cancel.c
+++ b/io_uring/cancel.c
@@ -156,9 +156,16 @@ int io_async_cancel_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
cancel->fd = READ_ONCE(sqe->fd);
}
if (cancel->flags & IORING_ASYNC_CANCEL_OP) {
+ u32 op;
+
if (cancel->flags & IORING_ASYNC_CANCEL_ANY)
return -EINVAL;
- cancel->opcode = READ_ONCE(sqe->len);
+
+ op = READ_ONCE(sqe->len);
+ if (op >= IORING_OP_LAST)
+ return -EINVAL;
+
+ cancel->opcode = op;
}
return 0;
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP
2026-03-31 23:21 [PATCH] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP Amir Mohammad Jahangirzad
@ 2026-04-01 13:31 ` Jens Axboe
2026-04-01 13:39 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-04-01 13:31 UTC (permalink / raw)
To: Amir Mohammad Jahangirzad; +Cc: io-uring, linux-kernel
On 3/31/26 5:21 PM, Amir Mohammad Jahangirzad wrote:
> 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.
Looks fine to me as a cleanup, as it's really the application being
buggy if you set ->len > IORING_OP_LAST and then match some opcode
that just happens to be == ->len & 255. I'll apply this for 7.1.
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP
2026-03-31 23:21 [PATCH] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP Amir Mohammad Jahangirzad
2026-04-01 13:31 ` Jens Axboe
@ 2026-04-01 13:39 ` Jens Axboe
1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2026-04-01 13:39 UTC (permalink / raw)
To: Amir Mohammad Jahangirzad; +Cc: io-uring, linux-kernel
On Wed, 01 Apr 2026 02:51:13 +0330, Amir Mohammad Jahangirzad wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP
commit: ab274887c2443f49d3a547a58a094787cd02d1dc
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-01 13:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 23:21 [PATCH] io_uring/cancel: validate opcode for IORING_ASYNC_CANCEL_OP Amir Mohammad Jahangirzad
2026-04-01 13:31 ` Jens Axboe
2026-04-01 13:39 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox