From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Greg Kurz <groug@kaod.org>
Cc: virtio-fs@redhat.com, Miklos Szeredi <miklos@szeredi.hu>,
qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>,
Vivek Goyal <vgoyal@redhat.com>
Subject: Re: [PATCH v2] virtiofsd: Don't allow file creation with FUSE_OPEN
Date: Wed, 30 Jun 2021 19:42:55 +0100 [thread overview]
Message-ID: <YNy7L/9ofbz6QoBB@work-vm> (raw)
In-Reply-To: <20210624101809.48032-1-groug@kaod.org>
* Greg Kurz (groug@kaod.org) wrote:
> 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>
Queued
> ---
>
> v2:
> - do the check in core FUSE code instead of passthrough_ll (libfuse folks)
>
>
> tools/virtiofsd/fuse_lowlevel.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
> index 7fe2cef1eb3b..3d725bcba2ca 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;
> --
> 2.31.1
>
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
prev parent reply other threads:[~2021-06-30 18:56 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 10:18 [PATCH v2] virtiofsd: Don't allow file creation with FUSE_OPEN Greg Kurz
2021-06-30 9:40 ` Dr. David Alan Gilbert
2021-06-30 18:42 ` Dr. David Alan Gilbert [this message]
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=YNy7L/9ofbz6QoBB@work-vm \
--to=dgilbert@redhat.com \
--cc=groug@kaod.org \
--cc=miklos@szeredi.hu \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vgoyal@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).