From: sashiko-bot@kernel.org
To: "Kumar Kartikeya Dwivedi" <memxor@gmail.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v1 1/3] bpf: Fix generic __uninit kfunc output buffers
Date: Tue, 15 Sep 2026 14:24:37 +0000 [thread overview]
Message-ID: <20260915142438.4E7671F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915141004.1196460-2-memxor@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] bpf: UBSAN out-of-bounds and NULL pointer arithmetic in mark_raw_stack()
--
commit fc77f675fb39113d85b64af5b859a8ccdbd2caef
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
bpf: Fix generic __uninit kfunc output buffers
This commit updates the verifier to check generic __uninit memory
arguments as write-only, tracking output sizes per argument slot so a call
can initialize multiple buffers, including those passed on the stack. It
reuses helper raw memory handling to record their definite initialization
after validating all arguments.
Link: https://lore.kernel.org/bpf/86d966ec88bbf27d21b2bb4e18c8aa00@kernel.org
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 6c6b8d8520cdf..070ec5daeec33 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -9550,6 +9556,33 @@ static int check_func_args(struct bpf_verifier_env *env, struct bpf_call_arg_met
> return 0;
> }
>
> +static int mark_raw_stack(struct bpf_verifier_env *env, struct bpf_call_arg_meta *meta,
> + int insn_idx)
> +{
> + struct bpf_func_state *caller = cur_func(env);
> + u32 slot;
> + int i, err;
> +
> + /*
> + * Validate every argument before initializing outputs: an input argument
> + * may alias an output buffer. Use the normal stack-write checks to discard
> + * stale spills and preserve the rules for special stack objects.
> + */
> + for (slot = 0; slot < MAX_BPF_FUNC_ARGS; slot++) {
> + struct bpf_reg_state *reg = get_func_arg_reg(caller, cur_regs(env), slot);
[Severity: High]
Does this unconditional call to get_func_arg_reg() for all MAX_BPF_FUNC_ARGS
slots cause an out-of-bounds or NULL pointer arithmetic issue?
Looking at get_func_arg_reg(), it computes a pointer offset based on the
caller's stack arguments:
kernel/bpf/verifier.c:get_func_arg_reg() {
...
return &caller->stack_arg_regs[arg - MAX_BPF_FUNC_REG_ARGS];
}
Since this loop unconditionally evaluates get_func_arg_reg() for all 12
potential slots (MAX_BPF_FUNC_ARGS), even if meta->arg_raw_mem.size[slot]
is 0, won't this trigger undefined behavior and a UBSAN panic for any
helper or kfunc call where caller->stack_arg_regs is NULL or smaller than
the computed offset?
> + argno_t argno = argno_from_arg(slot + 1);
> +
> + for (i = 0; i < meta->arg_raw_mem.size[slot]; i++) {
> + err = check_mem_access(env, insn_idx, reg, argno, i, BPF_B,
> + BPF_WRITE, -1, false, false);
> + if (err)
> + return err;
> + }
> + }
> +
> + return 0;
> +}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260915141004.1196460-1-memxor@gmail.com?part=1
next prev parent reply other threads:[~2026-09-15 14:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-15 14:10 [PATCH bpf-next v1 0/3] Fix generic __uninit kfunc output buffers Kumar Kartikeya Dwivedi
2026-09-15 14:10 ` [PATCH bpf-next v1 1/3] bpf: " Kumar Kartikeya Dwivedi
2026-09-15 14:24 ` sashiko-bot [this message]
2026-09-15 17:20 ` Amery Hung
2026-09-16 5:19 ` Eduard Zingerman
2026-09-16 16:08 ` Kumar Kartikeya Dwivedi
2026-09-15 14:10 ` [PATCH bpf-next v1 2/3] selftests/bpf: Allow privileged preparation for capability tests Kumar Kartikeya Dwivedi
2026-09-15 15:01 ` bot+bpf-ci
2026-09-15 14:10 ` [PATCH bpf-next v1 3/3] selftests/bpf: Cover generic __uninit kfunc output buffers Kumar Kartikeya Dwivedi
2026-09-15 15:01 ` bot+bpf-ci
2026-09-16 5:56 ` Eduard Zingerman
2026-09-15 14:14 ` [PATCH bpf-next v1 0/3] Fix " Kumar Kartikeya Dwivedi
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=20260915142438.4E7671F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=memxor@gmail.com \
--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.