tools/libs/evtchn: Add support for restricting a handle
PATCH 1/2 tools/libs/evtchn: Add support for restricting a handle
Implement support for restricting evtchn handles to a particular domain on Linux by calling the IOCTL_EVTCHN_RESTRICT_DOMID ioctl (support added in Linux v4.8).
--- tools/include/xen-sys/Linux/evtchn.h | 15 +++++++++++++++ tools/libs/evtchn/Makefile | 2 +- tools/libs/evtchn/core.c | 5 +++++ tools/libs/evtchn/freebsd.c | 6 ++++++ tools/libs/evtchn/include/xenevtchn.h | 10 ++++++++++ tools/libs/evtchn/libxenevtchn.map | 4 ++++ tools/libs/evtchn/linux.c | 9 +++++++++ tools/libs/evtchn/minios.c | 6 ++++++ tools/libs/evtchn/netbsd.c | 6 ++++++ tools/libs/evtchn/private.h | 3 +++ tools/libs/evtchn/solaris.c | 6 ++++++ tools/libvchan/init.c | 1 + tools/libvchan/libxenvchan.h | 1 + 13 files changed, 73 insertions(+), 1 deletion(-)
tools/include/xen-sys/Linux/evtchn.h +15 -0
@@ -85,4 +85,19 @@ struct ioctl_evtchn_notify {#define IOCTL_EVTCHN_RESET \ _IOC(_IOC_NONE, 'E', 5, 0) +/* +* Restrict this file descriptor so that it can only be used to bind +* new interdomain events from one domain. +* +* Once a file descriptor has been restricted it cannot be +* de-restricted, and must be closed and re-opened. Event channels +* which were bound before restricting remain bound afterwards, and +* can be notified as usual. +*/ +#define IOCTL_EVTCHN_RESTRICT_DOMID \ + _IOC(_IOC_NONE, 'E', 6, sizeof(struct ioctl_evtchn_restrict_domid)) +struct ioctl_evtchn_restrict_domid { +domid_t domid; +}; +#endif /* __LINUX_PUBLIC_EVTCHN_H__ */
tools/libs/evtchn/Makefile +1 -1
@@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 0 +MINOR = 1 SHLIB_LDFLAGS += -Wl,--version-script=libxenevtchn.map CFLAGS += -Werror -Wmissing-prototypes
tools/libs/evtchn/core.c +5 -0
@@ -61,6 +61,11 @@ int xenevtchn_close(xenevtchn_handle *xce)return rc; } +int xenevtchn_restrict (xenevtchn_handle *xce,domid_t domid) +{ +return osdep_evtchn_restrict (xce, domid); +} +/* * Local variables: * mode: C
tools/libs/evtchn/freebsd.c +6 -0
@@ -47,6 +47,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce)return close (xce->fd); } +int osdep_evtchn_restrict (xenevtchn_handle *xce,domid_t domid) +{ + errno = -EOPNOTSUPP ; +return -1 ; +} +int xenevtchn_fd (xenevtchn_handle *xce) {return xce->fd;
tools/libs/evtchn/include/xenevtchn.h +10 -0
@@ -151,6 +151,16 @@ xenevtchn_pending(xenevtchn_handle *xce);*/ int xenevtchn_unmask (xenevtchn_handle *xce,evtchn_port_t port); +/** +* This function restricts the use of this handle to the specified +* domain. +* +* @parm xce handle to the open evtchn interface +* @parm domid the domain id +* @return 0 on success, -1 on failure with errno set appropriately. +*/ +int xenevtchn_restrict (xenevtchn_handle *xce,domid_t domid); +#endif /*
tools/libs/evtchn/libxenevtchn.map +4 -0
@@ -17,3 +17,7 @@ VERS_1.0 { xenevtchn_pending; local: *; /* Do not expose anything by default */ }; +VERS_1.1 { + global: + xenevtchn_restrict; +} VERS_1.0;
tools/libs/evtchn/linux.c +9 -0
@@ -21,9 +21,11 @@#include <fcntl.h> #include <unistd.h> #include <stdlib.h> +#include <stdint.h> #include <sys/ioctl.h> +#include <xen/xen.h> #include <xen/sys/evtchn.h> #include "private.h"
@@ -49,6 +51,13 @@ int osdep_evtchn_close(xenevtchn_handle *xce)return close (xce->fd); } +int osdep_evtchn_restrict (xenevtchn_handle *xce,domid_t domid) +{ +struct ioctl_evtchn_restrict_domid restrict_domid = { domid }; + +return ioctl (xce->fd,IOCTL_EVTCHN_RESTRICT_DOMID , &restrict_domid); +} +int xenevtchn_fd (xenevtchn_handle *xce) {return xce->fd;
tools/libs/evtchn/minios.c +6 -0
@@ -82,6 +82,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce)return close (xce->fd); } +int osdep_evtchn_restrict (xenevtchn_handle *xce,domid_t domid) +{ + errno = -EOPNOTSUPP ; +return -1 ; +} +void minios_evtchn_close_fd (int fd) {struct evtchn_port_info *port_info, *tmp;
tools/libs/evtchn/netbsd.c +6 -0
@@ -47,6 +47,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce)return close (xce->fd); } +int osdep_evtchn_restrict (xenevtchn_handle *xce,domid_t domid) +{ + errno = -EOPNOTSUPP ; +return -1 ; +} +int xenevtchn_fd (xenevtchn_handle *xce) {return xce->fd;
tools/libs/evtchn/private.h +3 -0
@@ -4,6 +4,8 @@#include <xentoollog.h> #include <xenevtchn.h> +#include <xen/xen.h> +struct xenevtchn_handle {xentoollog_logger *logger, *logger_tofree;int fd;
@@ -11,6 +13,7 @@ struct xenevtchn_handle {int osdep_evtchn_open (xenevtchn_handle *xce);int osdep_evtchn_close (xenevtchn_handle *xce); +int osdep_evtchn_restrict (xenevtchn_handle *xce,domid_t domid);#endif
tools/libs/evtchn/solaris.c +6 -0
@@ -50,6 +50,12 @@ int osdep_evtchn_close(xenevtchn_handle *xce)return close (xce->fd); } +int osdep_evtchn_restrict (xenevtchn_handle *xce,domid_t domid) +{ + errno = -EOPNOTSUPP ; +return -1 ; +} +int xenevtchn_fd (xenevtchn_handle *xce) {return xce->fd;
tools/libvchan/init.c +1 -0
@@ -40,6 +40,7 @@#include <fcntl.h> #include <xenstore.h> +#include <xen/xen.h> #include <xen/sys/evtchn.h> #include <xen/sys/gntalloc.h> #include <xen/sys/gntdev.h>
tools/libvchan/libxenvchan.h +1 -0
@@ -43,6 +43,7 @@*/ #include <xen/io/libxenvchan.h> +#include <xen/xen.h> #include <xen/sys/evtchn.h> #include <xenevtchn.h> #include <xengnttab.h>
Signature · 7 lines
2.9.5 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
PATCH v2 2/2 xentoolcore_restrict_all: Implement for libxenevtchn
--- tools/Rules.mk | 2 +- tools/libs/evtchn/Makefile | 4 ++-- tools/libs/evtchn/core.c | 13 +++++++++++++ tools/libs/evtchn/private.h | 3 +++ tools/libs/toolcore/include/xentoolcore.h | 5 ----- 5 files changed, 19 insertions(+), 8 deletions(-)
tools/Rules.mk +1 -1
@@ -109,7 +109,7 @@ LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_LIBXENTOOLCORE)/libxentoo SHLIB_libxentoolcore = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_LIBXENTOOLCORE) CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude) -SHDEPS_libxenevtchn = +SHDEPS_libxenevtchn = $(SHLIB_libxentoolcore) LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension) SHLIB_libxenevtchn = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
tools/libs/evtchn/Makefile +2 -2
@@ -7,7 +7,7 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxenevtchn.map CFLAGS += -Werror -Wmissing-prototypes CFLAGS += -I./include $(CFLAGS_xeninclude) -CFLAGS += $(CFLAGS_libxentoollog) +CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore) SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.c
@@ -61,7 +61,7 @@ libxenevtchn.so.$(MAJOR): libxenevtchn.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenevtchn.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxenevtchn.map - $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenevtchn.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenevtchn.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) .PHONY: install install: build
tools/libs/evtchn/core.c +13 -0
@@ -18,6 +18,16 @@#include "private.h" +static int all_restrict_cb (Xentoolcore__Active_Handle *ah,domid_t domid) { +xenevtchn_handle *xce =CONTAINER_OF (ah, *xce, tc_ah); + +if (xce->fd <0 ) +/* just in case */ +return 0 ; + +return xenevtchn_restrict (xce, domid); +} +xenevtchn_handle *xenevtchn_open (xentoollog_logger *logger,unsigned open_flags) {xenevtchn_handle *xce =malloc (sizeof (*xce));
@@ -29,6 +39,9 @@ xenevtchn_handle *xenevtchn_open(xentoollog_logger *logger, unsigned open_flags) xce->logger = logger; xce->logger_tofree =NULL ; + xce->tc_ah.restrict_callback = all_restrict_cb; +xentoolcore__register_active_handle (&xce->tc_ah); +if (!xce->logger) { xce->logger = xce->logger_tofree = (xentoollog_logger*)
tools/libs/evtchn/private.h +3 -0
@@ -4,11 +4,14 @@#include <xentoollog.h> #include <xenevtchn.h> +#include <xentoolcore_internal.h> +#include <xen/xen.h> struct xenevtchn_handle {xentoollog_logger *logger, *logger_tofree;int fd; +Xentoolcore__Active_Handle tc_ah; };int osdep_evtchn_open (xenevtchn_handle *xce);
tools/libs/toolcore/include/xentoolcore.h +0 -5
@@ -31,11 +31,6 @@* Arranges that Xen library handles (fds etc.) which are currently held * by Xen libraries, can no longer be used other than to affect domid. * -* Does not prevent effects that amount only to -* - denial of service, possibly host-wide, by resource exhaustion etc. -* - leak of not-very-interesting metainformation about other domains -* eg, specifically, event channel signals relating to other domains -* * If this cannot be achieved, returns -1 and sets errno. * If called again with the same domid, it may succeed, or it may * fail (even though such a call is potentially meaningful).
Signature · 7 lines
2.9.5 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Re: [PATCH v2 2/2] xentoolcore_restrict_all: Implement for libxenevtchn
Ross Lagerwall writes ("[PATCH v2 2/2] xentoolcore_restrict_all: Implement for libxenevtchn"):
Quoted 1 line
Signed-off-by Ross Lagerwall <[email protected]>
...
tools/libs/toolcore/include/xentoolcore.h line 37
Quoted 13 lines
int
osdep_evtchn_open(xenevtchn_handle *xce);tools/libs/toolcore/include/xentoolcore.h +0
-4@@ -31,11 +31,6 @@* Arranges that Xen library handles (fds etc.) which are currently held * by Xen libraries, can no longer be used other than to affect domid. * -* Does not prevent effects that amount only to -* - denial of service, possibly host-wide, by resource exhaustion etc. -* - leak of not-very-interesting metainformation about other domains -* eg, specifically, event channel signals relating to other domains
Are we sure that all possible resource exhaustion attacks are now excluded ?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [PATCH v2 2/2] xentoolcore_restrict_all: Implement for libxenevtchn
Quoted 20 lines · Ian Jackson
Ross Lagerwall writes ("[PATCH v2 2/2]
xentoolcore_restrict_all: Implement for libxenevtchn"):Quoted 1 line
Signed-off-by Ross Lagerwall <[email protected]>...
tools/libs/toolcore/include/xentoolcore.h line 37
Quoted 13 lines
int osdep_evtchn_open(xenevtchn_handle *xce);tools/libs/toolcore/include/xentoolcore.h +0
-4@@ -31,11 +31,6 @@* Arranges that Xen library handles (fds etc.) which are currently held * by Xen libraries, can no longer be used other than to affect domid. * -* Does not prevent effects that amount only to -* - denial of service, possibly host-wide, by resource exhaustion etc. -* - leak of not-very-interesting metainformation about other domains -* eg, specifically, event channel signals relating to other domains Are we sure that all possible resource exhaustion attacks are now excluded ?
No, I'm not sure. I'll keep the first point for now.
Signature · 6 lines
Ross Lagerwall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Ross Lagerwall writes ("[PATCH v1 1/2] tools/libs/evtchn: Add support for restricting a handle"):
Quoted 3 lines
+/*
+ * Restrict this file descriptor so that it can only be used to bind
+ * new interdomain events from one domain.
Can it be used to bind other kinds of events ? The phrasing is ambigous.
The code LGTM.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 8 lines · Ian Jackson
Ross Lagerwall writes ("[PATCH v1 1/2]
tools/libs/evtchn: Add support for restricting a handle"):Quoted 3 lines
+/*
+ * Restrict this file descriptor so that it can only be used to bind
+ * new interdomain events from one domain.Can it be used to bind other kinds of events ? The phrasing is ambigous.
No. As far as I can see, it can only be used to bind new interdomain events, not other events.
This entire file (including the description) is copied directly from Linux's include/uapi/xen/evtchn.h so the description shouldn't be changed here anyway.
Signature · 6 lines
Ross Lagerwall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Ian Jackson
Acked-byRoss Lagerwall writes ("Re: [PATCH v1 1/2] tools/libs/evtchn: Add support for restricting a handle"):
Quoted 2 lines
No. As far as I can see, it can only be used to bind new interdomain events, not other events.
OK, good, thanks.
Quoted 3 lines
This entire file (including the description) is copied directly from Linux's
include/uapi/xen/evtchn.hso the description shouldn't be changed here anyway.
Not sure if you are targeting this at 4.9. If you are you should have CC'd the RM - doing that now. From an upstream pov these changes would make some difference to qemu depriv, improving it somewhat, and they seem very low risk.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 10 lines · Ian Jackson
Ross Lagerwall writes ("Re: [PATCH v1 1/2]
tools/libs/evtchn: Add support for restricting a handle"):Quoted 2 lines
No. As far as I can see, it can only be used to bind new interdomain events, not other events.
OK, good, thanks.
Quoted 3 lines
This entire file (including the description) is copied directly from Linux's
include/uapi/xen/evtchn.hso the description shouldn't be changed here anyway.
Quoted 7 lines
Acked-by Ian Jackson <[email protected]>Not sure if you are targeting this at 4.9. If you are you should have CC'd the RM - doing that now. From an upstream pov these changes would make some difference to qemu depriv, improving it somewhat, and they seem very low risk.
I wasn't targeting them at 4.10 since it bumps the version number of libxenevtchn and I thought it would be too late to submit a v1 of a patch which does that _after_ code freeze. I do agree that the change would be low risk.
Signature · 6 lines
Ross Lagerwall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Hi,
Quoted 13 lines · Ross Lagerwall
Quoted 12 lines · Ian Jackson
Ross Lagerwall writes ("Re: [PATCH v1 1/2]
tools/libs/evtchn: Add support for restricting a handle"):Quoted 2 lines
No. As far as I can see, it can only be used to bind new interdomain events, not other events.
OK, good, thanks.
Quoted 3 lines
This entire file (including the description) is copied directly from Linux's
include/uapi/xen/evtchn.hso the description shouldn't be changed here anyway.Acked-by Ian Jackson <[email protected]>
Quoted 7 lines
Quoted 5 lines
Not sure if you are targeting this at 4.9. If you are you should have CC'd the RM - doing that now. From an upstream pov these changes would make some difference to qemu depriv, improving it somewhat, and they seem very low risk.
I wasn't targeting them at 4.10 since it bumps the version number of libxenevtchn and I thought it would be too late to submit a v1 of a patch which does that _after_ code freeze. I do agree that the change would be low risk.
Cheers,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel