Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2632974pxa; Mon, 17 Aug 2020 15:00:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6G8FuaG0iSpLpEAG73Y81GQweTlshVNEB7Bc8bqdU0iVlho1LhW+lN7b3fZSInCzpkMXJ X-Received: by 2002:a05:6402:b1b:: with SMTP id bm27mr17360931edb.140.1597701644385; Mon, 17 Aug 2020 15:00:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701644; cv=none; d=google.com; s=arc-20160816; b=IQEaSFRl9r5x4uf+W5md0ZWLsEsIKcTfDiueXW9Jrn6mHwsHHojuLnDH5NhKIRZPeN geHkPaUdlathPrYCuYGp6fxNdiSgh39wbhrJQv45aSTUQ5VblvDrNcoYof5K+O4ANU/d H6yKzvNcB40iigznaexr6rJCUv77OjQLDXR1bGhmn9Ebk/w7H5/Pt1Dhb9NSThOoIXKG A6BEpIYMvXh6ujX65KB9YwoGxFLHmCMXZCKG/3Saa7mCRJBEJXHkOm4EKqQEBgR6fj0k R+vBkebZd8caUppPhw0mE+KJcYqbtR/EKImOHxlQlJ9HvEC1yqWillTywYS2+lzadqqM S6nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TocsFW1WJW3v5u7BNop37gAaKvksmatdpsx3ehgb8YU=; b=s7tswnn8bnaTC8BguntFgPB/ImvE4w3saOPFzjq9VGpwRz9LJI91/NgbqmOo2cMaIl zFMO6VNohnLL1R+Vn7dbt0NWAh9aOJR0ancCcZreFV7V0XPduu4pVa1Xuw3gXPUACeaD GQarCsel9zZVxHix+bNO9hUmAGzjr8A0sEEK5PqlutXc04ovHmBl/KNJdrprkO0b1Gxw yeggVSA4psm8dw9Tu3bA+DY8IcszTn/LSOLhwx0CAhyqCdL/kh8LK2Y8hfQrUP/iC3PR kDkYPMU7dUCcOjhAgbQFxjOAoY6LiDxZlyOKSNNzFMha9crdtxbWrH4XjnQJKhBvLkrT rCxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hEgD5cwV; 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=fail (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 y21si12038915ejj.370.2020.08.17.15.00.21; Mon, 17 Aug 2020 15:00:44 -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=@kernel.org header.s=default header.b=hEgD5cwV; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730533AbgHQPhK (ORCPT + 99 others); Mon, 17 Aug 2020 11:37:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:54264 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730254AbgHQPbG (ORCPT ); Mon, 17 Aug 2020 11:31:06 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC99A207FF; Mon, 17 Aug 2020 15:31:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678265; bh=0t6ozescBbuh+sDIOpBkP0M4S9nyTlk3Twg4ydMWNPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEgD5cwVH9dh2dDKDj1fZrgeozuMxjOeLE+4Wlx/9oqAlvG3fT542INYOCAjChcd7 RSy7ADj7MsutnooQfuJxkkiqFoiTYktH7KK2CGJCO/GTs8IiLnnx4OyzusdkfqYVUY Cjc+3X5jjOY74Wv+2DE/RoqNPZHYbjhI9al03Htc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Seth Forshee , Ilya Leoshkevich , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.8 274/464] s390/bpf: Fix sign extension in branch_ku Date: Mon, 17 Aug 2020 17:13:47 +0200 Message-Id: <20200817143846.896373797@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ilya Leoshkevich [ Upstream commit 7477d43be5b1448bc0d4c85cb185a0144cc080e1 ] Both signed and unsigned variants of BPF_JMP | BPF_K require sign-extending the immediate. JIT emits cgfi for the signed case, which is correct, and clgfi for the unsigned case, which is not correct: clgfi zero-extends the immediate. s390 does not provide an instruction that does sign-extension and unsigned comparison at the same time. Therefore, fix by first loading the sign-extended immediate into work register REG_1 and proceeding as if it's BPF_X. Fixes: 4e9b4a6883dd ("s390/bpf: Use relative long branches") Reported-by: Seth Forshee Signed-off-by: Ilya Leoshkevich Signed-off-by: Alexei Starovoitov Tested-by: Seth Forshee Link: https://lore.kernel.org/bpf/20200717165326.6786-3-iii@linux.ibm.com Signed-off-by: Sasha Levin --- arch/s390/net/bpf_jit_comp.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index f4242b894cf28..6b3d612948fba 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c @@ -1417,21 +1417,10 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp, } break; branch_ku: - is_jmp32 = BPF_CLASS(insn->code) == BPF_JMP32; - /* clfi or clgfi %dst,imm */ - EMIT6_IMM(is_jmp32 ? 0xc20f0000 : 0xc20e0000, - dst_reg, imm); - if (!is_first_pass(jit) && - can_use_rel(jit, addrs[i + off + 1])) { - /* brc mask,off */ - EMIT4_PCREL_RIC(0xa7040000, - mask >> 12, addrs[i + off + 1]); - } else { - /* brcl mask,off */ - EMIT6_PCREL_RILC(0xc0040000, - mask >> 12, addrs[i + off + 1]); - } - break; + /* lgfi %w1,imm (load sign extend imm) */ + src_reg = REG_1; + EMIT6_IMM(0xc0010000, src_reg, imm); + goto branch_xu; branch_xs: is_jmp32 = BPF_CLASS(insn->code) == BPF_JMP32; if (!is_first_pass(jit) && -- 2.25.1