From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail202.messagelabs.com (unknown [216.82.254.227]) by kanga.kvack.org (Postfix) with SMTP id 7FB456B00E6 for ; Wed, 26 Aug 2009 05:37:17 -0400 (EDT) Received: from m4.gw.fujitsu.co.jp ([10.0.50.74]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n7Q9bIfD007158 for (envelope-from kosaki.motohiro@jp.fujitsu.com); Wed, 26 Aug 2009 18:37:18 +0900 Received: from smail (m4 [127.0.0.1]) by outgoing.m4.gw.fujitsu.co.jp (Postfix) with ESMTP id C06C045DE70 for ; Wed, 26 Aug 2009 18:37:17 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (s4.gw.fujitsu.co.jp [10.0.50.94]) by m4.gw.fujitsu.co.jp (Postfix) with ESMTP id 4746A45DE83 for ; Wed, 26 Aug 2009 18:37:13 +0900 (JST) Received: from s4.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id 1946AE18001 for ; Wed, 26 Aug 2009 18:37:13 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.249.87.105]) by s4.gw.fujitsu.co.jp (Postfix) with ESMTP id C2F37E08001 for ; Wed, 26 Aug 2009 18:37:12 +0900 (JST) From: KOSAKI Motohiro Subject: [mmotm][PATCH 4/4] oom: fix oom_adjust_write() input sanity check In-Reply-To: <20090826182634.3968.A69D9226@jp.fujitsu.com> References: <20090826182634.3968.A69D9226@jp.fujitsu.com> Message-Id: <20090826183626.3974.A69D9226@jp.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Wed, 26 Aug 2009 18:37:12 +0900 (JST) Sender: owner-linux-mm@kvack.org To: LKML Cc: kosaki.motohiro@jp.fujitsu.com, linux-mm , Andrew Morton , Paul Menage , David Rientjes , KAMEZAWA Hiroyuki , Oleg Nesterov List-ID: Andrew Morton pointed out oom_adjust_write() has very strange EIO and new line handling. this patch fixes it. Cc: Paul Menage Cc: David Rientjes Cc: KAMEZAWA Hiroyuki Cc: Andrew Morton Signed-off-by: KOSAKI Motohiro --- fs/proc/base.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index 0c1757c..ea71cae 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1022,21 +1022,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') - end++; + task = get_proc_task(file->f_path.dentry->d_inode); if (!task) return -ESRCH; @@ -1055,9 +1058,8 @@ static ssize_t oom_adjust_write(struct file *file, const char __user *buf, unlock_task_sighand(task, &flags); put_task_struct(task); - if (end - buffer == 0) - return -EIO; - return end - buffer; + + return count; } static const struct file_operations proc_oom_adjust_operations = { -- 1.6.2.5 -- 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: email@kvack.org