mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: bot+bpf-ci@kernel.org
To: random6.xyz@gmail.com,bpf@vger.kernel.org
Cc: ast@kernel.org,daniel@iogearbox.net,andrii@kernel.org,eddyz87@gmail.com,memxor@gmail.com,martin.lau@linux.dev,song@kernel.org,yonghong.song@linux.dev,jolsa@kernel.org,emil@etsalapatis.com,ihor.solodrai@linux.dev,shuah@kernel.org,linux-kselftest@vger.kernel.org,linux-kernel@vger.kernel.org,random6.xyz@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf v2 1/2] bpf: Zero-extend the index in inlined bpf_get_func_arg()
Date: Sun, 18 Oct 2026 04:55:12 +0000 (UTC)	[thread overview]
Message-ID: <0413b3f51a48a8f318fd0923859cee1cf2837f1ffd431fa76f594dde6169d89f@mail.kernel.org> (raw)
In-Reply-To: <20261018-get-func-arg-v2-1-048848b3eddf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2985 bytes --]

> bpf: Zero-extend the index in inlined bpf_get_func_arg()

TL;DR: Commit message only: the code looks correct, but the claim that the
raw_tp argument count is capped at MAX_BPF_FUNC_ARGS appears inaccurate; the
real bound is the 24-bit BTF vlen.

>     bpf: Zero-extend the index in inlined bpf_get_func_arg()
>
>     bpf_get_func_arg() takes a u32 index, but the inlined expansion compared
>     only the low 32 bits of R2 with the argument count and then shifted the
>     full 64-bit register to compute the context address. R2 is ARG_ANYTHING,
>     so nothing guarantees that its upper bits are zero: an index of
>     1ULL << 32 passes the bounds check as index zero while the load is
>     performed at ctx + (1ULL << 35).
>
>     Shift the index as a 32-bit value. When the 32-bit bounds check passes,
>     the low 32 bits of R2 are below R0, and R0 is at most 255: the trampoline
>     arm masks the argument count with 0xFF and the raw_tp arm uses the BTF
>     argument count minus one, which the verifier caps at MAX_BPF_FUNC_ARGS.
>     The 3-bit shift therefore cannot overflow and it clears the upper bits of
>     the register. Widening the comparison instead would reject indices whose
>     low 32 bits are valid. The check itself is unchanged, so this cannot
>     change which programs are accepted, only the address that is computed.
>
>     Fixes: f92c1e183604 ("bpf: Add get_func_[arg|ret|arg_cnt] helpers")
>     Assisted-by: LLM
>     Signed-off-by: Woojin Ji <random6.xyz@gmail.com>

This isn't a bug in the code, but is the commit message accurate about the
raw_tp arm?  It says R0 is at most 255 because the raw_tp arm uses "the BTF
argument count minus one, which the verifier caps at MAX_BPF_FUNC_ARGS".

For BPF_TRACE_RAW_TP, bpf_check_attach_target() only checks that the
typedef's target is a func_proto and then leaves the switch.  Unlike the
fentry/fexit/iter arms, it never calls btf_distill_func_proto(), which is
the only place nargs > MAX_BPF_FUNC_ARGS is rejected.

btf_ctx_access() only does:

    nr_args = btf_type_vlen(t);
    if (attach_btf_trace)
        nr_args--;

and compares the ctx argument index against it.  The MAX_BPF_FUNC_ARGS limit
that does exist for tracing programs is in bpf_tracing_ctx_access(), which
bounds ctx load offsets rather than the value that
BPF_MOV64_IMM(BPF_REG_0, nr_args - 1) places in R0.

The generated code itself looks correct, since btf_type_vlen() is a 24-bit
field (BTF_MAX_VLEN is 0x00ffffff), so (nr_args - 1) << 3 stays below 2^27
and cannot overflow a 32-bit shift.

Could the changelog either drop the "caps at MAX_BPF_FUNC_ARGS" claim for the
raw_tp arm, or state the real bound (the BTF vlen is 24 bits, so the shifted
value always fits in 32 bits)?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/39097593630

  reply	other threads:[~2026-10-18  4:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-18  4:21 [PATCH bpf v2 0/2] " Woojin Ji
2026-10-18  4:21 ` [PATCH bpf v2 1/2] " Woojin Ji
2026-10-18  4:55   ` bot+bpf-ci [this message]
2026-10-18  4:21 ` [PATCH bpf v2 2/2] selftests/bpf: Test out-of-range index bits in bpf_get_func_arg() Woojin Ji
2026-10-18 15:30 ` [PATCH bpf v2 0/2] bpf: Zero-extend the index in inlined bpf_get_func_arg() patchwork-bot+netdevbpf

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=0413b3f51a48a8f318fd0923859cee1cf2837f1ffd431fa76f594dde6169d89f@mail.kernel.org \
    --to=bot+bpf-ci@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mason@kernel.org \
    --cc=memxor@gmail.com \
    --cc=random6.xyz@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yonghong.song@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

all inboxes | Powered by JetHome®