Received: by 10.223.176.5 with SMTP id f5csp2829923wra; Mon, 5 Feb 2018 10:33:20 -0800 (PST) X-Google-Smtp-Source: AH8x225o98n4HcLAzsy9BSagxqPuiuFNZ3P16w4fuYclyhwF4CfVf+XsRWA4zv017M6fMDkxJITS X-Received: by 10.98.57.131 with SMTP id u3mr14310273pfj.237.1517855600230; Mon, 05 Feb 2018 10:33:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517855600; cv=none; d=google.com; s=arc-20160816; b=OGwIatjN6bRURuF3hgd4pwRt9AWJUP86R2656sv3J1niVqNPo6cISrz+1TF+rVmG6W 4jTrwo6gA5c6BaFpgaEOQeg81McQF3hhoOVZ3mz5idTrz4VsMGACSy27jx5Rj1zeoFBz xdkQHd7PD/IzQA6+bQnzoCToanikPACQiivxcQGPP2mBlltSn0PEntDuLNKXfDRu1QRQ FsnQmvNpFfSeKRuo8KLgOQ1E6y3wKGewPDxxlZr1nqUsBGkCbg0Z8k4030LwtQN3/Seh 6w+a1+hn7t7/IuQQKGjiTvtX2m5I5LvdlZJ+H1WeKkuSsEtp5Depwh4IV6tPeiK4+TcM Rz1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=wpIrKwddccgdj9qAN62EyhTsTFnFD4v0SA04jklC2Wc=; b=vELaJMkkDipOJJdUJkkBs8gNI8P5EDBv2wnR/rFDOrcDI0IQ/zgasc9oBoWo35SqDs t2gwXYxSdHyXVkBXvyPp3NxCvQlnjaI96GFRvtmGfhkyBfYBOiuyrEgjFI+aIW9DYC/n EBYcImXPMeAZAmxijG7HmJzYosUzBMCjnT5v6M+/lx1ZPRACW55Xmu1jyPgw8z6/UMSW DdR3xBjpvxMWGQ99ChVRtqLgMfP2FU64IXyQAYfcjSJQnFm0V64qXxPD5wNBdvk8u6D9 VC0l5y5TctH91wzxb3AvzaFWFsVhwhS985KdhxmUDRnLH1vzXyJEMHIED9bvzlOAnnbo HjQw== ARC-Authentication-Results: i=1; mx.google.com; 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 p1si7242624pfb.357.2018.02.05.10.33.06; Mon, 05 Feb 2018 10:33:20 -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; 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 S1753568AbeBESa5 (ORCPT + 99 others); Mon, 5 Feb 2018 13:30:57 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:52738 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753757AbeBESZc (ORCPT ); Mon, 5 Feb 2018 13:25:32 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id BF157FEF; Mon, 5 Feb 2018 18:25:21 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Linus Torvalds , Andi Kleen , Ingo Molnar , Dan Williams , Thomas Gleixner , linux-arch@vger.kernel.org, Tom Lendacky , Kees Cook , kernel-hardening@lists.openwall.com, Al Viro , alan@linux.intel.com Subject: [PATCH 4.15 36/60] x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec Date: Mon, 5 Feb 2018 10:23:09 -0800 Message-Id: <20180205182215.444654864@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182213.902626065@linuxfoundation.org> References: <20180205182213.902626065@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dan Williams dan.j.williams@intel.com commit b3bbfb3fb5d25776b8e3f361d2eedaabb0b496cd For __get_user() paths, do not allow the kernel to speculate on the value of a user controlled pointer. In addition to the 'stac' instruction for Supervisor Mode Access Protection (SMAP), a barrier_nospec() causes the access_ok() result to resolve in the pipeline before the CPU might take any speculative action on the pointer value. Given the cost of 'stac' the speculation barrier is placed after 'stac' to hopefully overlap the cost of disabling SMAP with the cost of flushing the instruction pipeline. Since __get_user is a major kernel interface that deals with user controlled pointers, the __uaccess_begin_nospec() mechanism will prevent speculative execution past an access_ok() permission check. While speculative execution past access_ok() is not enough to lead to a kernel memory leak, it is a necessary precondition. To be clear, __uaccess_begin_nospec() is addressing a class of potential problems near __get_user() usages. Note, that while the barrier_nospec() in __uaccess_begin_nospec() is used to protect __get_user(), pointer masking similar to array_index_nospec() will be used for get_user() since it incorporates a bounds check near the usage. uaccess_try_nospec provides the same mechanism for get_user_try. No functional changes. Suggested-by: Linus Torvalds Suggested-by: Andi Kleen Suggested-by: Ingo Molnar Signed-off-by: Dan Williams Signed-off-by: Thomas Gleixner Cc: linux-arch@vger.kernel.org Cc: Tom Lendacky Cc: Kees Cook Cc: kernel-hardening@lists.openwall.com Cc: gregkh@linuxfoundation.org Cc: Al Viro Cc: alan@linux.intel.com Link: https://lkml.kernel.org/r/151727415922.33451.5796614273104346583.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/uaccess.h | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -124,6 +124,11 @@ extern int __get_user_bad(void); #define __uaccess_begin() stac() #define __uaccess_end() clac() +#define __uaccess_begin_nospec() \ +({ \ + stac(); \ + barrier_nospec(); \ +}) /* * This is a type: either unsigned long, if the argument fits into @@ -487,6 +492,10 @@ struct __large_struct { unsigned long bu __uaccess_begin(); \ barrier(); +#define uaccess_try_nospec do { \ + current->thread.uaccess_err = 0; \ + __uaccess_begin_nospec(); \ + #define uaccess_catch(err) \ __uaccess_end(); \ (err) |= (current->thread.uaccess_err ? -EFAULT : 0); \