Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5710908imm; Mon, 27 Aug 2018 02:56:56 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZwAu5NZf8Qd/OFolCwgjEPwUIXcr3P3BPX9crZnukxfFyAtqICs9DTt8+FeNv/P7yaCtbJ X-Received: by 2002:a62:fd06:: with SMTP id p6-v6mr13592913pfh.167.1535363816865; Mon, 27 Aug 2018 02:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535363816; cv=none; d=google.com; s=arc-20160816; b=qC+DCQ1sbUKWWxkUIuPkWcbNaZpF0/7hR1SZYQHzoIWlwJU7yPfRKPjriVtg+OHgHo tC8y4Zjj3i5lyyNN4ML+BBSqv1wdf9acp8i9CAIP9eAEa9excmbISxpt+JwvCy6qpmgo zfqeTvVP2sk1ud72M78jtoMmU7Y3klTCIXAJ61h58NlX9T+Pq6OyGGfHP2Ouhokwt6RT SC5TqGFY3spYANBU2cFLVhTsgIixy6FxSrZtBLA+hhYPxQRFj3DC59BYDQ58alA1ToRa /OsB0vLe0WkQH+9/Z/pcFiVIb3Hbx9nNU2IemsVUTX1EUtxEnGOWdvjeBhxnfbPK10fi aRGQ== 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 :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=xjtbmH2va80cETjTwP12yR1eFr9X+4EFx0tThrCOsVo=; b=PHp7/gIbB/ygMnN62eO9Tqjwfi4Fw9TXbyzD7mg09LEdkNKG8F4V9x+Fo/7P0pH10B bSKEPiaVuXfN1QDeaAt69pCb88lBelLHS8ZRwOR9ldI8NlG4LPCO1GghF1txHMfmoJ2k sPwYQGBW2cExZ3trmev37QySS6Hn8QIisnQ8o3HXLA7QfNsfvAHM/gs7fZJczxDOmWuy GIqCWYvURrEaVUTiCbjTvmPtNvO0yCX/phMA9ThimOL3sSobKgPIeDip4lXHb2P8lO90 UxPhczQ0SzWXXl8EgK9vLdy+mEP7NnOUdwbXX0IXR++7Eu8uyjWbZAZgwzlWMorE+8+g Ufsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bQMBv1P5; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8-v6si12890167pgr.445.2018.08.27.02.56.41; Mon, 27 Aug 2018 02:56:56 -0700 (PDT) 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=@google.com header.s=20161025 header.b=bQMBv1P5; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727162AbeH0Nl0 (ORCPT + 99 others); Mon, 27 Aug 2018 09:41:26 -0400 Received: from mail-oi0-f54.google.com ([209.85.218.54]:39249 "EHLO mail-oi0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726925AbeH0NlZ (ORCPT ); Mon, 27 Aug 2018 09:41:25 -0400 Received: by mail-oi0-f54.google.com with SMTP id c190-v6so26207174oig.6 for ; Mon, 27 Aug 2018 02:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xjtbmH2va80cETjTwP12yR1eFr9X+4EFx0tThrCOsVo=; b=bQMBv1P5YhH7WgQOO+TJ1kG45mMqRPnYvPZdxheGMY6KE9Z7mJfxjUclGIpdhCMkay MfKCN7Mx1xcsphWDpMjmitT0CX+lgL2AJWiXVzaWnvwUwRXnt/KF7eKZ9DmjlJE6wweG 2TaMA/HOIhDsIPjrkV+A6Uje92uJUWk5GRQ3ZTKHaT0OXMKhLYDCaaavEwQkQvM0tdQt fJUR6uJQrbqnZvhAKWxUxhh+ul5qwNN6RFohIxQA9fKaiqNCnTtcypecpIVfFqtCKzzS 79309U2/lBNHyBoQKSlUy4iS682YezLgK5eqfoEnUR6h5Ugoyvo4jIW+NE1db45GgQ55 2rzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xjtbmH2va80cETjTwP12yR1eFr9X+4EFx0tThrCOsVo=; b=uFhIvE7shyQ3UREYhoLg3+XABvTc7q3DtSUxhkgoucICkSJVZn4zedGkoOItYw1uOt KX7+W+AdJFaoiYgE3fEqMz+g/BI0fnIEREXEo7bCLd9BTrCRrkVmSkA+P0HmRcBshn2H 3aEWPvnTjrfsjQ0SR4d5q9WPKeJuipXn07QGaP0KecFcPFwT77oXw6gXv/YgqZ81e760 OPSktu0r9EkpjAzZfyh6BF/Dffeg6FCDNZ5N6chOs5WO5tdSp6qA3lQ1IAtZom8HaXXN XRxaTHwUC/wGIgE+pgI7EN8PWIP7Xbm9zDAYnf+UF4lKApSSjQnBOmMYKfjCXI9fqf0E rSuw== X-Gm-Message-State: APzg51DdADozA0TyCswDNh+4EufVbt2Lj8WsI32VG0yT7bSVgb32beTM nC2VSxQP4fxUqklM45RUn6Q6/AZfr0qh9VkiuoVNSw== X-Received: by 2002:aca:b40a:: with SMTP id d10-v6mr12617792oif.190.1535363727475; Mon, 27 Aug 2018 02:55:27 -0700 (PDT) MIME-Version: 1.0 References: <56A9902F-44BE-4520-A17C-26650FCC3A11@gmail.com> <9A38D3F4-2F75-401D-8B4D-83A844C9061B@gmail.com> <8E0D8C66-6F21-4890-8984-B6B3082D4CC5@gmail.com> <20180826112341.f77a528763e297cbc36058fa@kernel.org> <20180826090958.GT24124@hirez.programming.kicks-ass.net> <20180827120305.01a6f26267c64610cadec5d8@kernel.org> <20180827081329.GZ24124@hirez.programming.kicks-ass.net> In-Reply-To: <20180827081329.GZ24124@hirez.programming.kicks-ass.net> From: Jann Horn Date: Mon, 27 Aug 2018 11:55:00 +0200 Message-ID: Subject: Re: TLB flushes on fixmap changes To: Peter Zijlstra , Andy Lutomirski , Dave Hansen Cc: mhiramat@kernel.org, Kees Cook , Nadav Amit , Linus Torvalds , Paolo Bonzini , jkosina@suse.cz, Will Deacon , benh@au1.ibm.com, npiggin@gmail.com, "the arch/x86 maintainers" , Borislav Petkov , Rik van Riel , Adin Scannell , kernel list , Linux-MM , "David S. Miller" , Martin Schwidefsky , Michael Ellerman 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 Mon, Aug 27, 2018 at 10:13 AM Peter Zijlstra wrote: > > On Mon, Aug 27, 2018 at 12:03:05PM +0900, Masami Hiramatsu wrote: > > On Sun, 26 Aug 2018 11:09:58 +0200 > > Peter Zijlstra wrote: > > > > FWIW, before text_poke_bp(), text_poke() would only be used from > > > stop_machine, so all the other CPUs would be stuck busy-waiting with > > > IRQs disabled. These days, yeah, that's lots more dodgy, but yes > > > text_mutex should be serializing all that. > > > > I'm still not sure that speculative page-table walk can be done > > over the mutex. Also, if the fixmap area is for aliasing > > pages (which always mapped to memory), what kind of > > security issue can happen? > > So suppose CPU-A is doing the text_poke (let's say through text_poke_bp, > such that other CPUs get to continue with whatever they're doing). > > While at that point, CPU-B gets an interrupt, and the CPU's > branch-trace-buffer for the IRET points to / near our fixmap. Then the > CPU could do a speculative TLB fill based on the BTB value, either > directly or indirectly (through speculative driven fault-ahead) of > whatever is in te fixmap at the time. Worse: The way academics have been defeating KASLR for a while is based on TLB fills for kernel addresses, triggered from userspace. Quoting https://www.ieee-security.org/TC/SP2013/papers/4977a191.pdf : | Additionally, even if a permission error occurs, this still allows to | launch address translations and, hence, generate valid TLB entries | by accessing privileged kernel space memory from user mode. This was actually part of the original motivation for KAISER/KPTI. Quoting https://gruss.cc/files/kaiser.pdf : | Modern operating system kernels employ address space layout | randomization (ASLR) to prevent control-flow hijacking attacks and | code-injection attacks. While kernel security relies fundamentally on preventing | access to address information, recent attacks have shown that the | hardware directly leaks this information. I believe that PTI probably prevents this way of directly triggering TLB fills for now (under the assumption that hyperthreads with equal CR3 don't share TLB entries), but I would still assume that an attacker can probably trigger TLB fills for arbitrary addresses anytime. And at some point in the future, I believe people would probably like to be able to disable PTI again? > Then CPU-A completes the text_poke and only does a local TLB invalidate > on CPU-A, leaving CPU-B with an active translation. > > *FAIL*