Received: by 10.223.176.46 with SMTP id f43csp44790wra; Thu, 18 Jan 2018 13:42:46 -0800 (PST) X-Google-Smtp-Source: ACJfBouWbanDX4Rfbd6ZAcUsVkknhxLDoNOcIiBIiH27aZFcBdB1lwZDmVp8ml592iIWSqBrW0Ma X-Received: by 2002:a17:902:6a89:: with SMTP id n9-v6mr441591plk.212.1516311766773; Thu, 18 Jan 2018 13:42:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516311766; cv=none; d=google.com; s=arc-20160816; b=VgWEU4hEU5rIVF4/nsBObGo26Nx+Bat9C4uCjqm4KMu52QCrs6CRWRmcW3EpCNXq8I EzonR4p8XJVrEk6W+qOBlGi133ZlcgkEhdk10ezJtlhGWJt8UYEbdGzEbbMoiPEl9TNq pShFrTxh0wukBtCQAoU17VrleSt98E8oKmdXuS7UDseX6i+UVjpfGQvdObrPW43T6Gn3 SwLqVOzqgz3yj995c/Xu16ASlvcek3uDI7sPJrqX2DkIEXWJ8xRoTO6B3vnK3hBFDUi3 Qpu892RrTFdhAyyOQ1Wwoud8hT1OJ69wkTHu/tq5+1OFxtHU/G1LKZUjPP5+p8Id/tvh BDpQ== 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:organization:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=2RjYJMWSoQgUGpxf/NmrZAo4jq2Z2Vz/n344IKBE/os=; b=wpK7lLMX3G759gvJ/zcp0u3UIel8jlOBrIQqqb2L509eZXR/JhsaYTOskAGrMRkhiR mxVwHrNmVIRuvzAWmeHRH2aplqFixXS5LSv6vCCEBUlexdoR9e01kCwtSmWr8524/eWU 3RKWmXhLYQ1kYDRlDqR93vXMTGle7VNH2e+dq98WHgGRnPm7t+3lIQ4nL6A+7CyFKU50 rqP69O5fd7kFP/orqJ3RrkuX/il1Iq0G1YBlVRzRL8LlptOd6pCOEd+cZpJogo1aXTVO lx3Az8OSubKpExoxcbhrEEJ3BWW6LbbNvlzam3bzC0IV6t0AuDeXryBOI6T94W6f/AJa r9/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=EleUUnMU; 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 a17si6764531pgv.479.2018.01.18.13.42.31; Thu, 18 Jan 2018 13:42:46 -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; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=EleUUnMU; 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 S1753881AbeARVl6 (ORCPT + 99 others); Thu, 18 Jan 2018 16:41:58 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:36481 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750767AbeARVlw (ORCPT ); Thu, 18 Jan 2018 16:41:52 -0500 Received: from avalon.localnet (dfj612ybrt5fhg77mgycy-3.rev.dnainternet.fi [IPv6:2001:14ba:21f5:5b00:2e86:4862:ef6a:2804]) by galahad.ideasonboard.com (Postfix) with ESMTPSA id 43F9320226; Thu, 18 Jan 2018 22:40:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1516311656; bh=v0UV3NZAGFq/nVxDxNdY7YkwZecJb2nTrdmq8lwad8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EleUUnMUZaTEOB+ruthgHmnGjwdXqFaJBkGDk1hyFaRt9Zs/9fHAUEold9CBHO5Sq +/o05m8qE8QBmOJLNInGoKHujy5wV0hZJJyaIFkU08j7MKxvh3riDUQKoraI8jhxya mScAKqQAADTgm26mapoMa1qDXAi8dSMpS4MEs6u8= From: Laurent Pinchart To: Will Deacon Cc: Dan Williams , 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" Subject: Re: [PATCH v2 00/19] prevent bounds-check bypass via speculative execution Date: Thu, 18 Jan 2018 23:41:57 +0200 Message-ID: <1726114.TonTVukLyd@avalon> Organization: Ideas on Board Oy In-Reply-To: <20180118170547.GF12394@arm.com> References: <151571798296.27429.7166552848688034184.stgit@dwillia2-desk3.amr.corp.intel.com> <20180118170547.GF12394@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Will, On Thursday, 18 January 2018 19:05:47 EET Will Deacon wrote: > On Thu, Jan 18, 2018 at 08:58:08AM -0800, Dan Williams wrote: > > On Thu, Jan 18, 2018 at 5:18 AM, Will Deacon wrote: > >> 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. > > > > At least in the conditional mask case near set_fs() usage the approach > > we are taking is to use a barrier. I.e. the following guidance from > > Linus: > > > > "Basically, the rule is trivial: find all 'stac' users, and use address > > masking if those users already integrate the limit check, and lfence > > they don't." > > > > ...which translates to narrow the pointer for get_user() and use a > > barrier for __get_user(). > > Great, that matches my thinking re set_fs but I'm still worried about > finding all the places where the bound is conditional for other users > of the macro. Then again, finding the places that need this macro in the > first place is tough enough so perhaps analysing the bound calculation > doesn't make it much worse. It might not now, but if the bound calculation changes later, I'm pretty sure we'll forget to update the speculation barrier macro at least in some cases. Without the help of static (or possibly dynamic) code analysis I think we're bound to reintroduce problems over time, but that's true for finding places where the barrier is needed, not just for barrier selection based on bound calculation. -- Regards, Laurent Pinchart