From: Paul Durrant <Paul.Durrant@citrix.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: Anthony Perard <anthony.perard@citrix.com>,
Ian Jackson <Ian.Jackson@citrix.com>,
Wei Liu <wei.liu2@citrix.com>,
George Dunlap <George.Dunlap@citrix.com>
Subject: Re: [PATCH v4 3/6] tools/dm_restrict: Ask QEMU to chroot
Date: Tue, 6 Nov 2018 09:14:26 +0000 [thread overview]
Message-ID: <47ff2f996ada4b23b58265aea74e62af@AMSPEX02CL03.citrite.net> (raw)
In-Reply-To: <20181105180711.20322-3-george.dunlap@citrix.com>
> -----Original Message-----
> From: Xen-devel [mailto:xen-devel-bounces@lists.xenproject.org] On Behalf
> Of George Dunlap
> Sent: 05 November 2018 18:07
> To: xen-devel@lists.xenproject.org
> Cc: Anthony Perard <anthony.perard@citrix.com>; Ian Jackson
> <Ian.Jackson@citrix.com>; Wei Liu <wei.liu2@citrix.com>; George Dunlap
> <George.Dunlap@citrix.com>
> Subject: [Xen-devel] [PATCH v4 3/6] tools/dm_restrict: Ask QEMU to chroot
>
> When dm_restrict is enabled, ask QEMU to chroot into an empty directory.
>
> * Create /var/run/qemu/root-domid (deleting the old one if it's there)
This does not appear to match the code: the path should be /var/run/qemu-root-<domid> AFAICT
> * Pass the -chroot option to QEMU
>
> Rather than running `rm -rf` on the directory before creating it
> (since there is no library function to do this), simply rmdir the
> directory, relying on the fact that the previous QEMU instance, if
> properly restricted, shouldn't have been able to write anything
> anyway.
>
> 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 v2:
> - Style fixes
> - Testing moved to a different patch
>
> 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 | 12 +++++-----
> tools/libxl/libxl_dm.c | 41 +++++++++++++++++++++++++++++++-
> 2 files changed, 46 insertions(+), 7 deletions(-)
>
> diff --git a/docs/designs/qemu-deprivilege.md b/docs/designs/qemu-
> deprivilege.md
> index 787ae1ac7c..0395bbbb40 100644
> --- a/docs/designs/qemu-deprivilege.md
> +++ b/docs/designs/qemu-deprivilege.md
> @@ -61,12 +61,6 @@ source tree.)
>
> '''Testing status''': 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.
> -
> ## Chroot
>
> '''Description''': Qemu runs in its own chroot, such that even if it
> @@ -84,6 +78,12 @@ 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
> diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
> index 26eb16af34..ad3efcc783 100644
> --- a/tools/libxl/libxl_dm.c
> +++ b/tools/libxl/libxl_dm.c
> @@ -1410,9 +1410,48 @@ static int
> libxl__build_device_model_args_new(libxl__gc *gc,
> }
> }
>
> - if (libxl_defbool_val(b_info->dm_restrict))
> + if (libxl_defbool_val(b_info->dm_restrict)) {
> + char *chroot_dir = GCSPRINTF("%s/qemu-root-%d",
> + libxl__run_dir_path(),
> guest_domid);
> + int r;
> +
> flexarray_append(dm_args, "-xen-domid-restrict");
>
> + /*
> + * Run QEMU in a chroot at XEN_RUN_DIR/qemu-root-%d
Maybe '<domid>' in the comment rather than '%d'?
> + *
> + * There is no library function to do the equivalent of `rm
> + * -rf`. However deprivileged QEMU in theory shouldn't be
> + * able to write any files, as the chroot would be owned by
> + * root, but it would be running as an unprivileged process.
> + * So in theory, old chroots should always be empty.
How does logging work if QEMU can't write to the chroot? I assume we are relying on stderr? Does using syslog still work?
Paul
> + *
> + * rmdir the directory before attempting to create
> + * it; if it returns anything other than ENOENT, fail domain
> + * creation.
> + */
> + r = rmdir(chroot_dir);
> + if (r != 0 && errno != ENOENT) {
> + LOGED(ERROR, guest_domid,
> + "failed to remove existing chroot dir %s", chroot_dir);
> + return ERROR_FAIL;
> + }
> +
> + for (;;) {
> + r = mkdir(chroot_dir, 0000);
> + if (!r)
> + break;
> + if (errno == EINTR) continue;
> + LOGED(ERROR, guest_domid,
> + "failed to create chroot dir %s", chroot_dir);
> + return ERROR_FAIL;
> + }
> +
> + /* Add "-chroot [dir]" to command-line */
> + flexarray_append(dm_args, "-chroot");
> + flexarray_append(dm_args, chroot_dir);
> + }
> +
> if (state->saved_state) {
> /* This file descriptor is meant to be used by QEMU */
> *dm_state_fd = open(state->saved_state, O_RDONLY);
> --
> 2.19.1
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-11-06 9:14 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-05 18:07 [PATCH v4 1/6] docs/qemu-deprivilege: Revise and update with status and future plans George Dunlap
2018-11-05 18:07 ` [PATCH v4 2/6] SUPPORT.md: Add qemu-depriv section George Dunlap
2018-11-06 9:08 ` Paul Durrant
2018-11-06 12:14 ` George Dunlap
2018-11-06 11:50 ` Ian Jackson
2018-11-05 18:07 ` [PATCH v4 3/6] tools/dm_restrict: Ask QEMU to chroot George Dunlap
2018-11-06 9:14 ` Paul Durrant [this message]
2018-11-06 10:28 ` George Dunlap
2018-11-06 10:53 ` Paul Durrant
2018-11-06 11:11 ` Anthony PERARD
2018-11-06 11:12 ` Paul Durrant
2018-11-05 18:07 ` [PATCH v4 4/6] tools/dm_restrict: Unshare mount and IPC namespaces on Linux George Dunlap
2018-11-06 9:16 ` Paul Durrant
2018-11-06 10:29 ` George Dunlap
2018-11-05 18:07 ` [PATCH v4 5/6] tools/dm_depriv: Add first cut RLIMITs George Dunlap
2018-11-06 9:22 ` Paul Durrant
2018-11-06 10:39 ` George Dunlap
2018-11-06 11:52 ` Ian Jackson
2018-11-05 18:07 ` [PATCH v4 6/6] RFC: test/depriv: Add a tool to check process-level depriv George Dunlap
2018-11-06 9:34 ` Paul Durrant
2018-11-06 10:43 ` George Dunlap
2018-11-05 18:08 ` [PATCH v4 1/6] docs/qemu-deprivilege: Revise and update with status and future plans George Dunlap
2018-11-06 9:07 ` Paul Durrant
2018-11-06 11:06 ` Anthony PERARD
2018-11-06 11:50 ` Ian Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47ff2f996ada4b23b58265aea74e62af@AMSPEX02CL03.citrite.net \
--to=paul.durrant@citrix.com \
--cc=George.Dunlap@citrix.com \
--cc=Ian.Jackson@citrix.com \
--cc=anthony.perard@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).