target/i386/mshv: zero-init msr hvcall args
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.
--- target/i386/mshv/msr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/mshv/msr.c +2 -2
@@ -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
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 c38eb12c85Signed-off-by Magnus Kulke <[email protected]>--- target/i386/mshv/msr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/mshv/msr.c +0
-0
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
-1size_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;
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 c38eb12c85Signed-off-by Magnus Kulke <[email protected]>--- target/i386/mshv/msr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/mshv/msr.c +2
-2@@ -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