Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752667AbeAFR4P (ORCPT + 1 other); Sat, 6 Jan 2018 12:56:15 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:37025 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750940AbeAFR4N (ORCPT ); Sat, 6 Jan 2018 12:56:13 -0500 X-Google-Smtp-Source: ACJfBovMiSc9AJn9lIoW0STLN+VVFmxKAmUAxtJxygu5BF4yLlD3+NgbqaMBCVnHkJJqMGjeGKiI3t3EXEiYKAl1VMU= MIME-Version: 1.0 In-Reply-To: <20180106123242.77f4d860@alans-desktop> References: <151520099201.32271.4677179499894422956.stgit@dwillia2-desk3.amr.corp.intel.com> <151520102670.32271.8447983009852138826.stgit@dwillia2-desk3.amr.corp.intel.com> <20180106123242.77f4d860@alans-desktop> From: Linus Torvalds Date: Sat, 6 Jan 2018 09:56:12 -0800 X-Google-Sender-Auth: wSrGhmM7Am6gfv17QvD-Mcbv5Ig Message-ID: Subject: Re: [PATCH 06/18] x86, barrier: stop speculation for failed access_ok To: Alan Cox Cc: Dan Williams , Linux Kernel Mailing List , linux-arch@vger.kernel.org, Andi Kleen , Arnd Bergmann , Greg Kroah-Hartman , Peter Zijlstra , Network Development , "the arch/x86 maintainers" , Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Sat, Jan 6, 2018 at 4:32 AM, Alan Cox wrote: > > Also for x86-64 if we are trusting that an AND with a constant won't get > speculated into something else surely we can just and the address with ~(1 > << 63) before copying from/to user space ? The user will then just > speculatively steal their own memory. User accesses *may* go to the kernel too, with set_fs(KERNEL_DS). We've been getting rid of those, but they still exist. We historically perhaps have 'and'ed the address with current->thread.addr_limit, but it's no longer a power-of-two mask, so that doesn't work. We'd have to play tricks there, but it might work to do something like addr &= current->thread.addr_limit | 0xfff; or similar. But this is one area where the 'lfence' is probably not too bad. The cost of the existing 'stac' instruction is much higher, and in fact depending on how lfence works (and how stac affects the memory unit pipeline, it might even _help_ to serialize the stac with the actual address. Linus