All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Utku Erol" <utkuerol71@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH] bpf: disasm: guard print_bpf_insn against BPF_MEMSX | BPF_DW
Date: Thu, 03 Sep 2026 13:45:14 +0000	[thread overview]
Message-ID: <20260903134514.AA6D71F00AC4@smtp.kernel.org> (raw)
In-Reply-To: <20260903133434.17860-1-utkuerol71@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The patch adds a redundant check for `BPF_MEMSX` with `BPF_DW` size that is unreachable dead code, because the preceding `if` statement already checks the exact same condition and returns.
--

commit ae7a2255ead6c3e59e5776083e563c01d78b10e7
Author: Utku Erol <utkuerol71@gmail.com>

bpf: disasm: guard print_bpf_insn against BPF_MEMSX | BPF_DW

This patch adds a check in print_bpf_insn() to reject BPF_MEMSX instructions
with BPF_DW size. It intends to prevent an out-of-bounds array access that
occurs on unvalidated instructions during disassembly.

[ ... ]

> The LDX branch checks only that the mode is
> BPF_MEM or BPF_MEMSX; it never rejects BPF_MEMSX | BPF_DW. For that opcode

[Severity: Medium]
Is this description accurate?

Looking at print_bpf_insn(), the preceding check in the baseline code already
explicitly evaluates and rejects the (BPF_MEMSX | BPF_DW) condition.

[ ... ]

> diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c
> index b1a3fbe3fda53..7c24136268026 100644
> --- a/kernel/bpf/disasm.c
> +++ b/kernel/bpf/disasm.c
> @@ -300,6 +300,10 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs,
>  			verbose(cbs->private_data, "BUG_ldx_%02x", insn->code);
>  			return;
>  		}
> +		if (BPF_MODE(insn->code) == BPF_MEMSX && BPF_SIZE(insn->code) == BPF_DW) {

[Severity: Medium]
Does this code ever execute?

The immediately preceding if statement checks the exact same condition:

	} else if (class == BPF_LDX) {
		if ((BPF_MODE(insn->code) != BPF_MEM && BPF_MODE(insn->code) != BPF_MEMSX) ||
		    (BPF_MODE(insn->code) == BPF_MEMSX && BPF_SIZE(insn->code) == BPF_DW)) {
			verbose(cbs->private_data, "BUG_ldx_%02x", insn->code);
			return;
		}

Since the previous check unconditionally returns, won't this newly added block
be completely unreachable dead code?

> +			verbose(cbs->private_data, "BUG_ldsx_%02x", insn->code);
> +			return;
> +		}
>  		verbose(cbs->private_data, "(%02x) r%d = *(%s *)(r%d %+d)",
>  			insn->code, insn->dst_reg,
>  			BPF_MODE(insn->code) == BPF_MEM ?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260903133434.17860-1-utkuerol71@gmail.com?part=1

  reply	other threads:[~2026-09-03 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-03 13:34 [PATCH] bpf: disasm: guard print_bpf_insn against BPF_MEMSX | BPF_DW Utku Erol
2026-09-03 13:45 ` sashiko-bot [this message]
2026-09-03 14:23 ` Kumar Kartikeya Dwivedi
2026-09-03 14:30 ` bot+bpf-ci

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=20260903134514.AA6D71F00AC4@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=utkuerol71@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.