Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2344813ybz; Thu, 23 Apr 2020 16:25:41 -0700 (PDT) X-Google-Smtp-Source: APiQypI4zPu+B9+jGkLdA32gB9gyxX+LB5w3rT1muT62+AuSfi858CrMIqiNayeslcma1NaCWZK9 X-Received: by 2002:a17:906:e01:: with SMTP id l1mr4623040eji.76.1587684341296; Thu, 23 Apr 2020 16:25:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684341; cv=none; d=google.com; s=arc-20160816; b=rmBCwNZkArfD2Ody82AV8NB/93ezgavWrKAsJkryc/9RS5iI7FNljUQ/1ZP2jeB8Cm ZAxMW3vHT2adkaLsjJo7tFnhONj4o8eJ13iJ24qPZ1H9e7iJzqAMQ46p11diIhhF7ngL Dzd+NJGZz0E7pQlaC8kbnJNKfQAFLm14aisJuPsSKUSYFrY5Sm7kxtFJI6dN+i4doBLZ UnXjRnu+wJJfaAlmRXl9N1QK+AVkFwsvCMpsdenH9uZGTY+zBgejVtcAUYBJZ6dbKDgJ kVBIBdWSqz52oE/fWMlfL0b0bxUPmfhi219Anm74V/EILXm8Q8uE54xG42unE4ZmLiSm 8eDQ== 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=92rPmVgRzodfxTnGCgczpguitX/oxTndRFA+h4+OBJ0=; b=Mo1q3aVO/MpyyZLiVyJiQbvE9FSQlix0CvARv/DTcZlO56nBB55wNhfukNC6hfkKaE CsvMQ9FdpssFDy6ZH+ifdvq1rG5/KF5e54PXPB6E37HrDe7fSh/qnhjqPooE4RNcv/El //cTJmHL04LhVpRQGmmMOOgp1ysvMHkepXzf6b02FcEl3MtzZdAhTqW1qOtBfdv0ia5K O2CD+OBY/47FZbgrdwNsD2ZhO6drxLXZs9Ez8Si2LnW+zYEPGC7d8PmQf6RZib6zprNL WDw/Hp9jo2rWkAf3xAUwaaht6pO6JiNOIsbnPVNEBi8/UeqNyc+EuZvlVviM4SbsYkr+ rTdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Omq3cVv3; 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 ng3si2100246ejb.189.2020.04.23.16.25.15; Thu, 23 Apr 2020 16:25: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=Omq3cVv3; 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 S1729448AbgDWXWe (ORCPT + 99 others); Thu, 23 Apr 2020 19:22:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:59280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729720AbgDWXWc (ORCPT ); Thu, 23 Apr 2020 19:22:32 -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 526F82166E; Thu, 23 Apr 2020 23:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587684151; bh=CXpuQQ0f72KBBMKGxQEhYLGsLmjcQPUNk1FFBPei8A4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Omq3cVv3M+qUpu38N31eLW2ejUhykf1c1nHx54z1bFJy82f/M3rOoikQS6WG+pkgX Mex3pfpqYJ9Pj2CSfPfbDQ/opyj+9a3vtGPtaVOrfs5LJh9ssS/2z6oqc+SsER4UZL 4XtLFlkNoixd9zXXRFbjq4ouGpcwjF0FGwZ0MRYw= 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 v10 14/18] x86/speculation/swapgs: Check FSGSBASE in enabling SWAPGS mitigation Date: Thu, 23 Apr 2020 19:22:03 -0400 Message-Id: <20200423232207.5797-15-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200423232207.5797-1-sashal@kernel.org> References: <20200423232207.5797-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 Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Tony Luck Cc: Andi Kleen Signed-off-by: Sasha Levin --- 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