Skip to content

Commit dd2a5b5

Browse files
Tetsuo Handaakpm00
authored andcommitted
mm/util: make memdup_user_nul() similar to memdup_user()
Since the string data to copy from userspace is likely less than PAGE_SIZE bytes, replace GFP_KERNEL with GFP_USER like commit 6c2c97a ("memdup_user(): switch to GFP_USER") does and add __GFP_NOWARN like commit 6c8fcc0 ("mm: don't let userspace spam allocations warnings") does. Also, use dedicated slab buckets like commit d73778e ("mm/util: Use dedicated slab buckets for memdup_user()") does. Link: https://lkml.kernel.org/r/014cd694-cc27-4a07-a34a-2ae95d744515@I-love.SAKURA.ne.jp Reported-by: syzbot+7e12e97b36154c54414b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=7e12e97b36154c54414b Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 62e72d2 commit dd2a5b5

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

mm/util.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,7 @@ void *memdup_user_nul(const void __user *src, size_t len)
297297
{
298298
char *p;
299299

300-
/*
301-
* Always use GFP_KERNEL, since copy_from_user() can sleep and
302-
* cause pagefault, which makes it pointless to use GFP_NOFS
303-
* or GFP_ATOMIC.
304-
*/
305-
p = kmalloc_track_caller(len + 1, GFP_KERNEL);
300+
p = kmem_buckets_alloc_track_caller(user_buckets, len + 1, GFP_USER | __GFP_NOWARN);
306301
if (!p)
307302
return ERR_PTR(-ENOMEM);
308303

0 commit comments

Comments
 (0)