[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20090729161341.269b90e3.akpm@linux-foundation.org>
Date: Wed, 29 Jul 2009 16:13:41 -0700
From: Andrew Morton <akpm@...ux-foundation.org>
To: David Rientjes <rientjes@...gle.com>
Cc: riel@...hat.com, menage@...gle.com, kosaki.motohiro@...fujitsu.com,
linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [patch -mm v2] mm: introduce oom_adj_child
On Tue, 28 Jul 2009 21:27:15 -0700 (PDT)
David Rientjes <rientjes@...gle.com> wrote:
> +static ssize_t oom_adj_child_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_adj_child;
> +
> + memset(buffer, 0, sizeof(buffer));
> + if (count > sizeof(buffer) - 1)
> + count = sizeof(buffer) - 1;
> + if (copy_from_user(buffer, buf, count))
> + return -EFAULT;
> + oom_adj_child = simple_strtol(buffer, &end, 0);
> + if ((oom_adj_child < OOM_ADJUST_MIN ||
> + oom_adj_child > OOM_ADJUST_MAX) && oom_adj_child != OOM_DISABLE)
> + return -EINVAL;
> + if (*end == '\n')
> + end++;
> + task = get_proc_task(file->f_path.dentry->d_inode);
> + if (!task)
> + return -ESRCH;
> + task_lock(task);
> + if (task->mm && oom_adj_child < task->mm->oom_adj &&
> + !capable(CAP_SYS_RESOURCE)) {
> + task_unlock(task);
> + put_task_struct(task);
> + return -EINVAL;
> + }
> + task_unlock(task);
> + task->oom_adj_child = oom_adj_child;
> + put_task_struct(task);
> + if (end - buffer == 0)
> + return -EIO;
> + return end - buffer;
> +}
Do we really need to do all that string hacking? All it does is reads
a plain old integer from userspace.
It's weird that the obfuscated check for zero-length input happens
right at the end of the function, particularly as we couldn't have got
that far anyway, because we'd already have returned -EINVAL.
And even after all that, I suspect the function will permit illogical
input such as "12foo" - which is what strict_strtoul() is for (as
checkpatch points out!).
grumble. At how many codesites do we read an ascii integer from
userspace? Thousands, surely. You'd think we'd have a little function
to do it by now.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists