[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-stable] [PATCH 20/54] i386: Change X86CPUDefinition::model_id to c
From: |
Michael Roth |
Subject: |
[Qemu-stable] [PATCH 20/54] i386: Change X86CPUDefinition::model_id to const char* |
Date: |
Tue, 6 Feb 2018 13:14:41 -0600 |
From: Eduardo Habkost <address@hidden>
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" <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Eduardo Habkost <address@hidden>
(cherry picked from commit 807e9869b8c4119b81df902625af818519e01759)
Signed-off-by: Michael Roth <address@hidden>
---
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
- [Qemu-stable] [PATCH 00/54] Patch Round-up for stable 2.11.1, freeze on 2018-02-12, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 09/54] block: Open backing image in force share mode for size probe, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 11/54] hw/intc/arm_gicv3: Make reserved register addresses RAZ/WI, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 12/54] hw/intc/arm_gic: reserved register addresses are RAZ/WI, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 13/54] virtio_error: don't invoke status callbacks, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 14/54] vhost: remove assertion to prevent crash, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 18/54] scsi-disk: release AioContext in unaligned WRITE SAME case, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 15/54] hw/sd/pl181: Reset SD card on controller reset, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 17/54] hw/sd/ssi-sd: Reset SD card on controller reset, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 16/54] hw/sd/milkymist-memcard: Reset SD card on controller reset, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 20/54] i386: Change X86CPUDefinition::model_id to const char*,
Michael Roth <=
- [Qemu-stable] [PATCH 01/54] target/i386: Fix handling of VEX prefixes, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 21/54] i386: Add support for SPEC_CTRL MSR, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 23/54] i386: Add FEAT_8000_0008_EBX CPUID feature word, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 19/54] hw/pci-bridge: fix QEMU crash because of pcie-root-port, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 27/54] s390x: fix storage attributes migration for non-small guests, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 22/54] i386: Add spec-ctrl CPUID bit, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 26/54] linux-user: Fix locking order in fork_start(), Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 28/54] linux-headers: update to 4.15-rc1, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 37/54] spapr: Add pseries-2.12 machine type, Michael Roth, 2018/02/06
- [Qemu-stable] [PATCH 35/54] linux-user/signal.c: Rename MC_* defines, Michael Roth, 2018/02/06