Skip to content

bpf: Update env->prev_insn_idx after do_check_insn() #9221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: bpf-next_base
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -19854,16 +19854,15 @@ static int do_check(struct bpf_verifier_env *env)
struct bpf_insn *insns = env->prog->insnsi;
int insn_cnt = env->prog->len;
bool do_print_state = false;
int prev_insn_idx = -1;

env->prev_insn_idx = -1;
for (;;) {
struct bpf_insn *insn;
int err;
int err, tmp;

/* reset current history entry on each new instruction */
env->cur_hist_ent = NULL;

env->prev_insn_idx = prev_insn_idx;
if (env->insn_idx >= insn_cnt) {
verbose(env, "invalid insn idx %d insn_cnt %d\n",
env->insn_idx, insn_cnt);
Expand Down Expand Up @@ -19942,15 +19941,16 @@ static int do_check(struct bpf_verifier_env *env)
}

sanitize_mark_insn_seen(env);
prev_insn_idx = env->insn_idx;

/* Reduce verification complexity by stopping speculative path
* verification when a nospec is encountered.
*/
if (state->speculative && cur_aux(env)->nospec)
goto process_bpf_exit;

tmp = env->insn_idx;
err = do_check_insn(env, &do_print_state);
env->prev_insn_idx = tmp;
if (error_recoverable_with_nospec(err) && state->speculative) {
/* Prevent this speculative path from ever reaching the
* insn that would have been unsafe to execute.
Expand Down Expand Up @@ -19978,13 +19978,13 @@ static int do_check(struct bpf_verifier_env *env)
* to document this in case nospec_result is used
* elsewhere in the future.
*/
WARN_ON_ONCE(env->insn_idx != prev_insn_idx + 1);
WARN_ON_ONCE(env->insn_idx != env->prev_insn_idx + 1);
process_bpf_exit:
mark_verifier_state_scratched(env);
err = update_branch_counts(env, env->cur_state);
if (err)
return err;
err = pop_stack(env, &prev_insn_idx, &env->insn_idx,
err = pop_stack(env, &env->prev_insn_idx, &env->insn_idx,
pop_log);
if (err < 0) {
if (err != -ENOENT)
Expand Down
Loading