summaryrefslogtreecommitdiffstats
path: root/tools/virtiofsd
diff options
context:
space:
mode:
authorGreg Kurz2021-06-24 12:18:09 +0200
committerDr. David Alan Gilbert2021-07-05 11:51:26 +0200
commit1d03e5660711c40f79917054328e0dc6bcb879a3 (patch)
treeffb792629e4a5e975439029c120d3e2506bbce9b /tools/virtiofsd
parentdocs: describe the security considerations with virtiofsd xattr mapping (diff)
downloadqemu-1d03e5660711c40f79917054328e0dc6bcb879a3.tar.gz
qemu-1d03e5660711c40f79917054328e0dc6bcb879a3.tar.xz
qemu-1d03e5660711c40f79917054328e0dc6bcb879a3.zip
virtiofsd: Don't allow file creation with FUSE_OPEN
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 the client happens to do it anyway, the server ends up passing this flag to open() without the mandatory mode_t 4th argument. Since open() is a variadic function, glibc will happily pass whatever it finds on the stack to the syscall. If this file is compiled with -D_FORTIFY_SOURCE=2, glibc will even detect that and abort: *** invalid openat64 call: O_CREAT or O_TMPFILE without mode ***: terminated Specifying O_CREAT with FUSE_OPEN is a protocol violation. Check this in do_open(), print out a message and return an error to the client, EINVAL like we already do when fuse_mbuf_iter_advance() fails. 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> Message-Id: <20210624101809.48032-1-groug@kaod.org> Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Diffstat (limited to 'tools/virtiofsd')
-rw-r--r--tools/virtiofsd/fuse_lowlevel.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
index 7fe2cef1eb..3d725bcba2 100644
--- a/tools/virtiofsd/fuse_lowlevel.c
+++ b/tools/virtiofsd/fuse_lowlevel.c
@@ -1084,6 +1084,12 @@ static void do_open(fuse_req_t req, fuse_ino_t nodeid,
return;
}
+ /* File creation is handled by do_create() or do_mknod() */
+ if (arg->flags & (O_CREAT | O_TMPFILE)) {
+ fuse_reply_err(req, EINVAL);
+ return;
+ }
+
memset(&fi, 0, sizeof(fi));
fi.flags = arg->flags;
fi.kill_priv = arg->open_flags & FUSE_OPEN_KILL_SUIDGID;