target/i386: Check NULL monitor pointer when injecting MCE
PATCH 1/1 target/i386: Check NULL monitor pointer when injecting MCE
monitor_puts() doesn't check the monitor pointer, but do_inject_x86_mce() may have a parameter with NULL monitor pointer. Check the monitor pointer before calling monitor_puts().
--- target/i386/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/helper.c +2 -1
@@ -430,7 +430,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)if (need_reset) {emit_guest_memory_failure (MEMORY_FAILURE_ACTION_RESET , ar, recursive); -monitor_puts (params->mon, msg); +if (params->mon) +monitor_puts (params->mon, msg);qemu_log_mask (CPU_LOG_RESET ,"%s\n" , msg);qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET );return ;
Signature · 1 line
2.34.1
Quoted 16 lines · Tao Su
monitor_puts()doesn't check the monitor pointer, butdo_inject_x86_mce()may have a parameter with NULL monitor pointer. Check the monitor pointer before callingmonitor_puts().Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)Reviwed-by Xiaoyao Li <[email protected]>Signed-off-by Tao Su <[email protected]>--- target/i386/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/i386/helper.c +0
-0
target/i386/helper.c static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) · line 437
Quoted 9 lines
target/i386/helper.c +2
-1@@ -430,7 +430,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)if (need_reset) {emit_guest_memory_failure (MEMORY_FAILURE_ACTION_RESET , ar, recursive); -monitor_puts (params->mon, msg); +if (params->mon) +monitor_puts (params->mon, msg);qemu_log_mask (CPU_LOG_RESET ,"%s\n" , msg);qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET );return ;
Could instead revert the broken part of commit bf0c50d4aa85:
- monitor_puts(params->mon, msg);
+ monitor_printf(params->mon, "%s", msg);
qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);Then the fact that we send the same message to monitor and log is again more obvious.
Either way:
Hi Tao,
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Tao Su
monitor_puts()doesn't check the monitor pointer, butdo_inject_x86_mce()may have a parameter with NULL monitor pointer. Check the monitor pointer before callingmonitor_puts().Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)Reviwed-by Xiaoyao Li <[email protected]>Signed-off-by Tao Su <[email protected]>--- target/i386/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 10 lines
target/i386/helper.c static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) · line 433
Quoted 10 lines
target/i386/helper.c +1
-1@@ -430,7 +430,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)if (need_reset) {emit_guest_memory_failure (MEMORY_FAILURE_ACTION_RESET , ar, recursive); -monitor_puts (params->mon, msg); +if (params->mon)
Missing braces, see QEMU coding style:
https://www.qemu.org/docs/master/devel/style.html#block-structure
Quoted 18 lines
target/i386/helper.c static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) · line 437
Quoted 4 lines
target/i386/helper.c +1
-0+monitor_puts (params->mon, msg);qemu_log_mask (CPU_LOG_RESET ,"%s\n" , msg);qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET );return ;Could instead revert the broken part of commit
bf0c50d4aa85:-
monitor_puts(params->mon, msg);+ monitor_printf(params->mon, "%s", msg); qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);Then the fact that we send the same message to monitor and log is again more obvious.
Either way:
Reviewed-by Markus Armbruster <[email protected]>
Quoted 16 lines · Philippe Mathieu-Daudé
Hi Tao,
Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Tao Su
monitor_puts()doesn't check the monitor pointer, butdo_inject_x86_mce()may have a parameter with NULL monitor pointer. Check the monitor pointer before callingmonitor_puts().Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)Reviwed-by Xiaoyao Li <[email protected]>Signed-off-by Tao Su <[email protected]>--- target/i386/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 13 lines
Quoted 10 lines
target/i386/helper.c static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) · line 433
Quoted 10 lines
target/i386/helper.c +1
-1@@ -430,7 +430,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)if (need_reset) {emit_guest_memory_failure (MEMORY_FAILURE_ACTION_RESET , ar, recursive); -monitor_puts (params->mon, msg); +if (params->mon)Missing braces, see QEMU coding style:
https://www.qemu.org/docs/master/devel/style.html#block-structure
Yes, I prefer to revert the broken part.
Anyway, I got this point and will always pay attention to it, thanks for reminding.
Quoted 20 lines
Quoted 19 lines
target/i386/helper.c static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) · line 437
Quoted 5 lines
target/i386/helper.c +1
-0+monitor_puts (params->mon, msg);qemu_log_mask (CPU_LOG_RESET ,"%s\n" , msg);qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET );return ;Could instead revert the broken part of commit
bf0c50d4aa85:-
monitor_puts(params->mon, msg);+ monitor_printf(params->mon, "%s", msg); qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);Then the fact that we send the same message to monitor and log is again more obvious.
Either way:
Reviewed-by Markus Armbruster <[email protected]>
Quoted 30 lines · Markus Armbruster
Quoted 16 lines · Tao Su
monitor_puts()doesn't check the monitor pointer, butdo_inject_x86_mce()may have a parameter with NULL monitor pointer. Check the monitor pointer before callingmonitor_puts().Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)Reviwed-by Xiaoyao Li <[email protected]>Signed-off-by Tao Su <[email protected]>--- target/i386/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/i386/helper.c +0
-0target/i386/helper.c static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data) · line 437
Quoted 9 lines
target/i386/helper.c +2
-1@@ -430,7 +430,8 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)if (need_reset) {emit_guest_memory_failure (MEMORY_FAILURE_ACTION_RESET , ar, recursive); -monitor_puts (params->mon, msg); +if (params->mon) +monitor_puts (params->mon, msg);qemu_log_mask (CPU_LOG_RESET ,"%s\n" , msg);qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET );return ;Could instead revert the broken part of commit
bf0c50d4aa85:
Quoted 6 lines
-
monitor_puts(params->mon, msg);+ monitor_printf(params->mon, "%s", msg); qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);Then the fact that we send the same message to monitor and log is again more obvious.
Good suggestion. I will send a v2 with this change.
Quoted 3 lines
Either way:
Reviewed-by Markus Armbruster <[email protected]>
Thanks for review!