mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
fs/proc/task_mmu.c v1: fix clear_refs_write() input sanity check
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. Signed-off-by: Vincent Li <macli@brc.ubc.ca> Acked-by: David Rientjes <rientjes@google.com> Cc: Matt Mackall <mpm@selenic.com> Cc: Amerigo Wang <xiyou.wangcong@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
acef82b873
commit
fb92a4b068
1 changed files with 6 additions and 8 deletions
|
@ -473,21 +473,20 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
|
||||||
size_t count, loff_t *ppos)
|
size_t count, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct task_struct *task;
|
struct task_struct *task;
|
||||||
char buffer[PROC_NUMBUF], *end;
|
char buffer[PROC_NUMBUF];
|
||||||
struct mm_struct *mm;
|
struct mm_struct *mm;
|
||||||
struct vm_area_struct *vma;
|
struct vm_area_struct *vma;
|
||||||
int type;
|
long type;
|
||||||
|
|
||||||
memset(buffer, 0, sizeof(buffer));
|
memset(buffer, 0, sizeof(buffer));
|
||||||
if (count > sizeof(buffer) - 1)
|
if (count > sizeof(buffer) - 1)
|
||||||
count = sizeof(buffer) - 1;
|
count = sizeof(buffer) - 1;
|
||||||
if (copy_from_user(buffer, buf, count))
|
if (copy_from_user(buffer, buf, count))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
type = simple_strtol(buffer, &end, 0);
|
if (strict_strtol(strstrip(buffer), 10, &type))
|
||||||
|
return -EINVAL;
|
||||||
if (type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED)
|
if (type < CLEAR_REFS_ALL || type > CLEAR_REFS_MAPPED)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
if (*end == '\n')
|
|
||||||
end++;
|
|
||||||
task = get_proc_task(file->f_path.dentry->d_inode);
|
task = get_proc_task(file->f_path.dentry->d_inode);
|
||||||
if (!task)
|
if (!task)
|
||||||
return -ESRCH;
|
return -ESRCH;
|
||||||
|
@ -523,9 +522,8 @@ static ssize_t clear_refs_write(struct file *file, const char __user *buf,
|
||||||
mmput(mm);
|
mmput(mm);
|
||||||
}
|
}
|
||||||
put_task_struct(task);
|
put_task_struct(task);
|
||||||
if (end - buffer == 0)
|
|
||||||
return -EIO;
|
return count;
|
||||||
return end - buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct file_operations proc_clear_refs_operations = {
|
const struct file_operations proc_clear_refs_operations = {
|
||||||
|
|
Loading…
Reference in a new issue