From nobody Tue Apr 7 06:15:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1773645062; cv=none; d=zohomail.com; s=zohoarc; b=nh58sam6WMk/+G/P+eUmeFod3g3iXYznwLUterPqBtp6Zj4kSlLkosEPopfsoYgVhq3m25mWADxA+tpIgMzS4RFdLYYS/BEARC+5yfwVx+GCkPqTCV1sw9f5BPFp++1c8OMUgaI3G1fwa7hxo5PpIYnnS6Ywn58nZ451EVsUx1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773645062; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=0sQvGD4mLE1PTHsrmlLO4cSbsFsQwyCjvQ4cOsM9pGE=; b=Dv8j2JheD5dGYlt0rNpoaK+eAMgWUt4PP3yxc6f78nD+pWOLt9mfPCKn37H5qDyI8rlfZ59FLiIyKZkfjK0FRHO1Lhgr9+tFhXZBdxHWa8h3/GvCRhVOLDZoQ3RnDTWXBaFs75e0NF/27db+uQ7sFUVwXLGnYp2xt52jWRHQjFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773645062381460.4383663237695; Mon, 16 Mar 2026 00:11:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w226M-0007eC-89; Mon, 16 Mar 2026 03:10:58 -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 1w225t-0007Vz-EJ; Mon, 16 Mar 2026 03:10:32 -0400 Received: from isrv.corpit.ru ([212.248.84.144]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w225p-0007lz-D3; Mon, 16 Mar 2026 03:10:26 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id CB50C193C28; Mon, 16 Mar 2026 10:10:02 +0300 (MSK) Received: from think4mjt.tls.msk.ru (mjtthink.wg.tls.msk.ru [192.168.177.146]) by tsrv.corpit.ru (Postfix) with ESMTP id D3D14380050; Mon, 16 Mar 2026 10:10:05 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tls.msk.ru; s=202602; t=1773645002; bh=9IpVhPyCFj+eYKjRuj7uW3sNmKuxLubWVST1vOIbdUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fMsEcutiZotXTh9GWnw4RQjQSGld7l6kgYvRm9uNmyZhAX+akkWOCm7tCAK4RIQAw AbWwmAP4+W24xynqbdithhWhU4guJ26ynvzd1kDDmYTMLY74/bmror6jptPuNhC1t4 8TZRnSWkT9hebA5FOKA0Cxpy7NZf87XPxtO6axZH8rNKootiajP3aNeMTmW+7oI+jc 6IwjlDVXygEw+HiWKCx5B685nRfMQyUKdIjnu0clkm2+GLhsVfQWYE7F88oNGtlHtb vVRod/cJmEkXhsdZz+ztp1V1FTCW9tamJthUvXfWwSzQRaWOw/Spb6nndWcpqoP6f6 vgcraOx8UTDmA== From: Michael Tokarev To: qemu-devel@nongnu.org Cc: Sergei Heifetz , qemu-trivial@nongnu.org, Michael Tokarev Subject: [PULL 06/14] target/i386: fix NULL pointer dereference in legacy-cache=off handling Date: Mon, 16 Mar 2026 10:09:54 +0300 Message-ID: <20260316071005.91624-7-mjt@tls.msk.ru> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260316071005.91624-1-mjt@tls.msk.ru> References: <20260316071005.91624-1-mjt@tls.msk.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=212.248.84.144; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -2 X-Spam_score: -0.3 X-Spam_bar: / X-Spam_report: (-0.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @tls.msk.ru) X-ZM-MESSAGEID: 1773645065509154100 Content-Type: text/plain; charset="utf-8" From: Sergei Heifetz The check that xcc->model is not NULL occurs after it is dereferenced inside x86_cpu_get_versioned_cache_info(), so something like `-cpu host,legacy-cache=3Doff` leads to a segfault rather than an error. This patch fixes that. Fixes: cca0a000d06f897411a8a ("target/i386: allow versioned CPUs to specify= new cache_info") Signed-off-by: Sergei Heifetz Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Zhao Liu Reviewed-by: Michael Tokarev [Mjt: simplify the following condition too] Signed-off-by: Michael Tokarev --- target/i386/cpu.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 5b9ae79f16..b5e483e8cd 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -10107,10 +10107,11 @@ static void x86_cpu_realizefn(DeviceState *dev, E= rror **errp) =20 /* Cache information initialization */ if (!cpu->legacy_cache) { - const CPUCaches *cache_info =3D - x86_cpu_get_versioned_cache_info(cpu, xcc->model); + const CPUCaches *cache_info =3D xcc->model + ? x86_cpu_get_versioned_cache_info(cpu, xcc->model) + : NULL; =20 - if (!xcc->model || !cache_info) { + if (!cache_info) { g_autofree char *name =3D x86_cpu_class_get_model_name(xcc); error_setg(errp, "CPU model '%s' doesn't support legacy-cache=3Doff"= , name); --=20 2.47.3