From patchwork Fri Oct 22 21:12:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thadeu Lima de Souza Cascardo X-Patchwork-Id: 1545104 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=HViqi3GZ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbcYd0sr8z9sSf for ; Sat, 23 Oct 2021 08:14:45 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1me1s3-0001Xe-Ta; Fri, 22 Oct 2021 21:14:35 +0000 Received: from smtp-relay-canonical-0.internal ([10.131.114.83] helo=smtp-relay-canonical-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1me1s2-0001XO-72 for kernel-team@lists.ubuntu.com; Fri, 22 Oct 2021 21:14:34 +0000 Received: from localhost.localdomain (1.general.cascardo.us.vpn [10.172.70.58]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id 4501740007 for ; Fri, 22 Oct 2021 21:14:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1634937274; bh=UXUElaIXlRwTT9TWKpU7g0VCQH+o17Quj8Xsvptqafo=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HViqi3GZwjSsMebj5gxuKmfOJ+KdFkDCE9dAZbB9G9pYAk6kjUx/gvTy1CaCbJm03 +1XpKAL0UrqD2Ntxb2EDW5p2ilVtImiZ3l39vf2MQiK7YMZFE3yfEl9p7Q05dgFrgG 6a/YPI3a5IzhYONLP77iEE4stOyzrcomRNLLWnu3TwQ7jdwFyE3iQIK8Xb5Zgl1FHy Q3xW4wAIlvbM0nH5ZPyDQlLTLX8iOvAP4cWMXirSV+BlSLfJBSRP9FY7n6xmCxhyyR UJrsnssGMyrL6VHtlMfOSAjgLg8vGEsTISb4XWn5TDqNk6DRwQajL7C8yr7G7xJiuF zBWbXwiigU+Bg== From: Thadeu Lima de Souza Cascardo To: kernel-team@lists.ubuntu.com Subject: [SRU Bionic/Focal] powerpc/bpf: Fix BPF_MOD when imm == 1 Date: Fri, 22 Oct 2021 18:12:32 -0300 Message-Id: <20211022211233.422431-2-cascardo@canonical.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211022211233.422431-1-cascardo@canonical.com> References: <20211022211233.422431-1-cascardo@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: "Naveen N. Rao" BugLink: https://bugs.launchpad.net/bugs/1948351 Only ignore the operation if dividing by 1. Fixes: 156d0e290e969c ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF") Signed-off-by: Naveen N. Rao Tested-by: Johan Almbladh Reviewed-by: Christophe Leroy Acked-by: Song Liu Acked-by: Johan Almbladh Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/c674ca18c3046885602caebb326213731c675d06.1633464148.git.naveen.n.rao@linux.vnet.ibm.com (backported from commit 8bbc9d822421d9ac8ff9ed26a3713c9afc69d6c8) [cascardo: use PPC_LI instead of EMIT(PPC_RAW_LI)] Signed-off-by: Thadeu Lima de Souza Cascardo --- arch/powerpc/net/bpf_jit_comp64.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c index 20bfd753bcba..81e6279c9874 100644 --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -408,8 +408,14 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, case BPF_ALU64 | BPF_DIV | BPF_K: /* dst /= imm */ if (imm == 0) return -EINVAL; - else if (imm == 1) - goto bpf_alu32_trunc; + if (imm == 1) { + if (BPF_OP(code) == BPF_DIV) { + goto bpf_alu32_trunc; + } else { + PPC_LI(dst_reg, 0); + break; + } + } PPC_LI32(b2p[TMP_REG_1], imm); switch (BPF_CLASS(code)) {