xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
	wei.liu2@citrix.com, ian.jackson@eu.citrix.com
Subject: [PATCH v2] tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set
Date: Mon,  3 Sep 2018 14:59:42 +0200	[thread overview]
Message-ID: <20180903125942.30551-1-jgross@suse.com> (raw)

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>
---
 tools/libxl/libxl_domain.c | 6 ++++++
 tools/xl/xl_vcpu.c         | 5 +++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c
index 533bcdf240..3377bba994 100644
--- a/tools/libxl/libxl_domain.c
+++ b/tools/libxl/libxl_domain.c
@@ -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!",
diff --git a/tools/xl/xl_vcpu.c b/tools/xl/xl_vcpu.c
index aef486864c..3057c22aae 100644
--- a/tools/xl/xl_vcpu.c
+++ b/tools/xl/xl_vcpu.c
@@ -331,13 +331,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;
     }
-- 
2.16.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

             reply	other threads:[~2018-09-03 12:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 12:59 Juergen Gross [this message]
2018-09-03 17:06 ` [PATCH v2] tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set Wei Liu
2018-09-05 10:19 ` Wei Liu
2018-09-05 10:55   ` Wei Liu
2018-09-05 12:14     ` Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180903125942.30551-1-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).