mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pablo Fraile Alonso <pablo@pablofraile.net>
To: Masami Hiramatsu <mhiramat@kernel.org>,
	Oleg Nesterov <oleg@redhat.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	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,  "H. Peter Anvin" <hpa@zytor.com>,
	Denys Vlasenko <dvlasenk@redhat.com>
Cc: Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org,
	 linux-trace-kernel@vger.kernel.org,
	 Pablo Fraile Alonso <pablo@pablofraile.net>
Subject: [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation
Date: Mon, 16 Nov 2026 16:40:22 +0100	[thread overview]
Message-ID: <20261116-x86-uprobes-two-byte-opcode-v1-1-2b6dbabead52@pablofraile.net> (raw)

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>


             reply	other threads:[~2026-11-16 15:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 15:40 Pablo Fraile Alonso [this message]
2026-11-19 23:59 ` Edgecombe, Rick P

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=20261116-x86-uprobes-two-byte-opcode-v1-1-2b6dbabead52@pablofraile.net \
    --to=pablo@pablofraile.net \
    --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=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

all inboxes | Powered by JetHome®