From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Cc: daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org,
memxor@gmail.com
Subject: Re: [PATCH bpf-next 6/6] bpf: Add helper and kfunc stack access size resolution
Date: Wed, 01 Apr 2026 12:08:22 -0700 [thread overview]
Message-ID: <32efe62013c49a332fc1c6ae6e4690a2f271b92f.camel@gmail.com> (raw)
In-Reply-To: <20260401021635.34636-7-alexei.starovoitov@gmail.com>
On Tue, 2026-03-31 at 19:16 -0700, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> The static stack liveness analysis needs to know how many bytes a
> helper or kfunc accesses through a stack pointer argument, so it can
> precisely mark the affected stack slots as stack 'def' or 'use'.
>
> Add bpf_helper_stack_access_bytes() and bpf_kfunc_stack_access_bytes()
> which resolve the access size for a given call argument.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
(Please see below, I think a few cases can be slightly improved).
Acked-by: Eduard Zingerman <eddyz87@gmail.com>
[...]
> +s64 bpf_helper_stack_access_bytes(struct bpf_verifier_env *env, struct bpf_insn *insn,
> + int arg, int insn_idx)
> +{
[...]
> + case ARG_PTR_TO_MEM:
> + if (at & MEM_FIXED_SIZE) {
> + size = fn->arg_size[arg];
> + goto out;
> + }
> + if (arg + 1 < ARRAY_SIZE(fn->arg_type) &&
> + arg_type_is_mem_size(fn->arg_type[arg + 1])) {
> + int size_reg = BPF_REG_1 + arg + 1;
> +
> + if (aux->const_reg_mask & BIT(size_reg)) {
> + size = (s64)aux->const_reg_vals[size_reg];
> + goto out;
if `at & MEM_WRITE`, I think it would be correct to `return 0;` here.
> + }
> + /*
> + * Size arg is const on each path but differs across
> + * merged paths. 512 is a safe upper bound for reads.
> + */
> + if (at & MEM_UNINIT)
> + return S64_MIN;
> + return 512;
Nit: `return MAX_BPF_STACK;`
> + }
> + return S64_MIN;
> + case ARG_PTR_TO_DYNPTR:
> + return BPF_DYNPTR_SIZE;
> + case ARG_PTR_TO_STACK:
> + /*
> + * Only used by bpf_calls_callback() helpers. The helper itself
> + * doesn't access stack. The callback subprog does and it's
> + * analyzed separately.
> + */
> + return 0;
> + default:
> + return S64_MIN;
> + }
> +out:
> + /*
> + * MEM_UNINIT args are write-only: the helper initializes the
> + * buffer without reading it.
> + */
> + if (size > 0 && at & MEM_UNINIT)
> + return -size;
Same question about MEM_WRITE here, might be possible to `return 0` in
some cases.
> + return size;
> +}
[...]
next prev parent reply other threads:[~2026-04-01 19:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 2:16 [PATCH bpf-next 0/6] bpf: Prep patches for static stack liveness Alexei Starovoitov
2026-04-01 2:16 ` [PATCH bpf-next 1/6] bpf: Do register range validation early Alexei Starovoitov
2026-04-01 3:38 ` bot+bpf-ci
2026-04-01 15:33 ` Alexei Starovoitov
2026-04-01 15:56 ` Mykyta Yatsenko
2026-04-01 16:25 ` Alexei Starovoitov
2026-04-01 2:16 ` [PATCH bpf-next 2/6] bpf: Sort subprogs in topological order after check_cfg() Alexei Starovoitov
2026-04-01 17:06 ` Mykyta Yatsenko
2026-04-01 21:10 ` Eduard Zingerman
2026-04-02 0:17 ` Alexei Starovoitov
2026-04-01 2:16 ` [PATCH bpf-next 3/6] selftests/bpf: Add tests for subprog topological ordering Alexei Starovoitov
2026-04-01 2:16 ` [PATCH bpf-next 4/6] bpf: Add compute_const_regs() and prune_dead_branches() passes Alexei Starovoitov
2026-04-01 3:49 ` bot+bpf-ci
2026-04-01 15:46 ` Alexei Starovoitov
2026-04-01 21:07 ` Eduard Zingerman
2026-04-01 22:32 ` Alexei Starovoitov
2026-04-02 2:45 ` Alexei Starovoitov
2026-04-02 2:49 ` Eduard Zingerman
2026-04-02 3:00 ` Alexei Starovoitov
2026-04-01 2:16 ` [PATCH bpf-next 5/6] bpf: Move verifier helpers to header Alexei Starovoitov
2026-04-01 20:16 ` Eduard Zingerman
2026-04-01 2:16 ` [PATCH bpf-next 6/6] bpf: Add helper and kfunc stack access size resolution Alexei Starovoitov
2026-04-01 19:08 ` Eduard Zingerman [this message]
2026-04-01 10:02 ` [syzbot ci] Re: bpf: Prep patches for static stack liveness syzbot 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=32efe62013c49a332fc1c6ae6e4690a2f271b92f.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=martin.lau@kernel.org \
--cc=memxor@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox