bpf-next: Avoid goto in regs_refine_cond_op()
authorHarishankar Vishwanathan <harishankar.vishwanathan@gmail.com>
Thu, 21 Mar 2024 00:29:54 +0000 (20:29 -0400)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 21 Mar 2024 18:56:26 +0000 (11:56 -0700)
In case of GE/GT/SGE/JST instructions, regs_refine_cond_op()
reuses the logic that does analysis of LE/LT/SLE/SLT instructions.
This commit avoids the use of a goto to perform the reuse.

Signed-off-by: Harishankar Vishwanathan <harishankar.vishwanathan@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240321002955.808604-1-harishankar.vishwanathan@gmail.com
kernel/bpf/verifier.c

index de7813947981a15774cfa630966e997e15753659..ca6cacf7b42f216fedbaccda99ac2fb04dac5cb0 100644 (file)
@@ -14544,7 +14544,19 @@ static void regs_refine_cond_op(struct bpf_reg_state *reg1, struct bpf_reg_state
        struct tnum t;
        u64 val;
 
-again:
+       /* In case of GE/GT/SGE/JST, reuse LE/LT/SLE/SLT logic from below */
+       switch (opcode) {
+       case BPF_JGE:
+       case BPF_JGT:
+       case BPF_JSGE:
+       case BPF_JSGT:
+               opcode = flip_opcode(opcode);
+               swap(reg1, reg2);
+               break;
+       default:
+               break;
+       }
+
        switch (opcode) {
        case BPF_JEQ:
                if (is_jmp32) {
@@ -14687,14 +14699,6 @@ again:
                        reg2->smin_value = max(reg1->smin_value + 1, reg2->smin_value);
                }
                break;
-       case BPF_JGE:
-       case BPF_JGT:
-       case BPF_JSGE:
-       case BPF_JSGT:
-               /* just reuse LE/LT logic above */
-               opcode = flip_opcode(opcode);
-               swap(reg1, reg2);
-               goto again;
        default:
                return;
        }