All of lore.kernel.org
 help / color / mirror / Atom feed
* [Virtio-fs] [PATCH] virtiofsd: Open fd O_RDONLY in setxattr/removexattr
@ 2020-01-08 20:24 Vivek Goyal
  2020-01-09  2:23 ` Eryu Guan
  0 siblings, 1 reply; 6+ messages in thread
From: Vivek Goyal @ 2020-01-08 20:24 UTC (permalink / raw)
  To: virtio-fs-list

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>
---
 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;


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-01-10  0:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-01-10  0:50       ` misono.tomohiro

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.