Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1575515ybk; Sun, 10 May 2020 21:56:41 -0700 (PDT) X-Google-Smtp-Source: APiQypLrmjHhMiIj04ZZ5BKN9cdipXjTocOIB3rs0Jzu8WeQA4ZE4DjBwvv7WiEiSsxA/gHA4w1T X-Received: by 2002:a17:906:6b1b:: with SMTP id q27mr11423015ejr.158.1589173001135; Sun, 10 May 2020 21:56:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589173001; cv=none; d=google.com; s=arc-20160816; b=UCB0C6srQItT9dU8gcbDpoJHSDtsdz7lxPK6t15Ui30BFkj0wPJRkT8Y1pbTDoid2V G9rJbR2+Qh9SgSXag3ZG04kWRSaibjHHhUh0DKJiGTFoGPnRDCIwStjjda4t6j7n88Gq z/6tw4rd4sb+8GH52prwjsHlrFVNfHCTWfkqsAbd1O2mLM4T0PLFqqWfnyWX8PDGD4E9 U1glD7pYHJSJ/QhnsMq/7oWVOo6lUCYaIhNf1dW1x+lldNsVNrEr5O2/qb/Pr8RFEEVC fnVha+ELk2tXfZVtN13xXpuX7UoZBq+hFSLBrQRIsrH4i6DcXgap6NCF+Ym/pAurxPt6 LNHg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=jDB2uc5WAZIijKVbT7hNnvW7bKLUcvuONqzZqLSu9rU=; b=02ZUze096afMnLrD3iN1CDMDhoVKI0fH0LjhgY4EmrBC62ryVVXziwsOh+MHFVSKgM Cjebgqj56tJ/UJqx37lA1XlOzkAcd6pYAyRhuzBiHJxxk8/Z9/9yZHZ2/TLuSN+VuT55 ovDsheGF7Oo4X27WmnUGvQa5KMMNPpqcvvgMSxpfx+TYkLZXdMEJZf1Oyq2rXEn9Zt8t vznpndmD7ZOLXAY+feKyiJx1cXqLPvco4bKSxGaOyXpMjDRiUm/Rg/LQhYI22+va0hhp mDJ2R4x/iz6iSa4DNITfKXK2kLU8eMlGQSEi6k4sWR39cZiPBNnz6NTamtgUmEChChgn i8GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=D6rCWsGU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si5435154eje.107.2020.05.10.21.56.10; Sun, 10 May 2020 21:56:41 -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=D6rCWsGU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729232AbgEKEyH (ORCPT + 99 others); Mon, 11 May 2020 00:54:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:37984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728750AbgEKExq (ORCPT ); Mon, 11 May 2020 00:53:46 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D13402063A; Mon, 11 May 2020 04:53:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589172825; bh=284oPI9GIPHpEC5gNFA9Sv4pwU6P4+U98zOmf/LPL2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D6rCWsGUNmFE2wgipUWge3Igud3unskkHO3DxOvxdRCL3qseYR1z836Y3PZA7Zf99 tCmZ63mzy8MBghSopVk0zkd/6rQ3RUpVQIT+K2EcdoBg/H4KobzTqz3t0v55QUP45E a4pAEmgoWVOz1h9Pc49E/ILOT5OfRslxgyd7hJds= From: Sasha Levin To: linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, luto@kernel.org Cc: hpa@zytor.com, dave.hansen@intel.com, tony.luck@intel.com, ak@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com, Sasha Levin Subject: [PATCH v12 14/18] x86/speculation/swapgs: Check FSGSBASE in enabling SWAPGS mitigation Date: Mon, 11 May 2020 00:53:07 -0400 Message-Id: <20200511045311.4785-15-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200511045311.4785-1-sashal@kernel.org> References: <20200511045311.4785-1-sashal@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tony Luck Before enabling FSGSBASE the kernel could safely assume that the content of GS base was a user address. Thus any speculative access as the result of a mispredicted branch controlling the execution of SWAPGS would be to a user address. So systems with speculation-proof SMAP did not need to add additional LFENCE instructions to mitigate. With FSGSBASE enabled a hostile user can set GS base to a kernel address. So they can make the kernel speculatively access data they wish to leak via a side channel. This means that SMAP provides no protection. Add FSGSBASE as an additional condition to enable the fence-based SWAPGS mitigation. Signed-off-by: Tony Luck Signed-off-by: Chang S. Bae Signed-off-by: Sasha Levin Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Tony Luck Cc: Andi Kleen --- arch/x86/kernel/cpu/bugs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c index ed54b3b21c396..487603ea51cd1 100644 --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -450,14 +450,12 @@ static void __init spectre_v1_select_mitigation(void) * If FSGSBASE is enabled, the user can put a kernel address in * GS, in which case SMAP provides no protection. * - * [ NOTE: Don't check for X86_FEATURE_FSGSBASE until the - * FSGSBASE enablement patches have been merged. ] - * * If FSGSBASE is disabled, the user can only put a user space * address in GS. That makes an attack harder, but still * possible if there's no SMAP protection. */ - if (!smap_works_speculatively()) { + if (boot_cpu_has(X86_FEATURE_FSGSBASE) || + !smap_works_speculatively()) { /* * Mitigation can be provided from SWAPGS itself or * PTI as the CR3 write in the Meltdown mitigation -- 2.20.1