From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kamala Narasimhan Subject: Re: [PATCH] xl: Perform minimal validation of virtual disk file while parsing config file Date: Fri, 21 Jan 2011 21:33:39 -0500 Message-ID: <4D3A4203.2050706@gmail.com> References: <1294995912.8240.86.camel@zakaz.uk.xensource.com> <1295024348.12018.222.camel@qabil.uk.xensource.com> <1295532296.12018.337.camel@qabil.uk.xensource.com> <19768.22912.878633.622270@mariner.uk.xensource.com> <19769.31094.274199.464586@mariner.uk.xensource.com> <1295616468.12018.352.camel@qabil.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1295616468.12018.352.camel@qabil.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Gianni Tedesco Cc: Ian Campbell , "xen-devel@lists.xensource.com" , Ian Jackson , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Ian - Apologies for the delay. I think I have covered all comments so far. If there are more I will get to it ASAP. Please let me know. Also, I switched email client to avoid word wrapping and other issues. If you still find the format of the patches inconvenient, please let me know. Signed-off-by: Kamala Narasimhan Kamala 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 Fri Jan 21 18:00:37 2011 -0500 @@ -826,6 +826,35 @@ skip_autopass: /******************************************************************************/ +static int validate_virtual_disk(libxl_ctx *ctx, char *file_name, libxl_disk_phystype disk_type) +{ + struct stat stat_buf; + + /* 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 ( (file_name[0] == '\0') && (disk_type == PHYSTYPE_PHY) ) + return 0; + + if ( stat(file_name, &stat_buf) != 0 ) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to stat %s", file_name); + return ERROR_INVAL; + } + if ( disk_type == PHYSTYPE_PHY ) { + if ( !(S_ISBLK(stat_buf.st_mode)) ) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual disk %s is not a block device!\n", + file_name); + return ERROR_INVAL; + } + } else if ( stat_buf.st_size == 0 ) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual disk %s size is 0!\n", file_name); + return ERROR_INVAL; + } + + return 0; +} + int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) { libxl__gc gc = LIBXL_INIT_GC(ctx); @@ -835,6 +864,10 @@ int libxl_device_disk_add(libxl_ctx *ctx int devid; libxl__device device; int major, minor, rc; + + rc = validate_virtual_disk(ctx, disk->physpath, disk->phystype); + if (rc) + return rc; front = flexarray_make(16, 1); if (!front) {