[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/2] x86/svm: Keep the RAS balanced for guests


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Fri, 12 Aug 2022 09:29:06 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=09jxNHr8AlzaG54Wd637e6Mtl0Lzx6yO38Rpe5px4WQ=; b=bd012ATtA2kVH8VqyYmyhRjLJvYfHdWNYmdblxPrNiAzOkBYoqjjdaD66rUzNWXAcHXMgwqM1IZJ9u4bVW8lJrxwwGR+acvj9eS+hOEzY/TB415tmnZUIw1jHsk4mT/s8KJfxFyomy0La/jQPydAR8Rb9kGjrhHMpmIXBe4Z7dAhtjkJu8T8gQ8TML7YZnCZ5LWjZevfXTtrKVNjgm5kQkpLQh7+geNGym7t+nW7gpczow3wMB+ErPlEholb3e1fb6bNci2CgjqYlKDe7so7/LaWZraOCTYHdeg/4l/IPbnLy4EB77ChXXebwrmAgHCCYpFVx7WXvwBNjIcx6O04ag==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XJ4V3swva0PYXMcHJ2U1W5t06tfybUTt/Rg4WR64mYCEb1VdVxRoKB4wx4IdPGVmYyBx/O4L0YksDGItR+/4IICDiLyAZYBt+CXkFD0urAKSuxgUskE0nR4Nj65Nyh2b7yTejIRQA5GlwawbmbpXkYKIBxZuxFHvLM4EyiyomBjGUSpByhqVlZcBXVXBQBJ+rVJdeeEShpOqPvx4EW3hvdf7WQjPfwl1UWh4RRbaO15g841MLuos1VcZGSlzBKgZhq/QHinf8sOfJgx0/50lYFUvQlGkpVnZvulSroa3z7js9NMPPWCviQZZSKgPiS3N7kkpBEsKMrGLPVUNXy7Jpg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Fri, 12 Aug 2022 07:29:21 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 11.08.2022 21:59, Andrew Cooper wrote:
> One source of lost performance was that fact that to protect Xen from a
> malicious guests, we had to flush the RAS.
> 
> It turns out that CET Shadow Stacks give us enough architectural guarantees to
> construct a lower overhead mitigation, which keeps the RAS balanced for the
> guest so their return performance is still good.
> 
> To keep the RAS balanced, Xen must execute the same number of CALLs as RETs
> across one VMexit->VMEntry.  Without CET-SS, we could achieve this fairly
> easily with a `call; add $8, %rsp` and `push; ret` pair, but this is not legal
> under CET-SS.  In fact, CALL is the only shadow stack "push" operation we
> have, and we can't use it a second time if we intend to keep the RAS balanced.
> 
> Instead, we keep a real return address on the stack.  This means that for some
> of entry.S, %rsp conditionally doesn't reference CPUINFO.
> 
> This necessitates swapping the current order of DO_OVERWRITE_RSB and
> svm_vmexit_spec_ctrl; while they don't have any specific ordering
> requirements, push_one_ras needs to come after svm_vmexit_spec_ctrl or else we
> need some very invasive changes to fix up the %rsp changes.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Jan Beulich <JBeulich@xxxxxxxx>
> CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> CC: Wei Liu <wl@xxxxxxx>
> 
> RFC for a couple of reasons.  This does function correctly, but I still want
> to do more perf testing.

As per further down you mean to say it functions correctly without the
use of alternatives. And even then (see below) I suppose it doesn't
function correctly with no (or unused) CET-SS but CONFIG_XEN_SHSTK=y.

> Secondly, X86_FEATURE_ALWAYS is clearly not ok for committing.  I'm still
> debating whether to make this construct available in !CET-SS cases.
> Mechanically, its fine, but the safety arguments depend on CET-SS being
> active.

I'm afraid it's not entirely clear what you mean here, nor why you've used
X86_FEATURE_ALWAYS in the first place when we have X86_FEATURE_XEN_SHSTK.
If "this construct" is push_one_ras, then the mere use of WRSSQ requires
it to not be used based on a runtime characteristic, not just a build
time one. Hence afaict you could as well put the entire macro body in the
#ifdef that currently encloses only the CET-SS insns.

> In principle, on CPUs which do not suffer Branch Type Confusion, you might be
> able to reason a defence-in-depth argument that if an attacker can't control
> indirect speculation, then they can't bypass the 1-stuff safety either, but
> the only AMD CPUs not vulnerable to BTC have CET-SS anyway.

Yet people may have reasons to turn off its use.

> Third, I'd like some early feedback on how clear it the logic is given the
> conditional nature of %rsp not referencing CPUINFO.

It's assembly code, touching of which needs extra care. Taking together
the size of the entire file (quite small) and the comments you add, I'd
say that's fine.

> Fourth, the alternatives logic (I think) needs improving to not fix up a
> direct CALL/JMP displacement if the destination is within the replacement
> length.  I did the functional testing before wrapping things in alternatives.

Yes, unless you want to prefix the CALL with a redundant insn prefix to
hide it from the displacement adjustment logic.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.