Skip to contentSkip to conversation

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

PATCH In review Matthew Barnes 2 participants 2 messages Jul 5, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v3 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 v3:
- Keep xc_domain_{un,}pause() calls
- Update xen-hvmcrash comment to reflect new behaviour

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 | 84 ++++++++++-----------------------------
 2 files changed, 22 insertions(+), 64 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 +21 -63

123 lines not on this page · raw message

Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 11 lines · Matthew Barnes

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.

Quoted 8 lines

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.

I'll queue this in my for-4.20 branch in due course.