[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.LFD.2.02.1201120909510.2652@tux.localdomain>
Date: Thu, 12 Jan 2012 09:12:12 +0200 (EET)
From: Pekka Enberg <penberg@...nel.org>
To: Andrew Morton <akpm@...ux-foundation.org>
cc: Sasha Levin <levinsasha928@...il.com>, lizf@...fujitsu.com,
linux-kernel@...r.kernel.org, linux-mm@...ck.org,
Tyler Hicks <tyhicks@...onical.com>,
Dustin Kirkland <kirkland@...onical.com>,
ecryptfs@...r.kernel.org
Subject: Re: [PATCH] mm: Don't warn if memdup_user fails
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 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