Skip to content

Commit 67afdc7

Browse files
borkmanngregkh
authored andcommitted
bpf: Fix verifier jsgt branch analysis on max bound
commit ee114dd upstream. Fix incorrect is_branch{32,64}_taken() analysis for the jsgt case. The return code for both will tell the caller whether a given conditional jump is taken or not, e.g. 1 means branch will be taken [for the involved registers] and the goto target will be executed, 0 means branch will not be taken and instead we fall-through to the next insn, and last but not least a -1 denotes that it is not known at verification time whether a branch will be taken or not. Now while the jsgt has the branch-taken case correct with reg->s32_min_value > sval, the branch-not-taken case is off-by-one when testing for reg->s32_max_value < sval since the branch will also be taken for reg->s32_max_value == sval. The jgt branch analysis, for example, gets this right. Fixes: 3f50f13 ("bpf: Verifier, do explicit ALU32 bounds tracking") Fixes: 4f7b3e8 ("bpf: improve verifier branch analysis") Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: John Fastabend <john.fastabend@gmail.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1d16cc2 commit 67afdc7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6822,7 +6822,7 @@ static int is_branch32_taken(struct bpf_reg_state *reg, u32 val, u8 opcode)
68226822
case BPF_JSGT:
68236823
if (reg->s32_min_value > sval)
68246824
return 1;
6825-
else if (reg->s32_max_value < sval)
6825+
else if (reg->s32_max_value <= sval)
68266826
return 0;
68276827
break;
68286828
case BPF_JLT:
@@ -6895,7 +6895,7 @@ static int is_branch64_taken(struct bpf_reg_state *reg, u64 val, u8 opcode)
68956895
case BPF_JSGT:
68966896
if (reg->smin_value > sval)
68976897
return 1;
6898-
else if (reg->smax_value < sval)
6898+
else if (reg->smax_value <= sval)
68996899
return 0;
69006900
break;
69016901
case BPF_JLT:

0 commit comments

Comments
 (0)