From: Vincent Li <macli@brc.ubc.ca>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
David Rientjes <rientjes@google.com>,
Vincent Li <macli@brc.ubc.ca>
Subject: [PATCH] fs/proc/task_mmu.c: fix clear_refs_write() input sanity check
Date: Wed, 12 Aug 2009 15:04:50 -0700 [thread overview]
Message-ID: <1250114690-24829-1-git-send-email-macli@brc.ubc.ca> (raw)
Andrew Morton pointed out similar string hacking and obfuscated check for zero-length input
at the end of the function, David Rientjes suggested to use strict_strtol to replace
simple_strtol, this patch cover above suggestions, add removing of leading and trailing
whitespace from user input. It does not change function behavious.
This patch is rebased on mmotm-2009-08-04-14-22.
Signed-off-by: Vincent Li <macli@brc.ubc.ca>
---
fs/proc/task_mmu.c | 18 ++++++++----------
1 files changed, 8 insertions(+), 10 deletions(-)
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 2079969..026b532 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -494,18 +494,17 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
char buffer[PROC_NUMBUF], *end;
struct mm_struct *mm;
struct vm_area_struct *vma;
- int type;
+ long res;
memset(buffer, 0, sizeof(buffer));
if (count > sizeof(buffer) - 1)
count = sizeof(buffer) - 1;
if (copy_from_user(buffer, buf, count))
return -EFAULT;
- type = simple_strtol(buffer, &end, 0);
- if (type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED)
+ if (strict_strtol(strstrip(buffer), 10, &res)
+ return -EINVAL;
+ if (res < CLEAR_REFS_ALL || res > CLEAR_REFS_MAPPED)
return -EINVAL;
- if (*end == '\n')
- end++;
task = get_proc_task(file->f_path.dentry->d_inode);
if (!task)
return -ESRCH;
@@ -529,9 +528,9 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
* Writing 3 to /proc/pid/clear_refs only affects file
* mapped pages.
*/
- if (type == CLEAR_REFS_ANON && vma->vm_file)
+ if (res == CLEAR_REFS_ANON && vma->vm_file)
continue;
- if (type == CLEAR_REFS_MAPPED && !vma->vm_file)
+ if (res == CLEAR_REFS_MAPPED && !vma->vm_file)
continue;
walk_page_range(vma->vm_start, vma->vm_end,
&clear_refs_walk);
@@ -541,9 +540,8 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
mmput(mm);
}
put_task_struct(task);
- if (end - buffer == 0)
- return -EIO;
- return end - buffer;
+
+ return count;
}
const struct file_operations proc_clear_refs_operations = {
--
1.6.0.4
next reply other threads:[~2009-08-12 22:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-12 22:04 Vincent Li [this message]
2009-08-12 22:24 ` David Rientjes
2009-08-12 23:46 ` Li, Ming Chun
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=1250114690-24829-1-git-send-email-macli@brc.ubc.ca \
--to=macli@brc.ubc.ca \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rientjes@google.com \
/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®