debuggers.hg

diff tools/libxl/libxl.c @ 22855:1d1eec7e1fb4

xl: Perform minimal validation of virtual disk file while parsing config file

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.

[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Kamala Narasimhan <kamala.narasimhan@gmail.com>
date Tue Jan 25 18:09:49 2011 +0000 (2011-01-25)
parents 6ec61438713a
children 00e1fd80e1f7
line diff
     1.1 --- a/tools/libxl/libxl.c	Tue Jan 25 18:06:53 2011 +0000
     1.2 +++ b/tools/libxl/libxl.c	Tue Jan 25 18:09:49 2011 +0000
     1.3 @@ -833,6 +833,31 @@ skip_autopass:
     1.4  
     1.5  /******************************************************************************/
     1.6  
     1.7 +static int validate_virtual_disk(libxl_ctx *ctx, char *file_name, libxl_disk_phystype disk_type)
     1.8 +{
     1.9 +    struct stat stat_buf;
    1.10 +
    1.11 +    if ( (file_name[0] == '\0') && (disk_type == PHYSTYPE_EMPTY) )
    1.12 +        return 0;
    1.13 +
    1.14 +    if ( stat(file_name, &stat_buf) != 0 ) {
    1.15 +        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to stat %s", file_name);
    1.16 +        return ERROR_INVAL;
    1.17 +    }
    1.18 +    if ( disk_type == PHYSTYPE_PHY ) {
    1.19 +        if ( !(S_ISBLK(stat_buf.st_mode)) ) {
    1.20 +            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual disk %s is not a block device!\n",
    1.21 +                file_name);
    1.22 +            return ERROR_INVAL;
    1.23 +        }
    1.24 +    } else if ( stat_buf.st_size == 0 ) {
    1.25 +        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Virtual disk %s size is 0!\n", file_name);
    1.26 +        return ERROR_INVAL;
    1.27 +    }
    1.28 +
    1.29 +    return 0;
    1.30 +}
    1.31 +
    1.32  int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
    1.33  {
    1.34      libxl__gc gc = LIBXL_INIT_GC(ctx);
    1.35 @@ -843,6 +868,10 @@ int libxl_device_disk_add(libxl_ctx *ctx
    1.36      libxl__device device;
    1.37      int major, minor, rc;
    1.38  
    1.39 +    rc = validate_virtual_disk(ctx, disk->physpath, disk->phystype);
    1.40 +    if (rc)
    1.41 +        return rc;
    1.42 +
    1.43      front = flexarray_make(16, 1);
    1.44      if (!front) {
    1.45          rc = ERROR_NOMEM;