Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2283957imb; Mon, 4 Mar 2019 00:46:13 -0800 (PST) X-Google-Smtp-Source: AHgI3IaYV5mLwPGHjftdSsX1HoZAGz2UOZKL/7EzaY5RPX7N5f91pyjEs3jlsTXN1VGz9cz7IqkC X-Received: by 2002:a62:e04b:: with SMTP id f72mr19294053pfh.41.1551689173071; Mon, 04 Mar 2019 00:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551689173; cv=none; d=google.com; s=arc-20160816; b=t37TEvpK58fCW1vlwIOEcXzbWLJH3vfwXi0hqLuHLEoOBoJHffR01yGdfSAln+x88J R9JIwVT3qQbS9LN8AvRBn4FXc98+zYTRwYyLW9g4gsQJlzN/Nf+yNNEtv6Yv/kjaQW5p +JGGSGI4U7Ktuqr2/Kc8X0TNX3TMbM0hPrswUNsn+JJLdBuEgDskqK/fL0CVh5zvJFG1 QOorUOtaZX+WWLMe2MkK1PTIqnlUJ1JOmCTrBHIRdWymUAJDvCx2odvBVKX851CNteuq G/jOVJPk6H2oPmbtnBUOXXuj7ykZ3HB96PpngjXTfv7fjgrGBq2XnzObied/cEYqSZxh mF8A== 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=KBEKBUxtiBPt6aEyjKnqjkf6in/xJYxpN3vmFsJcu0c=; b=T94BcLzdVO+7Fd1ZeIJMdwiYcwoKjGPJyahlywgE2y1zLWMYG3UzaHWys5DQWLLZg4 sFsP3SmOMrmJa6h6nuKlRzI6UEYFrMxILFj1IXk6UqmVCm4RDhEz+gy/pDCqrinPeUrA Oz89vrcM65+tAyZztRygqNsN00uGIyGPEysNB1ah/xtQ+KBzvdWpz9TMu9H2Vm6QK+YQ 8BFncNpfMpK2/eKfFR0kvCgiiEsKniACNTJiJN4/WdFOWWQbUkAjp+fMLOu2ZvtOkUc6 JHXugSIdcY6ISzF0ijmmTr+L/srNLhSWLWfZe2LEPl2oZfb28VptZEQGxvTlrDlaOzQv FwKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fs5qlpln; 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 x17si4909137plr.435.2019.03.04.00.45.58; Mon, 04 Mar 2019 00:46:13 -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=fs5qlpln; 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 S1726837AbfCDI1r (ORCPT + 99 others); Mon, 4 Mar 2019 03:27:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:51932 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726137AbfCDI1o (ORCPT ); Mon, 4 Mar 2019 03:27:44 -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 F2216208E4; Mon, 4 Mar 2019 08:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551688063; bh=E4z72FJAjyBItHQpbqElvBL3DjaeWsJGE/FNur1u29k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fs5qlpln74qywRTs1LHzrS/N+s2tiKgIzgs1UELKkIqnuy5Yy2H3SRG155d63Leu4 i+LVVkI6z+v5gY/45zR0HCip64zB9UQhOe8DaoCz8+LdTgRKXWsd3ybaVDTD5rf22D GeMWVCRsGIynHAZRY3Z1cFAFqOH4WCxMW2qqCvt8= 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.14 51/52] MIPS: eBPF: Fix icache flush end address Date: Mon, 4 Mar 2019 09:22:49 +0100 Message-Id: <20190304081620.015835385@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190304081617.159014799@linuxfoundation.org> References: <20190304081617.159014799@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.14-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 @@ -1971,7 +1971,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 */