qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: qemu-stable@nongnu.org, christian.ehrhardt@canonical.com,
	Eduardo Habkost <ehabkost@redhat.com>
Subject: [Qemu-devel] [PATCH 20/54] i386: Change X86CPUDefinition::model_id to const char*
Date: Tue,  6 Feb 2018 13:14:41 -0600	[thread overview]
Message-ID: <20180206191515.25830-21-mdroth@linux.vnet.ibm.com> (raw)
In-Reply-To: <20180206191515.25830-1-mdroth@linux.vnet.ibm.com>

From: Eduardo Habkost <ehabkost@redhat.com>

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" <dgilbert@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20180109154519.25634-2-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
(cherry picked from commit 807e9869b8c4119b81df902625af818519e01759)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 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 045d66191f..63279526a1 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -748,7 +748,7 @@ struct X86CPUDefinition {
     int model;
     int stepping;
     FeatureWordArray features;
-    char model_id[48];
+    const char *model_id;
 };
 
 static X86CPUDefinition builtin_x86_defs[] = {
@@ -917,6 +917,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_1_EDX] =
             I486_FEATURES,
         .xlevel = 0,
+        .model_id = "",
     },
     {
         .name = "pentium",
@@ -928,6 +929,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_1_EDX] =
             PENTIUM_FEATURES,
         .xlevel = 0,
+        .model_id = "",
     },
     {
         .name = "pentium2",
@@ -939,6 +941,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_1_EDX] =
             PENTIUM2_FEATURES,
         .xlevel = 0,
+        .model_id = "",
     },
     {
         .name = "pentium3",
@@ -950,6 +953,7 @@ static X86CPUDefinition builtin_x86_defs[] = {
         .features[FEAT_1_EDX] =
             PENTIUM3_FEATURES,
         .xlevel = 0,
+        .model_id = "",
     },
     {
         .name = "athlon",
@@ -2708,6 +2712,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 long */
+    assert(def->model_id && strlen(def->model_id) <= 48);
+
 
     type_register(&ti);
     g_free(typename);
-- 
2.11.0

  parent reply	other threads:[~2018-02-06 19:15 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06 19:14 [Qemu-devel] [PATCH 00/54] Patch Round-up for stable 2.11.1, freeze on 2018-02-12 Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 01/54] target/i386: Fix handling of VEX prefixes Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 02/54] block/iscsi: dont leave allocmap in an invalid state on UNMAP failure Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 03/54] target/sh4: fix TCG leak during gusa sequence Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 04/54] qemu-options: Remove stray colons from output of --help Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 05/54] qemu-pr-helper: miscellaneous fixes Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 06/54] block/nbd: fix segmentation fault when .desc is not null-terminated Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 07/54] block: Make bdrv_drain_invoke() recursive Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 08/54] block: Call .drain_begin only once in bdrv_drain_all_begin() Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 09/54] block: Open backing image in force share mode for size probe Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 10/54] vfio: Fix vfio-kvm group registration Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 11/54] hw/intc/arm_gicv3: Make reserved register addresses RAZ/WI Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 12/54] hw/intc/arm_gic: reserved register addresses are RAZ/WI Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 13/54] virtio_error: don't invoke status callbacks Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 14/54] vhost: remove assertion to prevent crash Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 15/54] hw/sd/pl181: Reset SD card on controller reset Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 16/54] hw/sd/milkymist-memcard: " Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 17/54] hw/sd/ssi-sd: " Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 18/54] scsi-disk: release AioContext in unaligned WRITE SAME case Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 19/54] hw/pci-bridge: fix QEMU crash because of pcie-root-port Michael Roth
2018-02-06 19:14 ` Michael Roth [this message]
2018-02-06 19:14 ` [Qemu-devel] [PATCH 21/54] i386: Add support for SPEC_CTRL MSR Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 22/54] i386: Add spec-ctrl CPUID bit Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 23/54] i386: Add FEAT_8000_0008_EBX CPUID feature word Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 24/54] i386: Add new -IBRS versions of Intel CPU models Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 25/54] i386: Add EPYC-IBPB CPU model Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 26/54] linux-user: Fix locking order in fork_start() Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 27/54] s390x: fix storage attributes migration for non-small guests Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 28/54] linux-headers: update to 4.15-rc1 Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 29/54] linux-headers: update Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 30/54] s390x/kvm: Handle bpb feature Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 31/54] s390x/kvm: provide stfle.81 Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 32/54] osdep: Retry SETLK upon EINTR Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 33/54] usb-storage: Fix share-rw option parsing Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 34/54] spapr_pci: fix MSI/MSIX selection Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 35/54] linux-user/signal.c: Rename MC_* defines Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 36/54] spapr: don't initialize PATB entry if max-cpu-compat < power9 Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 37/54] spapr: Add pseries-2.12 machine type Michael Roth
2018-02-06 19:14 ` [Qemu-devel] [PATCH 38/54] spapr: Capabilities infrastructure Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 39/54] spapr: Treat Hardware Transactional Memory (HTM) as an optional capability Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 40/54] spapr: Validate capabilities on migration Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 41/54] target/ppc: Clean up probing of VMX, VSX and DFP availability on KVM Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 42/54] spapr: Handle VMX/VSX presence as an spapr capability flag Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 43/54] spapr: Handle Decimal Floating Point (DFP) as an optional capability Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 44/54] hw/ppc/spapr_caps: Rework spapr_caps to use uint8 internal representation Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 45/54] ppc: Change Power9 compat table to support at most 8 threads/core Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 46/54] spapr: fix device tree properties when using compatibility mode Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 47/54] target/ppc: introduce the PPC_BIT() macro Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 48/54] target/ppc/spapr_caps: Add macro to generate spapr_caps migration vmstate Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 49/54] target/ppc/kvm: Add cap_ppc_safe_[cache/bounds_check/indirect_branch] Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 50/54] target/ppc/spapr_caps: Add support for tristate spapr_capabilities Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 51/54] target/ppc/spapr_caps: Add new tristate cap safe_cache Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 52/54] target/ppc/spapr_caps: Add new tristate cap safe_bounds_check Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 53/54] target/ppc/spapr_caps: Add new tristate cap safe_indirect_branch Michael Roth
2018-02-06 19:15 ` [Qemu-devel] [PATCH 54/54] target/ppc/spapr: Add H-Call H_GET_CPU_CHARACTERISTICS Michael Roth
2018-02-07  6:47 ` [Qemu-devel] [PATCH 00/54] Patch Round-up for stable 2.11.1, freeze on 2018-02-12 Thomas Huth
2018-02-07 10:28   ` Daniel P. Berrangé
2018-02-07  9:28 ` Cornelia Huck
2018-02-07  9:42 ` [Qemu-devel] [Qemu-stable] " Greg Kurz
2018-02-08 12:51 ` Peter Lieven
2018-02-12 16:13   ` Dr. David Alan Gilbert
2018-02-13 16:30     ` Greg Kurz
2018-02-16  9:46     ` Peter Lieven
2018-02-08 13:26 ` [Qemu-devel] " Philippe Mathieu-Daudé
2018-02-13  1:44 ` [Qemu-devel] [Qemu-stable] " Michael Roth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180206191515.25830-21-mdroth@linux.vnet.ibm.com \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=christian.ehrhardt@canonical.com \
    --cc=ehabkost@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).