Skip to content

Commit cfbebb5

Browse files
Binbin Wusean-jc
authored andcommitted
KVM: TDX: Reject concurrent change to CPUID entry count
Reject KVM_TDX_INIT_VM if userspace changes cpuid.nent between the initial read and the subsequent copy of the initialization data. tdx_td_init() first reads user_data->cpuid.nent to size the flexible kvm_tdx_init_vm copy. The copied structure also contains cpuid.nent, and that field can differ from the value used to size the allocation if userspace modifies the input concurrently. setup_tdparams_cpuids() later passes init_vm->cpuid.nent to kvm_find_cpuid_entry2(), which uses it as the array bound for the copied entries. Require the copied count to match the value used to size the allocation so that CPUID parsing cannot access beyond the entries actually copied. Fixes: 0bd0a4a ("KVM: TDX: Replace kmalloc + copy_from_user with memdup_user in tdx_td_init()") Reported-by: Sashiko:gemini-3.1-pro-preview Cc: <stable@vger.kernel.org> Signed-off-by: Binbin Wu <binbin.wu@linux.intel.com> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com> Reviewed-by: Thorsten Blum <thorsten.blum@linux.dev> Link: https://patch.msgid.link/20260710035324.3170534-1-binbin.wu@linux.intel.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent df371f2 commit cfbebb5

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

arch/x86/kvm/vmx/tdx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2797,7 +2797,11 @@ static int tdx_td_init(struct kvm *kvm, struct kvm_tdx_cmd *cmd)
27972797
goto out;
27982798
}
27992799

2800-
if (init_vm->cpuid.padding) {
2800+
/*
2801+
* Reject the request if userspace changes cpuid.nent between the
2802+
* initial read and the subsequent copy.
2803+
*/
2804+
if (init_vm->cpuid.padding || init_vm->cpuid.nent != nr_user_entries) {
28012805
ret = -EINVAL;
28022806
goto out;
28032807
}

0 commit comments

Comments
 (0)