Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/bpf: Reject atomic ops in ppc32 JIT

Commit 91c960b0056672 ("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: 51c66ad849a7 ("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

authored by

Naveen N. Rao and committed by
Michael Ellerman
307e5042 419ac821

+11 -3
+11 -3
arch/powerpc/net/bpf_jit_comp32.c
··· 773 773 break; 774 774 775 775 /* 776 - * BPF_STX XADD (atomic_add) 776 + * BPF_STX ATOMIC (atomic ops) 777 777 */ 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 + 779 787 bpf_set_seen_register(ctx, tmp_reg); 780 788 /* Get offset into TMP_REG */ 781 789 EMIT(PPC_RAW_LI(tmp_reg, off)); ··· 797 789 PPC_BCC_SHORT(COND_NE, (ctx->idx - 3) * 4); 798 790 break; 799 791 800 - case BPF_STX | BPF_XADD | BPF_DW: /* *(u64 *)(dst + off) += src */ 792 + case BPF_STX | BPF_ATOMIC | BPF_DW: /* *(u64 *)(dst + off) += src */ 801 793 return -EOPNOTSUPP; 802 794 803 795 /*