All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] virtiofsd: Don't allow file creation with FUSE_OPEN
@ 2021-06-17 14:15 ` Greg Kurz
  0 siblings, 0 replies; 20+ messages in thread
From: Greg Kurz @ 2021-06-17 14:15 UTC (permalink / raw)
  To: qemu-devel
  Cc: Miklos Szeredi, Greg Kurz, Dr. David Alan Gilbert, virtio-fs,
	Stefan Hajnoczi, Vivek Goyal

A well behaved FUSE client uses FUSE_CREATE to create files. It isn't
supposed to pass O_CREAT along a FUSE_OPEN request, as documented in
the "fuse_lowlevel.h" header :

    /**
     * Open a file
     *
     * Open flags are available in fi->flags. The following rules
     * apply.
     *
     *  - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
     *    filtered out / handled by the kernel.

But if it does anyway, virtiofsd crashes with:

*** invalid openat64 call: O_CREAT or O_TMPFILE without mode ***: terminated

This is because virtiofsd ends up passing this flag to openat() without
passing a mode_t 4th argument which is mandatory with O_CREAT, and glibc
aborts.

The offending path is:

lo_open()
    lo_do_open()
        lo_inode_open()

Other callers of lo_inode_open() only pass O_RDWR and lo_create()
passes a valid fd to lo_do_open() which thus doesn't even call
lo_inode_open() in this case.

Specifying O_CREAT with FUSE_OPEN is a protocol violation. Check this
in lo_open() and return an error to the client : EINVAL since this is
already what glibc returns with other illegal flag combinations.

The FUSE filesystem doesn't currently support O_TMPFILE, but the very
same would happen if O_TMPFILE was passed in a FUSE_OPEN request. Check
that as well.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 tools/virtiofsd/passthrough_ll.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough_ll.c
index 49c21fd85570..14f62133131c 100644
--- a/tools/virtiofsd/passthrough_ll.c
+++ b/tools/virtiofsd/passthrough_ll.c
@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)
         return;
     }
 
+    /* File creation is handled by lo_create() */
+    if (fi->flags & (O_CREAT | O_TMPFILE)) {
+        fuse_reply_err(req, EINVAL);
+        return;
+    }
+
     err = lo_do_open(lo, inode, -1, fi);
     lo_inode_put(lo, &inode);
     if (err) {
-- 
2.31.1



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

end of thread, other threads:[~2021-06-22 16:04 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17 14:15 [PATCH] virtiofsd: Don't allow file creation with FUSE_OPEN Greg Kurz
2021-06-17 14:15 ` [Virtio-fs] " Greg Kurz
2021-06-17 14:29 ` Dr. David Alan Gilbert
2021-06-17 14:29   ` [Virtio-fs] " Dr. David Alan Gilbert
2021-06-17 16:18   ` Greg Kurz
2021-06-17 16:18     ` [Virtio-fs] " Greg Kurz
2021-06-18  1:40 ` Vivek Goyal
2021-06-18  1:40   ` [Virtio-fs] " Vivek Goyal
2021-06-18  8:20   ` Greg Kurz
2021-06-18  8:20     ` [Virtio-fs] " Greg Kurz
2021-06-18  8:58 ` Miklos Szeredi
2021-06-18  8:58   ` [Virtio-fs] " Miklos Szeredi
2021-06-18  9:21   ` Greg Kurz
2021-06-18  9:21     ` [Virtio-fs] " Greg Kurz
2021-06-18  9:34     ` Miklos Szeredi
2021-06-18  9:34       ` [Virtio-fs] " Miklos Szeredi
2021-06-21 13:36 ` Stefan Hajnoczi
2021-06-21 13:36   ` [Virtio-fs] " Stefan Hajnoczi
2021-06-22 16:01   ` Greg Kurz
2021-06-22 16:01     ` [Virtio-fs] " Greg Kurz

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.