Received: by 10.223.176.46 with SMTP id f43csp2143933wra; Sun, 21 Jan 2018 12:20:30 -0800 (PST) X-Google-Smtp-Source: AH8x226cgSEdlAu5sf36LBLMW/WRmh5psW8ERHZ4gLs0WBftI278JTQm33OvHRV0Qnnc5Fli8tCp X-Received: by 10.101.96.67 with SMTP id b3mr5341692pgv.23.1516566030023; Sun, 21 Jan 2018 12:20:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516566029; cv=none; d=google.com; s=arc-20160816; b=mt9IyJcbda/6o4q9eJiN2IHvTrZ9Ex+RjLIgaRhg5ke2Su4bL68ZBpc8QQN3TjbGXw ntz3hYH6Oyt1PsYcGkWYnFcoMthUzqTDyyPnydCrhSoJJnoiI4g8pSlUKe2am9dBTWpF xrpIpntVT0AmHYsZqWnw64nbGYIGNp7lKtBD0wU6bjXEZ5AqXh16FdMAB+PdETczDOIR dO/hv78lIUsbzhgo9EAFrpM9AXe1LH+Xlz6Tg7a/FCdZ/c442lF6ODVNx4bkHrNgEhK2 fDckCU2oWCHbAy8rZlSNKOv5JuHINMQp1V4mjk82Wsuxy+DV20otpnfFuoXyvVMjYzdL rWrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=OSWvYjWwRzClVoIkhpZyGDvtk3TfFFLeZLgX1wSN0jo=; b=OUtkIiulX1Eai72TgytEI/4m1+3/1p5T8JeLMBFFvvekpePMXZiUIA089bid5dQbNA uD/pMuFwsZ51Kd6tob/v52ydhV6o2gnb/d7PGAZzZlLNoun//Ow+hTzY3Bf/M+qTEsQf i44CgoVJRZbf9k2SrMx5QCMM9ytHkUNNGZBwqz9aq/BZEpmFfUDkBHNvMYasVkymlJEB yZIC6hqysA8mTme+2cwtrpfbOjje/AvRQXYjYyRxRFvFF65/MUw2ZtljaezhTpa50/tE 8IQoE68qSnEJWM98w49UMeC0DBoq7YOKuTa7mo6+fir3fpUbt+UFq0ZaqpCM4K4L6Qsx qHrA== ARC-Authentication-Results: i=1; mx.google.com; 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 v76si14191239pfk.83.2018.01.21.12.20.15; Sun, 21 Jan 2018 12:20:29 -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; 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 S1751062AbeAUUTx (ORCPT + 99 others); Sun, 21 Jan 2018 15:19:53 -0500 Received: from ppsw-31.csi.cam.ac.uk ([131.111.8.131]:59366 "EHLO ppsw-31.csi.cam.ac.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750914AbeAUUTw (ORCPT ); Sun, 21 Jan 2018 15:19:52 -0500 X-Cam-AntiVirus: no malware found X-Cam-ScannerInfo: http://help.uis.cam.ac.uk/email-scanner-virus Received: from 88-111-108-209.dynamic.dsl.as9105.com ([88.111.108.209]:53770 helo=[192.168.1.6]) by ppsw-31.csi.cam.ac.uk (smtp.hermes.cam.ac.uk [131.111.8.157]:587) with esmtpsa (PLAIN:amc96) (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) id 1edM5g-000SPg-L9 (Exim 4.90) (return-path ); Sun, 21 Jan 2018 20:19:45 +0000 Subject: Re: [PATCH v2 5/8] x86/speculation: Add basic support for IBPB To: David Woodhouse , Borislav Petkov , KarimAllah Ahmed Cc: arjan@linux.intel.com, tglx@linutronix.de, karahmed@amazon.de, x86@kernel.org, linux-kernel@vger.kernel.org, tim.c.chen@linux.intel.com, peterz@infradead.org, pbonzini@redhat.com, ak@linux.intel.com, torvalds@linux-foundation.org, gregkh@linux-foundation.org References: <1516528149-9370-1-git-send-email-dwmw@amazon.co.uk> <1516528149-9370-6-git-send-email-dwmw@amazon.co.uk> <20180121180621.ufmc5m7nr6v4tjvc@pd.tnic> <31c52131-5f7a-8af0-3092-5fc9e322a734@amazon.com> <20180121190145.uuk3xizxejckth5s@pd.tnic> <1516563060.9814.52.camel@infradead.org> <1516565047.9814.59.camel@infradead.org> From: Andrew Cooper Message-ID: <648c29c2-eeda-f34b-e7ea-1be59b60a6e5@citrix.com> Date: Sun, 21 Jan 2018 20:19:43 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <1516565047.9814.59.camel@infradead.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-GB Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/01/2018 20:04, David Woodhouse wrote: > On Sun, 2018-01-21 at 19:37 +0000, Andrew Cooper wrote: >> It doesn't matter if an attacker can use SP1 to try and skip the IBPB. >> >> Exits to userspace/guest are serialising (with some retroactive updates >> to the architecture spec coming), so an attacker can't cause victim code >> to be executed before speculation has caught up and noticed that the >> IBPB did need to happen. > For the specific case of IBPB, knowing what we do about non- > architectural behaviour, that's probably true. > > In the early patch sets in both Xen and Linux, we did have a > conditional branch on {sys,hyper}call entry that blithely let the CPU > speculate all the way to the {sys,hyper}call table jump. No exit to > userspace/guest there. Right, but that is a different situation.  That is an attacker trying to attack the kernel/hypervisor directly using SP2, which is mitigated with retpoline/lfence+jmp/IBRS (as appropriate). This IBPB case is an attacker trying to attack a new piece of userspace using SP2, and furthermore, trying to use SP1 to skip the IBPB. It is an inherent property of all these issues that an attacker can't cause the misdirected basic blocks to be retired, which means they can't change the actual behaviour of execution in supervisor context. As the exit to user/guest context is serialising, the only thing the attacker can usefully do is tickle a speculatively-leaky block. > Which is why I've been saying I want call sites to have an *explicit* > comment saying why they're safe to use conditional branches without > taking extra steps to be safe, like the 'else lfence'. And why I'd > really like the underlying primitives to *support* being fixed at > runtime. I'm afraid that, by this logic, every conditional branch needs a comment, and that is impractical.  I don't see what is special about this conditional branch vs every other conditional branch in the codebase, and calling it out in isolation feels wrong. ~Andrew