debuggers.hg

changeset 20935:7a10f8513b3f

libxc: Check there's enough memory for segments we're creating

Previously, xc_dom_alloc_segment would go ahead even if the segment
we're trying to create is too big for the domain's RAM (or the
requested addr is out of range). It would pass invalid parameters to
xc_dom_seg_to_ptr giving undefined behaviour.

Fixing xc_dom_seg_to_ptr to fail is not sufficient because we want to
provide a comprehensible explanation to the caller - which may
ultimately be the user.

In particular, with this change attempting "xl create" with a ramdisk
image bigger than the guest's specified RAM will provide a useful
error message mentioning the ramdisk.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 03 09:46:01 2010 +0000 (2010-02-03)
parents 02107eca8fb7
children 0c3e4a2f14d6
files tools/libxc/xc_dom_core.c
line diff
     1.1 --- a/tools/libxc/xc_dom_core.c	Wed Feb 03 09:45:40 2010 +0000
     1.2 +++ b/tools/libxc/xc_dom_core.c	Wed Feb 03 09:46:01 2010 +0000
     1.3 @@ -409,8 +409,19 @@ int xc_dom_alloc_segment(struct xc_dom_i
     1.4      }
     1.5  
     1.6      seg->vstart = start;
     1.7 +    seg->pfn = (seg->vstart - dom->parms.virt_base) / page_size;
     1.8 +
     1.9 +    if ( pages > dom->total_pages || /* double test avoids overflow probs */
    1.10 +         pages > dom->total_pages - seg->pfn)
    1.11 +    {
    1.12 +        xc_dom_panic(XC_OUT_OF_MEMORY,
    1.13 +                     "%s: segment %s too large (0x%"PRIpfn" > "
    1.14 +                     "0x%"PRIpfn" - 0x%"PRIpfn" pages)\n",
    1.15 +                     __FUNCTION__, name, pages, dom->total_pages, seg->pfn);
    1.16 +        return -1;
    1.17 +    }
    1.18 +
    1.19      seg->vend = start + pages * page_size;
    1.20 -    seg->pfn = (seg->vstart - dom->parms.virt_base) / page_size;
    1.21      dom->virt_alloc_end = seg->vend;
    1.22      if (dom->allocate)
    1.23          dom->allocate(dom, dom->virt_alloc_end);