From: None
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 0/5] x86/insn, uprobes: Fix opcode map handling for multi-byte, REX2, and VEX/EVEX/XOP instructions
Date: Mon, 23 Nov 2026 11:47:10 +0900 [thread overview]
Message-ID: <179540203033.233843.12951034848925983867.stgit@devnote2> (raw)
Hi,
Following up on Pablo Fraile Alonso's report and patch [1], as well as the
additional review points from Sashiko and Rick Edgecombe, this series fixes
the underlying x86 instruction decoder issues and the related opcode-map
assumptions in x86 uprobes.
Originally, the x86 instruction decoder was designed primarily for
instructions typically emitted in the kernel. Since uprobes uses it on
arbitrary user-space instruction encodings, several issues around multi-byte,
REX2, and VEX/EVEX/XOP encodings have surfaced:
1. insn_is_nop() in arch/x86/lib/insn-eval.c mutates insn->opcode.value
in-place for REX2 M0=1 instructions without updating insn->opcode.nbytes,
corrupting struct insn for subsequent callers (e.g. uprobe_init_insn()
and branch_setup_xol_ops()).
2. gen-insn-attr-x86.awk skips emitting INAT_REX2_VARIANT for 0xa1 (JMPABS)
because the check is placed after 'if (length(flags) == 0) continue'.
3. insn_get_opcode() never checks INAT_NO_REX2 / INAT_REX2_VARIANT or
invalid REX2 encodings such as REX2 M0=0 + 0x0f or REX2 M0=1 + 0x38/0x3a.
4. insn->opcode.nbytes represents the physical opcode byte count (needed for
field offset calculations such as insn_offset_modrm()), so REX2 M0=1 and
VEX/EVEX/XOP instructions all have insn->opcode.nbytes == 1. Callers
need a helper to determine the logical opcode map; insn_masking_exception()
also lacked this check and could misidentify non-map-0 0x1f/0x8e opcodes.
5. In arch/x86/kernel/uprobes.c, bit 0x0f in good_insns_{32,64} bypassed
good_2byte_insns, and uprobe_init_insn(), branch_setup_xol_ops(),
arch_uprobe_analyze_insn(), and riprel_analyze() assumed map-0 or 1-byte
REX encodings, causing misidentification of AVX/VEX instructions such as
VZEROUPPER (c5 f8 77), VPSHUFD (c5 f9 70), VPOR (c5 f9 eb), and VCMPPS
(c5 f8 c2), as well as REX2 prefix corruption in riprel_analyze().
Patch overview:
- Patch 1: Fix insn_is_nop() not to mutate struct insn.
- Patch 2: Fix gen-insn-attr-x86.awk to emit INAT_REX2_VARIANT.
- Patch 3: Reject invalid REX2 encodings in insn_get_opcode().
- Patch 4: Add insn_opcode_map() / insn_last_opcode() helpers and fix
insn_masking_exception().
- Patch 5: Fix opcode validation, branch/fixup analysis, and REX2 RIP-rel
handling in arch/x86/kernel/uprobes.c.
Notes:
- checkpatch.pl reports warnings on patch 5 for using -ENOTSUPP and -ENOSYS
in arch/x86/kernel/uprobes.c. Those match the existing error code
conventions of uprobe_init_insn() and branch_setup_xol_ops() across
uprobes; cleaning up error codes across uprobes should be done separately
and is intentionally left out of scope for this fix series.
- Auditing whether Group 15 (0f ae: lfence/mfence/sfence, fxsave/fxrstor,
CET instructions, etc.) should be enabled in good_2byte_insns (as raised
by Rick Edgecombe) is also left for a separate follow-up discussion/patch.
- Uprobes should audit the three-byte opcodes and provide good_3bytes1_insns
and good_3byte2_insns bit table if needed.
Testing:
- insn_decoder_test on vmlinux .text (7,926,007 instructions): 0 errors
- insn_sanity (64-bit and 32-bit, 1,000,000 random insns each): 0 errors
- Host unit tests covering REX2 (valid/invalid), JMPABS, VEX2, POP/MOV SS
- QEMU (KVM, -cpu host) uprobe runtime test verifying rejection of 8
disallowed/invalid encodings (0f 05, 0f 0b, REX2 M0=0+0f/e8/a1,
REX2 M0=1+05, 10-byte REX2 M0=1, EVEX map 4) and clean XOL/emulation
execution + trace hits for 7 allowed instructions (bswap, nop10,
vzeroupper, vcmpps, vpshufd, vpor, crc32).
[1] https://lore.kernel.org/r/20261116-x86-uprobes-two-byte-opcode-v1-1-2b6dbabead52@pablofraile.net
Thank you,
---
Masami Hiramatsu (5):
x86/insn-eval: Do not mutate struct insn in insn_is_nop()
x86/insn: Fix gen-insn-attr-x86.awk to emit INAT_REX2_VARIANT
x86/insn: Reject invalid REX2 encodings in insn_get_opcode()
x86/insn: Add insn_opcode_map() helper and fix insn_masking_exception()
uprobes/x86: Fix opcode validation and analysis for multi-byte, REX2, and VEX/EVEX/XOP instructions
arch/x86/include/asm/inat.h | 10 +++
arch/x86/include/asm/insn.h | 43 +++++++++++++
arch/x86/kernel/uprobes.c | 97 +++++++++++++++++++++---------
arch/x86/lib/insn-eval.c | 17 ++++--
arch/x86/lib/insn.c | 16 +++++
arch/x86/tools/gen-insn-attr-x86.awk | 6 +-
tools/arch/x86/include/asm/inat.h | 10 +++
tools/arch/x86/include/asm/insn.h | 43 +++++++++++++
tools/arch/x86/lib/insn.c | 16 +++++
tools/arch/x86/tools/gen-insn-attr-x86.awk | 6 +-
10 files changed, 225 insertions(+), 39 deletions(-)
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
--
Masami Hiramatsu (Google) <mhiramat@kernel.org>
next 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 None [this message]
2026-11-23 2:47 ` [PATCH 1/5] x86/insn-eval: Do not mutate struct insn in insn_is_nop() Masami Hiramatsu (Google)
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=179540203033.233843.12951034848925983867.stgit@devnote2 \
--to=tglx@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=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=pablo@pablofraile.net \
--cc=peterz@infradead.org \
--cc=rick.p.edgecombe@intel.com \
--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®