Linux Trace Kernel
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pablo Fraile Alonso" <pablo@pablofraile.net>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH] uprobes/x86: Fix bypass of two-byte opcode validation
Date: Mon, 16 Nov 2026 16:01:34 +0000	[thread overview]
Message-ID: <sashiko-outbox-217334@kernel.org> (raw)
In-Reply-To: <20261116-x86-uprobes-two-byte-opcode-v1-1-2b6dbabead52@pablofraile.net>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] uprobes/x86: REX2 map-1 opcodes bypass good_2byte_insns in
  uprobe_init_insn()
--

commit 4da9c45b309734e7a1e4eb07255d608c16d67ca3
Author: Pablo Fraile Alonso <pablo@pablofraile.net>

uprobes/x86: Fix bypass of two-byte opcode validation

This commit updates uprobe_init_insn() to switch on insn->opcode.nbytes so
that two-byte instructions starting with 0x0f are checked against
good_2byte_insns instead of matching bit 0x0f in good_insns.

> diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
> index 0f60c0d076b62..1cf901d186884 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;

[Severity: Medium]
Does switching solely on insn->opcode.nbytes still allow REX2-prefixed
map-1 (0x0f) instructions to bypass good_2byte_insns?

For a REX2 prefix with M0=1, insn_get_opcode() stores the map-1 opcode
byte in insn->opcode.bytes[0] (OPCODE1(insn)) and leaves
insn->opcode.nbytes == 1:

arch/x86/lib/insn.c:insn_get_opcode() {
    ...
	if (insn_is_rex2(insn)) {
		if (insn_rex2_m_bit(insn)) {
			/* map 1 is escape 0x0f */
			insn_attr_t esc_attr = inat_get_opcode_attribute(0x0f);

			pfx_id = insn_last_prefix_id(insn);
			insn->attr = inat_get_escape_attribute(op, pfx_id, esc_attr);
		} else {
			insn->attr = inat_get_opcode_attribute(op);
		}
		goto end;
	}
    ...
}

In uprobe_init_insn(), those instructions enter case 1 and test their
map-1 opcode against good_insns_64 (map 0) instead of good_2byte_insns,
allowing disallowed 2-byte instructions such as syscall (0xd5 0x80 0x05)
to pass validation while rejecting valid map-1 instructions such as
bswap (0x0f 0xc8..0xcf) whose opcode byte is 0 in good_insns_64.

In addition, because bit 0x0f remains set in good_insns_64, a 10-byte
REX2 M0=1 instruction has its insn->opcode.value shifted and ORed with
0x0f in-place by can_optimize() -> is_optimizable_nop10() ->
insn_is_nop() without updating insn->opcode.nbytes, so case 1 tests bit
0x0f and accepts any 10-byte REX2 M0=1 instruction regardless of opcode
(as well as an invalid REX2 M0=0 instruction with opcode byte 0x0f).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261116-x86-uprobes-two-byte-opcode-v1-1-2b6dbabead52@pablofraile.net?part=1

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

Thread overview: 2+ 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 [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=sashiko-outbox-217334@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=pablo@pablofraile.net \
    --cc=sashiko-reviews@lists.linux.dev \
    /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