Skip to content

Commit 4320c22

Browse files
iii-igregkh
authored andcommitted
s390/bpf: Fix 64-bit subtraction of the -0x80000000 constant
commit 6e61dc9 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 d92d3a9 commit 4320c22

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
@@ -795,8 +795,13 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
795795
case BPF_ALU64 | BPF_SUB | BPF_K: /* dst = dst - imm */
796796
if (!imm)
797797
break;
798-
/* agfi %dst,-imm */
799-
EMIT6_IMM(0xc2080000, dst_reg, -imm);
798+
if (imm == -0x80000000) {
799+
/* algfi %dst,0x80000000 */
800+
EMIT6_IMM(0xc20a0000, dst_reg, 0x80000000);
801+
} else {
802+
/* agfi %dst,-imm */
803+
EMIT6_IMM(0xc2080000, dst_reg, -imm);
804+
}
800805
break;
801806
/*
802807
* BPF_MUL

0 commit comments

Comments
 (0)