]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
virtiofs: forbid newlines in tags
authorStefan Hajnoczi <stefanha@redhat.com>
Tue, 13 Feb 2024 00:11:47 +0000 (19:11 -0500)
committerMiklos Szeredi <mszeredi@redhat.com>
Fri, 23 Feb 2024 08:40:26 +0000 (09:40 +0100)
Newlines in virtiofs tags are awkward for users and potential vectors
for string injection attacks.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/fuse/virtio_fs.c

index 5f1be1da92ce942cc1c8828bed888296a87c4d4e..d84dacbdce2c9de254e286685e9746679537bbff 100644 (file)
@@ -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_dbg(&vdev->dev, "refusing virtiofs tag with newline character\n");
+               return -EINVAL;
+       }
+
        return 0;
 }