From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AA75396588 for ; Fri, 10 Jul 2026 08:58:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783673885; cv=none; b=f24dM7v+KYqWh95HZ8/Fo2T+4t5oHeioZUpyetPI3HSGeNqZiol/Mrl8+TlEkAtK09EVYnvlX9QcH3kF9oEmtJQfvE46Ve3MbsZDrMXW2CFe+8CeS4lGLRVnWBPpYYD3Mfv+IBUgbrkGPpTHF+kYGHDVgQaezsCZ0/fqiNe+ygg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783673885; c=relaxed/simple; bh=8H/HsdoetcAOJZVv1k4ryiuDTR/E+4atDCtXI+XvUoA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=B0467+bHwud8I2jjrjSRZCPQbi/sisPCEiIYqfhHxRZkZODC+8VZWpMAQz5ONgxwLwRNVNNANqVdl7Frbw3C4vVT350jCmuYlK0ArDpQzq8gWEKdnZHDe0DRn+l1Fnftbd59yKbCWE0ZZoWXQV/9Fq1D1bAZ1Cp8ysmagNE/KJA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=BwL1XnJb; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="BwL1XnJb" Date: Fri, 10 Jul 2026 10:57:50 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783673881; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=V4lipBWZFiKZbcBCGrGNqJAdNSbDlvvBaJ40rsLV1ys=; b=BwL1XnJbI6qMhQVrMX9TiyLufLQn86s9X6401ev1gDRrnnT06dyPVqMOb73oRKpqsVGKrZ h43+rJY1hNASuum6AxXyJc4SokOths6/y9N+J9ohWW19GL8EARMDr5s6KJX1QKXEN07avc E3qc6rLE77JlG1smqFQ1NzElKY8jqEo= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: Binbin Wu Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, stable@vger.kernel.org, seanjc@google.com, pbonzini@redhat.com, kas@kernel.org, rick.p.edgecombe@intel.com Subject: Re: [PATCH v2] KVM: TDX: Reject concurrent change to CPUID entry count Message-ID: References: <20260710035324.3170534-1-binbin.wu@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260710035324.3170534-1-binbin.wu@linux.intel.com> X-Migadu-Flow: FLOW_OUT On Fri, Jul 10, 2026 at 11:53:23AM +0800, Binbin Wu wrote: > 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: 0bd0a4a1428b ("KVM: TDX: Replace kmalloc + copy_from_user with memdup_user in tdx_td_init()") > Reported-by: Sashiko:gemini-3.1-pro-preview > Cc: > Signed-off-by: Binbin Wu LGTM, and thanks for fixing this! Reviewed-by: Thorsten Blum > --- > v2: > - Reject the request if mismatch instead overwriting the value. (Thorsten, Rick) > - Lump the check into the existing sanity check on the cpuid field. (Sean) > - "KVM: x86: TDX:" -> "KVM: TDX:" in the shortlog. > > v1: > - https://lore.kernel.org/kvm/20260708022937.2465796-1-binbin.wu@linux.intel.com/ > --- > arch/x86/kvm/vmx/tdx.c | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c > index 6ff1469e91cc..d1af0a752e97 100644 > --- a/arch/x86/kvm/vmx/tdx.c > +++ b/arch/x86/kvm/vmx/tdx.c > @@ -2797,7 +2797,11 @@ static int tdx_td_init(struct kvm *kvm, struct kvm_tdx_cmd *cmd) > goto out; > } > > - if (init_vm->cpuid.padding) { > + /* > + * Reject the request if userspace changes cpuid.nent between the > + * initial read and the subsequent copy. > + */ > + if (init_vm->cpuid.padding || init_vm->cpuid.nent != nr_user_entries) { > ret = -EINVAL; > goto out; > } > > base-commit: f1e5ada5ab62dbe32350bc161771c9afc6a896de > -- > 2.46.0 >