Skip to contentSkip to conversation

target/i386: Check NULL monitor pointer when injecting MCE

PATCH In review Tao Su 3 participants 5 messages Mar 20, 2024

lore
Share & tools
lore

Tao Su

author
#0 lore raw

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().

Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)
---
 target/i386/helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/helper.c +2 -1
index 2070dd0dda..a9ff830a17 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines · Tao Su

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().

Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)
---
 target/i386/helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/helper.c +0 -0
index 2070dd0dda..a9ff830a17 100644

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:

#2 lore raw

Hi Tao,

Quoted 13 lines · Markus Armbruster
Quoted 11 lines · Tao Su

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().

Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)
---
  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
index 2070dd0dda..a9ff830a17 100644
@@ -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:

author
#3 lore raw
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, but do_inject_x86_mce() may have a parameter with NULL monitor pointer. Check the monitor pointer before calling monitor_puts().

Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)
---
  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
index 2070dd0dda..a9ff830a17 100644
@@ -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:

author
#4 lore raw
In reply to Markus Armbruster
Quoted 30 lines · Markus Armbruster
Quoted 16 lines · Tao Su

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().

Fixes bf0c50d4aa85 (monitor: expose monitor_puts to rest of code)
---
 target/i386/helper.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/helper.c +0 -0
index 2070dd0dda..a9ff830a17 100644

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:

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:

Thanks for review!

Quoted 1 line