virtio-fs.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: linux-fsdevel@vger.kernel.org
Cc: Alyssa Ross <hi@alyssa.is>,
	gmaglione@redhat.com, virtio-fs@lists.linux.dev,
	vgoyal@redhat.com, mzxreary@0pointer.de,
	Greg KH <gregkh@linuxfoundation.org>,
	miklos@szeredi.hu, Stefan Hajnoczi <stefanha@redhat.com>
Subject: [PATCH v2 1/3] virtiofs: forbid newlines in tags
Date: Thu,  8 Feb 2024 14:32:09 -0500	[thread overview]
Message-ID: <20240208193212.731978-2-stefanha@redhat.com> (raw)
In-Reply-To: <20240208193212.731978-1-stefanha@redhat.com>

Newlines in virtiofs tags are awkward for users and potential vectors
for string injection attacks.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 fs/fuse/virtio_fs.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/fs/fuse/virtio_fs.c b/fs/fuse/virtio_fs.c
index 5f1be1da92ce..de9a38efdf1e 100644
--- a/fs/fuse/virtio_fs.c
+++ b/fs/fuse/virtio_fs.c
@@ -323,6 +323,16 @@ static int virtio_fs_read_tag(struct virtio_device *vdev, struct virtio_fs *fs)
 		return -ENOMEM;
 	memcpy(fs->tag, tag_buf, len);
 	fs->tag[len] = '\0';
+
+	/* While the VIRTIO specification allows any character, newlines are
+	 * awkward on mount(8) command-lines and cause problems in the sysfs
+	 * "tag" attr and uevent TAG= properties. Forbid them.
+	 */
+	if (strchr(fs->tag, '\n')) {
+		dev_err(&vdev->dev, "refusing virtiofs tag with newline character\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
-- 
2.43.0


  reply	other threads:[~2024-02-08 19:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-08 19:32 [PATCH v2 0/3] virtiofs: export filesystem tags through sysfs Stefan Hajnoczi
2024-02-08 19:32 ` Stefan Hajnoczi [this message]
2024-02-09 10:33   ` [PATCH v2 1/3] virtiofs: forbid newlines in tags Greg KH
2024-02-09 11:30     ` Stefan Hajnoczi
2024-02-08 19:32 ` [PATCH v2 2/3] virtiofs: export filesystem tags through sysfs Stefan Hajnoczi
2024-02-09 10:36   ` Greg KH
2024-02-09 11:33     ` Stefan Hajnoczi
2024-02-08 19:32 ` [PATCH v2 3/3] virtiofs: emit uevents on filesystem events Stefan Hajnoczi
2024-02-09 10:39   ` Greg KH
2024-02-09 12:15     ` Stefan Hajnoczi

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=20240208193212.731978-2-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=gmaglione@redhat.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hi@alyssa.is \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mzxreary@0pointer.de \
    --cc=vgoyal@redhat.com \
    --cc=virtio-fs@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 read-only IMAP folder(s) and NNTP newsgroup(s).