From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, Masami Hiramatsu <mhiramat@kernel.org>,
Oleg Nesterov <oleg@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Lukas Zobernig <lukas.zobernig@gmail.com>
Cc: "H . Peter Anvin" <hpa@zytor.com>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org,
Pablo Fraile Alonso <pablo@pablofraile.net>,
Edgecombe Rick P <rick.p.edgecombe@intel.com>
Subject: [PATCH 1/5] x86/insn-eval: Do not mutate struct insn in insn_is_nop()
Date: Mon, 23 Nov 2026 11:47:22 +0900 [thread overview]
Message-ID: <179540204209.233843.2595774240986518615.stgit@devnote2> (raw)
In-Reply-To: <179540203033.233843.12951034848925983867.stgit@devnote2>
From: Masami Hiramatsu <mhiramat@kernel.org>
For REX2 M0=1 (map 1) instructions, insn_is_nop() shifts insn->opcode.value
left by 8 bits and ORs in 0x0f in-place without updating
insn->opcode.nbytes.
This corrupts the decoded struct insn for subsequent callers. For example,
in uprobes arch_uprobe_analyze_insn(), can_optimize() ->
is_optimizable_nop10() calls insn_is_nop() on any 10-byte instruction
before uprobe_init_insn(), leaving OPCODE1(insn) == 0x0f with
opcode.nbytes == 1, and a second call from branch_setup_xol_ops() shifts
it a second time.
Use local variables for the opcode bytes instead of mutating insn->opcode.
Fixes: 8a5c6cbfe4a3 ("x86/insn,uprobes,alternative: Unify insn_is_nop()")
Cc: stable@vger.kernel.org
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
arch/x86/lib/insn-eval.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c
index e03eeec55cfe..c67f8ac375c4 100644
--- a/arch/x86/lib/insn-eval.c
+++ b/arch/x86/lib/insn-eval.c
@@ -1700,6 +1700,7 @@ bool insn_is_nop(struct insn *insn)
u8 sib = 0, sib_scale, sib_index, sib_base;
u8 nrex, rex;
u8 p, rep = 0;
+ u8 op0, op1;
if ((nrex = insn->rex_prefix.nbytes)) {
rex = insn->rex_prefix.bytes[nrex-1];
@@ -1745,21 +1746,25 @@ bool insn_is_nop(struct insn *insn)
}
/*
- * Opcode map munging:
+ * Opcode map handling:
*
* REX2: 0 - single byte opcode
* 1 - 0f second byte opcode
*/
switch (m) {
- case 0: break;
- case 1: insn->opcode.value <<= 8;
- insn->opcode.value |= 0x0f;
+ case 0:
+ op0 = insn->opcode.bytes[0];
+ op1 = insn->opcode.nbytes == 2 ? insn->opcode.bytes[1] : 0;
+ break;
+ case 1:
+ op0 = 0x0f;
+ op1 = insn->opcode.bytes[0];
break;
default:
return false;
}
- switch (insn->opcode.bytes[0]) {
+ switch (op0) {
case 0x0f: /* 2nd byte */
break;
@@ -1811,7 +1816,7 @@ bool insn_is_nop(struct insn *insn)
return false;
}
- switch (insn->opcode.bytes[1]) {
+ switch (op1) {
case 0x1f:
return modrm_reg == 0; /* 0f 1f /0 -- NOPL */
next prev parent reply other threads:[~2026-11-23 2:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-23 2:47 [PATCH 0/5] x86/insn, uprobes: Fix opcode map handling for multi-byte, REX2, and VEX/EVEX/XOP instructions None
2026-11-23 2:47 ` Masami Hiramatsu (Google) [this message]
2026-11-23 2:47 ` [PATCH 2/5] x86/insn: Fix gen-insn-attr-x86.awk to emit INAT_REX2_VARIANT Masami Hiramatsu (Google)
2026-11-23 2:47 ` [PATCH 3/5] x86/insn: Reject invalid REX2 encodings in insn_get_opcode() Masami Hiramatsu (Google)
2026-11-23 2:47 ` [PATCH 4/5] x86/insn: Add insn_opcode_map() helper and fix insn_masking_exception() Masami Hiramatsu (Google)
2026-11-23 2:48 ` [PATCH 5/5] uprobes/x86: Fix opcode validation and analysis for multi-byte, REX2, and VEX/EVEX/XOP instructions Masami Hiramatsu (Google)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=179540204209.233843.2595774240986518615.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=lukas.zobernig@gmail.com \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=pablo@pablofraile.net \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®