Skip to contentSkip to conversation

tools: Depriv fd checking, internal fd access

PATCH In review Ian Jackson 4 participants 24 messages Jun 11, 2018 – Jul 5, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover tools: Depriv fd checking, internal fd access

From: Ian Jackson <[email protected]>

This series provides the support in xen.git for auditing whether qemu file descriptors are deprivileged, as expected with libxl dm_restrict=1.

The approach I have chosen is to fish the descriptors out of qemu (by using debugging facilities), and try to make hypercalls etc. using them.

To take making a hypercall as an example: this is not easily done without libxc. So I need to make libxc make a hypercall with a different fd - actually, a different open-file. I do this by using dup2 to overwrite libxc's fd with the one stolen from qemu. That means I need to know libxc's fd number. Hence the handle access patches in this series.

Compared to v2, this fixes the issues identified, and also, as promised, introduces the actual descriptor checking utility here in xen.git. Building it out-of-tree is quite tiresome and anyway the utility might be useful for other purposes.

This is not 4.11 material. qemu depriv is not covered by support in 4.11 anyway. In 4.12 I want it to be supported, and, therefore, tested and audited. If it becomes fully supported there, it might be worth backporting some of these patches.

The utility `fishdescriptor', referred to, is part of the Debian package chiark-scripts.deb. A newish version of that package is needed. That will be dealt with fully in the corresponding osstest patches.

Ian Jackson (8):
libxc: Drop declarations of osdep_privcmd_open and _close
libxc: Provide access to internal handles
tools: xencall, xengnttab, xengntshr: Provide access to internal fds
libxl: Provide better error message when qemu restrict user not found tools/tests/depriv: New test utility for deprivilege auditing tools/tests: Allow a test subdir to have install' and uninstall'
targets
tools/tests/depriv: Install depriv-fd-checker in our private libexec
directory
tools/tests/depriv-fd-checker: Support checking of Linux tun devices

 .gitignore                             |   1 +
 tools/libs/call/core.c                 |   5 +
 tools/libs/call/include/xencall.h      |   8 +
 tools/libs/call/libxencall.map         |   6 +
 tools/libs/gnttab/gntshr_core.c        |   6 +
 tools/libs/gnttab/gnttab_core.c        |   5 +
 tools/libs/gnttab/include/xengnttab.h  |  17 ++
 tools/libs/gnttab/libxengnttab.map     |   6 +
 tools/libxc/include/xenctrl.h          |  10 +
 tools/libxc/xc_private.c               |  15 ++
 tools/libxc/xc_private.h               |   3 -
 tools/libxl/libxl_dm.c                 |   5 +-
 tools/tests/Makefile                   |   7 +-
 tools/tests/depriv/Makefile            |  51 ++++
 tools/tests/depriv/depriv-fd-checker.c | 433 +++++++++++++++++++++++++++++++++
 tools/tests/mce-test/Makefile          |   2 +
 tools/tests/mem-sharing/Makefile       |   2 +
 tools/tests/xen-access/Makefile        |   2 +
 tools/tests/xenstore/Makefile          |   2 +
 19 files changed, 576 insertions(+), 10 deletions(-)
 create mode 100644 tools/tests/depriv/Makefile
 create mode 100644 tools/tests/depriv/depriv-fd-checker.c
Signature · 7 lines
2.1.4


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

PATCH v2 1/8 libxc: Drop declarations of osdep_privcmd_open and _close

These functions are no longer defined or used anywhere. The declarations should have been deleted when the definitions were.

---
 tools/libxc/xc_private.h | 3 ---
 1 file changed, 3 deletions(-)
tools/libxc/xc_private.h +0 -3
index 03bc9a7..25bae8a 100644
@@ -103,9 +103,6 @@ struct xc_interface_core {
     xendevicemodel_handle *dmod;
 };
 
-int osdep_privcmd_open(xc_interface *xch);
-int osdep_privcmd_close(xc_interface *xch);
-
 void *osdep_alloc_hypercall_buffer(xc_interface *xch, int npages);
 void osdep_free_hypercall_buffer(xc_interface *xch, void *ptr, int npages);
 
Signature · 7 lines
2.1.4


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

PATCH v2 2/8 libxc: Provide access to internal handles

In reply to Ian Jackson

In order to support auditing of qemu depriv, my audit tool wants to know the fd of a privcmd handle on which it can easily make hypercalls. xencall provides such a handle, but has no cooked facilities for making hypercalls. So I open a libxc handle. That means I need to get the privcmd fd out of the libxc handle.

ISTM that it is best to do this by providing an interface to get the underlying library handles for a libxc handle. This kind of interface is quite common elsewhere and has not caused problems.

libxc is not a stable API so the downside risk of providing this access is not significant.

---
v2: Actually provide the fmem and dmod handle functions that the
declarations in the .h file promise.

---
 tools/libxc/include/xenctrl.h | 10 ++++++++++
 tools/libxc/xc_private.c      | 15 +++++++++++++++
 2 files changed, 25 insertions(+)
tools/libxc/include/xenctrl.h +10 -0
index 408fa1c..d7733aa 100644
@@ -183,6 +183,16 @@ enum xc_open_flags {
  */
 int xc_interface_close(xc_interface *xch);
 
+/**
+ * Return the handles which xch has opened and will use for
+ * hypercalls, foreign memory accesses and device model operations.
+ * These may be used with the corresponding libraries so long as the
+ * xch itself remains open.
+ */
+struct xencall_handle *xc_interface_xcall_handle(xc_interface *xch);
+struct xenforeignmemory_handle *xc_interface_fmem_handle(xc_interface *xch);
+struct xendevicemodel_handle *xc_interface_dmod_handle(xc_interface *xch);
+
 /*
  * HYPERCALL SAFE MEMORY BUFFER
  *
tools/libxc/xc_private.c +15 -0
index fcda981..5a2efe7 100644
@@ -104,6 +104,21 @@ int xc_interface_close(xc_interface *xch)
     return rc;
 }
 
+xencall_handle *xc_interface_xcall_handle(xc_interface *xch)
+{
+    return xch->xcall;
+}
+
+struct xenforeignmemory_handle *xc_interface_fmem_handle(xc_interface *xch)
+{
+    return xch->fmem;
+}
+
+struct xendevicemodel_handle *xc_interface_dmod_handle(xc_interface *xch)
+{
+    return xch->dmod;
+}
+
 static pthread_key_t errbuf_pkey;
 static pthread_once_t errbuf_pkey_once = PTHREAD_ONCE_INIT;
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 2/8
#3 lore raw

Re: [PATCH v2 2/8] libxc: Provide access to internal handles

Quoted 10 lines · Ian Jackson

In order to support auditing of qemu depriv, my audit tool wants to know the fd of a privcmd handle on which it can easily make hypercalls. xencall provides such a handle, but has no cooked facilities for making hypercalls. So I open a libxc handle. That means I need to get the privcmd fd out of the libxc handle.

ISTM that it is best to do this by providing an interface to get the underlying library handles for a libxc handle. This kind of interface is quite common elsewhere and has not caused problems.

Quoted 5 lines

libxc is not a stable API so the downside risk of providing this access is not significant.

Thanks.

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

#4 lore raw

PATCH v2 3/8 tools: xencall, xengnttab, xengntshr: Provide access to internal fds

In reply to Ian Jackson

I want this to support my qemu depriv descriptor audit tool.

---
v2: Fix ABI breakage.

---
 tools/libs/call/core.c                |  5 +++++
 tools/libs/call/include/xencall.h     |  8 ++++++++
 tools/libs/call/libxencall.map        |  6 ++++++
 tools/libs/gnttab/gntshr_core.c       |  6 ++++++
 tools/libs/gnttab/gnttab_core.c       |  5 +++++
 tools/libs/gnttab/include/xengnttab.h | 17 +++++++++++++++++
 tools/libs/gnttab/libxengnttab.map    |  6 ++++++
 7 files changed, 53 insertions(+)
tools/libs/call/core.c +5 -0
index f3a3400..c155bd4 100644
@@ -81,6 +81,11 @@ int xencall_close(xencall_handle *xcall)
     return rc;
 }
 
+int xencall_fd(xencall_handle *xcall)
+{
+    return xcall->fd;
+}
+
 int xencall0(xencall_handle *xcall, unsigned int op)
 {
     privcmd_hypercall_t call = {
tools/libs/call/include/xencall.h +8 -0
index bafacdd..24bcafb 100644
@@ -74,6 +74,14 @@ xencall_handle *xencall_open(struct xentoollog_logger *logger,
 int xencall_close(xencall_handle *xcall);
 
 /*
+ * Return the fd used internally by xencall.  selecting on it is not
+ * useful.  But it could be useful for unusual use cases; perhaps,
+ * passing to other programs, calling ioctls on directly, or maybe
+ * calling fcntl.
+ */
+int xencall_fd(xencall_handle *xcall);
+
+/*
  * Call hypercalls with varying numbers of arguments.
  *
  * On success the return value of the hypercall is the return value of
tools/libs/call/libxencall.map +6 -0
index 2f96144..c6a0181 100644
@@ -17,3 +17,9 @@ VERS_1.0 {
 		xencall_free_buffer_pages;
 	local: *; /* Do not expose anything by default */
 };
+
+VERS_1.1 {
+	global:
+		xencall_fd;
+		
+} VERS_1.0;
tools/libs/gnttab/gntshr_core.c +6 -0
index 7f6bf9d..1117e29 100644
@@ -64,6 +64,12 @@ int xengntshr_close(xengntshr_handle *xgs)
     free(xgs);
     return rc;
 }
+
+int xengntshr_fd(xengntshr_handle *xgs)
+{
+    return xgs->fd;
+}
+
 void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid,
                             int count, uint32_t *refs, int writable)
 {
tools/libs/gnttab/gnttab_core.c +5 -0
index 98f1591..bd075f8 100644
@@ -75,6 +75,11 @@ int xengnttab_close(xengnttab_handle *xgt)
     return rc;
 }
 
+int xengnttab_fd(xengnttab_handle *xgt)
+{
+    return xgt->fd;
+}
+
 int xengnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count)
 {
     return osdep_gnttab_set_max_grants(xgt, count);
tools/libs/gnttab/include/xengnttab.h +17 -0
index 35be6c1..91d4cd5 100644
@@ -149,6 +149,15 @@ xengnttab_handle *xengnttab_open(struct xentoollog_logger *logger,
  */
 int xengnttab_close(xengnttab_handle *xgt);
 
+
+/*
+ * Return the fd used internally by xengnttab.  selecting on it is not
+ * useful.  But it could be useful for unusual use cases; perhaps,
+ * passing to other programs, calling ioctls on directly, or maybe
+ * calling fcntl.
+ */
+int xengnttab_fd(xengnttab_handle *xgt);
+
 /**
  * Memory maps a grant reference from one domain to a local address range.
  * Mappings should be unmapped with xengnttab_unmap.  Logs errors.
@@ -334,6 +343,14 @@ xengntshr_handle *xengntshr_open(struct xentoollog_logger *logger,
  */
 int xengntshr_close(xengntshr_handle *xgs);
 
+/*
+ * Return the fd used internally by xengntshr.  selecting on it is not
+ * useful.  But it could be useful for unusual use cases; perhaps,
+ * passing to other programs, calling ioctls on directly, or maybe
+ * calling fcntl.
+ */
+int xengntshr_fd(xengntshr_handle *xgs);
+
 /**
  * Allocates and shares pages with another domain.
  *
tools/libs/gnttab/libxengnttab.map +6 -0
index f78da22..d5da388 100644
@@ -26,3 +26,9 @@ VERS_1.1 {
     global:
         xengnttab_grant_copy;
 } VERS_1.0;
+
+VERS_1.2 {
+    global:
+		xengnttab_fd;
+		xengntshr_fd;
+} VERS_1.1;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 3/8
#5 lore raw

Re: [PATCH v2 3/8] tools: xencall, xengnttab, xengntshr: Provide access to internal fds

Quoted 4 lines · Ian Jackson

I want this to support my qemu depriv descriptor audit tool.

tools/libs/call/libxencall.map VERS_1.0 { · line 24

Quoted 13 lines
tools/libs/call/libxencall.map +5 -0
index 2f96144..c6a0181 100644
@@ -17,3 +17,9 @@ VERS_1.0 {
 		xencall_free_buffer_pages;
 	local: *; /* Do not expose anything by default */
 };
+
+VERS_1.1 {
+	global:
+		xencall_fd;
+		

^ Extra newline?

Thanks, Roger.

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

#6 lore raw

Re: [PATCH v2 3/8] tools: xencall, xengnttab, xengntshr: Provide access to internal fds

Roger Pau Monné writes ("Re: [PATCH v2 3/8] tools: xencall, xengnttab, xengntshr: Provide access to internal fds"):

Quoted 7 lines · Ian Jackson
Quoted 4 lines

I want this to support my qemu depriv descriptor audit tool.

Thanks.

Quoted 2 lines
Quoted 2 lines
tools/libs/call/libxencall.map +0 -0
index 2f96144..c6a0181 100644

...

Quoted 6 lines

tools/libs/call/libxencall.map VERS_1.0 { · line 24

Quoted 4 lines
tools/libs/call/libxencall.map +4 -0
+VERS_1.1 {
+	global:
+		xencall_fd;
+		

^ Extra newline?

Cor, you're eagle-eyed ! I have deleted that line.

Thanks,
Ian.

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

Acked-by on v2 3/8
#7 lore raw

Re: [PATCH v2 3/8] tools: xencall, xengnttab, xengntshr: Provide access to internal fds

In reply to Ian Jackson
Quoted 4 lines · Ian Jackson

I want this to support my qemu depriv descriptor audit tool.

With Roger's comment addressed:

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

#8 lore raw

PATCH v2 4/8 libxl: Provide better error message when qemu restrict user not found

In reply to Ian Jackson

Add mention of LIBXL_QEMU_USER_RANGE_BASE, in case that is what the user was intending.

---
 tools/libxl/libxl_dm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/libxl/libxl_dm.c +3 -2
index 18ada69..7289509 100644
@@ -1699,8 +1699,9 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
         }
 
         LOGD(ERROR, guest_domid,
-             "Could not find user %s%d or %s, cannot restrict",
-             LIBXL_QEMU_USER_BASE, guest_domid, LIBXL_QEMU_USER_SHARED);
+ "Could not find user %s%d or %s or range base pseudo-user %s, cannot restrict",
+             LIBXL_QEMU_USER_BASE, guest_domid, LIBXL_QEMU_USER_SHARED,
+             LIBXL_QEMU_USER_RANGE_BASE);
         return ERROR_INVAL;
 
 end_search:
Signature · 7 lines
2.1.4


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

PATCH v2 5/8 tools/tests/depriv: New test utility for deprivilege auditing

In reply to Ian Jackson

I have chosen to licence this utility as LGPL-v2.1-only, similar to other LGPL elements of the Xen tools, because it may want to be moved into or combined with osstest or some other project at some point in the future, so it wants a licence compatible with osstest's AGPLv3+.

---
v2: New patch

---
 .gitignore                             |   1 +
 tools/tests/depriv/Makefile            |  42 ++++
 tools/tests/depriv/depriv-fd-checker.c | 399 +++++++++++++++++++++++++++++++++
 3 files changed, 442 insertions(+)
 create mode 100644 tools/tests/depriv/Makefile
 create mode 100644 tools/tests/depriv/depriv-fd-checker.c
.gitignore +1 -0
index 7004349..5b8448d 100644
@@ -237,6 +237,7 @@ tools/python/build/*
 tools/security/secpol_tool
 tools/security/xen/*
 tools/security/xensec_tool
+tools/tests/depriv/depriv-fd-checker
 tools/tests/x86_emulator/*.bin
 tools/tests/x86_emulator/*.tmp
 tools/tests/x86_emulator/3dnow*.[ch]
tools/tests/depriv/Makefile new file +42 -0

42 lines not on this page · raw message

tools/tests/depriv/depriv-fd-checker.c new file +399 -0

399 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v2 5/8
#10 lore raw

Re: [PATCH v2 5/8] tools/tests/depriv: New test utility for deprivilege auditing

Quoted 6 lines · Ian Jackson

I have chosen to licence this utility as LGPL-v2.1-only, similar to other LGPL elements of the Xen tools, because it may want to be moved into or combined with osstest or some other project at some point in the future, so it wants a licence compatible with osstest's AGPLv3+.

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

#11 lore raw

PATCH v2 6/8 tools/tests: Allow a test subdir to have `install' and `uninstall' targets

In reply to Ian Jackson

---
v2: New patch

---
 tools/tests/Makefile             | 7 ++-----
 tools/tests/depriv/Makefile      | 2 ++
 tools/tests/mce-test/Makefile    | 2 ++
 tools/tests/mem-sharing/Makefile | 2 ++
 tools/tests/xen-access/Makefile  | 2 ++
 tools/tests/xenstore/Makefile    | 2 ++
 6 files changed, 12 insertions(+), 5 deletions(-)
tools/tests/Makefile +2 -5
index f6942a9..26c46b4 100644
@@ -13,11 +13,8 @@ endif
 SUBDIRS-$(CONFIG_X86) += x86_emulator
 SUBDIRS-y += xen-access
 SUBDIRS-y += xenstore
+SUBDIRS-y += depriv
 SUBDIRS-$(CONFIG_HAS_PCI) += vpci
 
 .PHONY: all clean install distclean uninstall
-all clean distclean: %: subdirs-%
-
-install:
-
-uninstall:
+all clean distclean install uninstall: %: subdirs-%
tools/tests/depriv/Makefile +2 -0
index 2af1e29..643d2c5 100644
@@ -39,4 +39,6 @@ clean:
 .PHONY: distclean
 distclean: clean
 
+install uninstall:
+
 -include $(DEPS_INCLUDE)
tools/tests/mce-test/Makefile +2 -0
index 07a774a..1395df3 100644
@@ -8,3 +8,5 @@ clean:
 
 distclean:
 	$(MAKE) -C tools distclean
+
+install uninstall:
tools/tests/mem-sharing/Makefile +2 -0
index 497696f..5cd96e4 100644
@@ -27,3 +27,5 @@ memshrtool: memshrtool.o
 	$(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl)
 
 -include $(DEPS_INCLUDE)
+
+install uninstall:
tools/tests/xen-access/Makefile +2 -0
index 0ca3f6f..131c9f3 100644
@@ -28,4 +28,6 @@ distclean: clean
 xen-access: xen-access.o Makefile
 	$(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenevtchn)
 
+install uninstall:
+
 -include $(DEPS_INCLUDE)
tools/tests/xenstore/Makefile +2 -0
index b37b90d..a367d88 100644
@@ -24,4 +24,6 @@ distclean: clean
 xs-test: xs-test.o Makefile
 	$(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenstore)
 
+install uninstall:
+
 -include $(DEPS_INCLUDE)
Signature · 7 lines
2.1.4


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

PATCH v2 7/8 tools/tests/depriv: Install depriv-fd-checker in our private libexec directory

In reply to Ian Jackson

osstest is going to want to call it, and should not be expected to fish it out of the build tree.

---
v2: New patch

---
 tools/tests/depriv/Makefile | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
tools/tests/depriv/Makefile +10 -3
index 643d2c5..11e07b7 100644
@@ -23,8 +23,9 @@ LDLIBS += $(LDLIBS_libxendevicemodel)
 LDLIBS += $(LDLIBS_libxentoolcore)
 LDLIBS += $(LDLIBS_libxentoollog)
 
-TARGETS-y := depriv-fd-checker
-TARGETS := $(TARGETS-y)
+INSTALL_PRIVBIN-y += depriv-fd-checker
+INSTALL_PRIVBIN := $(INSTALL_PRIVBIN-y)
+TARGETS += $(INSTALL_PRIVBIN)
 
 .PHONY: all
 all: build
@@ -39,6 +40,12 @@ clean:
 .PHONY: distclean
 distclean: clean
 
-install uninstall:
+install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
+	$(INSTALL_PROG) $(INSTALL_PRIVBIN) $(DESTDIR)$(LIBEXEC_BIN)
+
+.PHONY: uninstall
+uninstall:
+	rm -f $(addprefix $(DESTDIR)$(LIBEXEC_BIN)/, $(INSTALL_PRIVBIN))
 
 -include $(DEPS_INCLUDE)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 7/8
#15 lore raw

Re: [PATCH v2 7/8] tools/tests/depriv: Install depriv-fd-checker in our private libexec directory

Quoted 4 lines · Ian Jackson

osstest is going to want to call it, and should not be expected to fish it out of the build tree.

Thanks

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

Acked-by on v2 7/8
#16 lore raw

Re: [PATCH v2 7/8] tools/tests/depriv: Install depriv-fd-checker in our private libexec directory

In reply to Ian Jackson
Quoted 4 lines · Ian Jackson

osstest is going to want to call it, and should not be expected to fish it out of the build tree.

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

#17 lore raw

PATCH v2 8/8 tools/tests/depriv-fd-checker: Support checking of Linux tun devices

In reply to Ian Jackson

---
v2: New patch

---
 tools/tests/depriv/depriv-fd-checker.c | 36 +++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
tools/tests/depriv/depriv-fd-checker.c +35 -1
index 67a3674..e57390f 100644
@@ -10,6 +10,7 @@
  *    privcmd gntdev evtchn     FD should be appropriate Xen control fd
  *    readonly                  FD is expected to be readonly
  *    appendonly                FD is expected to be append write only
+ #    tun                       FD is expected to be an open tun device
  *
  * In each case FD is probably a reference to an open-file stolen
  * from another process, eg by the use of fishdescriptor.
@@ -22,11 +23,14 @@
  *
  * depriv-fd-checker will perhaps print, for each triplet:
  *   CLASS checking FD INFORMATION... X-INFO
- * and in any case print, for each triplet:
+ * and in any case print, for each triplet, exactly one of:
  *   CLASS pass|fail FD INFORMATION... X-INFO
+ *   tun maybe FD IFNAME X-INFO
  *
  * "pass" means that the descriptor was restricted as expected.
  * "fail" means that the descriptor was unrestricted.
+ * "maybe" means that further information is printed, as detailed above,
+ *         and the caller should check that it is as expected
  */
 /*
  * Copyright (C)2018 Citrix Systems R&D
@@ -320,6 +324,35 @@ static void check_appendonly(void) {
     report("pass", "fcntl", mbuf);
 }
 
+#if defined(__linux__)
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include <linux/if_tun.h>
+
+/* linux tun */
+
+static void setup_tun(void) { }
+static void check_tun(void) {
+    struct ifreq ifr;
+    int r;
+
+    memset(&ifr,0,sizeof(ifr));
+    r = ioctl(object_fd, TUNGETIFF, (void*)&ifr);
+    if (r<0) trouble("TUNGETIFF");
+    printf("tun maybe %d %.*s %s\n", object_fd,
+           (int)IFNAMSIZ, ifr.ifr_ifrn.ifrn_name,
+           fd_desc);
+}
+
+#define PLATFORM_CLASSES \
+    DEFCHECK(tun),
+
+#else /* !defined(__linux__) */
+#define PLATFORM_CLASSES /* empty */
+#endif
+
 /* class table and main program */
 
 #define DEFCLASS(cl) \
@@ -341,6 +374,7 @@ static const struct classinfo {
     DEFCLASS(evtchn),
     DEFCHECK(readonly),
     DEFCHECK(appendonly),
+    PLATFORM_CLASSES
     { 0 }
 };
 
Signature · 7 lines
2.1.4


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

Re: [PATCH v2 8/8] tools/tests/depriv-fd-checker: Support checking of Linux tun devices

Wei Liu writes ("Re: [PATCH v2 8/8] tools/tests/depriv-fd-checker: Support checking of Linux tun devices"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

The code looks OK. But I'm not sure how this is supposed to be used.

I'm not sure what you mean. You arrange for it to get a tun device. It prints "tun maybe <fd> <ifname> ...". You decide whether that interface name is what you expected.

Ian.

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

Acked-by
#20 lore raw

Re: [PATCH v2 8/8] tools/tests/depriv-fd-checker: Support checking of Linux tun devices

Quoted 9 lines · Ian Jackson

Wei Liu writes ("Re: [PATCH v2 8/8] tools/tests/depriv-fd-checker: Support checking of Linux tun devices"):

Quoted 4 lines · Ian Jackson
Quoted 1 line

The code looks OK. But I'm not sure how this is supposed to be used.

I'm not sure what you mean. You arrange for it to get a tun device. It prints "tun maybe <fd> <ifname> ...". You decide whether that interface name is what you expected.

OK.

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

#21 lore raw

PATCH v4 3/8 tools: xencall, xengnttab, xengntshr: Provide access to internal fds

In reply to Ian Jackson

Ian Jackson writes ("[PATCH for-4.12 v2 0/8] tools: Depriv fd checking, internal fd access"):

Quoted 3 lines

This series provides the support in xen.git for auditing whether qemu file descriptors are deprivileged, as expected with libxl dm_restrict=1.

These were all acked.

However, on rebasing to current staging I had a merge conflict in libxengnttab.map. Here is the new version, therefore, with Roger's R-B and Wei's A-B dropped for that reason.

Thanks,
Ian.

From f61e6ee1a2a6530dabc15eef86845210d14aa53c Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Fri, 4 May 2018 16:29:17 +0100
Subject: [PATCH v4 3/8] tools: xencall, xengnttab, xengntshr: Provide access
to internal fds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

I want this to support my qemu depriv descriptor audit tool.

---
v4: Rebase onto current staging.
v3: Remove an erroneously-introduced blank line.
v2: Fix ABI breakage.

---
 tools/libs/call/core.c                |  5 +++++
 tools/libs/call/include/xencall.h     |  8 ++++++++
 tools/libs/call/libxencall.map        |  1 +
 tools/libs/gnttab/gntshr_core.c       |  6 ++++++
 tools/libs/gnttab/gnttab_core.c       |  5 +++++
 tools/libs/gnttab/include/xengnttab.h | 17 +++++++++++++++++
 tools/libs/gnttab/libxengnttab.map    |  6 ++++++
 7 files changed, 48 insertions(+)
tools/libs/call/core.c +5 -0
index 46ca615..57d3a33 100644
@@ -91,6 +91,11 @@ int xencall_close(xencall_handle *xcall)
     return rc;
 }
 
+int xencall_fd(xencall_handle *xcall)
+{
+    return xcall->fd;
+}
+
 int xencall0(xencall_handle *xcall, unsigned int op)
 {
     privcmd_hypercall_t call = {
tools/libs/call/include/xencall.h +8 -0
index 0d09bc8..2d0c42a 100644
@@ -74,6 +74,14 @@ xencall_handle *xencall_open(struct xentoollog_logger *logger,
 int xencall_close(xencall_handle *xcall);
 
 /*
+ * Return the fd used internally by xencall.  selecting on it is not
+ * useful.  But it could be useful for unusual use cases; perhaps,
+ * passing to other programs, calling ioctls on directly, or maybe
+ * calling fcntl.
+ */
+int xencall_fd(xencall_handle *xcall);
+
+/*
  * Call hypercalls with varying numbers of arguments.
  *
  * On success the return value of the hypercall is the return value of
tools/libs/call/libxencall.map +1 -0
index c482195..feacee3 100644
@@ -21,4 +21,5 @@ VERS_1.0 {
 VERS_1.1 {
 	global:
 		xencall_buffers_never_fault;
+		xencall_fd;
 } VERS_1.0;
tools/libs/gnttab/gntshr_core.c +6 -0
index 7f6bf9d..1117e29 100644
@@ -64,6 +64,12 @@ int xengntshr_close(xengntshr_handle *xgs)
     free(xgs);
     return rc;
 }
+
+int xengntshr_fd(xengntshr_handle *xgs)
+{
+    return xgs->fd;
+}
+
 void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid,
                             int count, uint32_t *refs, int writable)
 {
tools/libs/gnttab/gnttab_core.c +5 -0
index 98f1591..bd075f8 100644
@@ -75,6 +75,11 @@ int xengnttab_close(xengnttab_handle *xgt)
     return rc;
 }
 
+int xengnttab_fd(xengnttab_handle *xgt)
+{
+    return xgt->fd;
+}
+
 int xengnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count)
 {
     return osdep_gnttab_set_max_grants(xgt, count);
tools/libs/gnttab/include/xengnttab.h +17 -0
index 35be6c1..91d4cd5 100644
@@ -149,6 +149,15 @@ xengnttab_handle *xengnttab_open(struct xentoollog_logger *logger,
  */
 int xengnttab_close(xengnttab_handle *xgt);
 
+
+/*
+ * Return the fd used internally by xengnttab.  selecting on it is not
+ * useful.  But it could be useful for unusual use cases; perhaps,
+ * passing to other programs, calling ioctls on directly, or maybe
+ * calling fcntl.
+ */
+int xengnttab_fd(xengnttab_handle *xgt);
+
 /**
  * Memory maps a grant reference from one domain to a local address range.
  * Mappings should be unmapped with xengnttab_unmap.  Logs errors.
@@ -334,6 +343,14 @@ xengntshr_handle *xengntshr_open(struct xentoollog_logger *logger,
  */
 int xengntshr_close(xengntshr_handle *xgs);
 
+/*
+ * Return the fd used internally by xengntshr.  selecting on it is not
+ * useful.  But it could be useful for unusual use cases; perhaps,
+ * passing to other programs, calling ioctls on directly, or maybe
+ * calling fcntl.
+ */
+int xengntshr_fd(xengntshr_handle *xgs);
+
 /**
  * Allocates and shares pages with another domain.
  *
tools/libs/gnttab/libxengnttab.map +6 -0
index f78da22..d5da388 100644
@@ -26,3 +26,9 @@ VERS_1.1 {
     global:
         xengnttab_grant_copy;
 } VERS_1.0;
+
+VERS_1.2 {
+    global:
+		xengnttab_fd;
+		xengntshr_fd;
+} VERS_1.1;
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v4 3/8
#22 lore raw

Re: [PATCH v4 3/8] tools: xencall, xengnttab, xengntshr: Provide access to internal fds

Quoted 23 lines · Ian Jackson

Ian Jackson writes ("[PATCH for-4.12 v2 0/8] tools: Depriv fd checking, internal fd access"):

Quoted 3 lines

This series provides the support in xen.git for auditing whether qemu file descriptors are deprivileged, as expected with libxl dm_restrict=1.

These were all acked.

However, on rebasing to current staging I had a merge conflict in libxengnttab.map. Here is the new version, therefore, with Roger's R-B and Wei's A-B dropped for that reason.

Thanks,
Ian.

From f61e6ee1a2a6530dabc15eef86845210d14aa53c Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Fri, 4 May 2018 16:29:17 +0100
Subject: [PATCH v4 3/8] tools: xencall, xengnttab, xengntshr: Provide access
to internal fds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Quoted 4 lines

I want this to support my qemu depriv descriptor audit tool.

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

Acked-by on v4 3/8
#23 lore raw

Re: [PATCH v4 3/8] tools: xencall, xengnttab, xengntshr: Provide access to internal fds

In reply to Ian Jackson
Quoted 23 lines · Ian Jackson

Ian Jackson writes ("[PATCH for-4.12 v2 0/8] tools: Depriv fd checking, internal fd access"):

Quoted 3 lines

This series provides the support in xen.git for auditing whether qemu file descriptors are deprivileged, as expected with libxl dm_restrict=1.

These were all acked.

However, on rebasing to current staging I had a merge conflict in libxengnttab.map. Here is the new version, therefore, with Roger's R-B and Wei's A-B dropped for that reason.

Thanks,
Ian.

From f61e6ee1a2a6530dabc15eef86845210d14aa53c Mon Sep 17 00:00:00 2001
From: Ian Jackson <[email protected]>
Date: Fri, 4 May 2018 16:29:17 +0100
Subject: [PATCH v4 3/8] tools: xencall, xengnttab, xengntshr: Provide access
to internal fds
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Quoted 4 lines

I want this to support my qemu depriv descriptor audit tool.

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