From: Mykyta Yatsenko <mykyta.yatsenko5@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, eddyz87@gmail.com
Subject: Re: [PATCH bpf-next 1/6] bpf: Do register range validation early
Date: Wed, 1 Apr 2026 16:56:41 +0100 [thread overview]
Message-ID: <4f283d2c-dc06-4598-bb21-d4d2491a7fff@gmail.com> (raw)
In-Reply-To: <20260401021635.34636-2-alexei.starovoitov@gmail.com>
On 4/1/26 3:16 AM, Alexei Starovoitov wrote:
> From: Alexei Starovoitov <ast@kernel.org>
>
> Instead of checking src/dst range multiple times during
> the main verifier pass do them once.
>
> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
> ---
resolve_pseudo_ldimm64() runs earlier into verification, so it makes
sense to move this basic check there and remove from other places. Looks
good, other than issue that AI found.
> kernel/bpf/verifier.c | 34 ++++++++--------------------------
> 1 file changed, 8 insertions(+), 26 deletions(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 8c1cf2eb6cbb..3ec786361698 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -2249,13 +2249,6 @@ static void __mark_reg_const_zero(const struct bpf_verifier_env *env, struct bpf
> static void mark_reg_known_zero(struct bpf_verifier_env *env,
> struct bpf_reg_state *regs, u32 regno)
> {
> - if (WARN_ON(regno >= MAX_BPF_REG)) {
> - verbose(env, "mark_reg_known_zero(regs, %u)\n", regno);
> - /* Something bad happened, let's kill all regs */
> - for (regno = 0; regno < MAX_BPF_REG; regno++)
> - __mark_reg_not_init(env, regs + regno);
> - return;
> - }
> __mark_reg_known_zero(regs + regno);
> }
>
> @@ -2908,13 +2901,6 @@ static void __mark_reg_unknown(const struct bpf_verifier_env *env,
> static void mark_reg_unknown(struct bpf_verifier_env *env,
> struct bpf_reg_state *regs, u32 regno)
> {
> - if (WARN_ON(regno >= MAX_BPF_REG)) {
> - verbose(env, "mark_reg_unknown(regs, %u)\n", regno);
> - /* Something bad happened, let's kill all regs except FP */
> - for (regno = 0; regno < BPF_REG_FP; regno++)
> - __mark_reg_not_init(env, regs + regno);
> - return;
> - }
> __mark_reg_unknown(env, regs + regno);
> }
>
> @@ -2947,13 +2933,6 @@ static void __mark_reg_not_init(const struct bpf_verifier_env *env,
> static void mark_reg_not_init(struct bpf_verifier_env *env,
> struct bpf_reg_state *regs, u32 regno)
> {
> - if (WARN_ON(regno >= MAX_BPF_REG)) {
> - verbose(env, "mark_reg_not_init(regs, %u)\n", regno);
> - /* Something bad happened, let's kill all regs except FP */
> - for (regno = 0; regno < BPF_REG_FP; regno++)
> - __mark_reg_not_init(env, regs + regno);
> - return;
> - }
> __mark_reg_not_init(env, regs + regno);
> }
>
> @@ -3958,11 +3937,6 @@ static int __check_reg_arg(struct bpf_verifier_env *env, struct bpf_reg_state *r
> struct bpf_reg_state *reg;
> bool rw64;
>
> - if (regno >= MAX_BPF_REG) {
> - verbose(env, "R%d is invalid\n", regno);
> - return -EINVAL;
> - }
> -
> mark_reg_scratched(env, regno);
>
> reg = ®s[regno];
> @@ -22070,6 +22044,14 @@ static int resolve_pseudo_ldimm64(struct bpf_verifier_env *env)
> verbose(env, "unknown opcode %02x\n", insn->code);
> return -EINVAL;
> }
> + if (insn->dst_reg >= MAX_BPF_REG) {
> + verbose(env, "R%d is invalid\n", insn->dst_reg);
> + return -EINVAL;
> + }
> + if (insn->src_reg >= MAX_BPF_REG) {
> + verbose(env, "R%d is invalid\n", insn->src_reg);
> + return -EINVAL;
> + }
> }
>
> /* now all pseudo BPF_LD_IMM64 instructions load valid
next prev parent reply other threads:[~2026-04-01 15:56 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 [this message]
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
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=4f283d2c-dc06-4598-bb21-d4d2491a7fff@gmail.com \
--to=mykyta.yatsenko5@gmail.com \
--cc=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--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