Re: [PATCH] KVM: TDX: Use struct_size and simplify tdx_get_capabilities
From: Sean Christopherson
Date: Tue Nov 18 2025 - 18:28:36 EST
On Fri, 17 Oct 2025 23:39:14 +0200, Thorsten Blum wrote:
> Retrieve the number of user entries with get_user() first and return
> -E2BIG early if 'user_caps' is too small to fit 'caps'.
>
> Allocate memory for 'caps' only after checking the user buffer's number
> of entries, thus removing two gotos and the need for premature freeing.
>
> Use struct_size() instead of manually calculating the number of bytes to
> allocate for 'caps', including the nested flexible array.
>
> [...]
Applied to kvm-x86 tdx, with Rick's tags and suggested fixups from the RESEND[*]
(I had already applied the original patches, and now that these have been in
linux-next for a while, I don't want to modify the hashes just to change the
patch Link).
[*] https://lore.kernel.org/all/20251112171630.3375-1-thorsten.blum@xxxxxxxxx
[1/2] KVM: TDX: Check size of user's kvm_tdx_capabilities array before allocating
https://github.com/kvm-x86/linux/commit/11b79f8318ae
[2/2] KVM: TDX: Use struct_size to simplify tdx_get_capabilities()
https://github.com/kvm-x86/linux/commit/398180f93cf3
--
https://github.com/kvm-x86/linux/tree/next