Skip to content

Commit 8bbc9d8

Browse files
rnavmpe
authored andcommitted
powerpc/bpf: Fix BPF_MOD when imm == 1
Only ignore the operation if dividing by 1. Fixes: 156d0e2 ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF") Signed-off-by: Naveen N. Rao <[email protected]> Tested-by: Johan Almbladh <[email protected]> Reviewed-by: Christophe Leroy <[email protected]> Acked-by: Song Liu <[email protected]> Acked-by: Johan Almbladh <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/c674ca18c3046885602caebb326213731c675d06.1633464148.git.naveen.n.rao@linux.vnet.ibm.com
1 parent 3832ba4 commit 8bbc9d8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/powerpc/net/bpf_jit_comp64.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,8 +391,14 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
391391
case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */
392392
if (imm == 0)
393393
return -EINVAL;
394-
else if (imm == 1)
395-
goto bpf_alu32_trunc;
394+
if (imm == 1) {
395+
if (BPF_OP(code) == BPF_DIV) {
396+
goto bpf_alu32_trunc;
397+
} else {
398+
EMIT(PPC_RAW_LI(dst_reg, 0));
399+
break;
400+
}
401+
}
396402

397403
PPC_LI32(b2p[TMP_REG_1], imm);
398404
switch (BPF_CLASS(code)) {

0 commit comments

Comments
 (0)