Skip to content

Commit 307e504

Browse files
rnavmpe
authored andcommitted
powerpc/bpf: Reject atomic ops in ppc32 JIT
Commit 91c960b ("bpf: Rename BPF_XADD and prepare to encode other atomics in .imm") converted BPF_XADD to BPF_ATOMIC and updated all JIT implementations to reject JIT'ing instructions with an immediate value different from BPF_ADD. However, ppc32 BPF JIT was implemented around the same time and didn't include the same change. Update the ppc32 JIT accordingly. Fixes: 51c66ad ("powerpc/bpf: Implement extended BPF on PPC32") Cc: stable@vger.kernel.org # v5.13+ Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/426699046d89fe50f66ecf74bd31c01eda976ba5.1625145429.git.naveen.n.rao@linux.vnet.ibm.com
1 parent 419ac82 commit 307e504

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

arch/powerpc/net/bpf_jit_comp32.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,9 +773,17 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
773773
break;
774774

775775
/*
776-
* BPF_STX XADD (atomic_add)
776+
* BPF_STX ATOMIC (atomic ops)
777777
*/
778-
case BPF_STX | BPF_XADD | BPF_W: /* *(u32 *)(dst + off) += src */
778+
case BPF_STX | BPF_ATOMIC | BPF_W:
779+
if (imm != BPF_ADD) {
780+
pr_err_ratelimited("eBPF filter atomic op code %02x (@%d) unsupported\n",
781+
code, i);
782+
return -ENOTSUPP;
783+
}
784+
785+
/* *(u32 *)(dst + off) += src */
786+
779787
bpf_set_seen_register(ctx, tmp_reg);
780788
/* Get offset into TMP_REG */
781789
EMIT(PPC_RAW_LI(tmp_reg, off));
@@ -789,7 +797,7 @@ int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, struct codegen_context *
789797
PPC_BCC_SHORT(COND_NE, (ctx->idx - 3) * 4);
790798
break;
791799

792-
case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */
800+
case BPF_STX | BPF_ATOMIC | BPF_DW: /* *(u64 *)(dst + off) += src */
793801
return -EOPNOTSUPP;
794802

795803
/*

0 commit comments

Comments
 (0)