From nobody Sun Oct 26 00:03:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516241185555718.5350741555955; Wed, 17 Jan 2018 18:06:25 -0800 (PST) Received: from localhost ([::1]:51753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebzay-0005ZS-PB for importer@patchew.org; Wed, 17 Jan 2018 21:06:24 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebzWw-0002O4-QD for qemu-devel@nongnu.org; Wed, 17 Jan 2018 21:02:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebzWu-0003uu-VP for qemu-devel@nongnu.org; Wed, 17 Jan 2018 21:02:14 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37450) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ebzWu-0003to-Kv for qemu-devel@nongnu.org; Wed, 17 Jan 2018 21:02:12 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E3B58762E; Thu, 18 Jan 2018 02:02:06 +0000 (UTC) Received: from localhost (ovpn-116-6.gru2.redhat.com [10.97.116.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 706D75D97C; Thu, 18 Jan 2018 02:02:05 +0000 (UTC) From: Eduardo Habkost To: Peter Maydell Date: Thu, 18 Jan 2018 00:01:52 -0200 Message-Id: <20180118020157.25401-4-ehabkost@redhat.com> In-Reply-To: <20180118020157.25401-1-ehabkost@redhat.com> References: <20180118020157.25401-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 18 Jan 2018 02:02:06 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/8] i386: Change X86CPUDefinition::model_id to const char* X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , qemu-devel@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It is valid to have a 48-character model ID on CPUID, however the definition of X86CPUDefinition::model_id is char[48], which can make the compiler drop the null terminator from the string. If a CPU model happens to have 48 bytes on model_id, "-cpu help" will print garbage and the object_property_set_str() call at x86_cpu_load_def() will read data outside the model_id array. We could increase the array size to 49, but this would mean the compiler would not issue a warning if a 49-char string is used by mistake for model_id. To make things simpler, simply change model_id to be const char*, and validate the string length using an assert() on x86_register_cpudef_type(). Reported-by: "Dr. David Alan Gilbert" Signed-off-by: Eduardo Habkost Message-Id: <20180109154519.25634-2-ehabkost@redhat.com> Signed-off-by: Eduardo Habkost --- target/i386/cpu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4385853646..0e26fa4ea7 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -754,7 +754,7 @@ struct X86CPUDefinition { int model; int stepping; FeatureWordArray features; - char model_id[48]; + const char *model_id; }; =20 static X86CPUDefinition builtin_x86_defs[] =3D { @@ -923,6 +923,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { .features[FEAT_1_EDX] =3D I486_FEATURES, .xlevel =3D 0, + .model_id =3D "", }, { .name =3D "pentium", @@ -934,6 +935,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { .features[FEAT_1_EDX] =3D PENTIUM_FEATURES, .xlevel =3D 0, + .model_id =3D "", }, { .name =3D "pentium2", @@ -945,6 +947,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { .features[FEAT_1_EDX] =3D PENTIUM2_FEATURES, .xlevel =3D 0, + .model_id =3D "", }, { .name =3D "pentium3", @@ -956,6 +959,7 @@ static X86CPUDefinition builtin_x86_defs[] =3D { .features[FEAT_1_EDX] =3D PENTIUM3_FEATURES, .xlevel =3D 0, + .model_id =3D "", }, { .name =3D "athlon", @@ -2736,6 +2740,9 @@ static void x86_register_cpudef_type(X86CPUDefinition= *def) * they shouldn't be set on the CPU model table. */ assert(!(def->features[FEAT_8000_0001_EDX] & CPUID_EXT2_AMD_ALIASES)); + /* catch mistakes instead of silently truncating model_id when too lon= g */ + assert(def->model_id && strlen(def->model_id) <=3D 48); + =20 type_register(&ti); g_free(typename); --=20 2.14.3