Skip to content

Commit 3bf1592

Browse files
4astborkmann
authored andcommitted
bpf: improve JEQ/JNE path walking
verifier knows how to trim paths that are known not to be taken at run-time when register containing run-time constant is compared with another constant. It was done only for JEQ comparison. Extend it to include JNE as well. More cases can be added in the future. before after bpf_lb-DLB_L3.o 2270 2051 bpf_lb-DLB_L4.o 3682 3287 bpf_lb-DUNKNOWN.o 1110 1080 bpf_lxc-DDROP_ALL.o 27876 24980 bpf_lxc-DUNKNOWN.o 38780 34308 bpf_netdev.o 16937 15404 bpf_overlay.o 7929 7191 Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: John Fastabend <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 2f18f62 commit 3bf1592

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,8 +2955,9 @@ static int check_cond_jmp_op(struct bpf_verifier_env *env,
29552955
if (BPF_SRC(insn->code) == BPF_K &&
29562956
(opcode == BPF_JEQ || opcode == BPF_JNE) &&
29572957
dst_reg->type == SCALAR_VALUE &&
2958-
tnum_equals_const(dst_reg->var_off, insn->imm)) {
2959-
if (opcode == BPF_JEQ) {
2958+
tnum_is_const(dst_reg->var_off)) {
2959+
if ((opcode == BPF_JEQ && dst_reg->var_off.value == insn->imm) ||
2960+
(opcode == BPF_JNE && dst_reg->var_off.value != insn->imm)) {
29602961
/* if (imm == imm) goto pc+off;
29612962
* only follow the goto, ignore fall-through
29622963
*/

0 commit comments

Comments
 (0)