Received: by 10.223.176.5 with SMTP id f5csp32525wra; Tue, 6 Feb 2018 16:34:09 -0800 (PST) X-Google-Smtp-Source: AH8x226tOUjzZMUSAMubDRX0T9SHkOmsS3wktcdRQf/pxwqcLD1Kb24aPzC1wvLvq5yxijnyKwfd X-Received: by 10.99.119.69 with SMTP id s66mr3265123pgc.261.1517963649614; Tue, 06 Feb 2018 16:34:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517963649; cv=none; d=google.com; s=arc-20160816; b=c5xOUT0zkZKv3CRYcetLRfz3lPOE0s6FsYPVZ2Inkvmaxvoldt0kU70CV86C73Kj39 ihoFba5OPEtFRQceKT3hNW3mn9W7mL5lRNQLQkErB3UYTIiqrx0PmLbKAkSUa7Ng4sRE 72wMMMz22cGULZnu4OL+Bi7oTSW3oLlqDZgburckhQ91NSe8Zh6EL+n+AKMnf7qh8FMN 9z5j8LlP8di1azHMN9Gt9HtiKT1HoXJU7NJV8CKarCE0INiC7401gCyR8a4cYoiyr5id e2xKYIZHuWUXYyGOTpx22jdU2+cOE5PEOwi+JN+eLLuT+HVSNyjSLdUB4gS/UzvdK2Me LqKA== 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=1Q0UfRApg17V5+sSryRii7TpBecbFJC8y3qs/GGb9jk=; b=Vc1r15Jr/4i94sYrgqz6/qItw7buHRWxKbbr/yz7F4tS8ZNl2UWY13eg/1tRLiDK65 eidTABRIwINnFrL9ivkTUM/2w072XhmHSS2tfnhkZuC/NtC+KtvDZE43o9IOqYSQwnb3 eWN1wlJY/Lon4O/6f4EoNOkRcs4XdOM0MENycDvNCA8HAgqDupLUdaooO9LDzKz/1BKF xSuayA5LnRAYUwc+kKViF+fyyd0RY4EkXnuNBS7Aex3Wec2BlD1Sc0hBPMMylWoHE7Zf eWfIiHHl6Vjq4JQM7BMoECLzwvmcrzSNrHi+lhg7c+bqsywceQdX2vg3QmqZv6LXMOFX yoUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20150623.gappssmtp.com header.s=20150623 header.b=kcANx9rL; 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 c11-v6si154276pls.365.2018.02.06.16.33.54; Tue, 06 Feb 2018 16:34:09 -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=kcANx9rL; 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 S1754198AbeBGAdI (ORCPT + 99 others); Tue, 6 Feb 2018 19:33:08 -0500 Received: from mail-ot0-f172.google.com ([74.125.82.172]:46127 "EHLO mail-ot0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754160AbeBGAdF (ORCPT ); Tue, 6 Feb 2018 19:33:05 -0500 Received: by mail-ot0-f172.google.com with SMTP id f56so3551827otj.13 for ; Tue, 06 Feb 2018 16:33:05 -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=1Q0UfRApg17V5+sSryRii7TpBecbFJC8y3qs/GGb9jk=; b=kcANx9rL/gp7VWnClD3SIKkqT68anqGnrtbW6yAcVZ8o/vxS+MEx1t9GHLTMNU+daz OiKpunkgsQxSogE4lkT/9FMKWEgxpqBaHvsxN8WeHESTzKaic4E+SHuAD5lt+3eTptiy 67kDBYHhISbYOwSunif/xSIcEjEGJ7i/kg1S3PJ9CO+ZXLG5vXxN5kPIKShj6E8Z/p5I ssaCM3u1Pj3Tdfg9XyEDBCGFZjG2EpZQvir946v13iG2TyLFihOOaLrffKn+mpZmVzWX 56rqVkeIivCMvVViMzebTN/D9AoNHfLfEgZErtzD4gZY9JiyoV2aHVfPmgmLJPxZRG58 Bq+A== 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=1Q0UfRApg17V5+sSryRii7TpBecbFJC8y3qs/GGb9jk=; b=HydED10JZVf0AkNpGErxtAjo6SKeMt8QeHJ2sAPE9CbbUne2l3Jw2GRcGdJoBTX5nM QS0oBJ67gLh+Q0hhZhJLhlzp1PFgYOn42OQHRHowjMrGxw1WLjT0zD0DwJ3cXNsEE9Xk ko/jBEazGrMlO6IeON/RNXDNMiCdjJPKiGtNEx+feWqswYfGlrjPbkHxZ71Fqkl4Ox+b w4wMBiDy+zuISfW0WOSqwlq4B4nmdNVE1tiAtn++29yOVcf0u0fl4VRNMJcjWV8fAsVg qEpUmnswjb7DQUJ1FOBAGCUSSqZHyEo4jT9fZEhOm7sGaKrOoHOkZpYNJI2Yxr8752FK OwnA== X-Gm-Message-State: APf1xPC+v29EJDnzz4AMyU4dAkdkmzTNneAJ4w0Rc0tU580slXkOigqg PVBBqmTh6BcbWesFKS0cbanbJWpYyrczCklcLGXXUQ== X-Received: by 10.157.20.180 with SMTP id d49mr3329330ote.46.1517963584639; Tue, 06 Feb 2018 16:33:04 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.62.91 with HTTP; Tue, 6 Feb 2018 16:33:04 -0800 (PST) In-Reply-To: References: <151632009605.21271.11304291057104672116.stgit@dwillia2-desk3.amr.corp.intel.com> <151632014097.21271.16980532033566583357.stgit@dwillia2-desk3.amr.corp.intel.com> <20180206192925.qkmghwsbaysr4iv2@hermes.olymp> From: Dan Williams Date: Tue, 6 Feb 2018 16:33:04 -0800 Message-ID: Subject: Re: [PATCH v4 07/10] x86: narrow out of bounds syscalls to sys_read under speculation To: Linus Torvalds Cc: Andy Lutomirski , Luis Henriques , Linux Kernel Mailing List , linux-arch , Kernel Hardening , Greg KH , X86 ML , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , Andrew Morton , Alan Cox 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 Tue, Feb 6, 2018 at 2:52 PM, Linus Torvalds wrote: > On Tue, Feb 6, 2018 at 1:37 PM, Dan Williams wrote: >> >> At that point we're basically just back to the array_ptr() version >> that returned a sanitized pointer to an array element. > > .. that one does an extra unnecessary 'andq' instead of the duplicated > cmp. But at least it avoids comparing that 32-bit integer twice, so > it's probably slightly smaller. > > (And your code generation is without the "r" -> "ir" fix for the size argument) > > Probably doesn't matter. But a "asm goto" would give you at least > potentially optimal code. > Should we go with array_element_nospec() in the meantime? So we're not depending on jump labels? With the constraint fix and killing that superfluous AND the assembly is now: e26: 48 81 fd 4d 01 00 00 cmp $0x14d,%rbp e2d: 48 19 d2 sbb %rdx,%rdx NR_syscalls); if (likely(call)) e30: 48 21 d0 and %rdx,%rax e33: 74 1e je e53 regs->ax = (*call)(regs->di, regs->si, regs->dx, e35: 48 8b 4b 38 mov 0x38(%rbx),%rcx e39: 48 8b 53 60 mov 0x60(%rbx),%rdx e3d: 48 8b 73 68 mov 0x68(%rbx),%rsi e41: 48 8b 7b 70 mov 0x70(%rbx),%rdi e45: 4c 8b 4b 40 mov 0x40(%rbx),%r9 e49: 4c 8b 43 48 mov 0x48(%rbx),%r8 e4d: ff 10 callq *(%rax) e4f: 48 89 43 50 mov %rax,0x50(%rbx) e53: 65 48 8b 04 25 00 00 mov %gs:0x0,%rax