Skip to contentSkip to conversation

tools/misc: xen-hvmcrash: Inject #DF instead of overwriting RIP

PATCH Superseded Matthew Barnes 2 participants 2 messages Jul 1, 2024 – Jul 2, 2024

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 tools/misc: xen-hvmcrash: Inject #DF instead of overwriting RIP

xen-hvmcrash would previously save records, overwrite the instruction pointer with a bogus value, and then restore them to crash a domain just enough to cause the guest OS to memdump.

This approach is found to be unreliable when tested on a guest running Windows 10 x64, with some executions doing nothing at all.

Another approach would be to trigger NMIs. This approach is found to be unreliable when tested on Linux (Ubuntu 22.04), as Linux will ignore NMIs if it is not configured to handle such.

Injecting a double fault abort to all vCPUs is found to be more reliable at crashing and invoking memdumps from Windows and Linux domains.

This patch modifies the xen-hvmcrash tool to inject #DF to all vCPUs belonging to the specified domain, instead of overwriting RIP.

---
Changes in v2:
- Use xendevicemodel API instead of legacy devicemodel API
- Return error status code if no vcpus could be injected
- Use existing exception vector macro defined in x86-defns.h
- Clean up unnecessary headers
- Fix NULL build errors

---
 tools/misc/Makefile       |  2 +-
 tools/misc/xen-hvmcrash.c | 90 ++++++++-------------------------------
 2 files changed, 19 insertions(+), 73 deletions(-)
tools/misc/Makefile +1 -1
index 66d0d6b09029..c26e544e8393 100644
@@ -81,7 +81,7 @@ xen-hvmctx: xen-hvmctx.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
 
 xen-hvmcrash: xen-hvmcrash.o
-	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(LDLIBS_libxendevicemodel) $(APPEND_LDFLAGS)
 
 xen-memshare: xen-memshare.o
 	$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS_libxenctrl) $(APPEND_LDFLAGS)
tools/misc/xen-hvmcrash.c +18 -72

119 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw

tools/misc/xen-hvmcrash.c main(int argc, char **argv) · line 84

Quoted 13 lines · Matthew Barnes
tools/misc/xen-hvmcrash.c +0 -5
index 1d058fa40a47..efa47c9dfec8 100644
@@ -77,65 +66,22 @@ main(int argc, char **argv)
         exit(1);
     }
 
-    ret = xc_domain_pause(xch, domid);
-    if (ret < 0) {
-        perror("xc_domain_pause");
-        exit(-1);
-    }

You can't really drop the xc_domain_{un,}pause() calls.

Previously, from the point of view of the guest, we atomically corrupted all vCPUs at once.

Without the pause, we're corrupting each vCPU in turn, with the guest able to run in the meantime.

~Andrew