Skip to contentSkip to conversation

target/i386/mshv: zero-init msr hvcall args

PATCH In review Magnus Kulke 3 participants 3 messages Jul 1 – Jul 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386/mshv: zero-init msr hvcall args

In the current code we leave the argument arrays for the get/set hvcall unitialized, setting only individual fields. some fields will be populated during the hvcall, but in any case the arg arrays will contain unitialized data (e.g. in reserved fields), to which static analysis objects to.

Fixes c38eb12c85
---
 target/i386/mshv/msr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/mshv/msr.c +2 -2
index 8c220a9942..a35415ed9d 100644
@@ -326,7 +326,7 @@ int mshv_get_msrs(CPUState *cpu)
 {
     int ret = 0;
     size_t n_assocs = MSHV_MSR_TOTAL_COUNT;
-    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT];
+    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT] = { 0 };
     size_t i, j;
     uint32_t name;
 
@@ -386,7 +386,7 @@ static void load_from_env(const CPUState *cpu, struct hv_register_assoc *assocs,
 int mshv_set_msrs(const CPUState *cpu)
 {
     size_t n_assocs = MSHV_MSR_TOTAL_COUNT;
-    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT];
+    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT] = { 0 };
     int ret;
     size_t i, j;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Magnus Kulke

In the current code we leave the argument arrays for the get/set hvcall unitialized, setting only individual fields. some fields will be populated during the hvcall, but in any case the arg arrays will contain unitialized data (e.g. in reserved fields), to which static analysis objects to.

Fixes c38eb12c85
---
  target/i386/mshv/msr.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/mshv/msr.c +0 -0
index 8c220a9942..a35415ed9d 100644

target/i386/mshv/msr.c int mshv_get_msrs(CPUState *cpu) · line 329

Quoted 5 lines
target/i386/mshv/msr.c +1 -1
@@ -326,7 +326,7 @@ int mshv_get_msrs(CPUState *cpu)
  {
      int ret = 0;
      size_t n_assocs = MSHV_MSR_TOTAL_COUNT;
-    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT];
+    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT] = { 0 };

Matter of style, '{ }' is clearer. Otherwise this can be read as "uint32_t name is explicitly set to 0, hv_register_value value is implicitly zeroed". Anyway nitpicking, so:

Quoted 12 lines
target/i386/mshv/msr.c +1 -1
      size_t i, j;
      uint32_t name;
 
@@ -386,7 +386,7 @@ static void load_from_env(const CPUState *cpu, struct hv_register_assoc *assocs,
  int mshv_set_msrs(const CPUState *cpu)
  {
      size_t n_assocs = MSHV_MSR_TOTAL_COUNT;
-    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT];
+    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT] = { 0 };
      int ret;
      size_t i, j;
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Magnus Kulke
Quoted 36 lines · Magnus Kulke

In the current code we leave the argument arrays for the get/set hvcall unitialized, setting only individual fields. some fields will be populated during the hvcall, but in any case the arg arrays will contain unitialized data (e.g. in reserved fields), to which static analysis objects to.

Fixes c38eb12c85
---
 target/i386/mshv/msr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/mshv/msr.c +2 -2
index 8c220a9942..a35415ed9d 100644
@@ -326,7 +326,7 @@ int mshv_get_msrs(CPUState *cpu)
 {
     int ret = 0;
     size_t n_assocs = MSHV_MSR_TOTAL_COUNT;
-    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT];
+    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT] = { 0 };
     size_t i, j;
     uint32_t name;
 
@@ -386,7 +386,7 @@ static void load_from_env(const CPUState *cpu, struct hv_register_assoc *assocs,
 int mshv_set_msrs(const CPUState *cpu)
 {
     size_t n_assocs = MSHV_MSR_TOTAL_COUNT;
-    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT];
+    struct hv_register_assoc assocs[MSHV_MSR_TOTAL_COUNT] = { 0 };
     int ret;
     size_t i, j;
 
Signature · 1 line
2.34.1