Skip to content

Commit efdb22d

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
bpf: Factor out visit_func_call_insn() in check_cfg()
During verifier check_cfg(), all instructions are visited to ensure verifier can handle program control flows. This patch factored out function visit_func_call_insn() so it can be reused in later patch to visit callback function calls. There is no functionality change for this patch. Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 86fd166 commit efdb22d

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

kernel/bpf/verifier.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8592,6 +8592,27 @@ static int push_insn(int t, int w, int e, struct bpf_verifier_env *env,
85928592
return DONE_EXPLORING;
85938593
}
85948594

8595+
static int visit_func_call_insn(int t, int insn_cnt,
8596+
struct bpf_insn *insns,
8597+
struct bpf_verifier_env *env,
8598+
bool visit_callee)
8599+
{
8600+
int ret;
8601+
8602+
ret = push_insn(t, t + 1, FALLTHROUGH, env, false);
8603+
if (ret)
8604+
return ret;
8605+
8606+
if (t + 1 < insn_cnt)
8607+
init_explored_state(env, t + 1);
8608+
if (visit_callee) {
8609+
init_explored_state(env, t);
8610+
ret = push_insn(t, t + insns[t].imm + 1, BRANCH,
8611+
env, false);
8612+
}
8613+
return ret;
8614+
}
8615+
85958616
/* Visits the instruction at index t and returns one of the following:
85968617
* < 0 - an error occurred
85978618
* DONE_EXPLORING - the instruction was fully explored
@@ -8612,18 +8633,8 @@ static int visit_insn(int t, int insn_cnt, struct bpf_verifier_env *env)
86128633
return DONE_EXPLORING;
86138634

86148635
case BPF_CALL:
8615-
ret = push_insn(t, t + 1, FALLTHROUGH, env, false);
8616-
if (ret)
8617-
return ret;
8618-
8619-
if (t + 1 < insn_cnt)
8620-
init_explored_state(env, t + 1);
8621-
if (insns[t].src_reg == BPF_PSEUDO_CALL) {
8622-
init_explored_state(env, t);
8623-
ret = push_insn(t, t + insns[t].imm + 1, BRANCH,
8624-
env, false);
8625-
}
8626-
return ret;
8636+
return visit_func_call_insn(t, insn_cnt, insns, env,
8637+
insns[t].src_reg == BPF_PSEUDO_CALL);
86278638

86288639
case BPF_JA:
86298640
if (BPF_SRC(insns[t].code) != BPF_K)

0 commit comments

Comments
 (0)