Received: by 10.223.176.5 with SMTP id f5csp2832353wra; Mon, 5 Feb 2018 10:35:47 -0800 (PST) X-Google-Smtp-Source: AH8x224c6LMJpdSJXrugk1CgvfHHriiXxXwE3lDOn5ch6fuQrDUdpeWriEnShMquq1ILLTLETDaV X-Received: by 2002:a17:902:9343:: with SMTP id g3-v6mr45438796plp.319.1517855747569; Mon, 05 Feb 2018 10:35:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517855747; cv=none; d=google.com; s=arc-20160816; b=VmAloA5Dt+uMGSRQ07QACzQ2+alQZx38mcbcxRdJsOAFv37Ub/Azc8li6o9bt8ZGyP g6s+YhY6r4ehrXdKnplzgc1B257Sow2HebhHw0Y9D7xC54xwu3isQ5y0jDKomh7Y/l9d qansabFozdcTFjHKf02jLBwBRXXaVe5LqFXPB/xX9EY59Wba/zimr2JSlIt3reR3R+JG Ja6PwFRJAoxEmbCEIb/up5g3z4vigVrvPWqzjCJYsm4hiXsuG8SXyMXtq0QWloUIU/r0 +bobdB5vORJFIcXzJgUkv8GmQ0xRcT7OEF39p50cePv7PetAUgs1ETEBWn30r/uLDg9+ Gilw== 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=YdC5uA6NRbgwvlNQRsunoP48JTn8lLBq2nUjHEaWCNE=; b=IEvGfURVnMzPNBANfuqdNVFM4jtu46Mpwxx27OK5mXFc78Em96zTHC8nB+71yoVIYr RlcIVdIRI/CltmOWiPmwzpUs/MD1edStxTAW6CiFDn2uHUe7htXP8ecKmXoJk+NdpnKS tT76oThE+iJM65LyFtrIdgqs7z163qlzdfwqcYoyNUAloKOJWfEwQfy4cF+En3bkkWUv cN6OJ9Or08OA/vvYeshr12vDr6fnf6KVOF95txc+Vs4o69JqoaT5Vp0Oa1kUatR063K3 03+EVbDUAkvUSuJfZCtL84cVgwe80TFK5z9FLs3jrK4nHvloRYt/qheSxhWXj9RMj7Ji netg== 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 m7si4219033pgq.449.2018.02.05.10.35.32; Mon, 05 Feb 2018 10:35:47 -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 S1754090AbeBESbH (ORCPT + 99 others); Mon, 5 Feb 2018 13:31:07 -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 S1753782AbeBESZj (ORCPT ); Mon, 5 Feb 2018 13:25:39 -0500 Received: from localhost (unknown [104.132.1.108]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E7835113C; Mon, 5 Feb 2018 18:25:24 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Williams , Thomas Gleixner , linux-arch@vger.kernel.org, Kees Cook , kernel-hardening@lists.openwall.com, Al Viro , Andy Lutomirski , torvalds@linux-foundation.org, alan@linux.intel.com Subject: [PATCH 4.15 39/60] x86/get_user: Use pointer masking to limit speculation Date: Mon, 5 Feb 2018 10:23:12 -0800 Message-Id: <20180205182215.573695155@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 c7f631cb07e7da06ac1d231ca178452339e32a94 Quoting Linus: I do think that it would be a good idea to very expressly document the fact that it's not that the user access itself is unsafe. I do agree that things like "get_user()" want to be protected, but not because of any direct bugs or problems with get_user() and friends, but simply because get_user() is an excellent source of a pointer that is obviously controlled from a potentially attacking user space. So it's a prime candidate for then finding _subsequent_ accesses that can then be used to perturb the cache. Unlike the __get_user() case get_user() includes the address limit check near the pointer de-reference. With that locality the speculation can be mitigated with pointer narrowing rather than a barrier, i.e. array_index_nospec(). Where the narrowing is performed by: cmp %limit, %ptr sbb %mask, %mask and %mask, %ptr With respect to speculation the value of %ptr is either less than %limit or NULL. Co-developed-by: Linus Torvalds Signed-off-by: Dan Williams Signed-off-by: Thomas Gleixner Cc: linux-arch@vger.kernel.org Cc: Kees Cook Cc: kernel-hardening@lists.openwall.com Cc: gregkh@linuxfoundation.org Cc: Al Viro Cc: Andy Lutomirski Cc: torvalds@linux-foundation.org Cc: alan@linux.intel.com Link: https://lkml.kernel.org/r/151727417469.33451.11804043010080838495.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/lib/getuser.S | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/x86/lib/getuser.S +++ b/arch/x86/lib/getuser.S @@ -40,6 +40,8 @@ ENTRY(__get_user_1) mov PER_CPU_VAR(current_task), %_ASM_DX cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX jae bad_get_user + sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ + and %_ASM_DX, %_ASM_AX ASM_STAC 1: movzbl (%_ASM_AX),%edx xor %eax,%eax @@ -54,6 +56,8 @@ ENTRY(__get_user_2) mov PER_CPU_VAR(current_task), %_ASM_DX cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX jae bad_get_user + sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ + and %_ASM_DX, %_ASM_AX ASM_STAC 2: movzwl -1(%_ASM_AX),%edx xor %eax,%eax @@ -68,6 +72,8 @@ ENTRY(__get_user_4) mov PER_CPU_VAR(current_task), %_ASM_DX cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX jae bad_get_user + sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ + and %_ASM_DX, %_ASM_AX ASM_STAC 3: movl -3(%_ASM_AX),%edx xor %eax,%eax @@ -83,6 +89,8 @@ ENTRY(__get_user_8) mov PER_CPU_VAR(current_task), %_ASM_DX cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX jae bad_get_user + sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ + and %_ASM_DX, %_ASM_AX ASM_STAC 4: movq -7(%_ASM_AX),%rdx xor %eax,%eax @@ -94,6 +102,8 @@ ENTRY(__get_user_8) mov PER_CPU_VAR(current_task), %_ASM_DX cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX jae bad_get_user_8 + sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */ + and %_ASM_DX, %_ASM_AX ASM_STAC 4: movl -7(%_ASM_AX),%edx 5: movl -3(%_ASM_AX),%ecx