All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>, bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v2 37/49] bpf: Verify in passes
Date: Sat, 21 Nov 2026 05:44:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-226658@kernel.org> (raw)
In-Reply-To: <20261120204959.614908-38-alexei.starovoitov@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] bpf: cost limit not bypassed during repeat run in
  log_failing_path()
--

commit 57a53f1fbdfbf66fd6d495ccd155fb967701e9d9
Author: Alexei Starovoitov <ast@kernel.org>

bpf: Verify in passes

This commit implements the multi-pass verification loop in do_check_all(),
running iterative partitioning passes and path-sensitive checks with cost
and memory budgets while re-running the final pass or failing path to
populate the verifier log.

> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index f34c010138497..92b0f4bbf8955 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
[ ... ]
> @@ -23466,40 +23488,202 @@ static int find_failing_path(struct bpf_verifier_env *env, struct bpf_snapshot *
>  	}
>  }
>  
> +/* Level 2 has the log of all passes. Else the log has one pass, or the failing path. */
> +struct pass_log {
> +	u32 level, len_max;
> +	u64 pos;
> +};
> +
> +static void restart_log(struct bpf_verifier_env *env, struct pass_log *log)
> +{
> +	env->log.level = log->level;
> +	/* the log is dropped when a function is found to be safe */
> +	log->pos = min(log->pos, env->log.end_pos);
> +	if (log->level & BPF_LOG_LEVEL2)
> +		return;
> +	bpf_vlog_reset(&env->log, log->pos);
> +	env->log.len_max = log->len_max;
> +}
> +
> +/* Repeat the last run. The verdict does not depend on the log, so it has no cost. */
> +static int log_failing_path(struct bpf_verifier_env *env, struct bpf_snapshot *initial,
> +			    struct pass_log *log)
> +{
> +	u32 insns = env->insn_processed, states = env->total_states;
> +	u64 cost = env->cost;
> +	int i, ret;
> +
> +	restart_log(env, log);
> +	ret = run_path_sensitive(env, initial, true);
> +	env->log.level = 0;
> +	env->cost = cost;

[Severity: Medium]
Can the repeat run in log_failing_path() hit env->max_cost in
bpf_check_limits()?

log_failing_path() saves and restores env->cost around
run_path_sensitive(), but neither rewinds env->cost to its value before
the unlogged run nor raises env->max_cost (unlike the env->for_log replay,
which sets env->max_cost = 2 * env->cost).  During the repeat run,
check_funcs() charges the path's cost a second time on top of env->cost
and checks it against env->max_cost:

kernel/bpf/flow.c:bpf_check_limits() {
	if (env->cost <= min(env->max_cost, env->pass_max_cost) && env->mem <= env->max_mem &&
	    !env->over_limit)
		return 0;
	verbose(env, "BPF program is too complex: cost %llu of %llu, memory %llu of %llu\n",
		env->cost, min(env->max_cost, env->pass_max_cost), env->mem, env->max_mem);
	env->over_limit = true;
	return -E2BIG;
}

When find_failing_path() succeeds near env->max_cost, the doubled run cost
pushes env->cost past env->max_cost.  That logs a complexity failure, sets
env->over_limit = true so env->err stays 0, and makes log_failing_path()
return 0 instead of err, losing the failing-path log.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120204959.614908-1-alexei.starovoitov@gmail.com?part=37

  reply	other threads:[~2026-11-21  5:44 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 20:49 [PATCH bpf-next v2 00/49] bpf: Verify in passes, with equations in the state Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 01/49] bpf: Look for bpf_clone_redirect() once in check_recursion() Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 02/49] bpf: Make stack liveness faster Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 03/49] bpf: Delete the old main pass of the verifier Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 04/49] bpf: Delete scalar evolution Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 05/49] bpf: Limit the cost and the memory of a load Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 06/49] bpf: Record what each insn reads and writes Alexei Starovoitov
2026-11-20 21:28   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 07/49] bpf: Name an id after the xreg that has it Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 08/49] bpf: Do not fail a check because a state has fewer values Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 09/49] bpf: Check fixups in the main pass and keep a snapshot of them Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 10/49] bpf: Reject a program with a call that needs two rewrites Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 11/49] bpf: Put a barrier where no mask fits Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 12/49] bpf: Keep more of what is known about a number Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 13/49] bpf: Remember how many bytes of a packet are checked Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 14/49] bpf: Mark a state that no run of the program has Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 15/49] bpf: Peel the first trips of a loop and join the other trips Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 16/49] bpf: Add equations and their arithmetic Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 17/49] bpf: Keep a table of equations in each state Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 18/49] bpf: Refine all related numbers after a jump Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 19/49] bpf: Make equations from ALU, spill, fill and call insns Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 20/49] bpf: Delete the equations that say nothing Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 21/49] bpf: Compare states by join_key, then by value Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 22/49] bpf: Continue a pass after an unproven insn Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 23/49] bpf: Find the xregs that an unproven insn depends on Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 24/49] bpf: Keep two states apart if data and control deps differ Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 25/49] bpf: Join any two states that have the same join_key Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 26/49] bpf: Check the equations when a state is pruned or joined Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 27/49] bpf: Guess the equations of a join Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 28/49] bpf: Prune or join each state that arrives Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 29/49] bpf: Order the pending states and free the states that are done Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 30/49] bpf: Get the trip count from the trip index Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 31/49] bpf: Give a loop a checked trip count or may_goto Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 32/49] bpf: Use the equations in the join rule Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 33/49] bpf: Verify a static function once for each instance Alexei Starovoitov
2026-11-21  4:46   ` sashiko-bot
2026-11-20 20:49 ` [PATCH bpf-next v2 34/49] bpf: Partition the states after an error Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 35/49] bpf: Reproduce an error on one path, with no joins Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 36/49] bpf: Do not let a join raise what a program requires Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 37/49] bpf: Verify in passes Alexei Starovoitov
2026-11-21  5:44   ` sashiko-bot [this message]
2026-11-20 20:49 ` [PATCH bpf-next v2 38/49] bpf: Make a returned pointer to the stack unreadable Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 39/49] bpf: Keep two states apart if a live xreg has two types Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 40/49] bpf: Check the body of a counted loop once Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 41/49] bpf: Refine the copies of a number that AND or OR splits Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 42/49] bpf: Allow a range of offsets for a constant string Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 43/49] bpf: Keep spilled pointers at a range of stack offsets Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 44/49] selftests/bpf: Adjust tests to the new log text Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 45/49] selftests/bpf: Adjust tests that get another verdict or may_goto Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 46/49] selftests/bpf: Test barriers and far pointers Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 47/49] selftests/bpf: Test passes, instances, precision and the failing path Alexei Starovoitov
2026-11-20 20:49 ` [PATCH bpf-next v2 48/49] selftests/bpf: Test equations Alexei Starovoitov
2026-11-20 21:51   ` bot+bpf-ci
2026-11-20 20:49 ` [PATCH bpf-next v2 49/49] bpf, docs: Rewrite verifier.rst Alexei Starovoitov
2026-11-20 21:28   ` bot+bpf-ci
2026-11-21  4:30 ` [PATCH bpf-next v2 00/49] bpf: Verify in passes, with equations in the state 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=sashiko-outbox-226658@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=alexei.starovoitov@gmail.com \
    --cc=bpf@vger.kernel.org \
    --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.