From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"bp@alien8.de" <bp@alien8.de>,
"peterz@infradead.org" <peterz@infradead.org>,
"x86@kernel.org" <x86@kernel.org>,
"mingo@redhat.com" <mingo@redhat.com>,
"mhiramat@kernel.org" <mhiramat@kernel.org>,
"hpa@zytor.com" <hpa@zytor.com>,
"tglx@kernel.org" <tglx@kernel.org>,
"dvlasenk@redhat.com" <dvlasenk@redhat.com>,
"oleg@redhat.com" <oleg@redhat.com>,
"pablo@pablofraile.net" <pablo@pablofraile.net>
Cc: "mingo@kernel.org" <mingo@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-trace-kernel@vger.kernel.org"
<linux-trace-kernel@vger.kernel.org>
Subject: Re: [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation
Date: Thu, 19 Nov 2026 23:59:00 +0000 [thread overview]
Message-ID: <ce2d62415a64636b8f31a67f8dddf0ab7fc878e9.camel@intel.com> (raw)
In-Reply-To: <20261116-x86-uprobes-two-byte-opcode-v1-1-2b6dbabead52@pablofraile.net>
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>
>
prev parent reply other threads:[~2026-11-19 23:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 15:40 [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation Pablo Fraile Alonso
2026-11-16 16:01 ` sashiko-bot
2026-11-16 16:53 ` Pablo Fraile Alonso
2026-11-19 23:59 ` Edgecombe, Rick P [this message]
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=ce2d62415a64636b8f31a67f8dddf0ab7fc878e9.camel@intel.com \
--to=rick.p.edgecombe@intel.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dvlasenk@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=pablo@pablofraile.net \
--cc=peterz@infradead.org \
--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