Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2445537yba; Mon, 15 Apr 2019 11:47:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqw43o0s/1zGLyIroqGVTDc2H3rF8UMnKyB9xGl1W+XQnLz8hpv+dtgtz+5fnuBt970HAnFY X-Received: by 2002:a17:902:4381:: with SMTP id j1mr12870509pld.173.1555354053824; Mon, 15 Apr 2019 11:47:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555354053; cv=none; d=google.com; s=arc-20160816; b=d8S0PwtKBeOMr0xrdzwbU4rb3Wl/DGr6SSMoIAN3TAUeJXiCOWnpKnl+s84GtEVRTi Ntd0KBqKvk4oan0yuHYZ+HGXiWeqLLNQCS2w/UMEveUHsz9baxW800fk7un6KqatbAV2 H/QcAdieMQCO0MBDL7vNloz7M3r6z+BXCyd1RpvUW8Mo0MCpF3pxtCn22WaalPG2V8Vp jbhLFb4nGBwLw1I2PMFUf1ufVdp2hS426zLtiUkMTx9fInT/x/z3sPUor0mhw23LMl/q ozsWQiq4zMwqYUTLkIkRRI8cItTfMJ81B1t+vUnobGVHroRX/0nf65pK5XwlgXMNkoeo oHsQ== 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=C5ev4N5zMA4cyj0FhW4BFprHpRORI7gezUBlH6uMwOk=; b=mRYo5BhNyjKP65Woq8lh53J98IvePLNWi7bVAawfJbK+Ic+DS3bMc7mJcJZ2UY99yw wICF1byVJI8axmdk7D6V8QwFXHrRNfKhiayKvGv4UxWXKZr95n+VeQDGxgII/wKFz5K1 eHMyKXYlDdtwBkUc1KZsr+sSH2VZGJ5GJn2hp3/xdVxFGbzMEuidPLlAHeDPInu7sb6W R7ToXDZULZxX4HqZWHWrcZ/89JAgjUOQ5oBpL7O9wihRxUBMebDSxUwwv1ea3Y6O0eEV sywVIlUnf7aifclwGxA+UdjwdWYZJJPSqWdQ3giZwvAmDb4/AXUTmVYlVhSlX4ang2Tp jhrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ScJ+uSCH; 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 p6si11328618plo.185.2019.04.15.11.47.17; Mon, 15 Apr 2019 11:47:33 -0700 (PDT) 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=ScJ+uSCH; 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 S1728543AbfDOSqO (ORCPT + 99 others); Mon, 15 Apr 2019 14:46:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:48802 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728523AbfDOSqJ (ORCPT ); Mon, 15 Apr 2019 14:46:09 -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 59CE52073F; Mon, 15 Apr 2019 18:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555353968; bh=/iBhd0db6RAHrS9uPkurLMWuvbwpHrvqpXA+58uELJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ScJ+uSCHX1KACXbkDFRXne00nhsSezekv3Fp/F5fqlQQdB6SqX+eDMXX9puOtey4a vUPIzOM1dvA5nuxH5cpu4zUGKw234GAiNY4PEP4Z/6JIoCmEjy2Vz8TFzfOznQ5iT3 nP2dQYJHQavQUHI2L28uqSJbQDsTc+i5OcZSrimY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Diana Craciun , Michael Ellerman , Sasha Levin Subject: [PATCH 4.9 37/76] powerpc/fsl: Flush the branch predictor at each kernel entry (64bit) Date: Mon, 15 Apr 2019 20:44:01 +0200 Message-Id: <20190415183717.331650481@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183707.712011689@linuxfoundation.org> References: <20190415183707.712011689@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 commit 10c5e83afd4a3f01712d97d3bb1ae34d5b74a185 upstream. In order to protect against speculation attacks on indirect branches, the branch predictor is flushed at kernel entry to protect for the following situations: - userspace process attacking another userspace process - userspace process attacking the kernel Basically when the privillege level change (i.e. the kernel is entered), the branch predictor state is flushed. Signed-off-by: Diana Craciun Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/kernel/entry_64.S | 5 +++++ arch/powerpc/kernel/exceptions-64e.S | 26 +++++++++++++++++++++++++- arch/powerpc/mm/tlb_low_64e.S | 7 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S index 6625cec9e7c0..390ebf4ef384 100644 --- a/arch/powerpc/kernel/entry_64.S +++ b/arch/powerpc/kernel/entry_64.S @@ -80,6 +80,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_TM) std r0,GPR0(r1) std r10,GPR1(r1) beq 2f /* if from kernel mode */ +#ifdef CONFIG_PPC_FSL_BOOK3E +START_BTB_FLUSH_SECTION + BTB_FLUSH(r10) +END_BTB_FLUSH_SECTION +#endif ACCOUNT_CPU_USER_ENTRY(r13, r10, r11) 2: std r2,GPR2(r1) std r3,GPR3(r1) diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S index ca03eb229a9a..79c6fee6368d 100644 --- a/arch/powerpc/kernel/exceptions-64e.S +++ b/arch/powerpc/kernel/exceptions-64e.S @@ -295,7 +295,8 @@ ret_from_mc_except: andi. r10,r11,MSR_PR; /* save stack pointer */ \ beq 1f; /* branch around if supervisor */ \ ld r1,PACAKSAVE(r13); /* get kernel stack coming from usr */\ -1: cmpdi cr1,r1,0; /* check if SP makes sense */ \ +1: type##_BTB_FLUSH \ + cmpdi cr1,r1,0; /* check if SP makes sense */ \ bge- cr1,exc_##n##_bad_stack;/* bad stack (TODO: out of line) */ \ mfspr r10,SPRN_##type##_SRR0; /* read SRR0 before touching stack */ @@ -327,6 +328,29 @@ ret_from_mc_except: #define SPRN_MC_SRR0 SPRN_MCSRR0 #define SPRN_MC_SRR1 SPRN_MCSRR1 +#ifdef CONFIG_PPC_FSL_BOOK3E +#define GEN_BTB_FLUSH \ + START_BTB_FLUSH_SECTION \ + beq 1f; \ + BTB_FLUSH(r10) \ + 1: \ + END_BTB_FLUSH_SECTION + +#define CRIT_BTB_FLUSH \ + START_BTB_FLUSH_SECTION \ + BTB_FLUSH(r10) \ + END_BTB_FLUSH_SECTION + +#define DBG_BTB_FLUSH CRIT_BTB_FLUSH +#define MC_BTB_FLUSH CRIT_BTB_FLUSH +#define GDBELL_BTB_FLUSH GEN_BTB_FLUSH +#else +#define GEN_BTB_FLUSH +#define CRIT_BTB_FLUSH +#define DBG_BTB_FLUSH +#define GDBELL_BTB_FLUSH +#endif + #define NORMAL_EXCEPTION_PROLOG(n, intnum, addition) \ EXCEPTION_PROLOG(n, intnum, GEN, addition##_GEN(n)) diff --git a/arch/powerpc/mm/tlb_low_64e.S b/arch/powerpc/mm/tlb_low_64e.S index eb82d787d99a..b7e9c09dfe19 100644 --- a/arch/powerpc/mm/tlb_low_64e.S +++ b/arch/powerpc/mm/tlb_low_64e.S @@ -69,6 +69,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) std r15,EX_TLB_R15(r12) std r10,EX_TLB_CR(r12) #ifdef CONFIG_PPC_FSL_BOOK3E +START_BTB_FLUSH_SECTION + mfspr r11, SPRN_SRR1 + andi. r10,r11,MSR_PR + beq 1f + BTB_FLUSH(r10) +1: +END_BTB_FLUSH_SECTION std r7,EX_TLB_R7(r12) #endif TLB_MISS_PROLOG_STATS -- 2.19.1