Skip to content

Commit 8e1acf4

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: starting_state parameter for __mark_chain_precision()
Allow `mark_chain_precision()` to run from an arbitrary starting state by replacing direct references to `env->cur_state` with a parameter. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 2ca9f34 commit 8e1acf4

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

kernel/bpf/verifier.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4677,12 +4677,13 @@ static void mark_all_scalars_imprecise(struct bpf_verifier_env *env, struct bpf_
46774677
* mark_all_scalars_imprecise() to hopefully get more permissive and generic
46784678
* finalized states which help in short circuiting more future states.
46794679
*/
4680-
static int __mark_chain_precision(struct bpf_verifier_env *env, int regno)
4680+
static int __mark_chain_precision(struct bpf_verifier_env *env,
4681+
struct bpf_verifier_state *starting_state, int regno)
46814682
{
4683+
struct bpf_verifier_state *st = starting_state;
46824684
struct backtrack_state *bt = &env->bt;
4683-
struct bpf_verifier_state *st = env->cur_state;
46844685
int first_idx = st->first_insn_idx;
4685-
int last_idx = env->insn_idx;
4686+
int last_idx = starting_state->insn_idx;
46864687
int subseq_idx = -1;
46874688
struct bpf_func_state *func;
46884689
struct bpf_reg_state *reg;
@@ -4693,7 +4694,7 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno)
46934694
return 0;
46944695

46954696
/* set frame number from which we are starting to backtrack */
4696-
bt_init(bt, env->cur_state->curframe);
4697+
bt_init(bt, starting_state->curframe);
46974698

46984699
/* Do sanity checks against current state of register and/or stack
46994700
* slot, but don't set precise flag in current state, as precision
@@ -4757,7 +4758,7 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno)
47574758
err = backtrack_insn(env, i, subseq_idx, hist, bt);
47584759
}
47594760
if (err == -ENOTSUPP) {
4760-
mark_all_scalars_precise(env, env->cur_state);
4761+
mark_all_scalars_precise(env, starting_state);
47614762
bt_reset(bt);
47624763
return 0;
47634764
} else if (err) {
@@ -4845,7 +4846,7 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno)
48454846
* fallback to marking all precise
48464847
*/
48474848
if (!bt_empty(bt)) {
4848-
mark_all_scalars_precise(env, env->cur_state);
4849+
mark_all_scalars_precise(env, starting_state);
48494850
bt_reset(bt);
48504851
}
48514852

@@ -4854,15 +4855,16 @@ static int __mark_chain_precision(struct bpf_verifier_env *env, int regno)
48544855

48554856
int mark_chain_precision(struct bpf_verifier_env *env, int regno)
48564857
{
4857-
return __mark_chain_precision(env, regno);
4858+
return __mark_chain_precision(env, env->cur_state, regno);
48584859
}
48594860

48604861
/* mark_chain_precision_batch() assumes that env->bt is set in the caller to
48614862
* desired reg and stack masks across all relevant frames
48624863
*/
4863-
static int mark_chain_precision_batch(struct bpf_verifier_env *env)
4864+
static int mark_chain_precision_batch(struct bpf_verifier_env *env,
4865+
struct bpf_verifier_state *starting_state)
48644866
{
4865-
return __mark_chain_precision(env, -1);
4867+
return __mark_chain_precision(env, starting_state, -1);
48664868
}
48674869

48684870
static bool is_spillable_regtype(enum bpf_reg_type type)
@@ -9515,7 +9517,7 @@ static int get_constant_map_key(struct bpf_verifier_env *env,
95159517
* to prevent pruning on it.
95169518
*/
95179519
bt_set_frame_slot(&env->bt, key->frameno, spi);
9518-
err = mark_chain_precision_batch(env);
9520+
err = mark_chain_precision_batch(env, env->cur_state);
95199521
if (err < 0)
95209522
return err;
95219523

@@ -18939,7 +18941,7 @@ static int propagate_precision(struct bpf_verifier_env *env,
1893918941
verbose(env, "\n");
1894018942
}
1894118943

18942-
err = mark_chain_precision_batch(env);
18944+
err = mark_chain_precision_batch(env, env->cur_state);
1894318945
if (err < 0)
1894418946
return err;
1894518947

0 commit comments

Comments
 (0)