All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xl: Perform minimal validation of virtual disk file while parsing config file
@ 2011-01-13 15:35 Kamala Narasimhan
  2011-01-14  9:05 ` Ian Campbell
  0 siblings, 1 reply; 28+ messages in thread
From: Kamala Narasimhan @ 2011-01-13 15:35 UTC (permalink / raw)
  To: xen-devel

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@citrix.com>

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 */

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2011-01-26 18:02 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-13 15:35 [PATCH] xl: Perform minimal validation of virtual disk file while parsing config file Kamala Narasimhan
2011-01-14  9:05 ` Ian Campbell
2011-01-14 14:55   ` Kamala Narasimhan
2011-01-14 16:59     ` Gianni Tedesco
2011-01-14 17:17       ` Kamala Narasimhan
2011-01-19 18:09         ` Kamala Narasimhan
2011-01-19 18:26           ` Kamala Narasimhan
2011-01-20 14:04             ` Gianni Tedesco
2011-01-20 14:12               ` Gianni Tedesco
2011-01-20 15:08               ` Kamala Narasimhan
2011-01-20 15:22                 ` Gianni Tedesco
2011-01-20 15:22                 ` Kamala Narasimhan
2011-01-20 15:41               ` Kamala Narasimhan
2011-01-20 15:49               ` Ian Jackson
2011-01-20 16:46                 ` Kamala Narasimhan
2011-01-20 21:14                   ` Kamala Narasimhan
2011-01-21 12:17                     ` Ian Jackson
2011-01-21 13:27                       ` Gianni Tedesco
2011-01-22  2:33                         ` Kamala Narasimhan
2011-01-25 18:10                           ` Ian Jackson
2011-01-26  3:07                             ` Kamala Narasimhan
2011-01-26 11:43                               ` Ian Jackson
2011-01-26 18:02                                 ` Kamala Narasimhan
2011-01-26 10:27                             ` Ian Campbell
2011-01-26 11:48                               ` Ian Jackson
2011-01-26 11:54                                 ` Ian Campbell
2011-01-24 14:18                       ` Kamala Narasimhan
2011-01-24 14:31                         ` Kamala Narasimhan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.