Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5813495imu; Mon, 26 Nov 2018 05:37:36 -0800 (PST) X-Google-Smtp-Source: AFSGD/WjhEkpE4d9lPsyTzLs1L5QKgk7uNjSJ80VyDxYcRF9OvGaEWQX4eDNlWeV0L0SaDtQYj82 X-Received: by 2002:a65:4904:: with SMTP id p4mr25109553pgs.384.1543239456360; Mon, 26 Nov 2018 05:37:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543239456; cv=none; d=google.com; s=arc-20160816; b=MzgM9bvODjGTDyBoCyR2kaiEM0BMQXJ5Ch6dg+NEKYU/9YnsJ5m2s2EuhFoVLW+agN N18CN6+zaVQJV4WzJ/2og3nVIYY9+jBk9+R52RXDpkUQxvw9g7i+kn6sRDX+pbkq+Wkk rYFc4A6h0/u9RUsIHUCz11jkdBk5gnVlFeI02puhByvtk+eqYwNpAsQobjJMWF9/yF9A RsWMOd4KxttylM+1zv4bgliAygo0CQ0oaouEbDiZ8oKmTDSYTHHXBqXML36MNPQWjajV BrA6cbTFylgx1U6ee7E6sMwqtFOFNi0TRHxWq3hB1C8diIg0in5Np2lrE+a1CKc+owRJ keiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hrRG+8DGJB5KYXK6fX7hN0b+wV3eWhvpfn5aeYmR0gQ=; b=IIzec3gW/w9OsydMBud9Rz5UNriVIzZvn21arbMpjgRMffUgFj6FSVbR2DDbNHiCrf TlnXgIWKX7y5YPDxWVRg+GnzzJ5tbr5j7ZIXXxLl8LFiiCqO4ydankWJghblmuX/eR0u 5fBbRcLWKR16yxbkNlT/9ns7fTv3xBoAWCxAUGXbWQbCoNwRZa37K1UKXDCjakJPhxXp //Th8+Ny+g6nFcL2trWD4fBmdNNZp2AlnuF1cxRBTLyKweG8WaKFrna3MsSiQqndfgHY YvztRKgOHhvT/fUrsN9vV/tCNHaCFAioNcWPc6+vupvdRcp/fl8gIMwaVF0PbAMVRQyX VXaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=r9aqBbYG; 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=fail (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 a11si425266pln.78.2018.11.26.05.37.07; Mon, 26 Nov 2018 05:37:36 -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=r9aqBbYG; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726568AbeK0AaY (ORCPT + 99 others); Mon, 26 Nov 2018 19:30:24 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:32820 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726201AbeK0AaY (ORCPT ); Mon, 26 Nov 2018 19:30:24 -0500 Received: by mail-wm1-f66.google.com with SMTP id 79so16598483wmo.0 for ; Mon, 26 Nov 2018 05:36:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=hrRG+8DGJB5KYXK6fX7hN0b+wV3eWhvpfn5aeYmR0gQ=; b=r9aqBbYGd+cJTgvi4jeeWZsEw1WwT3Sn3MPsAT94yQ3mQE01vll/OWLkQwmph12Ngd gT02P2rna+8lffvQOjBh/9g6/OmZ/XwPO41la0ucmEg7MJ+eI9FGoE/wXx3S8GkN5vmK V8aV9WM+o1aptsJ4/72Co52zV4Id0gN0V7Yg/wWiwtyzIwLSdrC7TVX9CXXwwwZyZoGX Yl+8rWJQ4kna+XxoM/1aPFs83dp4mrjOoWM7a3+EHv8ixmed4R4abaq1KvkiVeA1G8bI 0hISGgC7T74xYdJzbfU1RV7ejZ5hW6PdlTHYJqzwnwjdtfhP5bM+Uu8Pd0tqiv3wgSdW 7vxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=hrRG+8DGJB5KYXK6fX7hN0b+wV3eWhvpfn5aeYmR0gQ=; b=ewH8UsjQ1PQCv/ceu6jFPsNMOw/3txhC8E86gez66xIN9IDJHe/AKMGpTyOlTV5YaS GgTMlvgiQgSWmlIATp4j3GTvdtuyDljyUZA+8KYjxm9PUtziRboL+XxZCssJxlTetA96 1DBlVIGrZ3pZvsc4LMoanjOB0+5D+WqFtweba00Q8gXUOCn4CzQrus+++aK9wNqSH5WI O9k7jTKEfEQFWAfsTgXmuVMecMFbQbcNxtyapUKIq6QRt7ZoAqxfR3F0I4bdjTaF40l7 ymUCD2eOgaNSKhzFpR4/2o58oN7z6ES5Bu5K53K5TksCXIYwpDoH61dHCeI+iSuDgmIe 9JtA== X-Gm-Message-State: AGRZ1gLwzO9EAUFmDvJZH+p2Q+gzpg2AoYM/6ax4EmrHR+98xNm5WUag R7yEKQF63ElrU/xxqpYFCbA= X-Received: by 2002:a1c:128c:: with SMTP id 134-v6mr25214156wms.72.1543239374129; Mon, 26 Nov 2018 05:36:14 -0800 (PST) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id o8sm480073wrx.15.2018.11.26.05.36.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Nov 2018 05:36:13 -0800 (PST) Date: Mon, 26 Nov 2018 14:36:10 +0100 From: Ingo Molnar To: Thomas Gleixner Cc: Andy Lutomirski , Andi Kleen , LKML , x86@kernel.org, Peter Zijlstra , Andy Lutomirski , Linus Torvalds , Jiri Kosina , Tom Lendacky , Josh Poimboeuf , Andrea Arcangeli , David Woodhouse , Tim Chen , Dave Hansen , Casey Schaufler , Asit Mallick , Arjan van de Ven , Jon Masters , Waiman Long , Greg KH , Dave Stewart , Kees Cook Subject: Re: [patch V2 21/28] x86/speculation: Prepare for conditional IBPB in switch_mm() Message-ID: <20181126133610.GB108014@gmail.com> References: <20181125183328.318175777@linutronix.de> <20181125185005.466447057@linutronix.de> <20181125205330.GO13936@tassilo.jf.intel.com> <92833780-41BE-446E-A676-925BA1EC93D9@amacapital.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Thomas Gleixner wrote: > On Sun, 25 Nov 2018, Andy Lutomirski wrote: > > > On Nov 25, 2018, at 2:20 PM, Thomas Gleixner wrote: > > > On Sun, 25 Nov 2018, Andi Kleen wrote: > > > > > >>> The current check whether two tasks belong to the same context is using the > > >>> tasks context id. While correct, it's simpler to use the mm pointer because > > >>> it allows to mangle the TIF_SPEC_IB bit into it. The context id based > > >>> mechanism requires extra storage, which creates worse code. > > >> > > >> [We tried similar in some really early versions, but it was replaced > > >> with the context id later.] > > >> > > >> One issue with using the pointer is that the pointer can be reused > > >> when the original mm_struct is freed, and then gets reallocated > > >> immediately to an attacker. Then the attacker may avoid the IBPB. > > >> > > >> Given it's probably hard to generate any reasonable leak bandwidth with > > >> such a complex scenario, but it still seemed better to close the hole. > > > > > > Sorry, but that's really a purely academic exercise. > > > > I would guess that it’s actually very easy to force mm_struct* reuse. > > Don’t the various allocators try to allocate hot memory? There’s nothing > > hotter than a just-freed allocation of the same size. > > Sure, but this is about a indirect branch predictor attack against > something which reuses the mm. > > So you'd need to pull off: > > P1 poisons branch predictor > P1 exit > > P2 starts and resuses mm(P1) and uses the poisoned branch predictor > > the only thing between P1 and P2 is either idle or some other kernel > thread, but no other user task. If that happens then the code would not > issue IBPB as it assumes to switch back to the same process. > > Even if you can pull that off the speculation would hit the startup code of > P2, which is truly a source of secret information. Creating a valuable > attack based on mm reuse is really less proabable than a lottery jackpot. > > So using mm is really good enough and results in better assembly code which > is surely more valuable than addressing some hypothetical hole. OTOH we could probably close even this with very little cost if we added an IBPB to non-threaded fork() and vfork()+exec() paths? Those are really slow paths compared to all the context switch paths we are trying to optimize here. Alternatively we could IBPB on the post-exit() final task struct freeing, which too is a relative slow path compared to the context switch paths. But no strong opinion. Thanks, Ingo