]> xenbits.xensource.com Git - xen.git/commitdiff
tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set
authorJuergen Gross <jgross@suse.com>
Mon, 3 Sep 2018 12:59:42 +0000 (14:59 +0200)
committerWei Liu <wei.liu2@citrix.com>
Wed, 5 Sep 2018 10:53:35 +0000 (11:53 +0100)
Trying to set the number of vcpus of a domain to 0 isn't refused.
We should not allow that.

Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Signed-off-by: Wei Liu <wei.liu2@citrix.com>
tools/libxl/libxl_domain.c
tools/xl/xl_vcpu.c

index 533bcdf240d7c9f013d5a0da6baf966411714e15..3377bba9946516dd42db0f5501aa9b98700fce0f 100644 (file)
@@ -1369,6 +1369,12 @@ int libxl_set_vcpuonline(libxl_ctx *ctx, uint32_t domid, libxl_bitmap *cpumap)
     }
 
     maxcpus = libxl_bitmap_count_set(cpumap);
+    if (maxcpus == 0)
+    {
+        LOGED(ERROR, domid, "Requested 0 VCPUs!");
+        rc = ERROR_FAIL;
+        goto out;
+    }
     if (maxcpus > info.vcpu_max_id + 1)
     {
         LOGED(ERROR, domid, "Requested %d VCPUs, however maxcpus is %d!",
index aef486864ccda14c31a1d9123c643a5fb2b38878..71d3a5c96d86116a83f86e34ab807d97240580a3 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <stdlib.h>
+#include <limits.h>
 
 #include <libxl.h>
 #include <libxl_utils.h>
@@ -331,13 +332,14 @@ int main_vcpupin(int argc, char **argv)
 static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
 {
     char *endptr;
-    unsigned int max_vcpus, i;
+    unsigned int i;
+    unsigned long max_vcpus;
     libxl_bitmap cpumap;
     int rc;
 
     libxl_bitmap_init(&cpumap);
     max_vcpus = strtoul(nr_vcpus, &endptr, 10);
-    if (nr_vcpus == endptr) {
+    if (nr_vcpus == endptr || max_vcpus > INT_MAX) {
         fprintf(stderr, "Error: Invalid argument.\n");
         return 1;
     }
@@ -358,7 +360,7 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
 
         if (max_vcpus > online_vcpus && max_vcpus > host_cpu) {
             fprintf(stderr, "You are overcommmitting! You have %d physical" \
-                    " CPUs and want %d vCPUs! Aborting, use --ignore-host to" \
+                    " CPUs and want %ld vCPUs! Aborting, use --ignore-host to" \
                     " continue\n", host_cpu, max_vcpus);
             return 1;
         }
@@ -375,7 +377,7 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
     if (rc == ERROR_DOMAIN_NOTFOUND)
         fprintf(stderr, "Domain %u does not exist.\n", domid);
     else if (rc)
-        fprintf(stderr, "libxl_set_vcpuonline failed domid=%u max_vcpus=%d," \
+        fprintf(stderr, "libxl_set_vcpuonline failed domid=%u max_vcpus=%ld," \
                 " rc: %d\n", domid, max_vcpus, rc);
 
     libxl_bitmap_dispose(&cpumap);