Received: by 10.223.176.5 with SMTP id f5csp2854465wra; Mon, 5 Feb 2018 11:00:54 -0800 (PST) X-Google-Smtp-Source: AH8x225FPJcUdts2IudAD3eCrJurJQzHvWyF9uNwH1tsb4S6sGRyQPBQL59s6RCIxCnaGvHH2aF4 X-Received: by 10.98.196.13 with SMTP id y13mr9035950pff.73.1517857254705; Mon, 05 Feb 2018 11:00:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517857254; cv=none; d=google.com; s=arc-20160816; b=ioIZKzxCsvL9rpkvlf8mDq0Tp/VT7Cw6k8aeUjw40mdo/3cVMWVONswm3YIGU+SCXN wdEdfXV+qMhOZ5Ss8P9p2jOPyZvcGykYG4PCO+/kG0IlT2slJ1Wsm2T1gOm8rabKoAvu jItzgLOGSyaEprD2JCmry3fVuicOMVpJNu2f5wF8lNgXVINirW8IXbGWSDkYyOPeA4TF HLGsv/M4F+R0im9a4nOitdBsQxtwEmngsG3svSPLhJjP0GgijHm7Co0hNH8LK08rZ9ny BGgHiH2vKW6MUKcwT8zFRMuDkxHH2ogUdpksFKtRx9jEK48PvobDdelXwgrjZtACM2qW Sa2Q== 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=7uXzr6ZV7KBwGAEWofiwZ5E1NtHV+Y0YNMxOfNlbceQ=; b=tcDrqtiBdQgUtErvBacAEjujy2o7rp0C+zWJB2CBwHTh26vUW2u+TGAEU3d3mMy/9p bqS7aXc4paltXvxd5Ddh9k8HSIQNyzHt1qsDK1KUNQ8pUdr0z3EE0gLW9+GQP7kyiU84 ZhY9StorRkkvSsyh3dSDhH5yHwz7ebmCNNCnfuDVbirX1iJKpWoy7jEB7tOqZ50timuv uELKWQ5xcCmL1LwhU/rzs1W3c4DImb62g4zBt8l3qKIDIk9Q7PoqZRnp3javNHWFI2Uf wfP/pPyz74wXlO2X4jb+t9RqeJ2mtQWSyvU2IKM01w2gcDIVps+7EKBSe6ygKldGgvuK kxlw== 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 bj8-v6si310311plb.238.2018.02.05.11.00.39; Mon, 05 Feb 2018 11:00:54 -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 S1753476AbeBETAJ (ORCPT + 99 others); Mon, 5 Feb 2018 14:00:09 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:51868 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753601AbeBESYm (ORCPT ); Mon, 5 Feb 2018 13:24:42 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E450510F6; Mon, 5 Feb 2018 18:24:38 +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.14 40/64] x86: Introduce __uaccess_begin_nospec() and uaccess_try_nospec Date: Mon, 5 Feb 2018 10:22:59 -0800 Message-Id: <20180205182140.224786185@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180205182138.571333346@linuxfoundation.org> References: <20180205182138.571333346@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.14-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); \