From: "Darrick J. Wong" <djwong@kernel.org>
To: Brajesh Patil <brajeshpatil11@gmail.com>
Cc: miklos@szeredi.hu, stefanha@redhat.com, vgoyal@redhat.com,
eperezma@redhat.com, virtualization@lists.linux.dev,
virtio-fs@lists.linux.dev, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
linux-kernel-mentees@lists.linux.dev,
david.hunter.linux@gmail.com, khalid@kernel.org
Subject: Re: [PATCH] fuse: virtio_fs: add checks for FUSE protocol compliance
Date: Tue, 28 Oct 2025 23:01:08 -0700 [thread overview]
Message-ID: <20251029060108.GR4015566@frogsfrogsfrogs> (raw)
In-Reply-To: <c7zugpb4pzquasx67zypnuk2irxvb7cp5puwuw3rncy6gb5wdn@qigavsewium3>
On Wed, Oct 29, 2025 at 08:58:30AM +0530, Brajesh Patil wrote:
> On Tue, Oct 28, 2025 at 01:07:55PM -0700, Darrick J. Wong wrote:
> > On Wed, Oct 29, 2025 at 01:33:11AM +0530, Brajesh Patil wrote:
> > > Add validation in virtio-fs to ensure the server follows the FUSE
> > > protocol for response headers, addressing the existing TODO for
> > > verifying protocol compliance.
> > >
> > > Add checks for fuse_out_header to verify:
> > > - oh->unique matches req->in.h.unique
> > > - FUSE_INT_REQ_BIT is not set
> > > - error codes are valid
> > > - oh->len does not exceed the expected size
> > >
> > > Signed-off-by: Brajesh Patil <brajeshpatil11@gmail.com>
> > > ---
> > > fs/fuse/virtio_fs.c | 30 +++++++++++++++++++++++++-----
> > > 1 file changed, 25 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
> > > index 6bc7c97b017d..52e8338bf436 100644
> > > --- a/fs/fuse/virtio_fs.c
> > > +++ b/fs/fuse/virtio_fs.c
> > > @@ -764,14 +764,34 @@ static void virtio_fs_request_complete(struct fuse_req *req,
> > > {
> > > struct fuse_args *args;
> > > struct fuse_args_pages *ap;
> > > - unsigned int len, i, thislen;
> > > + struct fuse_out_header *oh;
> > > + unsigned int len, i, thislen, expected_len = 0;
> > > struct folio *folio;
> > >
> > > - /*
> > > - * TODO verify that server properly follows FUSE protocol
> > > - * (oh.uniq, oh.len)
> > > - */
> > > + oh = &req->out.h;
> > > +
> > > + if (oh->unique == 0)
> > > + pr_warn_once("notify through fuse-virtio-fs not supported");
> > > +
> > > + if ((oh->unique & ~FUSE_INT_REQ_BIT) != req->in.h.unique)
> > > + pr_warn_ratelimited("virtio-fs: unique mismatch, expected: %llu got %llu\n",
> > > + req->in.h.unique, oh->unique & ~FUSE_INT_REQ_BIT);
> >
> > Er... shouldn't these be rejecting the response somehow? Instead of
> > warning that something's amiss but continuing with known bad data?
> >
> > --D
> >
>
> Right, continuing here is unsafe.
>
> I plan to update the code so that in case of any header validation
> failure (e.g. unique mismatch, invalid error, length mismatch), it
> should skip copying data and jump directly to the section that marks
> request as complete
>
> Does this seem like a feasible approach?
Yeah, I think you can just set req->out.h.error to some errno (EIO?) and
jump to fuse_request_end, sort of like what fuse_dev_do_write sort of
does. I think that sends the errno back to whatever code initiated the
request. I don't know if virtiofs should be throwing an error back to
the server?
--D
> > > +
> > > + WARN_ON_ONCE(oh->unique & FUSE_INT_REQ_BIT);
> > > +
> > > + if (oh->error <= -ERESTARTSYS || oh->error > 0)
> > > + pr_warn_ratelimited("virtio-fs: invalid error code from server: %d\n",
> > > + oh->error);
> > > +
> > > args = req->args;
> > > +
> > > + for (i = 0; i < args->out_numargs; i++)
> > > + expected_len += args->out_args[i].size;
> > > +
> > > + if (oh->len > sizeof(*oh) + expected_len)
> > > + pr_warn("FUSE reply too long! got=%u expected<=%u\n",
> > > + oh->len, (unsigned int)(sizeof(*oh) + expected_len));
> > > +
> > > copy_args_from_argbuf(args, req);
> > >
> > > if (args->out_pages && args->page_zeroing) {
> > > --
> > > 2.43.0
> > >
> > >
next prev parent reply other threads:[~2025-10-29 6:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 20:03 [PATCH] fuse: virtio_fs: add checks for FUSE protocol compliance Brajesh Patil
2025-10-28 20:07 ` Darrick J. Wong
2025-10-29 3:28 ` Brajesh Patil
2025-10-29 6:01 ` Darrick J. Wong [this message]
2025-10-31 6:37 ` Brajesh Patil
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=20251029060108.GR4015566@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=brajeshpatil11@gmail.com \
--cc=david.hunter.linux@gmail.com \
--cc=eperezma@redhat.com \
--cc=khalid@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=skhan@linuxfoundation.org \
--cc=stefanha@redhat.com \
--cc=vgoyal@redhat.com \
--cc=virtio-fs@lists.linux.dev \
--cc=virtualization@lists.linux.dev \
/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).