Re: [PATCH bpf-next] bpf: arm64: Silent "UBSAN: negation-overflow" warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 20, 2025 at 4:35 AM Xu Kuohai <xukuohai@xxxxxxxxxxxxxxx> wrote:
>
> On 2/18/2025 4:02 PM, Song Liu wrote:
> > 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'):
> >
> > Silent these warnings by casting imm to u32 first.
> >
> > Fixes: fd868f148189 ("bpf, arm64: Optimize ADD,SUB,JMP BPF_K using arm64 add/sub immediates")
>
> I doubt this is a bug fix since I checked the build result and found nothing changed.

This is just to silence the UBSAN. We can remove the Fixes tag.

Thanks,
Song

> > Reported-by: Breno Leitao <leitao@xxxxxxxxxx>
> > Signed-off-by: Song Liu <song@xxxxxxxxxx>
> > ---
> >   arch/arm64/net/bpf_jit_comp.c | 6 +++---
> >   1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
> > index 8446848edddb..7409c8acbde3 100644
> > --- a/arch/arm64/net/bpf_jit_comp.c
> > +++ b/arch/arm64/net/bpf_jit_comp.c
> > @@ -272,7 +272,7 @@ static inline void emit_a64_add_i(const bool is64, const int dst, const int src,
> >   {
> >       if (is_addsub_imm(imm)) {
> >               emit(A64_ADD_I(is64, dst, src, imm), ctx);
> > -     } else if (is_addsub_imm(-imm)) {
> > +     } else if (is_addsub_imm(-(u32)imm)) {
> >               emit(A64_SUB_I(is64, dst, src, -imm), ctx);
> >       } else {
> >               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,
> >       case BPF_ALU64 | BPF_SUB | BPF_K:
> >               if (is_addsub_imm(imm)) {
> >                       emit(A64_SUB_I(is64, dst, dst, imm), ctx);
> > -             } else if (is_addsub_imm(-imm)) {
> > +             } else if (is_addsub_imm(-(u32)imm)) {
> >                       emit(A64_ADD_I(is64, dst, dst, -imm), ctx);
> >               } else {
> >                       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,
> >       case BPF_JMP32 | BPF_JSLE | BPF_K:
> >               if (is_addsub_imm(imm)) {
> >                       emit(A64_CMP_I(is64, dst, imm), ctx);
> > -             } else if (is_addsub_imm(-imm)) {
> > +             } else if (is_addsub_imm(-(u32)imm)) {
> >                       emit(A64_CMN_I(is64, dst, -imm), ctx);
> >               } else {
> >                       emit_a64_mov_i(is64, tmp, imm, ctx);
>





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux