WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH 2/2] libxc: Check there's enough memory for segme

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] Re: [PATCH 2/2] libxc: Check there's enough memory for segments
From: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Date: Tue, 2 Feb 2010 17:23:27 +0000
Delivery-date: Tue, 02 Feb 2010 09:25:01 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <19304.24432.883046.170490@xxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <19304.24432.883046.170490@xxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
# Date 1265131163 0
# Node ID aeb8a70f42a5cc2cc7b076d128fa446201a79103
# Parent  5fc5ee3e3530d38a21d00b4ec2d559b47a23cf07
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@xxxxxxxxxxxxx>

diff -r 5fc5ee3e3530 -r aeb8a70f42a5 tools/libxc/xc_dom_core.c
--- a/tools/libxc/xc_dom_core.c Tue Feb 02 17:16:07 2010 +0000
+++ b/tools/libxc/xc_dom_core.c Tue Feb 02 17:19:23 2010 +0000
@@ -409,8 +409,19 @@
     }
 
     seg->vstart = start;
+    seg->pfn = (seg->vstart - dom->parms.virt_base) / page_size;
+
+    if ( pages > dom->total_pages || /* double test avoids overflow probs */
+         pages > dom->total_pages - seg->pfn)
+    {
+        xc_dom_panic(XC_OUT_OF_MEMORY,
+                     "%s: segment %s too large (0x%"PRIpfn" > "
+                     "0x%"PRIpfn" - 0x%"PRIpfn" pages)\n",
+                     __FUNCTION__, name, pages, dom->total_pages, seg->pfn);
+        return -1;
+    }
+
     seg->vend = start + pages * page_size;
-    seg->pfn = (seg->vstart - dom->parms.virt_base) / page_size;
     dom->virt_alloc_end = seg->vend;
     if (dom->allocate)
         dom->allocate(dom, dom->virt_alloc_end);

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>