Skip to content

Commit cba8aaf

Browse files
Vincent Litorvalds
authored andcommitted
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: Vincent Li <macli@brc.ubc.ca> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent fb92a4b commit cba8aaf

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

‎fs/proc/base.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,17 +1187,16 @@ static ssize_t proc_fault_inject_write(struct file * file,
11871187
count = sizeof(buffer) - 1;
11881188
if (copy_from_user(buffer, buf, count))
11891189
return -EFAULT;
1190-
make_it_fail = simple_strtol(buffer, &end, 0);
1191-
if (*end == '\n')
1192-
end++;
1190+
make_it_fail = simple_strtol(strstrip(buffer), &end, 0);
1191+
if (*end)
1192+
return -EINVAL;
11931193
task = get_proc_task(file->f_dentry->d_inode);
11941194
if (!task)
11951195
return -ESRCH;
11961196
task->make_it_fail = make_it_fail;
11971197
put_task_struct(task);
1198-
if (end - buffer == 0)
1199-
return -EIO;
1200-
return end - buffer;
1198+
1199+
return count;
12011200
}
12021201

12031202
static const struct file_operations proc_fault_inject_operations = {

0 commit comments

Comments
 (0)