Skip to contentSkip to conversation

Add a Live Patch privilege check test

PATCH Superseded Ross Lagerwall 2 participants 2 messages Nov 17, 2016 Xen hypervisor interface

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add a Live Patch privilege check test

Add a test to check that Live Patch operations cannot be called from an unprivileged domain.

---
 docs/all-tests.dox                  |   2 +
 include/xen/sysctl.h                | 220 ++++++++++++++++++++++++++++++++++++
 include/xtf/hypercall.h             |   6 +
 tests/livepatch-priv-check/Makefile |   9 ++
 tests/livepatch-priv-check/main.c   | 144 +++++++++++++++++++++++
 5 files changed, 381 insertions(+)
 create mode 100755 include/xen/sysctl.h
 create mode 100644 tests/livepatch-priv-check/Makefile
 create mode 100644 tests/livepatch-priv-check/main.c
docs/all-tests.dox +2 -0
index 4f86182..2909b85 100644
@@ -22,6 +22,8 @@ and functionality.
 
 @subpage test-invlpg - `invlpg` instruction behaviour.
 
+@subpage test-livepatch-priv-check - Live Patch Privilege Check
+
 @subpage test-pv-iopl - IOPL emulation for PV guests.
 
 @subpage test-swint-emulation - Software interrupt emulation for HVM guests.
include/xen/sysctl.h new file +220 -0

220 lines not on this page · raw message

include/xtf/hypercall.h +6 -0
index a37ebc2..75c0e9d 100644
@@ -34,6 +34,7 @@ extern uint8_t hypercall_page[PAGE_SIZE];
 #include <xen/physdev.h>
 #include <xen/memory.h>
 #include <xen/version.h>
+#include <xen/sysctl.h>
 #include <xen/hvm/hvm_op.h>
 #include <xen/hvm/params.h>
 
@@ -114,6 +115,11 @@ static inline long hypercall_hvm_op(unsigned int cmd, void *arg)
     return HYPERCALL2(long, __HYPERVISOR_hvm_op, cmd, arg);
 }
 
+static inline long hypercall_sysctl(void *arg)
+{
+    return HYPERCALL1(long, __HYPERVISOR_sysctl, arg);
+}
+
 /*
  * Higher level hypercall helpers
  */
tests/livepatch-priv-check/Makefile new file +9 -0
new file mode 100644
index 0000000..e27b9da
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := livepatch-priv-check
+CATEGORY  := functional
+TEST-ENVS := $(ALL_ENVIRONMENTS)
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
tests/livepatch-priv-check/main.c new file +144 -0

144 lines not on this page · raw message

Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

include/xen/sysctl.h line 40

Quoted 8 lines · Ross Lagerwall
include/xen/sysctl.h new file +8 -0
+typedef struct {
+    union {
+        void *p;
+        uint64_t __attribute__((aligned(8))) q;
+    };
+} guest_handle_64;
+
+#define XEN_SYSCTL_INTERFACE_VERSION 0x0000000E

/sigh

This is going to require some rethinking. We cannot have the unstable ABI versions baked into the header files, as the tests wont function on older versions of Xen.

The sysctl ABI is actually fixed. The struct is always 136 bytes long, and has two uint32_t's at the top. XTF needs a library function to probe which interface version is accepted by Xen.

The livepatch layout is also fixed, so the sysctl version isn't actually relevant.

Quoted 13 lines
include/xtf/hypercall.h +1 -0
index a37ebc2..75c0e9d 100644
@@ -34,6 +34,7 @@ extern uint8_t hypercall_page[PAGE_SIZE];
 #include <xen/physdev.h>
 #include <xen/memory.h>
 #include <xen/version.h>
+#include <xen/sysctl.h>
 #include <xen/hvm/hvm_op.h>
 #include <xen/hvm/params.h>
 

include/xtf/hypercall.h static inline long hypercall_hvm_op(unsigned int cmd, void *arg) · line 118

Quoted 4 lines
include/xtf/hypercall.h +1 -0
@@ -114,6 +115,11 @@ static inline long hypercall_hvm_op(unsigned int cmd, void *arg)
     return HYPERCALL2(long, __HYPERVISOR_hvm_op, cmd, arg);
 }
 
+static inline long hypercall_sysctl(void *arg)

xen_sysctl_t * please.

Quoted 38 lines
include/xtf/hypercall.h +4 -0
+{
+    return HYPERCALL1(long, __HYPERVISOR_sysctl, arg);
+}
+
 /*
  * Higher level hypercall helpers
  */
tests/livepatch-priv-check/Makefile new file +9 -0
new file mode 100644
index 0000000..e27b9da
@@ -0,0 +1,9 @@
+include $(ROOT)/build/common.mk
+
+NAME      := livepatch-priv-check
+CATEGORY  := functional
+TEST-ENVS := $(ALL_ENVIRONMENTS)
+
+obj-perenv += main.o
+
+include $(ROOT)/build/gen.mk
tests/livepatch-priv-check/main.c new file +10 -0
new file mode 100644
index 0000000..357e4da
@@ -0,0 +1,144 @@
+/**
+ * @file tests/livepatch-priv-check/main.c
+ * @ref test-livepatch-priv-check
+ *
+ * @page test-livepatch-priv-check Live Patch Privilege Check
+ *
+ * Checks that Xen prevents using all live patching operations and
+ * sub-operations from an unprivileged guest.
+ *
+ * @see tests/livepatch-check-priv/main.c

tests/livepatch-priv-check/main.c line 20

Quoted 10 lines
tests/livepatch-priv-check/main.c new file +10 -0
+ */
+#include <xtf.h>
+
+static void check_ret(int rc)
+{
+    switch ( rc )
+    {
+    case -EPERM:
+        xtf_success("Xen correctly denied Live Patch calls\n");
+        break;

Newlines after breaks please.

Also, a quirk of multiple sub-tests like this is that you shouldn't call xtf_success multiple times. It can end up incorrectly declaring success if a logical bug caused you to skip part of the test logic.

Use printk here, and have a single xtf_success() as the final action in test_main().

tests/livepatch-priv-check/main.c line 26

Quoted 6 lines
tests/livepatch-priv-check/main.c new file +6 -0
+    case -ENOSYS:
+        xtf_skip("Live Patch support not detected\n");
+        break;
+    case 0:
+        xtf_failure("Live Patch call succeeded\n");
+        break;

I find it is helpful to manually prefix the strings with "Fail: ". It helps visually distinguish the logging if there is a mix of steps with different results.

tests/livepatch-priv-check/main.c line 29

Quoted 3 lines
tests/livepatch-priv-check/main.c new file +3 -0
+    default:
+        xtf_failure("Unexpected error %d\n", rc);
+        break;

This should be xtf_error().

~Andrew

tests/livepatch-priv-check/main.c line 32

Quoted 4 lines
tests/livepatch-priv-check/main.c new file +3 -0
+    }
+}
+

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel