summaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorEryu Guan <eguan@redhat.com>2018-01-23 12:20:00 -0500
committerJens Axboe <axboe@kernel.dk>2018-01-24 11:46:09 -0500
commit6b136a24b05c81a24e0b648a4bd938bcd0c4f69e (patch)
treeefa76cb522a4a75c2970b6ec0a59aa64ba391706 /block
parent20d59023c5ec4426284af492808bcea1f39787ef (diff)
blk-mq-debugfs: don't allow write on attributes with seq_operations set
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>
Diffstat (limited to 'block')
-rw-r--r--block/blk-mq-debugfs.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/block/blk-mq-debugfs.c b/block/blk-mq-debugfs.c
index fa31ceaa8de6..21cbc1f071c6 100644
--- a/block/blk-mq-debugfs.c
+++ b/block/blk-mq-debugfs.c
@@ -697,7 +697,11 @@ static ssize_t blk_mq_debugfs_write(struct file *file, const char __user *buf,
697 const struct blk_mq_debugfs_attr *attr = m->private; 697 const struct blk_mq_debugfs_attr *attr = m->private;
698 void *data = d_inode(file->f_path.dentry->d_parent)->i_private; 698 void *data = d_inode(file->f_path.dentry->d_parent)->i_private;
699 699
700 if (!attr->write) 700 /*
701 * Attributes that only implement .seq_ops are read-only and 'attr' is
702 * the same with 'data' in this case.
703 */
704 if (attr == data || !attr->write)
701 return -EPERM; 705 return -EPERM;
702 706
703 return attr->write(data, buf, count, ppos); 707 return attr->write(data, buf, count, ppos);