Re: [PATCH 2/2] x86/tdx: Do not allow #VE due to EPT violation on the private memory

From: Guorui Yu
Date: Mon Oct 31 2022 - 00:08:02 EST


The core of this vulnerability is not directly related to the ATTR_SEPT_VE_DISABLE, but the MMIO processing logic in #VE.

We have encountered similar problems on SEV-ES, here are their fixes on Kernel [1] and OVMF[2].

Instead of enforcing the ATTR_SEPT_VE_DISABLE in TDX guest kernel, I think the fix should also include necessary check on the MMIO path of the #VE routine.

static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
{
unsigned long *reg, val, vaddr;
char buffer[MAX_INSN_SIZE];
struct insn insn = {};
enum mmio_type mmio;
int size, extend_size;
u8 extend_val = 0;

// Some addtional security check about ve->gpa should be introduced here.

/* Only in-kernel MMIO is supported */
if (WARN_ON_ONCE(user_mode(regs)))
return -EFAULT;

// ...
}

If we don't fix the problem at the point where we found, but rely on complicated composite logic and long comments in the kernel, I'm confident we'll fall back into the same pit in the near future :).


[1] https://github.com/torvalds/linux/blob/1a2dcbdde82e3a5f1db9b2f4c48aa1aeba534fb2/arch/x86/kernel/sev.c#L503
[2] OVMF: https://github.com/tianocore/edk2/blob/db2c22633f3c761975d8f469a0e195d8b79e1287/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c#L670