From: Stefan Hajnoczi <stefanha@redhat.com>
To: Li Wang <liwang@kylinos.cn>
Cc: "German Maglione" <gmaglione@redhat.com>,
"Vivek Goyal" <vgoyal@redhat.com>,
"Miklos Szeredi" <miklos@szeredi.hu>,
"Eugenio Pérez" <eperezma@redhat.com>,
virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org,
"Yuto Ohnuki" <ytohnuki@amazon.com>
Subject: Re: [PATCH] [PATCH v2] virtiofs: Strengthen FUSE protocol validation for server responses
Date: Thu, 26 Mar 2026 14:47:01 -0400 [thread overview]
Message-ID: <20260326184701.GA6926@fedora> (raw)
In-Reply-To: <20260323081455.38007-1-liwang@kylinos.cn>
[-- Attachment #1: Type: text/plain, Size: 2594 bytes --]
On Mon, Mar 23, 2026 at 04:14:54PM +0800, Li Wang wrote:
> 1. We should not trust the length value provided by the server;
> 2. Only replies have an out header/argbuf data to parse;
> 3. Some minor refinements for performance and log throttling.
>
> Signed-off-by: Li Wang <liwang@kylinos.cn>
> ---
> fs/fuse/virtio_fs.c | 28 ++++++++++++++++++----------
> 1 file changed, 18 insertions(+), 10 deletions(-)
CCing Yuto Ohnuki since this touches their recent work.
>
> diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
> index 2f7485ffac52..c3f7f472f517 100644
> --- a/fs/fuse/virtio_fs.c
> +++ b/fs/fuse/virtio_fs.c
> @@ -759,23 +759,31 @@ static void copy_args_from_argbuf(struct fuse_args *args, struct fuse_req *req)
> }
>
> /* Verify that the server properly follows the FUSE protocol */
> -static bool virtio_fs_verify_response(struct fuse_req *req, unsigned int len)
> +static bool virtio_fs_verify_response(struct fuse_req *req)
> {
> + unsigned int num_out, cap;
> + struct fuse_args *args;
> struct fuse_out_header *oh = &req->out.h;
>
> - if (len < sizeof(*oh)) {
> - pr_warn("virtio-fs: response too short (%u)\n", len);
> + if (!test_bit(FR_ISREPLY, &req->flags))
> return false;
> - }
> - if (oh->len != len) {
> - pr_warn("virtio-fs: oh.len mismatch (%u != %u)\n", oh->len, len);
> + if (unlikely(oh->unique != req->in.h.unique)) {
> + pr_warn_ratelimited("virtio-fs: bad reply unique %llu (expected %llu)\n",
> + oh->unique, req->in.h.unique);
> return false;
> }
> - if (oh->unique != req->in.h.unique) {
> - pr_warn("virtio-fs: oh.unique mismatch (%llu != %llu)\n",
> - oh->unique, req->in.h.unique);
> + args = req->args;
> + num_out = args->out_numargs - args->out_pages;
> + cap = sizeof(req->out.h);
> + cap += fuse_len_args(num_out, args->out_args);
> + if (args->out_pages)
> + cap += args->out_args[args->out_numargs - 1].size;
> + if (unlikely(oh->len < sizeof(*oh) || oh->len > cap)) {
> + pr_warn_ratelimited("virtio-fs: bad reply len %u (cap %u)\n",
> + oh->len, cap);
> return false;
> }
> +
> return true;
> }
>
> @@ -841,7 +849,7 @@ static void virtio_fs_requests_done_work(struct work_struct *work)
> virtqueue_disable_cb(vq);
>
> while ((req = virtqueue_get_buf(vq, &len)) != NULL) {
> - if (!virtio_fs_verify_response(req, len)) {
> + if (test_bit(FR_ISREPLY, &req->flags) && !virtio_fs_verify_response(req)) {
> req->out.h.error = -EIO;
> req->out.h.len = sizeof(struct fuse_out_header);
> }
> --
> 2.34.1
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2026-03-26 18:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 8:14 [PATCH] [PATCH v2] virtiofs: Strengthen FUSE protocol validation for server responses Li Wang
2026-03-26 18:47 ` Stefan Hajnoczi [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=20260326184701.GA6926@fedora \
--to=stefanha@redhat.com \
--cc=eperezma@redhat.com \
--cc=gmaglione@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=liwang@kylinos.cn \
--cc=miklos@szeredi.hu \
--cc=vgoyal@redhat.com \
--cc=virtualization@lists.linux.dev \
--cc=ytohnuki@amazon.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