Skip to contentSkip to conversation

run QEMU as non-root

PATCH Superseded Stefano Stabellini 2 participants 4 messages Nov 2, 2015 – Nov 5, 2015

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v9 1/1 run QEMU as non-root

Try to use "xen-qemudepriv-domid$domid" first, then "xen-qemudepriv-shared" and root if everything else fails.

The uids need to be manually created by the user or, more likely, by the xen package maintainer.

Expose a device_model_user setting in libxl_domain_build_info, so that opinionated callers, such as libvirt, can set any user they like. Do not fall back to root if device_model_user is set. Users can also set device_model_user by hand in the xl domain config file.

QEMU is going to setuid and setgid to the user ID and the group ID of the specified user, soon after initialization, before starting to deal with any guest IO.

To actually secure QEMU when running in Dom0, we need at least to deprivilege the privcmd and xenstore interfaces, this is just the first step in that direction.

---

Changes in v9:
- add a device_model_user option to the xl domain config file

Changes in v8:
- no need to pass the -runas option if the user requested for root
- return ERROR_FAIL from libxl__dm_runas_helper in case of errors
- return NULL from libxl__build_device_model_args_new if libxl__dm_runas_helper failed
- fix line too long
- remove setting errno
- replace retry goto loop, with a while loop
- const char * as argument to libxl__dm_runas_helper
- fix comment

Changes in v7:
- do not fall back to root if the user explicitly set b_info->device_model_user.

Changes in v6:
- add device_model_user to libxl_domain_build_info
- improve doc
- improve wording in commit message

Changes in v5:
- improve wording in doc
- fix wording in warning message
- fix example in doc
- drop xen-qemudepriv-$domname

Changes in v4:
- rename qemu-deprivilege to qemu-deprivilege.txt
- add a note about qemu-deprivilege.txt to INSTALL
- instead of xen-qemudepriv-base + $domid, try xen-qemudepriv-domid$domid
- introduce libxl__dm_runas_helper to make the code nicer

Changes in v3:
- clarify doc
- handle errno == ERANGE

---
 INSTALL                      |    7 +++++
 docs/man/xl.cfg.pod.5        |    5 ++++
 tools/libxl/libxl.h          |    5 ++++
 tools/libxl/libxl_dm.c       |   67 +++++++++++++++++++++++++++++++++++++++++-
 tools/libxl/libxl_internal.h |    5 ++++
 tools/libxl/libxl_types.idl  |    1 +
 tools/libxl/xl_cmdimpl.c     |    3 ++
 7 files changed, 92 insertions(+), 1 deletion(-)
INSTALL +7 -0
index 56e2950..b7e426c 100644
@@ -304,6 +304,13 @@ systemctl enable xendomains.service
 systemctl enable xen-watchdog.service
 
 
+QEMU Deprivilege
+================
+It is recommended to run QEMU as non-root.
+See docs/misc/qemu-deprivilege.txt for an explanation on what you need
+to do at installation time to run QEMU as a dedicated user.
+
+
 History of options
 ==================
 
docs/man/xl.cfg.pod.5 +5 -0
index d422924..615822a 100644
@@ -1785,6 +1785,11 @@ Pass additional arbitrary options on the device-model command line for
 an HVM device model only. Each element in the list is passed as an
 option to the device-model.
 
+=item B<device_model_user="username">
+
+Run the device model as user "username", instead of
+xen-qemudepriv-domid$domid or xen-qemudepriv-shared or root.
+
 =back
 
 =head2 Keymaps
tools/libxl/libxl.h +5 -0
index fa5aedd..108e8fa 100644
@@ -204,6 +204,11 @@
  */
 #define LIBXL_HAVE_BUILDINFO_ARM_GIC_VERSION 1
 
+/* libxl_domain_build_info has device_model_user to specify the user to
+ * run the device model with. See docs/misc/qemu-deprivilege.txt.
+ */
+#define LIBXL_HAVE_DEVICE_MODEL_USER 1
+
 /*
  * libxl ABI compatibility
  *
tools/libxl/libxl_dm.c +66 -1

93 lines not on this page · raw message

tools/libxl/libxl_internal.h +5 -0
index 1699f32..41e8607 100644
@@ -4010,6 +4010,11 @@ void libxl__bitmap_copy_best_effort(libxl__gc *gc, libxl_bitmap *dptr,
                                     const libxl_bitmap *sptr);
 
 int libxl__count_physical_sockets(libxl__gc *gc, int *sockets);
+
+
+#define LIBXL_QEMU_USER_PREFIX "xen-qemuuser"
+#define LIBXL_QEMU_USER_BASE   LIBXL_QEMU_USER_PREFIX"-domid"
+#define LIBXL_QEMU_USER_SHARED LIBXL_QEMU_USER_PREFIX"-shared"
 #endif
 
 /*
tools/libxl/libxl_types.idl +1 -0
index 502a148..8cd78a8 100644
@@ -432,6 +432,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
     ("device_model",     string),
     ("device_model_ssidref", uint32),
     ("device_model_ssid_label", string),
+    ("device_model_user", string),
 
     # extra parameters pass directly to qemu, NULL terminated
     ("extra",            libxl_string_list),
tools/libxl/xl_cmdimpl.c +3 -0
index 9a2870e..1fe0be6 100644
@@ -2190,6 +2190,9 @@ skip_vfb:
         xlu_cfg_replace_string(config, "device_model_stubdomain_seclabel",
                                &b_info->device_model_ssid_label, 0);
 
+    xlu_cfg_replace_string(config, "device_model_user",
+                           &b_info->device_model_user, 0);
+
 #define parse_extra_args(type)                                            \
     e = xlu_cfg_get_list_as_string_list(config, "device_model_args"#type, \
                                     &b_info->extra##type, 0);            \
Signature · 1 line
1.7.10.4
Acked-by on v9 1/1
#1 lore raw
Quoted 15 lines · Stefano Stabellini

Try to use "xen-qemudepriv-domid$domid" first, then "xen-qemudepriv-shared" and root if everything else fails.

The uids need to be manually created by the user or, more likely, by the xen package maintainer.

Expose a device_model_user setting in libxl_domain_build_info, so that opinionated callers, such as libvirt, can set any user they like. Do not fall back to root if device_model_user is set. Users can also set device_model_user by hand in the xl domain config file.

QEMU is going to setuid and setgid to the user ID and the group ID of the specified user, soon after initialization, before starting to deal with any guest IO.

Quoted 5 lines

To actually secure QEMU when running in Dom0, we need at least to deprivilege the privcmd and xenstore interfaces, this is just the first step in that direction.

(based on previous plus eyeballing only the changes from:

Quoted 3 lines


Changes in v9:
- add a device_model_user option to the xl domain config file

Ian.

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

#2 lore raw
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Stefano Stabellini

Try to use "xen-qemudepriv-domid$domid" first, then "xen-qemudepriv-shared" and root if everything else fails.

The uids need to be manually created by the user or, more likely, by the
xen package maintainer.

Expose a device_model_user setting in libxl_domain_build_info, so that opinionated callers, such as libvirt, can set any user they like. Do not
fall back to root if device_model_user is set. Users can also set device_model_user by hand in the xl domain config file.

QEMU is going to setuid and setgid to the user ID and the group ID of the specified user, soon after initialization, before starting to deal with any guest IO.

Quoted 7 lines
Quoted 5 lines

To actually secure QEMU when running in Dom0, we need at least to deprivilege the privcmd and xenstore interfaces, this is just the first step in that direction.

There were some minor conflicts against some patches committed at the start of October. I had fixed them up (I think) but then I noticed that docs/misc/qemu-deprivilege.txt in my working tree wasn't actually committed.

Since this patch refers to it, but didn't include it I checked before acking that it was already in tree some how, but didn't realise it wasn't actually committed (somehow, not sure how). Was it supposed to be in this patch or was it supposed to be in some earlier patch?

In any case given something odd is clearly going on I don't want to just commit some random version of that doc which I just found in my working directory along with this patch. Please can you resubmit with that file included (or in a precursor patch).

Also please check the coding style of the comment in libxl.h, the "/*" should be by itself.

Thanks,
Ian.

Quoted 6 lines

(based on previous plus eyeballing only the changes from:

Quoted 3 lines


Changes in v9:
- add a device_model_user option to the xl domain config file

Quoted 6 lines

Ian.

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

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

#3 lore raw
Quoted 37 lines · Ian Campbell
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Stefano Stabellini

Try to use "xen-qemudepriv-domid$domid" first, then "xen-qemudepriv-shared" and root if everything else fails.

The uids need to be manually created by the user or, more likely, by the
xen package maintainer.

Expose a device_model_user setting in libxl_domain_build_info, so that opinionated callers, such as libvirt, can set any user they like. Do not
fall back to root if device_model_user is set. Users can also set device_model_user by hand in the xl domain config file.

QEMU is going to setuid and setgid to the user ID and the group ID of the specified user, soon after initialization, before starting to deal with any guest IO.

Quoted 7 lines
Quoted 5 lines

To actually secure QEMU when running in Dom0, we need at least to deprivilege the privcmd and xenstore interfaces, this is just the first step in that direction.

There were some minor conflicts against some patches committed at the start of October. I had fixed them up (I think) but then I noticed that docs/misc/qemu-deprivilege.txt in my working tree wasn't actually committed.

Since this patch refers to it, but didn't include it I checked before acking that it was already in tree some how, but didn't realise it wasn't actually committed (somehow, not sure how). Was it supposed to be in this patch or was it supposed to be in some earlier patch?

Quoted 4 lines

In any case given something odd is clearly going on I don't want to just commit some random version of that doc which I just found in my working directory along with this patch. Please can you resubmit with that file included (or in a precursor patch).

Done, see v10

Quoted 2 lines

Also please check the coding style of the comment in libxl.h, the "/*" should be by itself.

Sorry I forgot this change! Feel free to fix it as you commit if that's OK for you.

Quoted 16 lines

Thanks,
Ian.

Quoted 12 lines

(based on previous plus eyeballing only the changes from:

Quoted 3 lines


Changes in v9:
- add a device_model_user option to the xl domain config file

Ian.

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

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