All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v5 8/9] selftests/bpf: Add test to verify xlated insns for global percpu data
Date: Thu, 11 Jun 2026 13:12:11 +0800	[thread overview]
Message-ID: <c8b799df-8a38-4a15-a3f4-a71585c9c205@linux.dev> (raw)
In-Reply-To: <20260608152120.8B9181F00893@smtp.kernel.org>

On 8/6/26 23:21, sashiko-bot@kernel.org wrote:
[...]
>> +static __u64 ld_imm64_to_u64(const struct bpf_insn *insn)
>> +{
>> +	return ((__u64) insn[1].imm << 32) | (__u64) insn[0].imm;
> 
> [Severity: Low]
> Does this code inadvertently sign-extend the lower 32 bits?
> 
> The imm field in struct bpf_insn is a signed 32-bit integer (__s32). Casting
> it directly to __u64 performs sign extension. If insn[0].imm were to contain
> a value with its most significant bit set, it would be sign-extended,
> corrupting the resulting 64-bit value.
> 
> Should this cast to __u32 first before casting to __u64, like
> (__u64)(__u32)insn[0].imm?
> 

Ack.

Will add (__u32).

>> +}
>> +
>> +static void test_global_percpu_data_xlated(void)
>> +{
>> +	struct bpf_insn ld_imm64_raw[2], ld_imm64_xlated[2], mov64_percpu_reg, *insns = NULL;
> [ ... ]
>> +	prog = skel->progs.verifier_percpu_read;
>> +	idx = find_ld_imm64(bpf_program__insns(prog), bpf_program__insn_cnt(prog), ld_imm64_raw);
>> +	if (!ASSERT_GE(idx, 0, "find_ld_imm64 raw"))
>> +		goto out;
>> +
>> +	err = test_global_percpu_data__load(skel);
>> +	if (!ASSERT_OK(err, "test_global_percpu_data__load"))
>> +		goto out;
>> +
>> +	err = get_xlated_program(bpf_program__fd(prog), &insns, &cnt);
>> +	if (!ASSERT_OK(err, "get_xlated_program"))
>> +		goto out;
>> +	if (!ASSERT_GT(cnt, idx + 2, "xlated insn count"))
>> +		goto out;
> 
> [Severity: Low]
> Is this bounds check using the correct index variable?
> 
> At this point, idx holds the index from the raw BPF program. Because the
> BPF verifier can insert instructions, the index in the translated program
> might differ from the raw index.
> 
> Could this bounds check be moved after idx is updated below, since
> &insns[idx + 2] is accessed later using the translated index?
> 
Ack.

Will check cnt using the new idx.

Thanks,
Leon


  reply	other threads:[~2026-06-11  5:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-08 14:51 [PATCH bpf-next v5 0/9] bpf: Introduce global percpu data Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 1/9] bpf: Drop duplicate blank lines in verifier Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 2/9] bpf: Introduce global percpu data Leon Hwang
2026-06-08 15:13   ` sashiko-bot
2026-06-11  5:04     ` Leon Hwang
2026-06-08 15:56   ` bot+bpf-ci
2026-06-11  5:05     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 3/9] libbpf: Probe percpu data feature Leon Hwang
2026-06-08 15:05   ` sashiko-bot
2026-06-11  5:08     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 4/9] libbpf: Add support for global percpu data Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 5/9] bpftool: Generate skeleton " Leon Hwang
2026-06-08 15:11   ` sashiko-bot
2026-06-11  5:09     ` Leon Hwang
2026-06-08 15:29   ` bot+bpf-ci
2026-06-11  5:09     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 6/9] selftests/bpf: Add tests to verify " Leon Hwang
2026-06-08 15:20   ` sashiko-bot
2026-06-11  5:10     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 7/9] selftests/bpf: Add tests to verify verifier log for " Leon Hwang
2026-06-08 15:22   ` sashiko-bot
2026-06-11  5:11     ` Leon Hwang
2026-06-08 14:51 ` [PATCH bpf-next v5 8/9] selftests/bpf: Add test to verify xlated insns " Leon Hwang
2026-06-08 15:21   ` sashiko-bot
2026-06-11  5:12     ` Leon Hwang [this message]
2026-06-08 14:51 ` [PATCH bpf-next v5 9/9] selftests/bpf: Add test to verify bpf_iter " Leon Hwang

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=c8b799df-8a38-4a15-a3f4-a71585c9c205@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=bpf@vger.kernel.org \
    --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 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.