Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1616264pxb; Mon, 11 Oct 2021 09:33:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3a1iPo++8/wDa3X0Np8zkQDurW4nQkeD5USQB8kEEoSTcCxJbs9hPj+/fz2eLePsYGevW X-Received: by 2002:a17:906:8893:: with SMTP id ak19mr26899527ejc.124.1633969989933; Mon, 11 Oct 2021 09:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969989; cv=none; d=google.com; s=arc-20160816; b=e/xo7hbMxHBjNzZUSvnd2N2YEgiti29WgSq4bwpczt777v7Rn9zk0jvhobpUCjHoAh U3J8yhFaW9L9LPxYsTG4RqpVmnISkCs7DDLFaZaHdweJyfQjgLTToC1YZ7YPZrQ72Sq7 jFVZUhKswCrMMlg8+Q6OjIquuTPMO/G7ebreBnlTFVDsZ6nFqYvMBX44FJY3wHr/KnRQ tq7LoCudrLjikKojRPjt2c7QvU0Jqaj7XMgrKN4QLnRv2G2ouTxPwc3/ba1r9BlpglFb OAEapi/teDdZAPmbxXyoWZGO6VKFTyHX/F37gzR1Jci/WBVJ7AF5HclIxlkdW8PGdCp8 dcCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yo4B5v1u3l5gGgfnbMHaXalray0x3aLtYPL5YhSIZ0k=; b=c2lo/qJW9xm6o09qw+kiVKGlC/e2X5fzvWs3vxP1LyH7uOOztek/WN+mTu4YDQ97sB UAkNcSXvJMG8WeZ0NqTWEXzdGTH+gKigidOvTonH63eCQs/MTonHwfve0quWrwApVP4A 7um6ArCN4tqmECERUDR423gMFvrvHQ4sr1bT6+bs/DuacmvNEKJSSXWQSgYr78CTDD9D APQgMWtG9Zz0dTUlfgr+8SyMXwNsr4zKXwsoXQYrEMufXHJxYbi0aOIaVOffyESm7MeV ebXE0w6850Rs7ztrE4OzaH8GhnBIJWUMXX0cc8WYYfw361im2xBF7GVYaWURDAlSPTAw t65g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vzL+ET1j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k9si11386474edh.518.2021.10.11.09.32.44; Mon, 11 Oct 2021 09:33:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vzL+ET1j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238464AbhJKOA7 (ORCPT + 99 others); Mon, 11 Oct 2021 10:00:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:49798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237787AbhJKN7C (ORCPT ); Mon, 11 Oct 2021 09:59:02 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B7AC2611C3; Mon, 11 Oct 2021 13:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960533; bh=k/rFIUyOkql9VEApBtg14qShAinv3cD69+Va4UWDdvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vzL+ET1j49FPaIIMvfJXrdtS2yvp31b8W/BssTLhoZPfB7HZ/Lrbk6LaH5IanZGF8 2H2E7mL+cbnB8EssCaAq/ifNW/VCD4vM4VMsXegVB3AvkB9T9sOfd/bxZ2FRW1FQ34 br7CxpqW520QNHfz3MTUAAPeornhVrvXvPUSVTEU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Naveen N. Rao" , Christophe Leroy , Michael Ellerman , Sasha Levin Subject: [PATCH 5.10 74/83] powerpc/bpf: Fix BPF_SUB when imm == 0x80000000 Date: Mon, 11 Oct 2021 15:46:34 +0200 Message-Id: <20211011134510.938865273@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naveen N. Rao [ Upstream commit 5855c4c1f415ca3ba1046e77c0b3d3dfc96c9025 ] We aren't handling subtraction involving an immediate value of 0x80000000 properly. Fix the same. Fixes: 156d0e290e969c ("powerpc/ebpf/jit: Implement JIT compiler for extended BPF") Signed-off-by: Naveen N. Rao Reviewed-by: Christophe Leroy [mpe: Fold in fix from Naveen to use imm <= 32768] Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/fc4b1276eb10761fd7ce0814c8dd089da2815251.1633464148.git.naveen.n.rao@linux.vnet.ibm.com Signed-off-by: Sasha Levin --- arch/powerpc/net/bpf_jit_comp64.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/net/bpf_jit_comp64.c b/arch/powerpc/net/bpf_jit_comp64.c index e79f9eae2bc0..a2750d6ffd0f 100644 --- a/arch/powerpc/net/bpf_jit_comp64.c +++ b/arch/powerpc/net/bpf_jit_comp64.c @@ -347,18 +347,25 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, EMIT(PPC_RAW_SUB(dst_reg, dst_reg, src_reg)); goto bpf_alu32_trunc; case BPF_ALU | BPF_ADD | BPF_K: /* (u32) dst += (u32) imm */ - case BPF_ALU | BPF_SUB | BPF_K: /* (u32) dst -= (u32) imm */ case BPF_ALU64 | BPF_ADD | BPF_K: /* dst += imm */ + if (!imm) { + goto bpf_alu32_trunc; + } else if (imm >= -32768 && imm < 32768) { + EMIT(PPC_RAW_ADDI(dst_reg, dst_reg, IMM_L(imm))); + } else { + PPC_LI32(b2p[TMP_REG_1], imm); + EMIT(PPC_RAW_ADD(dst_reg, dst_reg, b2p[TMP_REG_1])); + } + goto bpf_alu32_trunc; + case BPF_ALU | BPF_SUB | BPF_K: /* (u32) dst -= (u32) imm */ case BPF_ALU64 | BPF_SUB | BPF_K: /* dst -= imm */ - if (BPF_OP(code) == BPF_SUB) - imm = -imm; - if (imm) { - if (imm >= -32768 && imm < 32768) - EMIT(PPC_RAW_ADDI(dst_reg, dst_reg, IMM_L(imm))); - else { - PPC_LI32(b2p[TMP_REG_1], imm); - EMIT(PPC_RAW_ADD(dst_reg, dst_reg, b2p[TMP_REG_1])); - } + if (!imm) { + goto bpf_alu32_trunc; + } else if (imm > -32768 && imm <= 32768) { + EMIT(PPC_RAW_ADDI(dst_reg, dst_reg, IMM_L(-imm))); + } else { + PPC_LI32(b2p[TMP_REG_1], imm); + EMIT(PPC_RAW_SUB(dst_reg, dst_reg, b2p[TMP_REG_1])); } goto bpf_alu32_trunc; case BPF_ALU | BPF_MUL | BPF_X: /* (u32) dst *= (u32) src */ -- 2.33.0