Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2279839imb; Mon, 4 Mar 2019 00:37:30 -0800 (PST) X-Google-Smtp-Source: APXvYqyXE4jwbjyIWtb1ulcgh8iWW//uzWjBkMTc0zlqd4WclLRSMsVOYfZt4eBqyYSvkIAwrVxz X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr19283553plb.169.1551688650881; Mon, 04 Mar 2019 00:37:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551688650; cv=none; d=google.com; s=arc-20160816; b=NRmI5x3cVolfKviOaDMDIYKV3J170mf078HbNqpJlPE+w5vzeXxVOqRH+Rkj9MHI7W m/2pneoZzh8qQvOwZQyVZedz707fgIoqs0+2k+KEWOJZ3oH3Um0T1OMUp7X7z79V9hGo tvABU5t3XDNyv+FEtcut20j4h834wXsaBPSmFCsSxOMrJzGrjxIHSg5nBvNF/V45zyXO 69r41yIgMhRTf/FBnjN6VEPxp9QO2rk4sl6Ztrghaxwx3V8+gzCoPWE2fL8QzBs/Roxi iEtKhjiEA7slooiqsr/sYS/U+aRUT04B8NqirA050mKiMCYDj7oLAH5UEknuY6qRMzwr m35g== 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=Gfn9Cbuqq/V5yZwjNkZGh60X8cmf3evYiWPSnNULY0Y=; b=0SvCDqDKtx162J9qpHpt02tB8yDniHGtSsXMA7Zx1IAS2ZTHTMdZChcVLuZq328BRH k9QPoxgk18u/5XUjAIv6eYHVuas4f/s98EIJ9kY9X6CqOv0lkkFUxFMX7Jo/ltWQnNMu KwNBULmwQYv0iO9sriRxGatR1c3CINNiVJDtSso98eFn/9ZVUgbMiSW2l/lCBj3Asn2Y 2Fbay8OIIUApu7bUCBz/mpwUtp5UrDCwUvf8On6ZOw7l6ymtFylmdcU8DyruGUrfpRob iwNYNOEuio9cwi1nOuBE6hMVOs9MaY+BPTZGoJFc+cOpY/wYvVc+E5cpsy/KKYbRSVkC wl+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L3zvF2CD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si4997505pgg.56.2019.03.04.00.37.13; Mon, 04 Mar 2019 00:37:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=L3zvF2CD; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728719AbfCDIgp (ORCPT + 99 others); Mon, 4 Mar 2019 03:36:45 -0500 Received: from mail.kernel.org ([198.145.29.99]:46468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728677AbfCDIgi (ORCPT ); Mon, 4 Mar 2019 03:36:38 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 7CF6D2146E; Mon, 4 Mar 2019 08:36:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688597; bh=CuGbEMLM6oAhFYrwVlX8Wqpq8sqnn6vIvFMlXrSp6cc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L3zvF2CDBTTVPEY0hiIIjRe2WQGSwUUE+h47G8c2vbnItEEVgdICJu/CknLrnLISR eDjLcBWdtCjNWihYMkLRMyxzIlIe6J7k5NSCWnRodvqpKyOYUH1+EwRhezpdEB2Xz0 SevD93MaUNWu8MqN91KgdbgtnaCy9C6nhvTLaIIs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paul Burton , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-mips@vger.kernel.org Subject: [PATCH 4.20 87/88] MIPS: eBPF: Fix icache flush end address Date: Mon, 4 Mar 2019 09:23:10 +0100 Message-Id: <20190304081634.141831263@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081630.610632175@linuxfoundation.org> References: <20190304081630.610632175@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paul Burton commit d1a2930d8a992fb6ac2529449f81a0056e1b98d1 upstream. The MIPS eBPF JIT calls flush_icache_range() in order to ensure the icache observes the code that we just wrote. Unfortunately it gets the end address calculation wrong due to some bad pointer arithmetic. The struct jit_ctx target field is of type pointer to u32, and as such adding one to it will increment the address being pointed to by 4 bytes. Therefore in order to find the address of the end of the code we simply need to add the number of 4 byte instructions emitted, but we mistakenly add the number of instructions multiplied by 4. This results in the call to flush_icache_range() operating on a memory region 4x larger than intended, which is always wasteful and can cause crashes if we overrun into an unmapped page. Fix this by correcting the pointer arithmetic to remove the bogus multiplication, and use braces to remove the need for a set of brackets whilst also making it obvious that the target field is a pointer. Signed-off-by: Paul Burton Fixes: b6bd53f9c4e8 ("MIPS: Add missing file for eBPF JIT.") Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Martin KaFai Lau Cc: Song Liu Cc: Yonghong Song Cc: netdev@vger.kernel.org Cc: bpf@vger.kernel.org Cc: linux-mips@vger.kernel.org Cc: stable@vger.kernel.org # v4.13+ Signed-off-by: Daniel Borkmann Signed-off-by: Greg Kroah-Hartman --- arch/mips/net/ebpf_jit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/arch/mips/net/ebpf_jit.c +++ b/arch/mips/net/ebpf_jit.c @@ -1818,7 +1818,7 @@ struct bpf_prog *bpf_int_jit_compile(str /* Update the icache */ flush_icache_range((unsigned long)ctx.target, - (unsigned long)(ctx.target + ctx.idx * sizeof(u32))); + (unsigned long)&ctx.target[ctx.idx]); if (bpf_jit_enable > 1) /* Dump JIT code */