Received: by 10.223.148.5 with SMTP id 5csp7419222wrq; Thu, 18 Jan 2018 05:20:06 -0800 (PST) X-Google-Smtp-Source: ACJfBotypAQSP0m6pWMQJ5bA8fM5+f9yXbXDrYxuJBGCPBAmA/s8mZlI8VMnvErwscbhuyAVQER2 X-Received: by 10.98.17.21 with SMTP id z21mr17952581pfi.86.1516281606282; Thu, 18 Jan 2018 05:20:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516281606; cv=none; d=google.com; s=arc-20160816; b=FDe9ALUONL2Fbiu5PGuwqKb+hKyhrE+eZBPUjuXws38Z/qBD4Yk3O5Kc6g5LoPyRVU q/c8LpwYOUDRxtBwhYg/93pWhB5mOxsqRJ0k1V1Oqf1U2Qsv8mrqEwr6m8PspGp9S+d/ +svVXpCI8LzmotHOtpmzYTXhOLARoryyxpiiftd7PdlbfMDWCohPA5H/SCYuBxeAOFrj i5x1AZd3wdZJ2T2aHOpKASqf/7lkcBHml67So7vrwgWJsxK5kpQoT+oZ+VXp1qBiWwgK plmzHlH6mFpnJgK+03PtTaFn7IcjDmMjG39NFTdjyahOyrW/XfI4Zq8HXeSkt5OzrD0j XFfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=HN1AUAatcfjkpSPs23jpCXdXhFtX461k3jFFPgGAtYc=; b=ofCBiNqgI5zsM7yPqaVqIDjDzzr4vFI4lEyUDBAF0RGif2z4O3Tt0Pc8CyqOCF8FMP F++rOZfd7XmY+y8Pb8PIKyvohN/Ap0EGfESolkbEba6COgCB5Mr2z0cu8oLmpTa4iM8+ lJiI3GxavLkPy8/ullvzapanumsd10JF+RrrtaITh56KpTKTKGlXqnXxyCZgoX21Ecz5 /BtRbaVxHILsoI3uhYFe/8o/+MNzN2K2iTEkUYHsvsIQQMfzArT2ojwm7gxrdldmgF+z syBN8LLGf9hoM1o9aJfSb8x2LwMCFpLZEsTxP1MDJOy9YhP0Y8vEXe+d0WgMoDmUqdyq 8b5Q== 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 z9si6762762pfk.333.2018.01.18.05.19.51; Thu, 18 Jan 2018 05:20:06 -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 S932326AbeARNSi (ORCPT + 99 others); Thu, 18 Jan 2018 08:18:38 -0500 Received: from foss.arm.com ([217.140.101.70]:55256 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756245AbeARNSc (ORCPT ); Thu, 18 Jan 2018 08:18:32 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A18D51435; Thu, 18 Jan 2018 05:18:31 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6FE763F487; Thu, 18 Jan 2018 05:18:31 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id 9593B1AE01EB; Thu, 18 Jan 2018 13:18:37 +0000 (GMT) Date: Thu, 18 Jan 2018 13:18:37 +0000 From: Will Deacon To: Dan Williams Cc: Linus Torvalds , Linux Kernel Mailing List , Mark Rutland , kernel-hardening@lists.openwall.com, Peter Zijlstra , Alan Cox , Alexei Starovoitov , Solomon Peachy , "H. Peter Anvin" , Christian Lamparter , Elena Reshetova , linux-arch@vger.kernel.org, Andi Kleen , "James E.J. Bottomley" , Linux SCSI List , Jonathan Corbet , the arch/x86 maintainers , Russell King , Ingo Molnar , Catalin Marinas , Alexey Kuznetsov , Linux Media Mailing List , Tom Lendacky , Kees Cook , Jan Kara , Al Viro , qla2xxx-upstream@qlogic.com, Thomas Gleixner , Mauro Carvalho Chehab , Kalle Valo , Alan Cox , "Martin K. Petersen" , Hideaki YOSHIFUJI , Greg KH , Linux Wireless List , "Eric W. Biederman" , Network Development , Andrew Morton , "David S. Miller" , Laurent Pinchart Subject: Re: [PATCH v2 00/19] prevent bounds-check bypass via speculative execution Message-ID: <20180118131837.GA20783@arm.com> References: <151571798296.27429.7166552848688034184.stgit@dwillia2-desk3.amr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Dan, Linus, On Thu, Jan 11, 2018 at 05:41:08PM -0800, Dan Williams wrote: > On Thu, Jan 11, 2018 at 5:19 PM, Linus Torvalds > wrote: > > On Thu, Jan 11, 2018 at 4:46 PM, Dan Williams wrote: > >> > >> This series incorporates Mark Rutland's latest ARM changes and adds > >> the x86 specific implementation of 'ifence_array_ptr'. That ifence > >> based approach is provided as an opt-in fallback, but the default > >> mitigation, '__array_ptr', uses a 'mask' approach that removes > >> conditional branches instructions, and otherwise aims to redirect > >> speculation to use a NULL pointer rather than a user controlled value. > > > > Do you have any performance numbers and perhaps example code > > generation? Is this noticeable? Are there any microbenchmarks showing > > the difference between lfence use and the masking model? > > I don't have performance numbers, but here's a sample code generation > from __fcheck_files, where the 'and; lea; and' sequence is portion of > array_ptr() after the mask generation with 'sbb'. > > fdp = array_ptr(fdt->fd, fd, fdt->max_fds); > 8e7: 8b 02 mov (%rdx),%eax > 8e9: 48 39 c7 cmp %rax,%rdi > 8ec: 48 19 c9 sbb %rcx,%rcx > 8ef: 48 8b 42 08 mov 0x8(%rdx),%rax > 8f3: 48 89 fe mov %rdi,%rsi > 8f6: 48 21 ce and %rcx,%rsi > 8f9: 48 8d 04 f0 lea (%rax,%rsi,8),%rax > 8fd: 48 21 c8 and %rcx,%rax > > > > Having both seems good for testing, but wouldn't we want to pick one in the end? > > I was thinking we'd keep it as a 'just in case' sort of thing, at > least until the 'probably safe' assumption of the 'mask' approach has > more time to settle out. From the arm64 side, the only concern I have (and this actually applies to our CSDB sequence as well) is the calculation of the array size by the caller. As Linus mentioned at the end of [1], if the determination of the size argument is based on a conditional branch, then masking doesn't help because you bound within the wrong range under speculation. We ran into this when trying to use masking to protect our uaccess routines where the conditional bound is either KERNEL_DS or USER_DS. It's possible that a prior conditional set_fs(KERNEL_DS) could defeat the masking and so we'd need to throw some heavy barriers in set_fs to make it robust. The question then is whether or not we're likely to run into this elsewhere, and I don't have a good feel for that. Will [1] http://lkml.kernel.org/r/CA+55aFz0tsreoa=5Ud2noFCpng-dizLBhT9WU9asyhpLfjdcYA@mail.gmail.com