]> xenbits.xensource.com Git - people/sstabellini/xen-unstable.git/.git/commitdiff
tools/dm_restrict: Unshare mount and IPC namespaces on Linux
authorGeorge Dunlap <george.dunlap@citrix.com>
Tue, 6 Nov 2018 15:41:24 +0000 (15:41 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Tue, 6 Nov 2018 15:41:24 +0000 (15:41 +0000)
QEMU running under Xen doesn't need mount or IPC functionality.
Create and enter separate namespaces for each of these before
executing QEMU, so that in the event that other restrictions fail, the
process won't be able to even name system mount points or exsting
non-file-based IPC descriptors to attempt to attack them.

Unsharing is something a process can only do to itself (it would
seem); so add an os-specific "dm_preexec_restrict()" hook just before
we exec() the device model.

Also add checks to depriv-process-checker.sh to verify that dm is
running in a new namespace (or at least, a different one than the
caller).

Suggested-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
Changes since v4:
- Fix function prototype for netbsd code

Changes since v3:
- Fix some more style issues

Changes since v2:
- Return an error rather than calling exit()
- Use LOGE() and print to the current stderr fd, rather than
  printing to the new stderr fd via write()
- Use r for external return values rather than rc.

CC: Ian Jackson <ian.jackson@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Anthony Perard <anthony.perard@citrix.com>
docs/designs/qemu-deprivilege.md
tools/libxl/libxl_dm.c
tools/libxl/libxl_freebsd.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_linux.c
tools/libxl/libxl_netbsd.c

index 82b0e15d817477b5722e3ba98a0defcfe4d3f4a0..65754ba6eecf17771c8a019949dfc753ba3092b7 100644 (file)
@@ -76,12 +76,6 @@ Then adds the following to the qemu command-line:
        
 '''Tested''': Not tested
 
-## Restrictions / improvements still to do
-
-This lists potential restrictions still to do.  It is meant to be
-listed in order of ease of implementation, with low-hanging fruit
-first.
-
 ## Namespaces for unused functionality (Linux only)
 
 '''Description''': QEMU doesn't use the functionality associated with
@@ -109,6 +103,12 @@ call:
 
 [qemu-namespaces]: https://lists.gnu.org/archive/html/qemu-devel/2017-10/msg04723.html
 
+# Restrictions / improvements still to do
+
+This lists potential restrictions still to do.  It is meant to be
+listed in order of ease of implementation, with low-hanging fruit
+first.
+
 ### Basic RLIMITs
 
 '''Description''': A number of limits on the resources that a given
index bb3e3a625c9c4f30cda0e36f070d8788616bddd3..9c4706047378545df9c751c9ab45e4f00d8f0f1c 100644 (file)
@@ -2393,6 +2393,11 @@ retry_transaction:
         goto out_close;
     if (!rc) { /* inner child */
         setsid();
+        if (libxl_defbool_val(b_info->dm_restrict)) {
+            rc = libxl__local_dm_preexec_restrict(gc);
+            if (rc)
+                _exit(-1);
+        }
         libxl__exec(gc, null, logfile_w, logfile_w, dm, args, envs);
     }
 
index 6442ccec724ce90444ba2e6b96476ccf2c99cf7d..f7ef4a891048caf66bf53d5f6ad3f815abf3aeda 100644 (file)
@@ -245,3 +245,8 @@ int libxl__pci_topology_init(libxl__gc *gc,
 {
     return ERROR_NI;
 }
+
+int libxl__local_dm_preexec_restrict(libxl__gc *gc)
+{
+    return 0;
+}
index ff889385fe8e44a3945ce421363f59a9e8090c01..e498435e1608bcb6791f2d7c62c0c23539e8491e 100644 (file)
@@ -3774,6 +3774,11 @@ struct libxl__dm_spawn_state {
 
 _hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*);
 
+/* 
+ * Called after forking but before executing the local devicemodel.
+ */
+_hidden int libxl__local_dm_preexec_restrict(libxl__gc *gc);
+
 /* Stubdom device models. */
 
 typedef struct {
index 6ef0abc6934b44ee7ccf7cdcb4cde6284e882ec5..c7a345f4bb7a2217b54248ae4e3f98a8edea1fa6 100644 (file)
@@ -307,6 +307,20 @@ int libxl__pci_topology_init(libxl__gc *gc,
     return err;
 }
 
+int libxl__local_dm_preexec_restrict(libxl__gc *gc)
+{
+    int r;
+
+    /* Unshare mount and IPC namespaces.  These are unused by QEMU. */
+    r = unshare(CLONE_NEWNS | CLONE_NEWIPC);
+    if (r) {
+        LOGE(ERROR, "libxl: Mount and IPC namespace unfailed");
+        return ERROR_FAIL;
+    }
+
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
index 2edfb00641e1bab774b1f7022f6dbb17d991ab01..e66a393d7fb418062fe2c52205d7977db506d3c9 100644 (file)
@@ -124,3 +124,8 @@ int libxl__pci_topology_init(libxl__gc *gc,
 {
     return ERROR_NI;
 }
+
+int libxl__local_dm_preexec_restrict(libxl__gc *gc)
+{
+    return 0;
+}