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

Re: [Xen-devel] [PATCH] xl: Perform minimal validation of virtual disk f

To: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] xl: Perform minimal validation of virtual disk file while parsing config file
From: Kamala Narasimhan <kamala.narasimhan@xxxxxxxxx>
Date: Wed, 19 Jan 2011 13:09:39 -0500
Cc: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Delivery-date: Wed, 19 Jan 2011 10:10:18 -0800
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=y3whFAQmM+Yne9yAW68t0nYqo7BjuqmsSLnuoKS6slU=; b=rR/vkiQetDER4PCjJevNQYkocZseMqvNXh3D+OX7bYy+eJrJLcH0jSbW3nQMVzuVg0 iuhfUSf7mRGSAKR2EcZlIvabTKH3PZ8OaxymZ5r9ny4oUw33bIvhqqen/W+uTtZ/BreS TakG74AAl0okgIhPrMnUnU8SuNlfmxdWxcBiQ=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=biLpmt2ieGY7GA0ONnURf1n2QOnHyAmEEo9v2ayCTRa10/w1TT3ZeYOxRhD85HGWcO vqYg84vSs5boDNvniO/SsFuVLjxbJje6RWF7W3YcqbHsCQEF3OCaxBdsqeE2KxrGE6By r8kaCVKoS39KmOND8AvUZMvrVtZpfcaik4d4k=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <AANLkTikf3TVJwE_N-OyuS-UhyA8+cgzAG__9hz3AETeM@xxxxxxxxxxxxxx>
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: <AANLkTimSUym0u+SNm0AvNp3AZQQFspetAaXmNShkPJd4@xxxxxxxxxxxxxx> <1294995912.8240.86.camel@xxxxxxxxxxxxxxxxxxxxxx> <AANLkTikfUHHc+-gVkgnRJc722wObLF3TumpK5WSfJVAE@xxxxxxxxxxxxxx> <1295024348.12018.222.camel@xxxxxxxxxxxxxxxxxxxxxx> <AANLkTikf3TVJwE_N-OyuS-UhyA8+cgzAG__9hz3AETeM@xxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
> I will make necessary changes and resend the patch.
>

Here is a modified patch for further review and to apply if ok.

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

diff -r fe8a177ae9cb tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Jan 19 15:29:04 2011 +0000
+++ b/tools/libxl/libxl.c       Wed Jan 19 12:41:11 2011 -0500
@@ -826,6 +826,41 @@ skip_autopass:

 
/******************************************************************************/

+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;
+    }
+
+    /* Return without further validation for empty cdrom drive.
+       Note: Post 4.1 we need to change the interface to handle empty
+       cdrom rather than go with the below assumption.
+     */
+    if ( (strncmp(file_name, "", sizeof("")) == 0) && (disk_type ==
PHYSTYPE_PHY) )
+        return 1;
+
+    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;
+}
+
 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
libxl_device_disk *disk)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
@@ -835,6 +870,9 @@ int libxl_device_disk_add(libxl_ctx *ctx
     int devid;
     libxl__device device;
     int major, minor, rc;
+
+    if ( validate_virtual_disk(disk->physpath, disk->phystype) == 0 )
+        return ERROR_FAIL;

     front = flexarray_make(16, 1);
     if (!front) {

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

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