]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
libxc: xc_dom_parse_elf_kernel: Return error for invalid kernel images
authorSimon Gaiser <simon@invisiblethingslab.com>
Thu, 8 Feb 2018 21:49:10 +0000 (22:49 +0100)
committerWei Liu <wei.liu2@citrix.com>
Tue, 13 Feb 2018 11:48:43 +0000 (11:48 +0000)
Commit 96edb111dd ("libxc: panic when trying to create a PVH guest
without kernel support") already improved the handling of non PVH
capable kernels. But xc_dom_parse_elf_kernel() still returned success on
invalid elf images and the domain build only failed later. Now the build
process will fail immediately on detecting the error.

Signed-off-by: Simon Gaiser <simon@invisiblethingslab.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
tools/libxc/xc_dom_elfloader.c

index c936f92a664d645269ceecef7d6c6378e3e87e66..26b2846365075196d621d0edb54abe5ad7a7f9c2 100644 (file)
@@ -64,7 +64,7 @@ static char *xc_dom_guest_type(struct xc_dom_image *dom,
         xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
                      "%s: image not capable of booting inside a HVM container",
                      __FUNCTION__);
-        return "xen-3.0-unknown";
+        return NULL;
     }
 
     switch ( machine )
@@ -86,7 +86,10 @@ static char *xc_dom_guest_type(struct xc_dom_image *dom,
     case EM_X86_64:
         return "xen-3.0-x86_64";
     default:
-        return "xen-3.0-unknown";
+        xc_dom_panic(dom->xch, XC_INVALID_KERNEL,
+                     "%s: unkown image type %"PRIu64,
+                     __FUNCTION__, machine);
+        return NULL;
     }
 }
 
@@ -192,6 +195,8 @@ static elf_negerrnoval xc_dom_parse_elf_kernel(struct xc_dom_image *dom)
     dom->kernel_seg.vend   = dom->parms.virt_kend;
 
     dom->guest_type = xc_dom_guest_type(dom, elf);
+    if ( dom->guest_type == NULL )
+        return -EINVAL;
     DOMPRINTF("%s: %s: 0x%" PRIx64 " -> 0x%" PRIx64 "",
               __FUNCTION__, dom->guest_type,
               dom->kernel_seg.vstart, dom->kernel_seg.vend);