From: Aravindh Puthiyaparambil <aravindh@virtuata.com>
To: xen-devel@lists.xensource.com
Cc: Andres Lagar-Cavilla <andres@lagarcavilla.org>
Subject: [PATCH] libxc: Replace alloca() with mmap() in linux_privcmd_map_foreign_bulk()
Date: Thu, 19 Apr 2012 15:24:53 -0700 [thread overview]
Message-ID: <2f68aefc46c35ef5c0c3.1334874293@vollum> (raw)
When mapping in large amounts of pages (in the GB range) from a guest in to Dom0 using xc_map_foreign_bulk(), a segfault occurs in the libxc client application. This is because the pfn array in linux_privcmd_map_foreign_bulk() is being allocated using alloca() and the subsequent memcpy causes the stack to blow. This patch replaces the alloca() with mmap().
Signed-off-by: Aravindh Puthiyaparambil <aravindh@virtuata.com>
Acked-by: Andres Lagar-Cavilla <andres@lagarcavilla.org>
diff -r 7c777cb8f705 -r 2f68aefc46c3 tools/libxc/xc_linux_osdep.c
--- a/tools/libxc/xc_linux_osdep.c Wed Apr 18 16:49:55 2012 +0100
+++ b/tools/libxc/xc_linux_osdep.c Thu Apr 19 15:21:43 2012 -0700
@@ -39,6 +39,7 @@
#include "xenctrl.h"
#include "xenctrlosdep.h"
+#define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
#define ERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m , ## _a )
#define PERROR(_m, _a...) xc_osdep_log(xch,XTL_ERROR,XC_INTERNAL_ERROR,_m \
" (%d = %s)", ## _a , errno, xc_strerror(xch, errno))
@@ -286,7 +287,14 @@ static void *linux_privcmd_map_foreign_b
* IOCTL_PRIVCMD_MMAPBATCH.
*/
privcmd_mmapbatch_t ioctlx;
- xen_pfn_t *pfn = alloca(num * sizeof(*pfn));
+ xen_pfn_t *pfn = mmap(NULL, ROUNDUP((num * sizeof(*pfn)), XC_PAGE_SHIFT),
+ PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON | MAP_POPULATE, -1, 0);
+ if ( pfn == MAP_FAILED )
+ {
+ PERROR("xc_map_foreign_bulk: mmap of pfn array failed");
+ return NULL;
+ }
memcpy(pfn, arr, num * sizeof(*arr));
@@ -328,6 +336,8 @@ static void *linux_privcmd_map_foreign_b
break;
}
+ munmap(pfn, ROUNDUP((num * sizeof(*pfn)), XC_PAGE_SHIFT));
+
if ( rc == -ENOENT && i == num )
rc = 0;
else if ( rc )
next reply other threads:[~2012-04-19 22:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-19 22:24 Aravindh Puthiyaparambil [this message]
2012-04-20 12:36 ` [PATCH] libxc: Replace alloca() with mmap() in linux_privcmd_map_foreign_bulk() Ian Campbell
2012-04-20 14:08 ` Andres Lagar-Cavilla
2012-04-20 14:15 ` Ian Campbell
2012-04-20 15:12 ` Aravindh Puthiyaparambil
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=2f68aefc46c35ef5c0c3.1334874293@vollum \
--to=aravindh@virtuata.com \
--cc=andres@lagarcavilla.org \
--cc=xen-devel@lists.xensource.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.