From: Vivek Goyal <vgoyal@redhat.com>
To: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
Cc: virtio-fs@redhat.com
Subject: Re: [Virtio-fs] [PATCH v2 1/2] virtiofsd: Fix xattr operations
Date: Thu, 30 Jan 2020 09:58:55 -0500 [thread overview]
Message-ID: <20200130145855.GA26448@redhat.com> (raw)
In-Reply-To: <20200128101819.21766-2-misono.tomohiro@jp.fujitsu.com>
On Tue, Jan 28, 2020 at 07:18:18PM +0900, Misono Tomohiro wrote:
> Current virtiofsd has problems about xattr operations and
> they does not work properly for directory/symlink/special file.
>
> The fundamental cause is that virtiofsd uses openat() + f...xattr()
> systemcalls for xattr operation but we should not open symlink/special
> file in the daemon. Therefore the function is restricted.
>
> Fix this problem by:
> 1. during setup of each thread, call unshare(CLONE_FS) so that chdir
> would not affect other threads
> 2. in xattr operations (i.e. lo_getxattr), use
> fchdir(proc_loot_fd) + ...xattr() + fchdir(root.fd)
> instead of openat() + f...xattr() to avoid open files
>
> With this patch, xfstests generic/062 passes on virtiofs.
> This fix is suggested by Miklos Szeredi and Stefan Hajnoczi.
>
> Signed-off-by: Misono Tomohiro <misono.tomohiro@jp.fujitsu.com>
> ---
> tools/virtiofsd/fuse_virtio.c | 13 ++++
> tools/virtiofsd/passthrough_ll.c | 100 +++++++++++++++++++------------
> tools/virtiofsd/seccomp.c | 10 ++--
> 3 files changed, 81 insertions(+), 42 deletions(-)
>
> diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
> index 1aac6b8687..ad03a7dcc0 100644
> --- a/tools/virtiofsd/fuse_virtio.c
> +++ b/tools/virtiofsd/fuse_virtio.c
> @@ -463,6 +463,8 @@ err:
> return ret;
> }
>
> +static __thread bool clone_fs_called;
> +
> /* Process one FVRequest in a thread pool */
> static void fv_queue_worker(gpointer data, gpointer user_data)
> {
> @@ -478,6 +480,17 @@ static void fv_queue_worker(gpointer data, gpointer user_data)
>
> assert(se->bufsize > sizeof(struct fuse_in_header));
>
> + if (!clone_fs_called) {
> + int ret;
> +
> + /* unshare FS for xattr operation */
> + ret = unshare(CLONE_FS);
> + /* should not fail */
> + assert(ret == 0);
> +
> + clone_fs_called = true;
> + }
> +
> /*
> * An element contains one request and the space to send our response
> * They're spread over multiple descriptors in a scatter/gather set
> diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
> index f0093ab84e..6bcc33e0eb 100644
> --- a/tools/virtiofsd/passthrough_ll.c
> +++ b/tools/virtiofsd/passthrough_ll.c
> @@ -2362,6 +2362,7 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
> ssize_t ret;
> int saverr;
> int fd = -1;
> + bool dir_changed = false;
>
> inode = lo_inode(req, ino);
> if (!inode) {
> @@ -2377,17 +2378,14 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
> fuse_log(FUSE_LOG_DEBUG, "lo_getxattr(ino=%" PRIu64 ", name=%s size=%zd)\n",
> ino, name, size);
>
> - if (inode->is_symlink) {
> - /* Sorry, no race free way to getxattr on symlink. */
> - saverr = EPERM;
> - goto out;
> - }
> -
> sprintf(procname, "%i", inode->fd);
> - fd = openat(lo->proc_self_fd, procname, O_RDONLY);
> - if (fd < 0) {
> + ret = fchdir(lo->proc_self_fd);
> + if (ret < 0) {
> + /* should not happen */
> + fuse_log(FUSE_LOG_ERR, "lo_getxattr: fail fchdir to proc_self_fd\n");
> goto out_err;
> }
> + dir_changed = true;
>
> if (size) {
> value = malloc(size);
I am wondering, is it better to allocate memory first (if need be) and
then do fchdir(). If memory allocation fails, we can return error right
away without having to do fchdir() twice.
Also do we need dir_changed variable? I think if we organize labels
properly, we should be able to get rid of this dir_changed variable.
Same comments apply to lo_listxattr() as well.
Thanks
Vivek
next prev parent reply other threads:[~2020-01-30 14:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 10:18 [Virtio-fs] [PATCH v2 0/2] virtiofsd: Fix xattr and ACL Misono Tomohiro
2020-01-28 10:18 ` [Virtio-fs] [PATCH v2 1/2] virtiofsd: Fix xattr operations Misono Tomohiro
2020-01-30 14:58 ` Vivek Goyal [this message]
2020-01-31 1:57 ` misono.tomohiro
2020-01-28 10:18 ` [Virtio-fs] [PATCH v2 2/2] virtiofsd: Add support of posix_acl Misono Tomohiro
2020-01-30 15:02 ` Vivek Goyal
2020-01-31 1:59 ` misono.tomohiro
2020-01-30 14:13 ` [Virtio-fs] [PATCH v2 0/2] virtiofsd: Fix xattr and ACL Vivek Goyal
2020-01-31 2:06 ` misono.tomohiro
2020-02-14 20:37 ` Vivek Goyal
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=20200130145855.GA26448@redhat.com \
--to=vgoyal@redhat.com \
--cc=misono.tomohiro@jp.fujitsu.com \
--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.