mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vincent Li <macli@brc.ubc.ca>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>, Vincent Li <macli@brc.ubc.ca>
Subject: [PATCH] fs/proc/base.c: fix proc_fault_inject_write() input sanity check
Date: Fri, 14 Aug 2009 13:18:40 -0700	[thread overview]
Message-ID: <1250281120-3308-1-git-send-email-macli@brc.ubc.ca> (raw)

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


             reply	other threads:[~2009-08-14 20:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-14 20:18 Vincent Li [this message]
2009-08-17  2:48 ` Amerigo Wang
2009-08-17 17:06   ` Vincent Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1250281120-3308-1-git-send-email-macli@brc.ubc.ca \
    --to=macli@brc.ubc.ca \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®