From: Andrew Morton <akpm@linux-foundation.org>
To: David Rientjes <rientjes@google.com>
Cc: riel@redhat.com, menage@google.com,
kosaki.motohiro@jp.fujitsu.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [patch -mm v2] mm: introduce oom_adj_child
Date: Wed, 29 Jul 2009 16:13:41 -0700 [thread overview]
Message-ID: <20090729161341.269b90e3.akpm@linux-foundation.org> (raw)
In-Reply-To: <alpine.DEB.2.00.0907282125260.554@chino.kir.corp.google.com>
On Tue, 28 Jul 2009 21:27:15 -0700 (PDT)
David Rientjes <rientjes@google.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.
WARNING: multiple messages have this Message-ID (diff)
From: Andrew Morton <akpm@linux-foundation.org>
To: David Rientjes <rientjes@google.com>
Cc: riel@redhat.com, menage@google.com,
kosaki.motohiro@jp.fujitsu.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [patch -mm v2] mm: introduce oom_adj_child
Date: Wed, 29 Jul 2009 16:13:41 -0700 [thread overview]
Message-ID: <20090729161341.269b90e3.akpm@linux-foundation.org> (raw)
In-Reply-To: <alpine.DEB.2.00.0907282125260.554@chino.kir.corp.google.com>
On Tue, 28 Jul 2009 21:27:15 -0700 (PDT)
David Rientjes <rientjes@google.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, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-07-29 23:14 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-29 4:27 [patch -mm v2] mm: introduce oom_adj_child David Rientjes
2009-07-29 4:27 ` David Rientjes
2009-07-29 23:13 ` Andrew Morton [this message]
2009-07-29 23:13 ` Andrew Morton
2009-07-29 23:25 ` Paul Menage
2009-07-29 23:25 ` Paul Menage
2009-07-30 2:32 ` KOSAKI Motohiro
2009-07-30 2:32 ` KOSAKI Motohiro
2009-07-30 7:06 ` David Rientjes
2009-07-30 7:06 ` David Rientjes
2009-07-31 6:47 ` KOSAKI Motohiro
2009-07-31 6:47 ` KOSAKI Motohiro
2009-07-31 9:31 ` David Rientjes
2009-07-31 9:31 ` David Rientjes
2009-08-03 11:58 ` KOSAKI Motohiro
2009-08-03 11:58 ` KOSAKI Motohiro
2009-08-03 12:12 ` KOSAKI Motohiro
2009-08-03 12:12 ` KOSAKI Motohiro
2009-07-30 9:00 ` KAMEZAWA Hiroyuki
2009-07-30 9:00 ` KAMEZAWA Hiroyuki
2009-07-30 9:31 ` David Rientjes
2009-07-30 9:31 ` David Rientjes
2009-07-30 10:02 ` KAMEZAWA Hiroyuki
2009-07-30 10:02 ` KAMEZAWA Hiroyuki
2009-07-30 19:05 ` David Rientjes
2009-07-30 19:05 ` David Rientjes
2009-07-31 0:33 ` KAMEZAWA Hiroyuki
2009-07-31 0:33 ` KAMEZAWA Hiroyuki
2009-07-31 6:50 ` KOSAKI Motohiro
2009-07-31 6:50 ` KOSAKI Motohiro
2009-07-31 19:38 ` David Rientjes
2009-07-31 19:38 ` David Rientjes
2009-08-03 12:16 ` KOSAKI Motohiro
2009-08-03 12:16 ` KOSAKI Motohiro
2009-07-31 9:36 ` David Rientjes
2009-07-31 9:36 ` David Rientjes
2009-07-31 10:49 ` KAMEZAWA Hiroyuki
2009-07-31 10:49 ` KAMEZAWA Hiroyuki
2009-07-31 19:18 ` David Rientjes
2009-07-31 19:18 ` David Rientjes
2009-08-01 1:10 ` KAMEZAWA Hiroyuki
2009-08-01 1:10 ` KAMEZAWA Hiroyuki
2009-08-01 20:26 ` David Rientjes
2009-08-01 20:26 ` David Rientjes
2009-08-03 1:42 ` KAMEZAWA Hiroyuki
2009-08-03 1:42 ` KAMEZAWA Hiroyuki
2009-08-03 7:59 ` David Rientjes
2009-08-03 7:59 ` David Rientjes
2009-08-03 8:02 ` KAMEZAWA Hiroyuki
2009-08-03 8:02 ` KAMEZAWA Hiroyuki
2009-08-03 8:08 ` David Rientjes
2009-08-03 8:08 ` David Rientjes
2009-08-03 8:45 ` KAMEZAWA Hiroyuki
2009-08-03 8:45 ` KAMEZAWA Hiroyuki
2009-08-03 8:55 ` KAMEZAWA Hiroyuki
2009-08-03 8:55 ` KAMEZAWA Hiroyuki
2009-08-03 12:19 ` KOSAKI Motohiro
2009-08-03 12:19 ` KOSAKI Motohiro
2009-08-03 12:32 ` KOSAKI Motohiro
2009-08-03 12:32 ` KOSAKI Motohiro
2009-08-03 12:21 ` KOSAKI Motohiro
2009-08-03 12:21 ` KOSAKI Motohiro
2009-08-03 16:17 ` Paul Menage
2009-08-03 16:17 ` Paul Menage
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=20090729161341.269b90e3.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=menage@google.com \
--cc=riel@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.