Add a Live Patch privilege check test
PATCH v3 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.
---
Changed in v3:
* Addressed review comments.
common/lib.c | 15 +++ docs/all-tests.dox | 2 + include/xen/sysctl.h | 211 ++++++++++++++++++++++++++++++++++++ include/xen/xen.h | 9 ++ include/xtf/hypercall.h | 6 + include/xtf/lib.h | 6 + tests/livepatch-priv-check/Makefile | 9 ++ tests/livepatch-priv-check/main.c | 153 ++++++++++++++++++++++++++ 8 files changed, 411 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
common/lib.c +15 -0
@@ -19,6 +19,21 @@ void __noreturn panic(const char *fmt, ...)arch_crash_hard (); } +int xtf_probe_sysctl_interface_version (void ) +{ +int i; +xen_sysctl_t op = {0 }; + +for ( i =0 ; i <128 ; i++ ) + { + op.interface_version = i; +if (hypercall_sysctl (&op) != -EACCES ) +return i; + } + +return -1 ; +} +/* * Local variables: * mode: C
docs/all-tests.dox +2 -0
@@ -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 +211 -0
211 lines not on this page · raw message
include/xen/xen.h +9 -0
@@ -255,6 +255,15 @@ enum XEN_UVMF { };#endif +#ifndef __ASSEMBLY__ +typedef struct { +union { +void *p; +uint64_t __aligned(8) q; + }; +}guest_handle_64_t ; +#endif +#endif /* XEN_PUBLIC_XEN_H */ /*
include/xtf/hypercall.h +6 -0
@@ -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 (xen_sysctl_t *arg) +{ +return HYPERCALL1 (long, __HYPERVISOR_sysctl, arg); +} +/* * Higher level hypercall helpers */
include/xtf/lib.h +6 -0
@@ -65,6 +65,12 @@ static inline void exec_user_void(void (*fn)(void)) exec_user((void *)fn); } +/** +* Probe for the SYSCTL_INTERFACE_VERSION in use by the hypervisor +* @returns version, or -1 on failure. +*/ +int xtf_probe_sysctl_interface_version (void ); +#endif /* XTF_LIB_H */ /*
tests/livepatch-priv-check/Makefile new file +9 -0
@@ -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 +153 -0
153 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
Quoted 4 lines · Ross Lagerwall
Add a test to check that Live Patch operations cannot be called from an unprivileged domain.
Signed-off-by Ross Lagerwall <[email protected]>
I made two very small adjustments.
common/lib.c void __noreturn panic(const char *fmt, ...) · line 25
Quoted 12 lines
common/lib.c +4
-0@@ -19,6 +19,21 @@ void __noreturn panic(const char *fmt, ...)arch_crash_hard (); } +int xtf_probe_sysctl_interface_version (void ) +{ +int i; +xen_sysctl_t op = {0 };
This breaks the build on Clang. Using { .cmd = 0 } instead is fine.
Quoted 20 lines
common/lib.c +11
-0+ +for ( i =0 ; i <128 ; i++ ) + { + op.interface_version = i; +if (hypercall_sysctl (&op) != -EACCES ) +return i; + } + +return -1 ; +} +/* * Local variables: * mode: C tests/livepatch-priv-check/Makefile new file +0
-0
tests/livepatch-priv-check/Makefile line 5
Quoted 5 lines
tests/livepatch-priv-check/Makefile new file +5
-0@@ -0,0 +1,9 @@ +include $(ROOT)/build/common.mk + +NAME := livepatch-priv-check +CATEGORY := functional +TEST-ENVS := $(ALL_ENVIRONMENTS)
I have dropped this down to pv32pae pv64 hvm32 hvm64
The hvm32pse and hvm32pae environments are an identical ABI to hvm32, so there is no point testing them all. The multiple paging options for 32bit HVM guests is only useful for testing pagetable related code.
~Andrew
tests/livepatch-priv-check/Makefile line 9
Quoted 4 lines
tests/livepatch-priv-check/Makefile new file +4
-0+ +obj-perenv += main.o + +include $(ROOT)/build/gen.mk
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel