]> xenbits.xensource.com Git - xtf.git/commitdiff
XSA-316 PoC
authorIgor Druzhinin <igor.druzhinin@citrix.com>
Tue, 7 Apr 2020 20:18:56 +0000 (21:18 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 3 Jun 2020 20:59:53 +0000 (21:59 +0100)
Signed-off-by: Igor Druzhinin <igor.druzhinin@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
docs/all-tests.dox
tests/xsa-316/Makefile [new file with mode: 0644]
tests/xsa-316/main.c [new file with mode: 0644]

index a725248c2d9ea8b1f2f5d030b3e0d1bfcc9ffb66..15eeccda21ae2f78ab7e0df622ee03014f7744bc 100644 (file)
@@ -148,6 +148,8 @@ emulation.
 @subpage test-xsa-308 - VMX: VMentry failure with debug exceptions and blocked
 states.
 
+@subpage test-xsa-316 - Bad error path in GNTTABOP_map_grant.
+
 
 @section index-utility Utilities
 
diff --git a/tests/xsa-316/Makefile b/tests/xsa-316/Makefile
new file mode 100644 (file)
index 0000000..af983ae
--- /dev/null
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := xsa-316
+CATEGORY  := xsa
+TEST-ENVS := pv64
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
diff --git a/tests/xsa-316/main.c b/tests/xsa-316/main.c
new file mode 100644 (file)
index 0000000..0f3d0ab
--- /dev/null
@@ -0,0 +1,71 @@
+/**
+ * @file tests/xsa-316/main.c
+ * @ref test-xsa-316
+ *
+ * @page test-xsa-316 XSA-316
+ *
+ * Advisory: [XSA-316](https://xenbits.xen.org/xsa/advisory-316.html)
+ *
+ * XSA-316 describes an issue with error handling in GNTTABOP_map_grant
+ * operation code.
+ *
+ * Grant table operations are expected to return 0 for success, and a negative
+ * number for errors. Some misplaced brackets cause one error path to return 1
+ * instead of a negative value.
+ *
+ * @see tests/xsa-316/main.c
+ */
+#include <xtf.h>
+
+const char test_title[] = "XSA-316 PoC";
+
+static uint8_t frame[PAGE_SIZE] __page_aligned_bss;
+
+void test_main(void)
+{
+    int rc = xtf_init_grant_table(1);
+
+    if ( rc )
+        return xtf_error("Error initialising grant table: %d\n", rc);
+
+    int domid = xtf_get_domid();
+
+    if ( domid < 0 )
+        return xtf_error("Error getting domid\n");
+
+    /*
+     * Construct gref 8 to allow frame[] to be mapped by ourselves..
+     */
+    gnttab_v1[8].domid = domid;
+    gnttab_v1[8].frame = virt_to_gfn(frame);
+    smp_wmb();
+    gnttab_v1[8].flags = GTF_permit_access;
+
+    struct gnttab_map_grant_ref map = {
+        .host_addr = KB(4),
+        .flags = GNTMAP_host_map,
+        .ref = 8,
+        .dom = 0, /* .. but provide incorrect domain id to map operation. */
+    };
+
+    /*
+     * Attempt to map gref to exercise the faulty error path.
+     */
+    rc = hypercall_grant_table_op(GNTTABOP_map_grant_ref, &map, 1);
+    if ( map.status > 0 )
+        return xtf_failure("Fail: Vulnerable to XSA-316\n");
+    else if ( !rc && map.status == GNTST_general_error )
+        return xtf_success("Success: Not vulnerable to XSA-316\n");
+    else
+        return xtf_error("Error: Unexpected result: %d/%d\n", rc, map.status);
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */