Received: by 10.223.176.5 with SMTP id f5csp71282wra; Tue, 6 Feb 2018 17:26:02 -0800 (PST) X-Google-Smtp-Source: AH8x227SWAqPcWBiS5mGozyIFXYgIxcU9pBIgjNLZy2EhqHPZJ84J19J3vLDMSC8yFMze7IP8W/D X-Received: by 2002:a17:902:523:: with SMTP id 32-v6mr4183566plf.283.1517966762741; Tue, 06 Feb 2018 17:26:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517966762; cv=none; d=google.com; s=arc-20160816; b=PkgnVp0C/fr7QAFctQ+DczqKvgxblgolB2tTZ/p85BM8IMv+2wFw1hW14p2Glzki/X M81Y0GlQYhvZ2BR4bAnUrEDD/9GmdLJrUqdLSZ0C0Nu4tGSXW0q9+/eJ61R0T9r33PLO 8tgJFeg1ECN8KGA7y0H/2wT7pqrHYdLLSZplwgp3i93AyznrFKMO3dfLTnTxwMI+2k01 o/ozQeEWnkcXDLeOGHWen/+k2wCfDVs0iNuCmMmSM3+N4qhdJxN76j8cvT6yMJnaNokc /vpOluqUIqO6zObRuNhJcTcAbUDBVMuG0FHrgL6RBQGaptGot50Oh0Drk2tE9oPqK4A+ f1og== 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=ETKrahDyXJBwVFHwVWGKomo4pLbuHJilNJcjPKe7cEA=; b=thS2JE6H7zZV67IhUX95SZBrNPaa2WyhbID8Yo9HTnY56YFFMvuMsBuq+3dy77cK0Z F1b95ORGM81cFFeFLGZleJ7XGNqPGKUhsYq2LLHsWs5nrGC/uj9eNrkwoNj24d/JufwV YjR5NNGp9NATOuxnI9kjKJ45+h7c7XOZ4w5s7hMEmbjKgPQUKUDrX+6UIIPY5hJQyCQT vwklnO2t/KbfOBg0+5a1Kd2LPHrepwyBqHGaF944iYOCJxcckeSdSyQuNQ0wcESLYkN2 txSK+Ki7307t9gSOK16xEqRSGDRm0BXiT5RNiDiNW4y1Dreu4xuX8y8W2u8DhBQ3DAQc pUsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=p+R/sMFJ; 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 m189si248094pfc.410.2018.02.06.17.25.47; Tue, 06 Feb 2018 17:26:02 -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=fail header.i=@gmail.com header.s=20161025 header.b=p+R/sMFJ; 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 S1754334AbeBGBXv (ORCPT + 99 others); Tue, 6 Feb 2018 20:23:51 -0500 Received: from mail-io0-f171.google.com ([209.85.223.171]:41145 "EHLO mail-io0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754306AbeBGBXs (ORCPT ); Tue, 6 Feb 2018 20:23:48 -0500 Received: by mail-io0-f171.google.com with SMTP id f4so192260ioh.8; Tue, 06 Feb 2018 17:23:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=ETKrahDyXJBwVFHwVWGKomo4pLbuHJilNJcjPKe7cEA=; b=p+R/sMFJQL7XkKZmhuEYHpu6pM0RzMt3Y9rIIS13V4EeQSH29A4E5hgkFGTgw5yqs5 o3MHf6yKSACbDlmyxdeeSIiLzuTtx8+ri4KwMH5frIqEcmaVbKeWi6x0rchQkul7BY/x EGa+MPtcP8uwhwGWEHkKALKCoIOArumXARKpHkEDgdy3RJ5CgBa3XYgeI8iFv/UcD5th rjn2I5t/lGi4dMcv0NOENpX4MiVAuFE+Q+UYY7UpzgcOWbsgsd+l9WtEh6oGcf8B64+I B64jzeU4Xd/CjrYKL4j4E8r7SAhx4sSlO6PoJfTzilMdiDxwL81HJdtmbjmdwe2EqWUz DXlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=ETKrahDyXJBwVFHwVWGKomo4pLbuHJilNJcjPKe7cEA=; b=oyGCN0hNeJ34QQU242k3IQWvbBeaZQVkqysKgoA5UDrYAL9nDSsGSchqGs9XWsrdhi 5eEXeCC7zrpLIlHjvJ5p/1FHNE+bfF5Jge9E56/7q2E1s74eMx0XlmJFEoXxAYcFP5i/ krVIshxe9PZWh0T6LMdVqRzbwxC/iJcINL8x3zm46peJFdAIO9bbbHO4tBpWUr5bgbxL 5w4l0+YkUAyaEVNwNSTu053+hVRBd9cJj4e1j9Lm5ZndYS+jdnVplKLW76GZoKXOBW4t 4t75P5OF8i9lijI+OtDzeGKMx3ieaxrGjxdS3KIsuY5/xNxeZ3Ic3zGi9d2BQro7wk6b 901Q== X-Gm-Message-State: APf1xPATSl1KS0Mg44we260tJJlwJ8S3Klp8K9XojbeXtF0IsBJP3hy4 3ZoperAm1xLj1oIJuwU0pXhOE4P6QKV5AgLOCCU= X-Received: by 10.107.132.3 with SMTP id g3mr5425177iod.46.1517966627439; Tue, 06 Feb 2018 17:23:47 -0800 (PST) MIME-Version: 1.0 Received: by 10.107.59.196 with HTTP; Tue, 6 Feb 2018 17:23:45 -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: Linus Torvalds Date: Tue, 6 Feb 2018 17:23:45 -0800 X-Google-Sender-Auth: m0RJ4JPOou-6tyqMPfAhKZl4wm8 Message-ID: Subject: Re: [PATCH v4 07/10] x86: narrow out of bounds syscalls to sys_read under speculation To: Dan Williams 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 4:33 PM, Dan Williams wrote: > > 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) That looks fairly optimal, except for the fact that the callq is through a register. Of course, that register-indirect calling convention is forced on us by retpoline anyway (which you don't have enabled, likely because of a lack of compiler). But without retpoline that callq could be callq sys_call_table(,%rax,8) if the masking is done on the index (and if the conditional jump had been done on the cmp rather than the later 'and'). Instead, you have a leaq sys_call_table(,%rbp,8),%rax hiding somewhere earlier that doesn't show in your asm snippet. Oh well. We'll have an extra instruction however we do this. I guess that's just something we'll have to live with. No more bikeshedding.. Linus