mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 02:24:24 +02:00
io_uring: propagate array_index_nospec opcode into req->opcode
Commit1e988c3fe1("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:1e988c3fe1("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>
This commit is contained in:
parent
93d93f5f8d
commit
cf18e36455
|
|
@ -1738,10 +1738,9 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
|
|||
const struct io_issue_def *def;
|
||||
unsigned int sqe_flags;
|
||||
int personality;
|
||||
u8 opcode;
|
||||
|
||||
req->ctx = ctx;
|
||||
req->opcode = opcode = READ_ONCE(sqe->opcode);
|
||||
req->opcode = READ_ONCE(sqe->opcode);
|
||||
/* same numerical values with corresponding REQ_F_*, safe to copy */
|
||||
sqe_flags = READ_ONCE(sqe->flags);
|
||||
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,
|
|||
req->cancel_seq_set = false;
|
||||
req->async_data = NULL;
|
||||
|
||||
if (unlikely(opcode >= IORING_OP_LAST)) {
|
||||
if (unlikely(req->opcode >= IORING_OP_LAST)) {
|
||||
req->opcode = 0;
|
||||
return io_init_fail_req(req, -EINVAL);
|
||||
}
|
||||
opcode = array_index_nospec(opcode, IORING_OP_LAST);
|
||||
req->opcode = array_index_nospec(req->opcode, IORING_OP_LAST);
|
||||
|
||||
def = &io_issue_defs[opcode];
|
||||
def = &io_issue_defs[req->opcode];
|
||||
if (def->is_128 && !(ctx->flags & IORING_SETUP_SQE128)) {
|
||||
/*
|
||||
* A 128b op on a non-128b SQ requires mixed SQE support as
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user