oom: fix oom_adjust_write() input sanity check
Andrew Morton pointed out oom_adjust_write() has very strange EIO and new line handling. this patch fixes it. Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Paul Menage <menage@google.com> Cc: David Rientjes <rientjes@google.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
8c5cd6f3a1
commit
5d863b8968
@@ -1021,21 +1021,24 @@ static ssize_t oom_adjust_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];
|
||||||
int oom_adjust;
|
long oom_adjust;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
int err;
|
||||||
|
|
||||||
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;
|
||||||
oom_adjust = simple_strtol(buffer, &end, 0);
|
|
||||||
|
err = strict_strtol(strstrip(buffer), 0, &oom_adjust);
|
||||||
|
if (err)
|
||||||
|
return -EINVAL;
|
||||||
if ((oom_adjust < OOM_ADJUST_MIN || oom_adjust > OOM_ADJUST_MAX) &&
|
if ((oom_adjust < OOM_ADJUST_MIN || oom_adjust > OOM_ADJUST_MAX) &&
|
||||||
oom_adjust != OOM_DISABLE)
|
oom_adjust != OOM_DISABLE)
|
||||||
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;
|
||||||
@@ -1054,9 +1057,8 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
|
|||||||
|
|
||||||
unlock_task_sighand(task, &flags);
|
unlock_task_sighand(task, &flags);
|
||||||
put_task_struct(task);
|
put_task_struct(task);
|
||||||
if (end - buffer == 0)
|
|
||||||
return -EIO;
|
return count;
|
||||||
return end - buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct file_operations proc_oom_adjust_operations = {
|
static const struct file_operations proc_oom_adjust_operations = {
|
||||||
|
Reference in New Issue
Block a user