Commit 5d863b89 authored by KOSAKI Motohiro's avatar KOSAKI Motohiro Committed by Linus Torvalds
Browse files

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: default avatarKOSAKI Motohiro <>
Cc: Paul Menage <>
Cc: David Rientjes <>
Cc: KAMEZAWA Hiroyuki <>
Cc: Oleg Nesterov <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 8c5cd6f3
......@@ -1021,21 +1021,24 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
struct task_struct *task;
char buffer[PROC_NUMBUF], *end;
int oom_adjust;
char buffer[PROC_NUMBUF];
long oom_adjust;
unsigned long flags;
int err;
memset(buffer, 0, sizeof(buffer));
if (count > sizeof(buffer) - 1)
count = sizeof(buffer) - 1;
if (copy_from_user(buffer, buf, count))
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) &&
oom_adjust != OOM_DISABLE)
return -EINVAL;
if (*end == '\n')
task = get_proc_task(file->f_path.dentry->d_inode);
if (!task)
return -ESRCH;
......@@ -1054,9 +1057,8 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf,
unlock_task_sighand(task, &flags);
if (end - buffer == 0)
return -EIO;
return end - buffer;
return count;
static const struct file_operations proc_oom_adjust_operations = {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment