Skip to content

Commit 2398608

Browse files
liu-song-6Alexei Starovoitov
authored andcommitted
bpf: arm64: Silence "UBSAN: negation-overflow" warning
With UBSAN, test_bpf.ko triggers warnings like: UBSAN: negation-overflow in arch/arm64/net/bpf_jit_comp.c:1333:28 negation of -2147483648 cannot be represented in type 's32' (aka 'int'): Silence these warnings by casting imm to u32 first. Reported-by: Breno Leitao <[email protected]> Signed-off-by: Song Liu <[email protected]> Tested-by: Breno Leitao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 201b62c commit 2398608

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/arm64/net/bpf_jit_comp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
272272
{
273273
if (is_addsub_imm(imm)) {
274274
emit(A64_ADD_I(is64, dst, src, imm), ctx);
275-
} else if (is_addsub_imm(-imm)) {
275+
} else if (is_addsub_imm(-(u32)imm)) {
276276
emit(A64_SUB_I(is64, dst, src, -imm), ctx);
277277
} else {
278278
emit_a64_mov_i(is64, tmp, imm, ctx);
@@ -1159,7 +1159,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
11591159
case BPF_ALU64 | BPF_SUB | BPF_K:
11601160
if (is_addsub_imm(imm)) {
11611161
emit(A64_SUB_I(is64, dst, dst, imm), ctx);
1162-
} else if (is_addsub_imm(-imm)) {
1162+
} else if (is_addsub_imm(-(u32)imm)) {
11631163
emit(A64_ADD_I(is64, dst, dst, -imm), ctx);
11641164
} else {
11651165
emit_a64_mov_i(is64, tmp, imm, ctx);
@@ -1330,7 +1330,7 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx,
13301330
case BPF_JMP32 | BPF_JSLE | BPF_K:
13311331
if (is_addsub_imm(imm)) {
13321332
emit(A64_CMP_I(is64, dst, imm), ctx);
1333-
} else if (is_addsub_imm(-imm)) {
1333+
} else if (is_addsub_imm(-(u32)imm)) {
13341334
emit(A64_CMN_I(is64, dst, -imm), ctx);
13351335
} else {
13361336
emit_a64_mov_i(is64, tmp, imm, ctx);

0 commit comments

Comments
 (0)