From: Yazhou Tang <tangyazhou@zju.edu.cn>
To: sashiko@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v9 2/3] bpf: Fix s16 truncation for large bpf-to-bpf call offsets
Date: Thu, 30 Apr 2026 22:47:56 +0800 [thread overview]
Message-ID: <c8fd766b-3704-4a8a-9366-1dcdcd84aed8@zju.edu.cn> (raw)
In-Reply-To: <20260429211006.E55AAC19425@smtp.kernel.org>
On 4/30/26 05:10, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Unprivileged users will see broken control flow graphs and `call pc+0` in BPF-to-BPF pseudo calls.
> --
>
> commit c7ae76817147356f188b1975260698d1d9dcd44a
> Author: Yazhou Tang <tangyazhou518@outlook.com>
>
> bpf: Fix s16 truncation for large bpf-to-bpf call offsets
>
> This commit fixes s16 truncation for large BPF-to-BPF call offsets by keeping
> the relative offset in the 32-bit imm field instead of downcasting it to the
> 16-bit off field. It updates the JIT, interpreter, and related dumper code to
> swap the usages of imm and off for BPF pseudo calls.
>
>> diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
>> index 300e4e251931..8947ef74f6a8 100644
>> --- a/kernel/bpf/fixups.c
>> +++ b/kernel/bpf/fixups.c
>> @@ -1250,9 +1250,9 @@ static int jit_subprogs(struct bpf_verifier_env *env)
>> }
>> if (!bpf_pseudo_call(insn))
>> continue;
>> - insn->off = env->insn_aux_data[i].call_imm;
>> - subprog = bpf_find_subprog(env, i + insn->off + 1);
>> - insn->imm = subprog;
>> + insn->imm = env->insn_aux_data[i].call_imm;
>> + subprog = bpf_find_subprog(env, i + insn->imm + 1);
>> + insn->off = subprog;
>> }
>
> Because this patch swaps the usage of insn->imm and insn->off for BPF pseudo
> calls, will this cause a regression for unprivileged users dumping programs?
>
> In kernel/bpf/syscall.c:bpf_insn_prepare_dump(), the kernel zeroes insn->imm
> for all BPF_CALL instructions when the user lacks privileges:
>
> if (code == (BPF_JMP | BPF_CALL)) {
> insns[i].imm = 0;
> ...
>
> Previously, this only hid the subprogram index. Now that insn->imm holds the
> actual relative offset, zeroing it means tools like bpftool will receive an
> offset of 0.
>
> Could this regression cause bpftool prog dump xlated to output call pc+0 and
> break the control flow graph generation for unprivileged users?
>
OK, this problem is confirmed.
As root user, executing "sysctl -w kernel.kptr_restrict=2" before "bpftool
prog dump xlated" will indeed demonstrate the bug. I will change the
bpf_insn_prepare_dump() function in v10.
next prev parent reply other threads:[~2026-04-30 14:47 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 17:19 [PATCH bpf-next v9 0/3] bpf: Fix call offset truncation and OOB read in bpf_patch_call_args() Yazhou Tang
2026-04-29 17:19 ` [PATCH bpf-next v9 1/3] bpf: Fix out-of-bounds " Yazhou Tang
2026-04-30 3:29 ` Xu Kuohai
2026-04-30 14:50 ` Yazhou Tang
2026-04-29 17:19 ` [PATCH bpf-next v9 2/3] bpf: Fix s16 truncation for large bpf-to-bpf call offsets Yazhou Tang
2026-04-29 21:10 ` sashiko-bot
2026-04-30 14:47 ` Yazhou Tang [this message]
2026-04-30 3:29 ` Xu Kuohai
2026-04-30 15:00 ` Yazhou Tang
2026-04-30 15:25 ` Quentin Monnet
2026-05-01 7:35 ` Yazhou Tang
2026-05-01 7:53 ` Alexei Starovoitov
2026-05-03 6:55 ` Yazhou Tang
2026-04-29 17:19 ` [PATCH bpf-next v9 3/3] selftests/bpf: Add test for large offset bpf-to-bpf call Yazhou Tang
2026-04-30 3:30 ` Xu Kuohai
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=c8fd766b-3704-4a8a-9366-1dcdcd84aed8@zju.edu.cn \
--to=tangyazhou@zju.edu.cn \
--cc=bpf@vger.kernel.org \
--cc=sashiko@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