From: Li Zefan <lizf@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Americo Wang <xiyou.wangcong@gmail.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
Arjan van de Ven <arjan@infradead.org>,
Roland Dreier <rdreier@cisco.com>,
LKML <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: [PATCH] memdup_user: introduce, fix
Date: Tue, 10 Mar 2009 09:47:11 +0800 [thread overview]
Message-ID: <49B5C69F.3010409@cn.fujitsu.com> (raw)
Always use GFP_KERNEL in kmalloc(), since copy_from_user() can sleep and
cause pagefault, thus it's pointless to use GFP_NOFS or GFP_ATOMIC here.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
Against memdup_user-introduce.patch
---
include/linux/string.h | 2 +-
mm/util.c | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 79f30f3..0863885 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -12,7 +12,7 @@
#include <linux/stddef.h> /* for NULL */
extern char *strndup_user(const char __user *, long);
-extern void *memdup_user(const void __user *, size_t, gfp_t);
+extern void *memdup_user(const void __user *, size_t);
/*
* Include machine specific inline routines
diff --git a/mm/util.c b/mm/util.c
index 3d21c21..7c122e4 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -74,15 +74,19 @@ EXPORT_SYMBOL(kmemdup);
*
* @src: source address in user space
* @len: number of bytes to copy
- * @gfp: GFP mask to use
*
* Returns an ERR_PTR() on failure.
*/
-void *memdup_user(const void __user *src, size_t len, gfp_t gfp)
+void *memdup_user(const void __user *src, size_t len)
{
void *p;
- p = kmalloc_track_caller(len, gfp);
+ /*
+ * Always use GFP_KERNEL, since copy_from_user() can sleep and
+ * cause pagefault, which makes it pointless to use GFP_NOFS
+ * or GFP_ATOMIC.
+ */
+ p = kmalloc_track_caller(len, GFP_KERNEL);
if (!p)
return ERR_PTR(-ENOMEM);
--
1.5.4.rc3
WARNING: multiple messages have this Message-ID (diff)
From: Li Zefan <lizf@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Americo Wang <xiyou.wangcong@gmail.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
Arjan van de Ven <arjan@infradead.org>,
Roland Dreier <rdreier@cisco.com>,
LKML <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: [PATCH] memdup_user: introduce, fix
Date: Tue, 10 Mar 2009 09:47:11 +0800 [thread overview]
Message-ID: <49B5C69F.3010409@cn.fujitsu.com> (raw)
Always use GFP_KERNEL in kmalloc(), since copy_from_user() can sleep and
cause pagefault, thus it's pointless to use GFP_NOFS or GFP_ATOMIC here.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
Against memdup_user-introduce.patch
---
include/linux/string.h | 2 +-
mm/util.c | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/include/linux/string.h b/include/linux/string.h
index 79f30f3..0863885 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -12,7 +12,7 @@
#include <linux/stddef.h> /* for NULL */
extern char *strndup_user(const char __user *, long);
-extern void *memdup_user(const void __user *, size_t, gfp_t);
+extern void *memdup_user(const void __user *, size_t);
/*
* Include machine specific inline routines
diff --git a/mm/util.c b/mm/util.c
index 3d21c21..7c122e4 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -74,15 +74,19 @@ EXPORT_SYMBOL(kmemdup);
*
* @src: source address in user space
* @len: number of bytes to copy
- * @gfp: GFP mask to use
*
* Returns an ERR_PTR() on failure.
*/
-void *memdup_user(const void __user *src, size_t len, gfp_t gfp)
+void *memdup_user(const void __user *src, size_t len)
{
void *p;
- p = kmalloc_track_caller(len, gfp);
+ /*
+ * Always use GFP_KERNEL, since copy_from_user() can sleep and
+ * cause pagefault, which makes it pointless to use GFP_NOFS
+ * or GFP_ATOMIC.
+ */
+ p = kmalloc_track_caller(len, GFP_KERNEL);
if (!p)
return ERR_PTR(-ENOMEM);
--
1.5.4.rc3
--
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 reply other threads:[~2009-03-10 1:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-10 1:47 Li Zefan [this message]
2009-03-10 1:47 ` [PATCH] memdup_user: introduce, fix Li Zefan
2009-03-10 1:53 ` KOSAKI Motohiro
2009-03-10 1:53 ` KOSAKI Motohiro
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=49B5C69F.3010409@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arjan@infradead.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=rdreier@cisco.com \
--cc=xiyou.wangcong@gmail.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.