Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2445588yba; Mon, 15 Apr 2019 11:47:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxG9qsf3J8z2ltSlyW7j1QdxdzPZMg4hRAzhXTsxAnHkfvx04ndVkT/KeqM+xZXRg1Dpwgv X-Received: by 2002:a17:902:8a8a:: with SMTP id p10mr77356281plo.8.1555354058148; Mon, 15 Apr 2019 11:47:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555354058; cv=none; d=google.com; s=arc-20160816; b=FGuZOWIvBDK5cnp81YvbClRJPN8sZ6ITIX/28U1GQXV5brYEHOdhHwVwgISW++FHpW aPrwQJZiDc6LgESzSEgBGG1axf0XR9AeIe2AoTakSOnJ9xtxAKN+WgJn3+4hrOD0kHqJ eBvixKEWnmSRTmc4NYRZUzJLYMDYjXlvDI/rrqHxwKHtFdwiMmTtRKxpQrrrNPOmxpCy oYSofeZFlf3+IkPJN3Js3yFxMlTtizPkWYVXL01Iw/8vk/A1ytWUHSIsGjo+AZ6O+pls ENcK9b7DOEhXh5tov7z1zBVFLSCC1d4N+3S/Y0z3X49CBpbicgPMyfhYto9gqa6ZPTVS fp6A== 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=vr+cgJEzEGvd8V3xteLBh6N18uQKRAmEVbpZGNdya7M=; b=E26TyNQrJt4afaOKa/6pxSMuD1r8VIBotJfF9i2VcHyZlAFA4Kp8ixa+qqi2oQmDyc 4VdcKyJxh6oSeANIwztaSP3W3gCZy28/ECkWTzwlRWigrIq/xJO9PKem+22KuxnYHZ9w +krv+hFx1potAPPNeAPb7Wf/Hc9Ol/UbYxuKD0MTz9YMYmgbOyUwtOLCl9yLyIg019iH HpcFi9mpfe7CZ9OvUWSPvaSjjzJFuzeTQukT1vQz55OAI7Kic9diW3Ian2z0xGhoJgSG AK1RBopgEGxmdrfO5XA7l/7X3DgN4VWMOf5NZSMgUwfuj7bIIIUjv8bU2B5AGbJmD3Lr WaXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xyj2XRA0; 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 b6si42423478plx.325.2019.04.15.11.47.22; Mon, 15 Apr 2019 11:47:38 -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=Xyj2XRA0; 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 S1728557AbfDOSqP (ORCPT + 99 others); Mon, 15 Apr 2019 14:46:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:48862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728532AbfDOSqN (ORCPT ); Mon, 15 Apr 2019 14:46:13 -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 2581E2087C; Mon, 15 Apr 2019 18:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555353971; bh=DwSdeP288kOuyytRsoktnn49/wtq75rGDnmJj7B6r8U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xyj2XRA0tBAAcV4mWgWFQIFq6NTiNTZNMd44f4UKmZbyc1iJVSBFPksjkqn6JFsDr UfX4R6sMWFOFdiofaIxO5E67nfEq/ZQNzGo4OyC7c5KF1Q3VoRmFwv4cmU7MDUIgtU aDwPnAIGa8SErkme/cwZ+01g2xBgZzJ3We37ufDQ= 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 38/76] powerpc/fsl: Flush the branch predictor at each kernel entry (32 bit) Date: Mon, 15 Apr 2019 20:44:02 +0200 Message-Id: <20190415183717.477172842@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 7fef436295bf6c05effe682c8797dfcb0deb112a 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/head_booke.h | 6 ++++++ arch/powerpc/kernel/head_fsl_booke.S | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/arch/powerpc/kernel/head_booke.h b/arch/powerpc/kernel/head_booke.h index a620203f7de3..384bb4d80520 100644 --- a/arch/powerpc/kernel/head_booke.h +++ b/arch/powerpc/kernel/head_booke.h @@ -42,6 +42,9 @@ andi. r11, r11, MSR_PR; /* check whether user or kernel */\ mr r11, r1; \ beq 1f; \ +START_BTB_FLUSH_SECTION \ + BTB_FLUSH(r11) \ +END_BTB_FLUSH_SECTION \ /* if from user, start at top of this thread's kernel stack */ \ lwz r11, THREAD_INFO-THREAD(r10); \ ALLOC_STACK_FRAME(r11, THREAD_SIZE); \ @@ -127,6 +130,9 @@ stw r9,_CCR(r8); /* save CR on stack */\ mfspr r11,exc_level_srr1; /* check whether user or kernel */\ DO_KVM BOOKE_INTERRUPT_##intno exc_level_srr1; \ +START_BTB_FLUSH_SECTION \ + BTB_FLUSH(r10) \ +END_BTB_FLUSH_SECTION \ andi. r11,r11,MSR_PR; \ mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\ lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\ diff --git a/arch/powerpc/kernel/head_fsl_booke.S b/arch/powerpc/kernel/head_fsl_booke.S index bf4c6021515f..60a0aeefc4a7 100644 --- a/arch/powerpc/kernel/head_fsl_booke.S +++ b/arch/powerpc/kernel/head_fsl_booke.S @@ -452,6 +452,13 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) mfcr r13 stw r13, THREAD_NORMSAVE(3)(r10) DO_KVM BOOKE_INTERRUPT_DTLB_MISS SPRN_SRR1 +START_BTB_FLUSH_SECTION + mfspr r11, SPRN_SRR1 + andi. r10,r11,MSR_PR + beq 1f + BTB_FLUSH(r10) +1: +END_BTB_FLUSH_SECTION mfspr r10, SPRN_DEAR /* Get faulting address */ /* If we are faulting a kernel address, we have to use the @@ -546,6 +553,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_EMB_HV) mfcr r13 stw r13, THREAD_NORMSAVE(3)(r10) DO_KVM BOOKE_INTERRUPT_ITLB_MISS SPRN_SRR1 +START_BTB_FLUSH_SECTION + mfspr r11, SPRN_SRR1 + andi. r10,r11,MSR_PR + beq 1f + BTB_FLUSH(r10) +1: +END_BTB_FLUSH_SECTION + mfspr r10, SPRN_SRR0 /* Get faulting address */ /* If we are faulting a kernel address, we have to use the -- 2.19.1