All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: "misono.tomohiro@fujitsu.com" <misono.tomohiro@fujitsu.com>
Cc: virtio-fs-list <virtio-fs@redhat.com>
Subject: Re: [Virtio-fs] [PATCH] virtiofsd: Open fd O_RDONLY in setxattr/removexattr
Date: Thu, 9 Jan 2020 14:10:28 -0500	[thread overview]
Message-ID: <20200109191028.GC1964@redhat.com> (raw)
In-Reply-To: <OSBPR01MB4582182B3FFD047E2FEC6326E5390@OSBPR01MB4582.jpnprd01.prod.outlook.com>

On Thu, Jan 09, 2020 at 09:27:15AM +0000, misono.tomohiro@fujitsu.com wrote:
> > On Wed, Jan 08, 2020 at 03:24:22PM -0500, Vivek Goyal wrote:
> > > Do not open fd O_RDWR as it will fail for directories with EISDIR.
> > > This code can be called both for regular files as well as directories.
> > >
> > > I noticed this when I tried "setfattr -n user.foo -v test <dir>"
> > > inside the guest and got EISDIR.
> > >
> > > To write xattr, we don't have to open fd with write permissions. Looks
> > > like kernel will do permission checks on inode.
> > >
> > > Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
> > 
> > Looks good to me.
> > 
> > Reviewed-by: Eryu Guan <eguan@linux.alibaba.com>
> > 
> > > ---
> > >  contrib/virtiofsd/passthrough_ll.c |    4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > Index: qemu/contrib/virtiofsd/passthrough_ll.c
> > > ===================================================================
> > > --- qemu.orig/contrib/virtiofsd/passthrough_ll.c	2020-01-08 15:01:03.821980889 -0500
> > > +++ qemu/contrib/virtiofsd/passthrough_ll.c	2020-01-08 15:05:15.209384352 -0500
> > > @@ -2424,7 +2424,7 @@ static void lo_setxattr(fuse_req_t req,
> > >  	}
> > >
> > >  	sprintf(procname, "%i", inode->fd);
> > > -	fd = openat(lo->proc_self_fd, procname, O_RDWR);
> > > +	fd = openat(lo->proc_self_fd, procname, O_RDONLY);
> > >  	if (fd < 0) {
> > >  		saverr = errno;
> > >  		goto out;
> > > @@ -2473,7 +2473,7 @@ static void lo_removexattr(fuse_req_t re
> > >  	}
> > >
> > >  	sprintf(procname, "%i", inode->fd);
> > > -	fd = openat(lo->proc_self_fd, procname, O_RDWR);
> > > +	fd = openat(lo->proc_self_fd, procname, O_RDONLY);
> > >  	if (fd < 0) {
> > >  		saverr = errno;
> > >  		goto out;
> > >
> 
> Hello,
> 
> So I sent the same patch last October[1] and got comments
> that it's would be better to fix the fundamental problem
> (do not call openat() to non regular file/directory) [2].
>   [1] https://www.redhat.com/archives/virtio-fs/2019-October/msg00030.html
>   [2] https://www.redhat.com/archives/virtio-fs/2019-October/msg00046.html
>  
> I tried the suggested approach which uses fchdir(proc_self_fd) + ...xattr() + fchdir(root.fd)
> combination instead of current openat() + f...xattr(). 
> However, it seems that always fchdir on xattr operation for regular files too incurs
> some performance overhead (~10% or more).
>  
> So I think hybrid approach is better: 
>   For regular file/directory: use f...xattr
>   For other file types: use fchdir + ...xattr + fchdir 
>  
> Attached patch adopts the above solution.

Hi Misono,

Can you post this patch again separately so that it is easier to give
comments and discuss this patch. I have a quick look and this patch
does look reasonable.

Only minor concern I have is that now each thread has done unshare(CLONE_FS).
Will we run into use cases where we want to enforce a particular change
aross all threads.

Thanks
Vivek


  parent reply	other threads:[~2020-01-09 19:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-08 20:24 [Virtio-fs] [PATCH] virtiofsd: Open fd O_RDONLY in setxattr/removexattr Vivek Goyal
2020-01-09  2:23 ` Eryu Guan
2020-01-09  9:27   ` misono.tomohiro
2020-01-09 17:56     ` Vivek Goyal
2020-01-09 19:10     ` Vivek Goyal [this message]
2020-01-10  0:50       ` misono.tomohiro

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=20200109191028.GC1964@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=misono.tomohiro@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.