Skip to content

Commit be935ab

Browse files
iii-igregkh
authored andcommitted
s390/bpf: Fix 64-bit subtraction of the -0x80000000 constant
commit 6e61dc9da0b7a0d91d57c2e20b5ea4fd2d4e7e53 upstream. The JIT uses agfi for subtracting constants, but -(-0x80000000) cannot be represented as a 32-bit signed binary integer. Fix by using algfi in this particular case. Reported-by: Johan Almbladh <johan.almbladh@anyfinetworks.com> Fixes: 0546231 ("s390/bpf: Add s390x eBPF JIT compiler backend") Reviewed-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0ade46e commit be935ab

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

arch/s390/net/bpf_jit_comp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,13 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, int i
625625
case BPF_ALU64 | BPF_SUB | BPF_K: /* dst = dst - imm */
626626
if (!imm)
627627
break;
628-
/* agfi %dst,-imm */
629-
EMIT6_IMM(0xc2080000, dst_reg, -imm);
628+
if (imm == -0x80000000) {
629+
/* algfi %dst,0x80000000 */
630+
EMIT6_IMM(0xc20a0000, dst_reg, 0x80000000);
631+
} else {
632+
/* agfi %dst,-imm */
633+
EMIT6_IMM(0xc2080000, dst_reg, -imm);
634+
}
630635
break;
631636
/*
632637
* BPF_MUL

0 commit comments

Comments
 (0)