Received: by 10.223.148.5 with SMTP id 5csp7748377wrq; Thu, 18 Jan 2018 09:00:18 -0800 (PST) X-Google-Smtp-Source: ACJfBouXKvM7rPBwjSDICUWti3/x0QUJTWPrJTqMYoAj9ERZKxhS9Uk/invsAEnjFX9I6ybx8Qyj X-Received: by 10.101.102.3 with SMTP id w3mr15169308pgv.326.1516294818008; Thu, 18 Jan 2018 09:00:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516294817; cv=none; d=google.com; s=arc-20160816; b=JrNymxhUrZJbUW7fc664ZR9AY6FuJStfzDDg3aZH53kVZSLMNEbf+aFDApsCBZdDGY B6BR8/2STDUJCL8AsG83h5xRrppwQ8DBwBHfxKlNI+g/SbaXnt41ETi9SDSkZzoDegNN xA/PQUkDoYUFY3FH6JqvL38ATafTdwygk8gZoh0AJHZLvW6wGaMvUwVG1m9/Ou/JQZ6t vD0AL8MqQr/el6HcQOBXrJ3svgIpOEtLSkW8Qig+6UThR5jC2AgOEE/BdV6W0fSIh74q FKYN3QeThfM2IHG5gET1iddxoh0nKsR45iM92USFaEbrYuaKwJaQIYsOGsV44rk4hsFW IPyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=vunjY0w+5ym94jnFmjcm80v3aTBWVjr6EwXTIKa+zTQ=; b=koUMlKXhocfIjolirUUDQlORI0wZBhLjbEwjexABp4XLYlVxOQCXJOdfSUJsTFkJHZ 37dBSRejpzS2g/wGMR4045vMWLFzJYMv4vM35wCaUcEpHm8Q6CHy2nLpgas4QzFpWdKH zgo4Q6KIjdb6568d0EOixrbrRuDDNdkfyRG0/gSFDu4DeAs/nZSgc7aVOSwa5k+gH1JK T6qy9ISm96t18EImFbUWIwpix7qpJ8vn2j2zj5byqnRo+Wft5TXJEo7J+FMyzLEwXZkq JGer4G6R7iAQVQnS6OuoSJh/M1XaHhurXMc1s5jxsVTVt4MStnTxcZijUOgxbwjwOuV0 XmmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=KJERngDa; 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 o123si7219289pfb.313.2018.01.18.09.00.03; Thu, 18 Jan 2018 09:00:17 -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 header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=KJERngDa; 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 S932755AbeARQ6R (ORCPT + 99 others); Thu, 18 Jan 2018 11:58:17 -0500 Received: from mail-ot0-f194.google.com ([74.125.82.194]:34846 "EHLO mail-ot0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932688AbeARQ6K (ORCPT ); Thu, 18 Jan 2018 11:58:10 -0500 Received: by mail-ot0-f194.google.com with SMTP id 53so20688665otj.2 for ; Thu, 18 Jan 2018 08:58:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=vunjY0w+5ym94jnFmjcm80v3aTBWVjr6EwXTIKa+zTQ=; b=KJERngDat9giimFTbFif8QVCELS7d1zFrDnwyp5z4+Cwit7mgGZ34YrsH3iNaxqT5U TBjDmTb+I3k1TAOMycdmK+FEggIpi0beoQWOSKWF2jBBiMzlkNj6t2Rfyk9hEtToI+Iq wfifTh240++iKix1B7nOLzZ21anpim9LT7gfsPMc1H8L3oxPYbyxAcDoWf9IcsIDdAc1 c52SW6dERFY8db+t81OPgQvcvMPNffQhxWT1HOmZRShHSmNn9Y8eQJkh127fnLVLUoJF ezkw7Us4TMdrnNuwcGI7StaSIQJTS7l/5TpH/poo53+hmThpdFjMS4UNFD8SjuHHniPz Wj0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=vunjY0w+5ym94jnFmjcm80v3aTBWVjr6EwXTIKa+zTQ=; b=en32N2ZjRfjOs5vKZzl/WeKdu38GeHJr5wGxSGZeHb3d52+oDXS4kYc1e9lI89o0CQ uPo5438bt/AcjkqnJ/dNZgRQhy66VeDLmkR+p0+g2VwHSx8NZBRUNVZC4Qgb1jbYd/z/ lDq/dBqFcBe76O9onHD0Io9uE/A6YLkQF4wqIlCD4xS/EM5o/dD685oFJbXnfcwlrbVt V2+kMIAUQGNR4Un0ds6LxQLvN+4ubHZznVAtrFJ6XjkCKPwLGVDU0ua2Zdf1SfZKjCcO Mw9WL2Q8sf3Nui3rO/OuU3fmZ9P1DhDe0H9OdXuiTZRq2aMMBJFyv88ebN+Llwhk48Lb wrhQ== X-Gm-Message-State: AKwxyte9hPUH84q/QM7LpGndPvEsdLvIcFeRDO5BIic8CvZ2xFAHfsfb Zou3sGRkk+vp9MUiAyRZ+ocGGRIVYy604VkGl8oLzQ== X-Received: by 10.157.0.102 with SMTP id 93mr3617776ota.175.1516294689608; Thu, 18 Jan 2018 08:58:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.59.70 with HTTP; Thu, 18 Jan 2018 08:58:08 -0800 (PST) In-Reply-To: <20180118131837.GA20783@arm.com> References: <151571798296.27429.7166552848688034184.stgit@dwillia2-desk3.amr.corp.intel.com> <20180118131837.GA20783@arm.com> From: Dan Williams Date: Thu, 18 Jan 2018 08:58:08 -0800 Message-ID: Subject: Re: [PATCH v2 00/19] prevent bounds-check bypass via speculative execution To: Will Deacon 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 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 On Thu, Jan 18, 2018 at 5:18 AM, Will Deacon wrote: > 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. 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().