public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Max Gurtovoy <mgurtovoy@nvidia.com>
To: <israelr@nvidia.com>, <stefanha@redhat.com>,
	<virtualization@lists.linux.dev>, <mst@redhat.com>,
	<linux-block@vger.kernel.org>
Cc: <oren@nvidia.com>, <nitzanc@nvidia.com>, <dbenbasat@nvidia.com>,
	<smalin@nvidia.com>, <larora@nvidia.com>, <izach@nvidia.com>,
	<aaptel@nvidia.com>, <parav@nvidia.com>, <kvm@vger.kernel.org>,
	Max Gurtovoy <mgurtovoy@nvidia.com>
Subject: [PATCH 2/2] virtio_fs: add length check for device writable portion
Date: Tue, 25 Feb 2025 01:31:06 +0200	[thread overview]
Message-ID: <20250224233106.8519-3-mgurtovoy@nvidia.com> (raw)
In-Reply-To: <20250224233106.8519-1-mgurtovoy@nvidia.com>

Add a safety check to ensure that the length of data written by the
device is at least as large the expected length. If this condition is
not met, it indicates a potential error in the device's response.

This change aligns with the virtio specification, which states:
"The driver MUST NOT make assumptions about data in device-writable
buffers beyond the first len bytes, and SHOULD ignore this data."

By setting an error status when len is insufficient, we ensure that
the driver does not process potentially invalid or incomplete data from
the device.

Signed-off-by: Aurelien Aptel <aaptel@nvidia.com>
Signed-off-by: Lokesh Arora <larora@nvidia.com>
Signed-off-by: Max Gurtovoy <mgurtovoy@nvidia.com>
---
 fs/fuse/virtio_fs.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 82afe78ec542..658e51e41292 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -827,6 +827,15 @@ static void virtio_fs_requests_done_work(struct work_struct *work)
 		virtqueue_disable_cb(vq);
 
 		while ((req = virtqueue_get_buf(vq, &len)) != NULL) {
+
+			/*
+			 * Check device writable portion length, and fail upon
+			 * error.
+			 */
+			if (unlikely(len < sizeof(req->out.h) ||
+			    len < req->out.h.len))
+				req->out.h.error = -EIO;
+
 			spin_lock(&fpq->lock);
 			list_move_tail(&req->list, &reqs);
 			spin_unlock(&fpq->lock);
-- 
2.18.1


  parent reply	other threads:[~2025-02-24 23:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-24 23:31 [PATCH v1 0/2] virtio: Add length checks for device writable portions Max Gurtovoy
2025-02-24 23:31 ` [PATCH 1/2] virtio_blk: add length check for device writable portion Max Gurtovoy
2025-05-14 12:41   ` Michael S. Tsirkin
2025-02-24 23:31 ` Max Gurtovoy [this message]
2025-02-27  8:17 ` [PATCH v1 0/2] virtio: Add length checks for device writable portions Stefan Hajnoczi
2025-02-27  8:53   ` Michael S. Tsirkin
2025-02-27 13:53     ` Max Gurtovoy
2025-05-14 12:40   ` Michael S. Tsirkin

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=20250224233106.8519-3-mgurtovoy@nvidia.com \
    --to=mgurtovoy@nvidia.com \
    --cc=aaptel@nvidia.com \
    --cc=dbenbasat@nvidia.com \
    --cc=israelr@nvidia.com \
    --cc=izach@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=larora@nvidia.com \
    --cc=linux-block@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=nitzanc@nvidia.com \
    --cc=oren@nvidia.com \
    --cc=parav@nvidia.com \
    --cc=smalin@nvidia.com \
    --cc=stefanha@redhat.com \
    --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