summary refs log tree commit diff
path: root/fs/proc
diff options
context:
space:
mode:
authorVincent Li <macli@brc.ubc.ca>2009-09-22 16:45:38 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2009-09-23 07:39:40 -0700
commitcba8aafe1e07dfc8bae5ba78be8e02883bd34d31 (patch)
tree473586963e635921613db5e4ae8ac339ae497a18 /fs/proc
parentfb92a4b068be96799da3748c11cbd69760e44d7b (diff)
downloadlinux-cba8aafe1e07dfc8bae5ba78be8e02883bd34d31.tar.gz
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>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/base.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 5bc587049b37..837469a96598 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1187,17 +1187,16 @@ static ssize_t proc_fault_inject_write(struct file * file,
 		count = sizeof(buffer) - 1;
 	if (copy_from_user(buffer, buf, count))
 		return -EFAULT;
-	make_it_fail = simple_strtol(buffer, &end, 0);
-	if (*end == '\n')
-		end++;
+	make_it_fail = simple_strtol(strstrip(buffer), &end, 0);
+	if (*end)
+		return -EINVAL;
 	task = get_proc_task(file->f_dentry->d_inode);
 	if (!task)
 		return -ESRCH;
 	task->make_it_fail = make_it_fail;
 	put_task_struct(task);
-	if (end - buffer == 0)
-		return -EIO;
-	return end - buffer;
+
+	return count;
 }
 
 static const struct file_operations proc_fault_inject_operations = {