Re: [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation

From: Masami Hiramatsu (Google)

Date: Sun Nov 22 2026 - 20:38:49 EST


Hi Pablo,

Thanks for the report and the patch, and thanks to Rick and Sashiko for
the additional findings.

When I checked this issue with LLM, the problem goes deeper than just the
missing 2-byte opcode check in uprobes. The x86 instruction decoder was
originally designed around instructions typically emitted in the kernel,
and as uprobes uses it on arbitrary user-space encodings, several gaps
around REX2 and VEX/EVEX/XOP have been found:

1. x86 instruction decoder / insn-eval issues:
- insn->opcode.nbytes represents the physical opcode byte count (used
by insn_offset_modrm() etc.), not what opcode map is used.
We need a helper function to identify the opcode map.
- As Sashiko pointed out, insn_is_nop() in arch/x86/lib/insn-eval.c
mutates insn->opcode.value in-place for REX2 M0=1 without updating
opcode.nbytes, corrupting struct insn for subsequent callers (and
shifting it twice when called from both can_optimize() and
branch_setup_xol_ops(), sigh...).
- insn_get_opcode() never checks INAT_NO_REX2 / INAT_REX2_VARIANT or
invalid REX2 encodings such as REX2 M0=0 + 0x0f (0xd5 0x00 0x0f) or
REX2 M0=1 + 0x38/0x3a. In addition, gen-insn-attr-x86.awk currently
skips emitting INAT_REX2_VARIANT for 0xa1 (JMPABS) because the check
is placed after 'if (length(flags) == 0) continue'.
(Note: Historically, the x86 insn decoder is designed for decoding
kernel text, and has assamption that decoding begins at the function
boundaries. Thus, it may not be able to perform verification
correctly.)
- insn_masking_exception() checks opcode.bytes[0] without verifying
map 0, so it can misidentify non-map-0 instructions (REX2 M0=1 or
VEX/EVEX/XOP) with opcode 0x1f/0x8e as POP SS / MOV SS.

2. Related map-0 assumptions in arch/x86/kernel/uprobes.c:
- uprobe_init_insn(): clearing bit 0x0f in good_insns_{32,64} and
dispatching via the logical opcode map is needed so that REX2 M0=1
is checked against good_2byte_insns, VEX/EVEX/XOP are not checked
against map-0 tables, and unsupported REX2 JMPABS (0xa1) / EVEX
map 4 (APX) instructions are rejected.
- branch_setup_xol_ops(): does not exclude VEX/EVEX/XOP or REX2, so
ordinary AVX instructions like VZEROUPPER (c5 f8 77), VPSHUFD
(c5 f9 70 ...), or VPOR (c5 .. eb) can be misidentified as branches.
- arch_uprobe_analyze_insn(): switches on OPCODE1(&insn) without
checking map 0, so e.g. VCMPPS/VCMPPD (VEX.0F.C2) matches case 0xc2
(RET) and skips UPROBE_FIX_IP.
- riprel_analyze(): clears bit 0 of the first REX byte, which for a
2-byte REX2 prefix corrupts 0xd5 into 0xd4 instead of clearing
B3/B4 in the second byte.

3. Regarding Rick's point about newly rejected 2-byte instructions:
- Group 15 (0f ae: lfence/mfence/sfence, fxsave/fxrstor, {rd,wr}{fs,gs}base,
etc.) is currently 0 in good_2byte_insns even though the comment notes
they are user-executable. We should audit whether 0f ae (note that
Grp15 also includes CET instructions like INCSSP/CLRSSBSY) should be
enabled in good_2byte_insns to avoid regressions on existing workloads.

I am preparing a patch series that fixes the x86 instruction decoder
issues first and then updates uprobes on top of it (with Reported-by
credit to you). I will post it shortly for review.

Thank you,