Commit c7e4145a authored by Omar Sandoval's avatar Omar Sandoval Committed by Jens Axboe

blk-mq-debugfs: error on long write to queue "state" file

blk_queue_flags_store() currently truncates and returns a short write if
the operation being written is too long. This can give us weird results,
like here:

$ echo "run            bar"
echo: write error: invalid argument
$ dmesg
[ 1103.075435] blk_queue_flags_store: unsupported operation bar. Use either 'run' or 'start'

Instead, return an error if the user does this. While we're here, make
the argument names consistent with everywhere else in this file.
Signed-off-by: default avatarOmar Sandoval <osandov@fb.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.com>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 1a435111
...@@ -107,14 +107,18 @@ static int blk_queue_flags_show(struct seq_file *m, void *v) ...@@ -107,14 +107,18 @@ static int blk_queue_flags_show(struct seq_file *m, void *v)
return 0; return 0;
} }
static ssize_t blk_queue_flags_store(struct file *file, const char __user *ubuf, static ssize_t blk_queue_flags_store(struct file *file, const char __user *buf,
size_t len, loff_t *offp) size_t count, loff_t *ppos)
{ {
struct request_queue *q = file_inode(file)->i_private; struct request_queue *q = file_inode(file)->i_private;
char op[16] = { }, *s; char op[16] = { }, *s;
len = min(len, sizeof(op) - 1); if (count >= sizeof(op)) {
if (copy_from_user(op, ubuf, len)) pr_err("%s: operation too long\n", __func__);
goto inval;
}
if (copy_from_user(op, buf, count))
return -EFAULT; return -EFAULT;
s = op; s = op;
strsep(&s, " \t\n"); /* strip trailing whitespace */ strsep(&s, " \t\n"); /* strip trailing whitespace */
...@@ -123,11 +127,12 @@ static ssize_t blk_queue_flags_store(struct file *file, const char __user *ubuf, ...@@ -123,11 +127,12 @@ static ssize_t blk_queue_flags_store(struct file *file, const char __user *ubuf,
} else if (strcmp(op, "start") == 0) { } else if (strcmp(op, "start") == 0) {
blk_mq_start_stopped_hw_queues(q, true); blk_mq_start_stopped_hw_queues(q, true);
} else { } else {
pr_err("%s: unsupported operation %s. Use either 'run' or 'start'\n", pr_err("%s: unsupported operation '%s'\n", __func__, op);
__func__, op); inval:
pr_err("%s: use either 'run' or 'start'\n", __func__);
return -EINVAL; return -EINVAL;
} }
return len; return count;
} }
static int blk_queue_flags_open(struct inode *inode, struct file *file) static int blk_queue_flags_open(struct inode *inode, struct file *file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment