Skip to contentSkip to conversation

dump/win_dump: limit number of processed PRCBs

PATCH In review Viktor Prutyanov 2 participants 2 messages Oct 20, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dump/win_dump: limit number of processed PRCBs

When number of CPUs utilized by guest Windows is less than defined in QEMU (i.e., desktop versions of Windows severely limits number of CPU sockets), patch_and_save_context routine accesses non-existent PRCB and fails. So, limit number of processed PRCBs by NumberProcessors taken from guest Windows driver.

---
 dump/win_dump.c | 7 +++++++
 1 file changed, 7 insertions(+)
dump/win_dump.c +7 -0
index fd91350fbb..f20b6051b6 100644
@@ -273,6 +273,13 @@ static void patch_and_save_context(WinDumpHeader *h, bool x64,
         uint64_t Context;
         WinContext ctx;
 
+        if (i >= WIN_DUMP_FIELD(NumberProcessors)) {
+            warn_report("win-dump: number of QEMU CPUs is bigger than"
+                        " NumberProcessors (%u) in guest Windows",
+                        WIN_DUMP_FIELD(NumberProcessors));
+            return;
+        }
+
         if (cpu_read_ptr(x64, first_cpu,
                 KiProcessorBlock + i * win_dump_ptr_size(x64),
                 &Prcb)) {
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 8 lines · Viktor Prutyanov

When number of CPUs utilized by guest Windows is less than defined in QEMU (i.e., desktop versions of Windows severely limits number of CPU sockets), patch_and_save_context routine accesses non-existent PRCB and fails. So, limit number of processed PRCBs by NumberProcessors taken from guest Windows driver.

Assuming the used CPUs are in the same order. Or is there a way to query it instead?

lgtm otherwise

Quoted 27 lines
---
 dump/win_dump.c | 7 +++++++
 1 file changed, 7 insertions(+)
dump/win_dump.c +7 -0
index fd91350fbb..f20b6051b6 100644
@@ -273,6 +273,13 @@ static void patch_and_save_context(WinDumpHeader *h,
 bool x64,
         uint64_t Context;
         WinContext ctx;
 
+        if (i >= WIN_DUMP_FIELD(NumberProcessors)) {
+            warn_report("win-dump: number of QEMU CPUs is bigger than"
+                        " NumberProcessors (%u) in guest Windows",
+                        WIN_DUMP_FIELD(NumberProcessors));
+            return;
+        }
+
         if (cpu_read_ptr(x64, first_cpu,
                 KiProcessorBlock + i * win_dump_ptr_size(x64),
                 &Prcb)) {

--
2.35.1