From: Pekka Enberg <penberg@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Sasha Levin <levinsasha928@gmail.com>,
lizf@cn.fujitsu.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, Tyler Hicks <tyhicks@canonical.com>,
Dustin Kirkland <kirkland@canonical.com>,
ecryptfs@vger.kernel.org
Subject: Re: [PATCH] mm: Don't warn if memdup_user fails
Date: Thu, 12 Jan 2012 09:12:12 +0200 (EET) [thread overview]
Message-ID: <alpine.LFD.2.02.1201120909510.2652@tux.localdomain> (raw)
In-Reply-To: <20120111141219.271d3a97.akpm@linux-foundation.org>
On Wed, 11 Jan 2012, Andrew Morton wrote:
>> diff --git a/mm/util.c b/mm/util.c
>> index 136ac4f..88bb4d4 100644
>> --- a/mm/util.c
>> +++ b/mm/util.c
>> @@ -91,7 +91,7 @@ void *memdup_user(const void __user *src, size_t len)
>> * cause pagefault, which makes it pointless to use GFP_NOFS
>> * or GFP_ATOMIC.
>> */
>> - p = kmalloc_track_caller(len, GFP_KERNEL);
>> + p = kmalloc_track_caller(len, GFP_KERNEL | __GFP_NOWARN);
>> if (!p)
>> return ERR_PTR(-ENOMEM);
>
> There's nothing particularly special about memdup_user(): there are
> many ways in which userspace can trigger GFP_KERNEL allocations.
>
> The problem here (one which your patch carefully covers up) is that
> ecryptfs_miscdev_write() is passing an unchecked userspace-provided
> `count' direct into kmalloc(). This is a bit problematic for other
> reasons: it gives userspace a way to trigger heavy reclaim activity and
> perhaps even to trigger the oom-killer.
>
> A better fix here would be to validate the incoming arg before using
> it. Preferably by running ecryptfs_parse_packet_length() before taking
> a copy of the data. That would require adding a small copy_from_user()
> to peek at the message header.
Yup, right you are. I didn't think about the reclaim and oom issue. We
should add a big fat warning on top of memdup_user() to tell users to
check 'len' for sanity themselves. I think they're now fooled into
thinking memdup_user() automagically does the right thing.
Pekka
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-01-12 7:12 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-11 16:50 [PATCH] mm: Don't warn if memdup_user fails Sasha Levin
2012-01-11 21:46 ` David Rientjes
2012-01-12 6:43 ` Pekka Enberg
2012-01-12 6:44 ` Pekka Enberg
2012-01-12 9:09 ` Li Zefan
2012-01-11 22:12 ` Andrew Morton
2012-01-12 7:12 ` Pekka Enberg [this message]
2012-01-12 8:06 ` Sasha Levin
2012-01-12 8:15 ` Pekka Enberg
2012-01-12 21:19 ` David Rientjes
2012-01-12 21:58 ` Andrew Morton
2012-01-12 22:29 ` David Rientjes
2012-01-13 7:17 ` Dan Carpenter
2012-01-13 7:36 ` Andrew Morton
2012-01-12 11:16 ` Tyler Hicks
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=alpine.LFD.2.02.1201120909510.2652@tux.localdomain \
--to=penberg@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=ecryptfs@vger.kernel.org \
--cc=kirkland@canonical.com \
--cc=levinsasha928@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lizf@cn.fujitsu.com \
--cc=tyhicks@canonical.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).