Skip to content

Commit cf18e36

Browse files
mjbommaraxboe
authored andcommitted
io_uring: propagate array_index_nospec opcode into req->opcode
Commit 1e988c3 ("io_uring: prevent opcode speculation") added array_index_nospec() to io_init_req(), but applied it only to a local opcode variable. req->opcode is initialized from sqe->opcode before the bounds check and remains the raw value. Keep req->opcode as the canonical opcode in io_init_req(): reject out-of-range values architecturally, then write the array_index_nospec() result back to req->opcode before any table lookup. This keeps downstream users of req->opcode from observing the raw user byte on a mispredicted path. No functional change: array_index_nospec() is a no-op for opcodes in [0, IORING_OP_LAST), and out-of-range opcodes are still rejected at the bounds check above the assignment. Fixes: 1e988c3 ("io_uring: prevent opcode speculation") Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito <michael.bommarito@gmail.com> Link: https://patch.msgid.link/20260517213010.696135-1-michael.bommarito@gmail.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 93d93f5 commit cf18e36

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

io_uring/io_uring.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,10 +1738,9 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
17381738
const struct io_issue_def *def;
17391739
unsigned int sqe_flags;
17401740
int personality;
1741-
u8 opcode;
17421741

17431742
req->ctx = ctx;
1744-
req->opcode = opcode = READ_ONCE(sqe->opcode);
1743+
req->opcode = READ_ONCE(sqe->opcode);
17451744
/* same numerical values with corresponding REQ_F_*, safe to copy */
17461745
sqe_flags = READ_ONCE(sqe->flags);
17471746
req->flags = (__force io_req_flags_t) sqe_flags;
@@ -1751,13 +1750,13 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
17511750
req->cancel_seq_set = false;
17521751
req->async_data = NULL;
17531752

1754-
if (unlikely(opcode >= IORING_OP_LAST)) {
1753+
if (unlikely(req->opcode >= IORING_OP_LAST)) {
17551754
req->opcode = 0;
17561755
return io_init_fail_req(req, -EINVAL);
17571756
}
1758-
opcode = array_index_nospec(opcode, IORING_OP_LAST);
1757+
req->opcode = array_index_nospec(req->opcode, IORING_OP_LAST);
17591758

1760-
def = &io_issue_defs[opcode];
1759+
def = &io_issue_defs[req->opcode];
17611760
if (def->is_128 && !(ctx->flags & IORING_SETUP_SQE128)) {
17621761
/*
17631762
* A 128b op on a non-128b SQ requires mixed SQE support as

0 commit comments

Comments
 (0)