From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Miklos Szeredi <mszeredi@redhat.com>
Cc: virtio-fs@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Virtio-fs] [PATCH] virtiofsd: jail lo->proc_self_fd
Date: Fri, 1 May 2020 18:47:21 +0100 [thread overview]
Message-ID: <20200501174721.GB38251@work-vm> (raw)
In-Reply-To: <20200429124733.22488-1-mszeredi@redhat.com>
* Miklos Szeredi (mszeredi@redhat.com) wrote:
> While it's not possible to escape the proc filesystem through
> lo->proc_self_fd, it is possible to escape to the root of the proc
> filesystem itself through "../..".
>
> Use a temporary mount for opening lo->proc_self_fd, that has it's root at
> /proc/self/fd/, preventing access to the ancestor directories.
>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Queued
> ---
> tools/virtiofsd/passthrough_ll.c | 27 +++++++++++++++++++++++++--
> 1 file changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index 4c35c95b256c..bc9c44c760f4 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -2536,6 +2536,8 @@ static void print_capabilities(void)
> static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
> {
> pid_t child;
> + char template[] = "virtiofsd-XXXXXX";
> + char *tmpdir;
>
> /*
> * Create a new pid namespace for *child* processes. We'll have to
> @@ -2597,12 +2599,33 @@ static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
> exit(1);
> }
>
> + tmpdir = mkdtemp(template);
> + if (!tmpdir) {
> + fuse_log(FUSE_LOG_ERR, "tmpdir(%s): %m\n", template);
> + exit(1);
> + }
> +
> + if (mount("/proc/self/fd", tmpdir, NULL, MS_BIND, NULL) < 0) {
> + fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, %s, MS_BIND): %m\n",
> + tmpdir);
> + exit(1);
> + }
> +
> /* Now we can get our /proc/self/fd directory file descriptor */
> - lo->proc_self_fd = open("/proc/self/fd", O_PATH);
> + lo->proc_self_fd = open(tmpdir, O_PATH);
> if (lo->proc_self_fd == -1) {
> - fuse_log(FUSE_LOG_ERR, "open(/proc/self/fd, O_PATH): %m\n");
> + fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", tmpdir);
> exit(1);
> }
> +
> + if (umount2(tmpdir, MNT_DETACH) < 0) {
> + fuse_log(FUSE_LOG_ERR, "umount2(%s, MNT_DETACH): %m\n", tmpdir);
> + exit(1);
> + }
> +
> + if (rmdir(tmpdir) < 0) {
> + fuse_log(FUSE_LOG_ERR, "rmdir(%s): %m\n", tmpdir);
> + }
> }
>
> /*
> --
> 2.21.1
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
WARNING: multiple messages have this Message-ID (diff)
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Miklos Szeredi <mszeredi@redhat.com>
Cc: virtio-fs@redhat.com, qemu-devel@nongnu.org
Subject: Re: [PATCH] virtiofsd: jail lo->proc_self_fd
Date: Fri, 1 May 2020 18:47:21 +0100 [thread overview]
Message-ID: <20200501174721.GB38251@work-vm> (raw)
In-Reply-To: <20200429124733.22488-1-mszeredi@redhat.com>
* Miklos Szeredi (mszeredi@redhat.com) wrote:
> While it's not possible to escape the proc filesystem through
> lo->proc_self_fd, it is possible to escape to the root of the proc
> filesystem itself through "../..".
>
> Use a temporary mount for opening lo->proc_self_fd, that has it's root at
> /proc/self/fd/, preventing access to the ancestor directories.
>
> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Queued
> ---
> tools/virtiofsd/passthrough_ll.c | 27 +++++++++++++++++++++++++--
> 1 file changed, 25 insertions(+), 2 deletions(-)
>
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index 4c35c95b256c..bc9c44c760f4 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -2536,6 +2536,8 @@ static void print_capabilities(void)
> static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
> {
> pid_t child;
> + char template[] = "virtiofsd-XXXXXX";
> + char *tmpdir;
>
> /*
> * Create a new pid namespace for *child* processes. We'll have to
> @@ -2597,12 +2599,33 @@ static void setup_namespaces(struct lo_data *lo, struct fuse_session *se)
> exit(1);
> }
>
> + tmpdir = mkdtemp(template);
> + if (!tmpdir) {
> + fuse_log(FUSE_LOG_ERR, "tmpdir(%s): %m\n", template);
> + exit(1);
> + }
> +
> + if (mount("/proc/self/fd", tmpdir, NULL, MS_BIND, NULL) < 0) {
> + fuse_log(FUSE_LOG_ERR, "mount(/proc/self/fd, %s, MS_BIND): %m\n",
> + tmpdir);
> + exit(1);
> + }
> +
> /* Now we can get our /proc/self/fd directory file descriptor */
> - lo->proc_self_fd = open("/proc/self/fd", O_PATH);
> + lo->proc_self_fd = open(tmpdir, O_PATH);
> if (lo->proc_self_fd == -1) {
> - fuse_log(FUSE_LOG_ERR, "open(/proc/self/fd, O_PATH): %m\n");
> + fuse_log(FUSE_LOG_ERR, "open(%s, O_PATH): %m\n", tmpdir);
> exit(1);
> }
> +
> + if (umount2(tmpdir, MNT_DETACH) < 0) {
> + fuse_log(FUSE_LOG_ERR, "umount2(%s, MNT_DETACH): %m\n", tmpdir);
> + exit(1);
> + }
> +
> + if (rmdir(tmpdir) < 0) {
> + fuse_log(FUSE_LOG_ERR, "rmdir(%s): %m\n", tmpdir);
> + }
> }
>
> /*
> --
> 2.21.1
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2020-05-01 17:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-29 12:47 [Virtio-fs] [PATCH] virtiofsd: jail lo->proc_self_fd Miklos Szeredi
2020-04-29 12:47 ` Miklos Szeredi
2020-04-29 14:36 ` [Virtio-fs] " Vivek Goyal
2020-04-29 14:47 ` Miklos Szeredi
2020-04-29 14:50 ` Miklos Szeredi
2020-04-29 15:00 ` Vivek Goyal
2020-04-29 15:05 ` Miklos Szeredi
2020-04-29 15:26 ` Stefan Hajnoczi
2020-04-29 16:32 ` Dr. David Alan Gilbert
2020-04-29 16:32 ` Dr. David Alan Gilbert
2020-05-01 17:47 ` Dr. David Alan Gilbert [this message]
2020-05-01 17:47 ` Dr. David Alan Gilbert
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=20200501174721.GB38251@work-vm \
--to=dgilbert@redhat.com \
--cc=mszeredi@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=virtio-fs@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.