Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752517AbbEHFj7 (ORCPT ); Fri, 8 May 2015 01:39:59 -0400 Received: from mail-qc0-f182.google.com ([209.85.216.182]:35455 "EHLO mail-qc0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752178AbbEHFj5 (ORCPT ); Fri, 8 May 2015 01:39:57 -0400 From: Xi Wang To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Xi Wang , Zi Shen Lim , Alexei Starovoitov , Catalin Marinas , Will Deacon Subject: [PATCH] arm64: bpf: fix signedness bug in loading 64-bit immediate Date: Fri, 8 May 2015 01:39:51 -0400 Message-Id: <1431063591-16668-1-git-send-email-xi.wang@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1900 Lines: 58 Consider "(u64)insn1.imm << 32 | imm" in the arm64 JIT. Since imm is signed 32-bit, it is sign-extended to 64-bit, losing the high 32 bits. The fix is to convert imm to u32 first and zero-extend it to u64. Also extend test_bpf to catch this JIT bug; the interpreter is correct. Before: test_bpf: #58 load 64-bit immediate ret -1 != 1 FAIL (1 times) After: test_bpf: #58 load 64-bit immediate 74 PASS Fixes: 30d3d94cc3d5 ("arm64: bpf: add 'load 64-bit immediate' instruction") Cc: Zi Shen Lim Cc: Alexei Starovoitov Cc: Catalin Marinas Cc: Will Deacon Signed-off-by: Xi Wang --- arch/arm64/net/bpf_jit_comp.c | 2 +- lib/test_bpf.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index edba042b2325..14cdc099fda0 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -487,7 +487,7 @@ emit_cond_jmp: return -EINVAL; } - imm64 = (u64)insn1.imm << 32 | imm; + imm64 = ((u64)(u32)insn1.imm) << 32 | (u64)(u32)imm; emit_a64_mov_i64(dst, imm64, ctx); return 1; diff --git a/lib/test_bpf.c b/lib/test_bpf.c index 80d78c51f65f..9f6849891b5f 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c @@ -1755,7 +1755,8 @@ static struct bpf_test tests[] = { BPF_EXIT_INSN(), BPF_JMP_IMM(BPF_JEQ, R3, 0x1234, 1), BPF_EXIT_INSN(), - BPF_ALU64_IMM(BPF_MOV, R0, 1), + BPF_LD_IMM64(R0, 0x1ffffffffLL), + BPF_ALU64_IMM(BPF_RSH, R0, 32), /* R0 = 1 */ BPF_EXIT_INSN(), }, INTERNAL, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/