From nobody Mon May 25 06:41:07 2026 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2274529898F for ; Sun, 17 May 2026 21:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779053417; cv=none; b=c2Qj44EerUdkFybrEnw67A5RNzwlLFPtzfJVuQVaQKHLYS/RfU9NgCl4I9ee7Gqpfxoqm5vQ3c3f7XuDOjs5cT0X3U7AebS2VfAPwAysiR6jYVl7AKXrejhhkMV9yiKpBZa0V0COosTkKKREmpC71cr6qbgIImMS3dZwTQthQns= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779053417; c=relaxed/simple; bh=2cHKYn2f6w0kDULHSqK48+9/oXwCGs+d9elAlUxEX9I=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Am8ydgneVFlA5hAPR/xtcJbg3w3G0MKZw+ecDfGoMHpEEYe5HgDvfNQTyPFYFOdB/U+GNsj/u1nYsT7rPtuWUQOcr4mDltpCTWmSkBOSIyjNFfA2ntw0VsWyZwz2nUpq5hz403hQri6k0wfOU/XwA7ojQ4ukOPTecd6qWcURbqA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZSBRvGZP; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZSBRvGZP" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-912475287a5so184551385a.2 for ; Sun, 17 May 2026 14:30:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779053415; x=1779658215; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=o2hXOV088N3HeC0bZzKE5fv3Wg815pFZ+IHEYgpTbM8=; b=ZSBRvGZPhjT4ig37wKQenTs1Ten/z4gFfuE7Ur0RzZAR2miFnNExhJbjRpr5L+MS73 f4BDZPeeCnHEcml4IjJAEXqTAjENnWhrJY2v9e8DXrX5C7dHk4PZZG3+pVO/wpJ/bSjN DqYTU8Bgsrv/D53o36fduUNlAQ3JglPv14HSwhH8E8aOmxKDWKGNDXDkQGlCnOmnUB4J HdpjcqhyTYiLLPpexJcfko9X2bJBmUNBzRijuw7bruPhjcM3TLDBuK3PnPGzan+HOMOU Do+URYe5ca0b7a+LnAoqUAWs3F+rW34GRqxy5GrevWUcc4oF2zPJ1m/w7PeN3I25ccms W/Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779053415; x=1779658215; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=o2hXOV088N3HeC0bZzKE5fv3Wg815pFZ+IHEYgpTbM8=; b=f3O7wCZmj1/Q3ISr8OgUMB3AcqpnFGEN24mpwFPtXew7t6LHtOMO6hM08YtDiVJG+V qiBqKdTtFPGmvYQOtkzYRZ8D0xiQrJyi3R3bGXAstJyRaAGpEGzbfhoGbjmQyhAVkb8z EhhVkP6WHBLjqpwE+7WuZ6ryIQeFSwxth9zT/tN6yD7afyzw+a87K9rvIJig5GyHBiOJ IyrFl9qwTZSHdCO6fpCTazNXzwJFp2+jlUA2ugCpSRAeh2O9854k8V08383AU6gKwXa1 fP4Ub0GEebG5JRn4JuH3MqML8f6q0LbPw4tn5IGX981ljFc/PxNrkvEUxmBVYtkFCkoV ZXog== X-Forwarded-Encrypted: i=1; AFNElJ/NUR34UyddlAm+gAdqb03NFRkOjXbypcVAt8OMpbS4WqAHUHSixh5KsztN1gTtb1wpz9Bvx9lFbTdBoCA=@vger.kernel.org X-Gm-Message-State: AOJu0YzmyICaawq/TjzZwx1Q5R7YuMc+Uondbt0P5JsZKjv38pKbtQzd yI297vSgF/ef7Ypf9yE5ipvOh9D0eOAGYtHmOK9vJBIAyDiEvf4wtdUO X-Gm-Gg: Acq92OGxpLj0CUNqftZ9nMF1QbIoDrmn1lw1hlv+DCGID9rLqrkcffnIfQNArFOnmHG XCPDiBCQTQzWVm+8IF86SWx3BoLCL9IUocoYIqGP8gv8XDkJAMXYsI8iITM7+2QIWW4ZjaqChR8 2KkD0kPERYGYKsQExLSN75s5tJaiLKpy0Uurv2ZVunaSqmMHTrk8GVoW0M8uys3/D2f6XzsfVe1 Q5a2RpXzERjFJfLcXtJAVUfW6SZtB+wAPKwuqUcmpQ37ru81rfFrCyD1bHY8BVlqpy/BOCcrKa5 1LgAI6fnIY2cT0ltVUumFU727BDE4fGvMZquHDdIWyAv+nMuEgktwPoXrMcNx21CfxrgKZWddYu M0SLIEAkLOPTM57RqJisjL+Yo2P51dYyrWtlzRfYNOSgvi2X+fR4J+W4D/ZsC6S46R/IGeQsGsw QgZcvqw46fgvLXfA7mVkLIa6ODPIqz7RieEqZ7tQWRWZsiCgL2LyVWT3v8O38OhOBoYlApPd9Rz xF9WTrXG6mpv0PUv9tCkUK6pAs7vP5PWvBaflsCkcI= X-Received: by 2002:a05:620a:2950:b0:90f:9cde:9788 with SMTP id af79cd13be357-911cda50d4dmr1955996785a.5.1779053415002; Sun, 17 May 2026 14:30:15 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id af79cd13be357-910bab3a207sm1265416685a.15.2026.05.17.14.30.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 May 2026 14:30:14 -0700 (PDT) From: Michael Bommarito To: Jens Axboe , io-uring@vger.kernel.org Cc: Pavel Begunkov , Li Zetao , Keith Busch , linux-kernel@vger.kernel.org Subject: [PATCH v2] io_uring: propagate array_index_nospec opcode into req->opcode Date: Sun, 17 May 2026 17:30:10 -0400 Message-ID: <20260517213010.696135-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Commit 1e988c3fe126 ("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. Boot-tested under UML (x86_64 defconfig) by building stock and patched kernels and running a 54-test subset of liburing against each; pass/fail results were identical. Fixes: 1e988c3fe126 ("io_uring: prevent opcode speculation") Assisted-by: Claude:claude-opus-4-7 Signed-off-by: Michael Bommarito --- v2: - Fold the clamped value into req->opcode and use req->opcode for the io_issue_defs[] lookup, rather than keeping a second local opcode variable. Suggested by Jens. - Keep the hardening-only framing; no functional behavior change. io_uring/io_uring.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 4ed998d60c09c..84e16c3ad3f47 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1721,10 +1721,9 @@ static int io_init_req(struct io_ring_ctx *ctx, stru= ct io_kiocb *req, const struct io_issue_def *def; unsigned int sqe_flags; int personality; - u8 opcode; =20 req->ctx =3D ctx; - req->opcode =3D opcode =3D READ_ONCE(sqe->opcode); + req->opcode =3D READ_ONCE(sqe->opcode); /* same numerical values with corresponding REQ_F_*, safe to copy */ sqe_flags =3D READ_ONCE(sqe->flags); req->flags =3D (__force io_req_flags_t) sqe_flags; @@ -1734,13 +1733,13 @@ static int io_init_req(struct io_ring_ctx *ctx, str= uct io_kiocb *req, req->cancel_seq_set =3D false; req->async_data =3D NULL; =20 - if (unlikely(opcode >=3D IORING_OP_LAST)) { + if (unlikely(req->opcode >=3D IORING_OP_LAST)) { req->opcode =3D 0; return io_init_fail_req(req, -EINVAL); } - opcode =3D array_index_nospec(opcode, IORING_OP_LAST); + req->opcode =3D array_index_nospec(req->opcode, IORING_OP_LAST); =20 - def =3D &io_issue_defs[opcode]; + def =3D &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 --=20 2.53.0