提交 cba8aafe 编写于 作者: V Vincent Li 提交者: Linus Torvalds

fs/proc/base.c: fix proc_fault_inject_write() input sanity check

Remove obfuscated zero-length input check and return -EINVAL instead of
-EIO error to make the error message clear to user.  Add whitespace
stripping.  No functionality changes.

The old code:

echo  1  > /proc/pid/make-it-fail (ok)
echo 1foo > /proc/pid/make-it-fail (-bash: echo: write error: Input/output error)

The new code:

echo  1  > /proc/pid/make-it-fail (ok)
echo 1foo > /proc/pid/make-it-fail (-bash: echo: write error: Invalid argument)

This patch is conservative in changes to not breaking existing
scripts/applications.
Signed-off-by: NVincent Li <macli@brc.ubc.ca>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 fb92a4b0
...@@ -1187,17 +1187,16 @@ static ssize_t proc_fault_inject_write(struct file * file, ...@@ -1187,17 +1187,16 @@ static ssize_t proc_fault_inject_write(struct file * file,
count = sizeof(buffer) - 1; count = sizeof(buffer) - 1;
if (copy_from_user(buffer, buf, count)) if (copy_from_user(buffer, buf, count))
return -EFAULT; return -EFAULT;
make_it_fail = simple_strtol(buffer, &end, 0); make_it_fail = simple_strtol(strstrip(buffer), &end, 0);
if (*end == '\n') if (*end)
end++; return -EINVAL;
task = get_proc_task(file->f_dentry->d_inode); task = get_proc_task(file->f_dentry->d_inode);
if (!task) if (!task)
return -ESRCH; return -ESRCH;
task->make_it_fail = make_it_fail; task->make_it_fail = make_it_fail;
put_task_struct(task); put_task_struct(task);
if (end - buffer == 0)
return -EIO; return count;
return end - buffer;
} }
static const struct file_operations proc_fault_inject_operations = { static const struct file_operations proc_fault_inject_operations = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册