Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BEFA1F532DD for ; Tue, 24 Mar 2026 05:48:04 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4ucN-0002g5-QT; Tue, 24 Mar 2026 01:47:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w4ucL-0002f1-On for qemu-devel@nongnu.org; Tue, 24 Mar 2026 01:47:53 -0400 Received: from mgamail.intel.com ([192.198.163.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w4ucK-0003Al-44 for qemu-devel@nongnu.org; Tue, 24 Mar 2026 01:47:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774331272; x=1805867272; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=Wv0X5NHyuEw0I0tSJIvkAzRvQq8ilmibRZSZA4wKbBI=; b=XeXmoG6SWc7sS9i4upbEuLYh4kE33lxQlr2SVknOZyY1txSi2N4is+qV tv9yJBvRVp79ASDmvpgB7uDLYQLD3tDZq7BXW9FukRVLNOi/rsrQhfbbB naDz8AxGE3CVMl90d3ChKkzBwMmuSuU54wLiOy8APC4bZH2EWNuOREyr7 HXHYco115qOSZYpFjO8CoaMK+Uz51pHAKl6IaCIxoa1Fhw9A2lYvOfLfF dmDuRuwm0n1XVNA5rIM6kg7ZEdBxqPN4N5/tYBMhhybYF9OTdhP0RXa5J 92DdTRUbt1QU1Htz7WwP/UqRA0YKizTUr6BTV6MI73bsF/gGyXxWT7+8E w==; X-CSE-ConnectionGUID: lfPodur9TsqkoWNONhYhww== X-CSE-MsgGUID: DBPiEVjGS8+VMbCqWVosNw== X-IronPort-AV: E=McAfee;i="6800,10657,11738"; a="75246803" X-IronPort-AV: E=Sophos;i="6.23,138,1770624000"; d="scan'208";a="75246803" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2026 22:47:50 -0700 X-CSE-ConnectionGUID: 7c/ev2w7RHeF8XgxQB+T2w== X-CSE-MsgGUID: kFvN4ASoTK26K94nz3Wf7w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,138,1770624000"; d="scan'208";a="219364640" Received: from unknown (HELO [10.239.158.22]) ([10.239.158.22]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2026 22:47:49 -0700 Message-ID: <0991e811-0ad3-4d96-9a4b-deee9c77ef20@intel.com> Date: Tue, 24 Mar 2026 13:47:47 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] i386/tdx: Fix the UAF issue in tdx_fetch_cpuid() To: =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= , Paolo Bonzini Cc: Marcelo Tosatti , qemu-devel@nongnu.org, Stefan Weil References: <20260324012313.1580760-1-xiaoyao.li@intel.com> <186c9ed2-5e41-42d5-8d07-f90654cf35a9@linaro.org> Content-Language: en-US From: Xiaoyao Li In-Reply-To: <186c9ed2-5e41-42d5-8d07-f90654cf35a9@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=192.198.163.17; envelope-from=xiaoyao.li@intel.com; helo=mgamail.intel.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HK_RANDOM_ENVFROM=0.999, HK_RANDOM_FROM=1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org On 3/24/2026 1:35 PM, Philippe Mathieu-Daudé wrote: > On 24/3/26 02:23, Xiaoyao Li wrote: >> Fix the UAF issue by reading the returned size before freeing the >> fetch_cpuid structure. >> >> Link: https://lore.kernel.org/ >> r/758d7f2c-938f-49cb-89fc-980fc8e020b2@weilnetz.de > > Fixes: e3d1a4a6d1d ("i386/tdx: Fetch and validate CPUID of TD guest") Oh, I missed this. Thanks for providing it! >> Reported-by: Stefan Weil >> Signed-off-by: Xiaoyao Li >> --- >>   target/i386/kvm/tdx.c | 2 +- >>   1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/target/i386/kvm/tdx.c b/target/i386/kvm/tdx.c >> index 4cae99c281ac..e578110df4da 100644 >> --- a/target/i386/kvm/tdx.c >> +++ b/target/i386/kvm/tdx.c >> @@ -847,8 +847,8 @@ static struct kvm_cpuid2 *tdx_fetch_cpuid(CPUState >> *cpu, int *ret) >>           fetch_cpuid->nent = size; >>           r = tdx_vcpu_ioctl(cpu, KVM_TDX_GET_CPUID, 0, fetch_cpuid, >> &local_err); >>           if (r == -E2BIG) { >> -            g_free(fetch_cpuid); >>               size = fetch_cpuid->nent; >> +            g_free(fetch_cpuid); >>           } >>       } while (r == -E2BIG); >