Skip to content

Commit 13f843c

Browse files
eddyz87Alexei Starovoitov
authored andcommitted
bpf: frame_insn_idx() utility function
A function to return IP for a given frame in a call stack of a state. Will be used by a next patch. The `state->insn_idx = env->insn_idx;` assignment in the do_check() allows to use frame_insn_idx with env->cur_state. At the moment bpf_verifier_state->insn_idx is set when new cached state is added in is_state_visited() and accessed only in the contexts when the state is already in the cache. Hence this assignment does not change verifier behaviour. Signed-off-by: Eduard Zingerman <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 96c6aa4 commit 13f843c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

kernel/bpf/verifier.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,6 +1964,14 @@ static void update_loop_entry(struct bpf_verifier_env *env,
19641964
}
19651965
}
19661966

1967+
/* Return IP for a given frame in a call stack */
1968+
static u32 frame_insn_idx(struct bpf_verifier_state *st, u32 frame)
1969+
{
1970+
return frame == st->curframe
1971+
? st->insn_idx
1972+
: st->frame[frame + 1]->callsite;
1973+
}
1974+
19671975
static void update_branch_counts(struct bpf_verifier_env *env, struct bpf_verifier_state *st)
19681976
{
19691977
struct bpf_verifier_state_list *sl = NULL, *parent_sl;
@@ -18790,9 +18798,7 @@ static bool states_equal(struct bpf_verifier_env *env,
1879018798
* and all frame states need to be equivalent
1879118799
*/
1879218800
for (i = 0; i <= old->curframe; i++) {
18793-
insn_idx = i == old->curframe
18794-
? env->insn_idx
18795-
: old->frame[i + 1]->callsite;
18801+
insn_idx = frame_insn_idx(old, i);
1879618802
if (old->frame[i]->callsite != cur->frame[i]->callsite)
1879718803
return false;
1879818804
if (!func_states_equal(env, old->frame[i], cur->frame[i], insn_idx, exact))
@@ -19687,6 +19693,7 @@ static int do_check(struct bpf_verifier_env *env)
1968719693
}
1968819694

1968919695
state->last_insn_idx = env->prev_insn_idx;
19696+
state->insn_idx = env->insn_idx;
1969019697

1969119698
if (is_prune_point(env, env->insn_idx)) {
1969219699
err = is_state_visited(env, env->insn_idx);

0 commit comments

Comments
 (0)