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] [PATCH] xl: Perform minimal validation of virtual disk file

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] xl: Perform minimal validation of virtual disk file while parsing config file
From: Kamala Narasimhan <kamala.narasimhan@xxxxxxxxx>
Date: Thu, 13 Jan 2011 10:35:34 -0500
Delivery-date: Thu, 13 Jan 2011 07:36:22 -0800
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=IaxwU1g0T7/e+ex/Fx+yvEP7U2thMQnNzkBKlnqoqPE=; b=LAwf7lceKwjj1SXCKj3qHVLX7SPxS3ynVHwlmxoRkFjfqS+hfaHb/HfaEkV62x+Vv4 g3bklGNhUb3EI2LyK7v+UUeqzs0wR7AktlZM8BuiGI+9BzvDe6Wz6HRiB2jrSWBKoass tXk3ZN9UpwwoBCvCzw0/NIi4d9yYLpKxW3ip4=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=iKEGHCtJ3dVjI6JFcn/X0rflV+JElwjFdOePJvKFrCa7l12pjyZ/ED5jOF8/w67LRP 3hQoskuft/Pueh60BhXZmPMEEJfAqfDnaPaNH0EbwWwLB2y/I01ySBYGNVtMMIMw50BV PNBGECBX604Pei49/q/IeJM9a6YWmkj54uBos=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
This patch performs some very basic validation on the virtual disk
file passed through the config file.  This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.  Obviously,
there is a lot of room for improvement in the kind of validations we
could do but the below is a minimal first stab at it.  Please consider
this for inclusion or feel free to tweak it as necessary.

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@xxxxxxxxxx>

Kamala


diff -r ce208811f540 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Jan 13 01:26:44 2011 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Thu Jan 13 10:16:57 2011 -0500
@@ -432,6 +432,35 @@ static int parse_action_on_shutdown(cons
 #define DSTATE_RW        5
 #define DSTATE_TERMINAL  6

+static int validate_virtual_disk(char *file_name, libxl_disk_phystype
disk_type)
+{
+    struct stat stat_buf;
+
+    if ( file_name == NULL )
+    {
+        fprintf(stderr, "Virtual disk file name is NULL!\n");
+        return 0;
+    }
+
+    if ( stat(file_name, &stat_buf) != 0 ) {
+        fprintf(stderr, "Stat on virtual disk %s returned error - \"%s\".\n",
+            file_name, strerror(errno));
+        return 0;
+    }
+    if ( disk_type == PHYSTYPE_PHY ) {
+        if ( !(S_ISBLK(stat_buf.st_mode)) ) {
+            fprintf(stderr, "Virtual disk %s is not a block device!\n",
+                file_name);
+            return 0;
+        }
+    }else if ( stat_buf.st_size == 0 ) {
+        fprintf(stderr, "Virtual disk %s size is 0!\n", file_name);
+        return 0;
+    }
+
+    return 1;
+}
+
 static int parse_disk_config(libxl_device_disk *disk, char *buf2)
 {
     int state = DSTATE_INITIAL;
@@ -485,6 +514,9 @@ static int parse_disk_config(libxl_devic

                 *p = '\0';
                 disk->physpath = (*tok) ? strdup(tok) : NULL;
+                if ( validate_virtual_disk(disk->physpath,
disk->phystype) == 0 )
+                    return 0;
+
                 tok = p + 1;

                 /* hack for ioemu disk spec */

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