aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKamala Narasimhan <kamala.narasimhan@gmail.com>2011-01-25 18:09:49 +0000
committerKamala Narasimhan <kamala.narasimhan@gmail.com>2011-01-25 18:09:49 +0000
commitf2b8b0882978d3d716d5a5ea2c1b5089633185a3 (patch)
tree708c3ccff989ed5dc92e6d68a36c3a3a5b09b9cc
parent62c2a1d0989f67827868171e52ecd4b916a496b3 (diff)
downloadxen-f2b8b0882978d3d716d5a5ea2c1b5089633185a3.tar.gz
xen-f2b8b0882978d3d716d5a5ea2c1b5089633185a3.tar.bz2
xen-f2b8b0882978d3d716d5a5ea2c1b5089633185a3.zip
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>
-rw-r--r--tools/libxl/libxl.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 93a22d2024..6fee2b1a60 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -833,6 +833,31 @@ skip_autopass:
/******************************************************************************/
+static int validate_virtual_disk(libxl_ctx *ctx, char *file_name, libxl_disk_phystype disk_type)
+{
+ struct stat stat_buf;
+
+ if ( (file_name[0] == '\0') && (disk_type == PHYSTYPE_EMPTY) )
+ 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);
@@ -843,6 +868,10 @@ int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *dis
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) {
rc = ERROR_NOMEM;