File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -17869,6 +17869,27 @@ static bool insn_is_gotox(struct bpf_insn *insn)
1786917869 BPF_SRC(insn->code) == BPF_X;
1787017870}
1787117871
17872+ static bool insn_is_ja(struct bpf_insn *insn)
17873+ {
17874+ return BPF_CLASS(insn->code) == BPF_JMP &&
17875+ BPF_OP(insn->code) == BPF_JA &&
17876+ BPF_SRC(insn->code) == BPF_K;
17877+ }
17878+
17879+ /*
17880+ * This is a workaround to overcome a LLVM "bug". The problem is that
17881+ * sometimes LLVM would generate code like
17882+ *
17883+ * gotox rX
17884+ * goto +offset
17885+ *
17886+ * even though rX never points to the goto +offset instruction.
17887+ */
17888+ static inline bool magic_dead_ja(struct bpf_insn *insn, bool have_prev)
17889+ {
17890+ return have_prev && insn_is_gotox(insn - 1) && insn_is_ja(insn);
17891+ }
17892+
1787217893/* non-recursive depth-first-search to detect loops in BPF program
1787317894 * loop == back-edge in directed graph
1787417895 */
@@ -17943,6 +17964,9 @@ static int check_cfg(struct bpf_verifier_env *env)
1794317964 struct bpf_insn *insn = &env->prog->insnsi[i];
1794417965
1794517966 if (insn_state[i] != EXPLORED) {
17967+ if (magic_dead_ja(insn, i > 0))
17968+ continue;
17969+
1794617970 verbose(env, "unreachable insn %d\n", i);
1794717971 ret = -EINVAL;
1794817972 goto err_free;
You can’t perform that action at this time.
0 commit comments