aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxc/xc_domain_restore.c
diff options
context:
space:
mode:
authorIan Jackson <ian.jackson@eu.citrix.com>2013-06-14 16:39:38 +0100
committerIan Jackson <Ian.Jackson@eu.citrix.com>2013-06-14 16:39:38 +0100
commit3d5a1d4733e55e33521cd5004cab1313e5c5d5ff (patch)
tree24b11362d42baa63117d9bb660d6ecce3602c83b /tools/libxc/xc_domain_restore.c
parentaaebaba5ae225f591e0602e071037a935bb281b6 (diff)
downloadxen-3d5a1d4733e55e33521cd5004cab1313e5c5d5ff.tar.gz
xen-3d5a1d4733e55e33521cd5004cab1313e5c5d5ff.tar.bz2
xen-3d5a1d4733e55e33521cd5004cab1313e5c5d5ff.zip
libxc: check return values from malloc
A sufficiently malformed input to libxc (such as a malformed input ELF or other guest-controlled data) might cause one of libxc's malloc() to fail. In this case we need to make sure we don't dereference or do pointer arithmetic on the result. Search for all occurrences of \b(m|c|re)alloc in libxc, and all functions which call them, and add appropriate error checking where missing. This includes the functions xc_dom_malloc*, which now print a message when they fail so that callers don't have to do so. The function xc_cpuid_to_str wasn't provided with a sane return value and has a pretty strange API, which now becomes a little stranger. There are no in-tree callers. This is part of the fix to a security issue, XSA-55. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com> v8: Move a check in xc_exchange_page to the previous patch (ie, remove it from this patch). v7: Add a missing check for a call to alloc_str. Add arithmetic overflow check in xc_dom_malloc. Coding style fix. v6: Fix a missed call `pfn_err = calloc...' in xc_domain_restore.c. Fix a missed call `new_pfn = xc_map_foreign_range...' in xc_offline_page.c v5: This patch is new in this version of the series.
Diffstat (limited to 'tools/libxc/xc_domain_restore.c')
-rw-r--r--tools/libxc/xc_domain_restore.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/libxc/xc_domain_restore.c b/tools/libxc/xc_domain_restore.c
index c7835ff6a9..f53ff88237 100644
--- a/tools/libxc/xc_domain_restore.c
+++ b/tools/libxc/xc_domain_restore.c
@@ -1243,6 +1243,11 @@ static int apply_batch(xc_interface *xch, uint32_t dom, struct restore_ctx *ctx,
/* Map relevant mfns */
pfn_err = calloc(j, sizeof(*pfn_err));
+ if ( pfn_err == NULL )
+ {
+ PERROR("allocation for pfn_err failed");
+ return -1;
+ }
region_base = xc_map_foreign_bulk(
xch, dom, PROT_WRITE, region_mfn, pfn_err, j);
@@ -1532,8 +1537,16 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
region_mfn = malloc(ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
ctx->p2m_batch = malloc(ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
if (!ctx->hvm && ctx->superpages)
+ {
ctx->p2m_saved_batch =
malloc(ROUNDUP(MAX_BATCH_SIZE * sizeof(xen_pfn_t), PAGE_SHIFT));
+ if ( ctx->p2m_saved_batch == NULL )
+ {
+ ERROR("saved batch memory alloc failed");
+ errno = ENOMEM;
+ goto out;
+ }
+ }
if ( (ctx->p2m == NULL) || (pfn_type == NULL) ||
(region_mfn == NULL) || (ctx->p2m_batch == NULL) )