]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
KVM: TDX: Replace kmalloc + copy_from_user with memdup_user in tdx_td_init()
authorThorsten Blum <thorsten.blum@linux.dev>
Tue, 16 Sep 2025 21:31:29 +0000 (23:31 +0200)
committerSean Christopherson <seanjc@google.com>
Mon, 13 Oct 2025 22:11:06 +0000 (15:11 -0700)
commit0bd0a4a1428baaf4447e95f0832492d9e3d64961
tree80f7beb2883c7014891824cfd5c28e5f4ac820e2
parentf505c7b16fbeea25f82a7e8d578e128178dd6706
KVM: TDX: Replace kmalloc + copy_from_user with memdup_user in tdx_td_init()

Use get_user() to retrieve the number of entries instead of allocating
memory for 'init_vm' with the maximum size, copying 'cmd->data' to it,
only to then read the actual entry count 'cpuid.nent' from the copy.

Use memdup_user() to allocate just enough memory to fit all entries and
to copy 'cmd->data' from userspace. Use struct_size() instead of
manually calculating the number of bytes to allocate and copy.

No functional changes intended.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20250916213129.2535597-2-thorsten.blum@linux.dev
[sean: s/user_init_vm/user_data]
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/tdx.c