Re: [PATCHv4 10/30] x86/tdx: Handle CPUID via #VE

Kirill A. Shutemov
2022-02-28T22:53:35Z

On Mon, Feb 28, 2022 at 08:41:38AM -0800, Dave Hansen wrote:
> > We realise that this is possible vector of attack and plan to implement
> > proper filtering. But it is beyon core enabling.
> >
> >> Is this better than just returning 0's, for instance?
> >
> > Plain 0 injection breaks the boot. More complicated solution is need.
>
> OK, so we're leaving the kernel open to something that might be an
> attack vector: we know that we don't know how this might be bad. It's a
> "known unknown"[1].

I looked deeper. The only CPUIDs that actually required are from the
hypervisor range (the range is reserved and never will be used by CPU, so
hypervisors adopt it for own use).

So this filtering makes kernel boot (I didn't test much beyond that).

/*
* Only allow VMM to control range reserved for hypervisor
* communication.
*
* Return all-zeros for any CPUID outside the range.
*/
if (regs->ax < 0x40000000 || regs->ax > 0x4FFFFFFF) {
regs->ax = regs->bx = regs->cx = regs->dx = 0;
return true;
}

We may tighten the range further (only few leafs from the range is
actually used during the boot), but this should be good enough for this
stage of enabling.

Comments?

--
Kirill A. Shutemov