Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5699243imm; Mon, 27 Aug 2018 02:41:04 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda03Z08+zos55zSiJHh0SLTp33/sv2OkCU3eZ8W+gjchhlWpG+zT07TXwRBVwyfmQamfoAL X-Received: by 2002:a17:902:758b:: with SMTP id j11-v6mr12518498pll.29.1535362864020; Mon, 27 Aug 2018 02:41:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535362863; cv=none; d=google.com; s=arc-20160816; b=Xb8bJc5pVQloXv90GxFCK+GpwFENN4Y3491CeOwB5+DoQ43oae5X07WyPmPtfGhhuu wJ8sZsUTdIgMzIFU/umuYD58Harb/rfKYCoR0HgG6/tnCTtx0GrrZcB916CAQEbTO/Jn dcAoCHRU5HS7fnjN4s75dUm1W6DrUan5Jy8+z86rS4wKJ8e8zIELZElXcknyhDPz9wz5 KBiOOrVbqKFs300n/9Xy51zsvTc0AQ0a4WcHAZkP+cscM/e6P0HjsT/xSIAM7WZO79Cu 6Cm7nkHObQkJXlzC0vYmBo7EmlaPv/CZ9axLUmk9s6dmK8GC4/EvYxbF6AYNeRk8Q5Jg CvAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=KpbjKfgjIclE+HHpFWxoVwHrYN8m3EFBDMq3y1kMELk=; b=QS5OagnIu9oI77+qee1JsqrXIoQxwmXqyXgqZtpseIQ6sekiV8wImbc4O0dzkVyLDy IBd5vlhhMYLOQ9iG8CqpqRpicB3SpbDV+q3fhTp2AM0rBIggmMzm93y7Vza34QqlzCQD 4QglS37KrHRp+uPDSM0Mksmq0FQjZ/FX4pwvwkQZyNBPb7qhxgqN6M0tT3wf5/W12HNQ qmqOelZW4k5G2I2e7c1MbMYi+cZPhrjbIkvMXIkpom9tWL7TYMtesTi0kso6EHPexHUC rbbQU0j5qKnrEVh1kD99cD1VU+4o+X7EFC0g+8QlXXtqOinjt9tEFObTZ8ICJHEG5xJb 2BlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="yuQsF/a0"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v70-v6si13281332pfa.103.2018.08.27.02.40.48; Mon, 27 Aug 2018 02:41:03 -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=@kernel.org header.s=default header.b="yuQsF/a0"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbeH0NZg (ORCPT + 99 others); Mon, 27 Aug 2018 09:25:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:54052 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726872AbeH0NZg (ORCPT ); Mon, 27 Aug 2018 09:25:36 -0400 Received: from devbox (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9E45C20A8B; Mon, 27 Aug 2018 09:39:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1535362781; bh=NswiXxKUMprlxnabLOVDpx3lhqa9GgiKTYFOXkWSPko=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=yuQsF/a0z1kJOhInlnaDXeTE7nz9Yzpb4NhwWCidra1il7VONNShxx2WAFkbxk33s IDH4bAAsdV8AObh/KI2QUjImRhnaw0bRPPrCM+9EGoWWD53H771S8ITLnG0IQph3QI P2LU823mIG1Td4Ci6mD+2vFRhakAHCPNC3t+u2no= Date: Mon, 27 Aug 2018 18:39:36 +0900 From: Masami Hiramatsu To: Peter Zijlstra Cc: Andy Lutomirski , Kees Cook , Nadav Amit , Linus Torvalds , Paolo Bonzini , Jiri Kosina , Will Deacon , Benjamin Herrenschmidt , Nick Piggin , the arch/x86 maintainers , Borislav Petkov , Rik van Riel , Jann Horn , Adin Scannell , Dave Hansen , Linux Kernel Mailing List , linux-mm , David Miller , Martin Schwidefsky , Michael Ellerman Subject: Re: TLB flushes on fixmap changes Message-Id: <20180827183936.75f4e9bc131cdeac943f44e3@kernel.org> In-Reply-To: <20180827081329.GZ24124@hirez.programming.kicks-ass.net> 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> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 27 Aug 2018 10:13:29 +0200 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. Hmm, but how "near" is it enough? Since text_poke just map a non executable alias page in fixmap, it is hard to suppose that IRET points there (except for attacker change the IRET address). I see that Intel CPU sometimes speculatively read-ahead the page tables, but in that case, I guess we just need to keep fixmap area away from text area. (Of course, it is hard to estimate how far is enough :( ) Anyway, I agree to introduce new page-table (and kthread?) for fixmap. > 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* Ah, I got it. So on CPU-B, it can write-access to fixmap'd pages unless the CPU-B shoot down the full TLB... Thank you, -- Masami Hiramatsu