Re: [RFC PATCH V6 01/14] x86/sev: Add a #HV exception handler

From: Peter Zijlstra
Date: Tue Jun 06 2023 - 03:54:40 EST


On Tue, Jun 06, 2023 at 08:00:32AM +0200, Gupta, Pankaj wrote:
>
> > > That should really say that a nested #HV should never be raised by the
> > > hypervisor, but if it is, then the guest should detect that and
> > > self-terminate knowing that the hypervisor is possibly being malicious.
> >
> > I've yet to see code that can do that reliably.
>
> - Currently, we are detecting the direct nested #HV with below check and
> guest self terminate.
>
> <snip>
> if (get_stack_info_noinstr(stack, current, &info) &&
> (info.type == (STACK_TYPE_EXCEPTION + ESTACK_HV) ||
> info.type == (STACK_TYPE_EXCEPTION + ESTACK_HV2)))
> panic("Nested #HV exception, HV IST corrupted, stack
> type = %d\n", info.type);
> </snip>
>
> - Thinking about below solution to detect the nested
> #HV reliably:
>
> -- Make reliable IST stack switching for #VC -> #HV -> #VC case
> (similar to done in __sev_es_ist_enter/__sev_es_ist_exit for NMI
> IST stack).

I'm not convinced any of that is actually correct; there is a *huge*
window between NMI hitting and calling __sev_es_ist_enter(), idem on the
exit side.

> -- In addition to this, we can make nested #HV detection (with another
> exception type) more reliable with refcounting (percpu?).

There is also #DB and the MOVSS shadow.

And no, I don't think any of that is what you'd call 'robust'. This is
what I call a trainwreck :/

And I'm more than willing to say no until the hardware is more sane.

Supervisor Shadow Stack support is in the same boat, that's on hold
until FRED makes things workable.