mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fs/proc/base.c: fix proc_fault_inject_write() input sanity check
@ 2009-08-14 20:18 Vincent Li
  2009-08-17  2:48 ` Amerigo Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Li @ 2009-08-14 20:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton, Vincent Li

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.
based on v2.6.31-rc6, compiled and tested ok.

Signed-off-by: Vincent Li <macli@brc.ubc.ca>
---
 fs/proc/base.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 175db25..ba345d9 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1182,17 +1182,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 = {
-- 
1.6.0.4


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/proc/base.c: fix proc_fault_inject_write() input sanity check
  2009-08-14 20:18 [PATCH] fs/proc/base.c: fix proc_fault_inject_write() input sanity check Vincent Li
@ 2009-08-17  2:48 ` Amerigo Wang
  2009-08-17 17:06   ` Vincent Li
  0 siblings, 1 reply; 3+ messages in thread
From: Amerigo Wang @ 2009-08-17  2:48 UTC (permalink / raw)
  To: Vincent Li; +Cc: linux-kernel, Andrew Morton

On Fri, Aug 14, 2009 at 01:18:40PM -0700, Vincent Li wrote:
>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.

If so, why not introduce a new wrapper which is simply strstrip+simple_strtol?
Now, at least it has two users.


>
>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.
>based on v2.6.31-rc6, compiled and tested ok.
>
>Signed-off-by: Vincent Li <macli@brc.ubc.ca>
>---
> fs/proc/base.c |   11 +++++------
> 1 files changed, 5 insertions(+), 6 deletions(-)
>
>diff --git a/fs/proc/base.c b/fs/proc/base.c
>index 175db25..ba345d9 100644
>--- a/fs/proc/base.c
>+++ b/fs/proc/base.c
>@@ -1182,17 +1182,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 = {
>-- 
>1.6.0.4
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/proc/base.c: fix proc_fault_inject_write() input sanity check
  2009-08-17  2:48 ` Amerigo Wang
@ 2009-08-17 17:06   ` Vincent Li
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Li @ 2009-08-17 17:06 UTC (permalink / raw)
  To: Amerigo Wang; +Cc: linux-kernel, Andrew Morton

On Mon, 17 Aug 2009, Amerigo Wang wrote:

> On Fri, Aug 14, 2009 at 01:18:40PM -0700, Vincent Li wrote:
> >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.
> 
> If so, why not introduce a new wrapper which is simply strstrip+simple_strtol?
> Now, at least it has two users.

The first patch I sent used strstrip + strict_strtol, I am not sure if it 
is neccesary.

Vincent Li
Biomedical Research Center
University of British Columbia

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-17 16:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-14 20:18 [PATCH] fs/proc/base.c: fix proc_fault_inject_write() input sanity check Vincent Li
2009-08-17  2:48 ` Amerigo Wang
2009-08-17 17:06   ` Vincent Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®