* [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation
@ 2026-11-16 15:40 Pablo Fraile Alonso
2026-11-19 23:59 ` Edgecombe, Rick P
0 siblings, 1 reply; 2+ messages in thread
From: Pablo Fraile Alonso @ 2026-11-16 15:40 UTC (permalink / raw)
To: Masami Hiramatsu, Oleg Nesterov, Peter Zijlstra, Thomas Gleixner,
Ingo Molnar, Borislav Petkov, Dave Hansen, x86, H. Peter Anvin,
Denys Vlasenko
Cc: Ingo Molnar, linux-kernel, linux-trace-kernel, Pablo Fraile Alonso
Commit 67fc809217dc ("uprobes/x86: Fix 1-byte opcode tables") set
bit 0x0f in both good_insns_32 and good_insns_64, assuming that
the opcode escape byte would not be reported by OPCODE1(insn).
However, unlike ordinary instruction prefixes, 0x0f is an opcode
escape byte retained in insn->opcode.bytes[0] by the x86 instruction
decoder. Subsequent opcode bytes are stored in the following positions.
For example, SYSCALL (0F 05) is decoded as:
insn->opcode.bytes[0] = 0x0f;
insn->opcode.bytes[1] = 0x05;
Consequently, OPCODE1(insn) returns 0x0f, causing the first
test_bit() in uprobe_init_insn() to succeed and return 0 before
good_2byte_insns is consulted.
This bypasses the secondary opcode allowlist for all legacy
two-byte instructions, including SYSCALL (0F 05), which is
explicitly disallowed by good_2byte_insns.
Three-byte opcodes (0F 38 and 0F 3A) are also affected by the
early return, since their decoded opcodes begin with 0x0f.
Fix the validation logic so that legacy two-byte instructions
are checked against good_2byte_insns. Preserve the existing
behavior for three-byte opcodes, which are not currently checked
against a dedicated allowlist (in my opinion, this should be
audited on another patch, instead of returning -ENOTSUPP).
Fixes: 67fc809217dc ("uprobes/x86: Fix 1-byte opcode tables")
Signed-off-by: Pablo Fraile Alonso <pablo@pablofraile.net>
---
I created two reproducers (and a brief explanation of them). One it's a simple one that demonstrates what I told (that you can attach to a non-allowed instruction), an another one that freezes a system by attaching a "poisoned" uprobe to glibc.
- Dummy: https://gist.github.com/Pablito2020/077fc8d8b6d7a75c23c702c7021d68e6
- Poisoned Glibc: https://gist.github.com/Pablito2020/bdda586ab023ec4760716b3be7cff102
After the fix, registration of the uprobe should fail because
the instruction is rejected by the secondary opcode bitmap.
---
arch/x86/kernel/uprobes.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
index 0f60c0d076b6..1cf901d18688 100644
--- a/arch/x86/kernel/uprobes.c
+++ b/arch/x86/kernel/uprobes.c
@@ -292,14 +292,24 @@ static int uprobe_init_insn(struct arch_uprobe *auprobe, struct insn *insn)
else
good_insns = good_insns_32;
- if (test_bit(OPCODE1(insn), (unsigned long *)good_insns))
- return 0;
-
- if (insn->opcode.nbytes == 2) {
+ switch (insn->opcode.nbytes) {
+ case 1:
+ if (test_bit(OPCODE1(insn), (unsigned long *)good_insns))
+ return 0;
+ break;
+ case 2:
if (test_bit(OPCODE2(insn), (unsigned long *)good_2byte_insns))
return 0;
+ break;
+ case 3:
+ /*
+ * As of today, allow three-byte opcodes, although
+ * one day we should investigate which instructions may
+ * not be compatible with XOL and reject specific
+ * problematic encodings.
+ */
+ return 0;
}
-
return -ENOTSUPP;
}
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261116-x86-uprobes-two-byte-opcode-7fa743830931
Best regards,
--
Pablo Fraile Alonso <pablo@pablofraile.net>
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation
2026-11-16 15:40 [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation Pablo Fraile Alonso
@ 2026-11-19 23:59 ` Edgecombe, Rick P
0 siblings, 0 replies; 2+ messages in thread
From: Edgecombe, Rick P @ 2026-11-19 23:59 UTC (permalink / raw)
To: dave.hansen, bp, peterz, x86, mingo, mhiramat, hpa, tglx,
dvlasenk, oleg, pablo
Cc: mingo, linux-kernel, linux-trace-kernel
On Mon, 2026-11-16 at 16:40 +0100, Pablo Fraile Alonso wrote:
> Commit 67fc809217dc ("uprobes/x86: Fix 1-byte opcode tables") set
> bit 0x0f in both good_insns_32 and good_insns_64, assuming that
> the opcode escape byte would not be reported by OPCODE1(insn).
>
> However, unlike ordinary instruction prefixes, 0x0f is an opcode
> escape byte retained in insn->opcode.bytes[0] by the x86 instruction
> decoder. Subsequent opcode bytes are stored in the following positions.
>
> For example, SYSCALL (0F 05) is decoded as:
>
> insn->opcode.bytes[0] = 0x0f;
> insn->opcode.bytes[1] = 0x05;
>
> Consequently, OPCODE1(insn) returns 0x0f, causing the first
> test_bit() in uprobe_init_insn() to succeed and return 0 before
> good_2byte_insns is consulted.
>
> This bypasses the secondary opcode allowlist for all legacy
> two-byte instructions, including SYSCALL (0F 05), which is
> explicitly disallowed by good_2byte_insns.
>
> Three-byte opcodes (0F 38 and 0F 3A) are also affected by the
> early return, since their decoded opcodes begin with 0x0f.
>
> Fix the validation logic so that legacy two-byte instructions
> are checked against good_2byte_insns. Preserve the existing
> behavior for three-byte opcodes, which are not currently checked
> against a dedicated allowlist (in my opinion, this should be
> audited on another patch, instead of returning -ENOTSUPP).
>
> Fixes: 67fc809217dc ("uprobes/x86: Fix 1-byte opcode tables")
>
> Signed-off-by: Pablo Fraile Alonso <pablo@pablofraile.net>
> ---
> I created two reproducers (and a brief explanation of them). One it's a simple one that demonstrates what I told (that you can attach to a non-allowed instruction), an another one that freezes a system by attaching a "poisoned" uprobe to glibc.
>
> - Dummy: https://gist.github.com/Pablito2020/077fc8d8b6d7a75c23c702c7021d68e6
It looks like this is a bug that can causes crashes in the userspace programs
being probed.
> - Poisoned Glibc: https://gist.github.com/Pablito2020/bdda586ab023ec4760716b3be7cff102
...and if the program being probed happens to be important to the system, a
crash there can cause system issues. Initially I thought this was a kernel
crash. I think a similar system stability argument could be made for any kernel
bug.
>
> After the fix, registration of the uprobe should fail because
> the instruction is rejected by the secondary opcode bitmap.
> ---
> arch/x86/kernel/uprobes.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index 0f60c0d076b6..1cf901d18688 100644
> --- a/arch/x86/kernel/uprobes.c
> +++ b/arch/x86/kernel/uprobes.c
> @@ -292,14 +292,24 @@ static int uprobe_init_insn(struct arch_uprobe *auprobe, struct insn *insn)
> else
> good_insns = good_insns_32;
>
> - if (test_bit(OPCODE1(insn), (unsigned long *)good_insns))
> - return 0;
> -
> - if (insn->opcode.nbytes == 2) {
> + switch (insn->opcode.nbytes) {
> + case 1:
> + if (test_bit(OPCODE1(insn), (unsigned long *)good_insns))
> + return 0;
> + break;
> + case 2:
> if (test_bit(OPCODE2(insn), (unsigned long *)good_2byte_insns))
> return 0;
> + break;
> + case 3:
> + /*
> + * As of today, allow three-byte opcodes, although
> + * one day we should investigate which instructions may
> + * not be compatible with XOL and reject specific
> + * problematic encodings.
> + */
> + return 0;
> }
Can you check whether this change newly rejects previously working instructions?
The l/m/sfence instructions?
> -
> return -ENOTSUPP;
> }
>
>
> ---
> base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
> change-id: 20261116-x86-uprobes-two-byte-opcode-7fa743830931
>
> Best regards,
> --
> Pablo Fraile Alonso <pablo@pablofraile.net>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 23:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 15:40 [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation Pablo Fraile Alonso
2026-11-19 23:59 ` Edgecombe, Rick P
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®