From: Lucas Tanure <tanure@linux.com>
To: Rusty Russell <rusty@rustcorp.com.au>,
Dave Hansen <dave@sr71.net>,
linux-kernel@vger.kernel.org
Subject: [PATCH] NoMoreModuleVmalloc - Try alloc_pages_exact before vmalloc, if fails do vmalloc
Date: Sun, 13 Jul 2014 10:04:08 -0300 [thread overview]
Message-ID: <20140713130407.GA27344@archDesk> (raw)
Convert vmalloc() call to alloc_pages_exact(). If alloc_pages_exact() fails,
then fall back to vmalloc(). If the address is a vmalloc address, then
call vfree(), otherwise call free_pages_exact().
Signed-off-by: Lucas Tanure <tanure@linux.com>
---
kernel/module.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/kernel/module.c b/kernel/module.c
index ae79ce6..50c1e77 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2484,6 +2484,7 @@ static int copy_module_from_user(const void __user *umod, unsigned long len,
struct load_info *info)
{
int err;
+ bool alloc_from_vmalloc = false;
info->len = len;
if (info->len < sizeof(*(info->hdr)))
@@ -2494,12 +2495,19 @@ static int copy_module_from_user(const void __user *umod, unsigned long len,
return err;
/* Suck in entire file: we'll want most of it. */
- info->hdr = vmalloc(info->len);
- if (!info->hdr)
- return -ENOMEM;
+ info->hdr = alloc_pages_exact(info->len, GFP_KERNEL);
+ if (!info->hdr) {
+ info->hdr = vmalloc(info->len);
+ if (!info->hdr)
+ return -ENOMEM;
+ alloc_from_vmalloc = true;
+ }
if (copy_from_user(info->hdr, umod, info->len) != 0) {
- vfree(info->hdr);
+ if(alloc_from_vmalloc)
+ vfree(info->hdr);
+ else
+ free_pages_exact(info->hdr,info->len);
return -EFAULT;
}
--
2.0.1
next reply other threads:[~2014-07-13 13:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-13 13:04 Lucas Tanure [this message]
2014-07-14 10:18 ` [PATCH] NoMoreModuleVmalloc - Try alloc_pages_exact before vmalloc, if fails do vmalloc Rusty Russell
2014-07-14 11:57 ` Lucas Tanure
2014-07-15 11:34 ` Rusty Russell
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=20140713130407.GA27344@archDesk \
--to=tanure@linux.com \
--cc=dave@sr71.net \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
/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.