]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
blk-mq-debugfs: don't allow write on attributes with seq_operations set
authorEryu Guan <eguan@redhat.com>
Tue, 23 Jan 2018 17:20:00 +0000 (01:20 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 24 Jan 2018 16:46:09 +0000 (09:46 -0700)
Attributes that only implement .seq_ops are read-only, any write to
them should be rejected. But currently kernel would crash when
writing to such debugfs entries, e.g.

chmod +w /sys/kernel/debug/block/<dev>/requeue_list
echo 0 > /sys/kernel/debug/block/<dev>/requeue_list
chmod -w /sys/kernel/debug/block/<dev>/requeue_list

Fix it by returning -EPERM in blk_mq_debugfs_write() when writing to
such attributes.

Cc: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq-debugfs.c

index fa31ceaa8de6c9a6b56fbe5e476820cda720858d..21cbc1f071c659a2e30a80df466420e38a4d0266 100644 (file)
@@ -697,7 +697,11 @@ static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
        const struct blk_mq_debugfs_attr *attr = m->private;
        void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
 
-       if (!attr->write)
+       /*
+        * Attributes that only implement .seq_ops are read-only and 'attr' is
+        * the same with 'data' in this case.
+        */
+       if (attr == data || !attr->write)
                return -EPERM;
 
        return attr->write(data, buf, count, ppos);