Skip to contentSkip to conversation

tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set

PATCH Superseded Juergen Gross 2 participants 3 messages Sep 3, 2018 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/xl: refuse to set number of vcpus to 0 via xl vcpu-set

Trying to set the number of vcpus of a domain to 0 isn't refused. We should not allow that.

---
 tools/xl/xl_vcpu.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/xl/xl_vcpu.c +4 -0
index aef486864c..45ac01beda 100644
@@ -341,6 +341,10 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
         fprintf(stderr, "Error: Invalid argument.\n");
         return 1;
     }
+    if (nr_vcpus == 0) {
+        fprintf(stderr, "Error: Setting number of vcpus to 0 isn't allowed.\n");
+        return 1;
+    }
 
     /*
      * Maximum amount of vCPUS the guest is allowed to set is limited
Signature · 7 lines
2.16.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

tools/xl/xl_vcpu.c static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host) · line 347

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 03.09.18 at 13:59, <[email protected]> wrote:
tools/xl/xl_vcpu.c +4 -0
@@ -341,6 +341,10 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
         fprintf(stderr, "Error: Invalid argument.\n");
         return 1;
     }
+    if (nr_vcpus == 0) {
+        fprintf(stderr, "Error: Setting number of vcpus to 0 isn't allowed.\n");
+        return 1;
+    }

This message is liable to be confusing when the string passed in represents a non-zero number which, when converted to unsigned int, yields zero. I think more thorough input checking is needed here. main_vcpupin(), for example, deliberately uses a type wider than seemingly necessary, to avoid such an issue.

I also wonder whether rejecting zero here is really the job of the frontend, rather than libxl.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 18 lines · Jan Beulich

tools/xl/xl_vcpu.c static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host) · line 347

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 03.09.18 at 13:59, <[email protected]> wrote:
tools/xl/xl_vcpu.c +4 -0
@@ -341,6 +341,10 @@ static int vcpuset(uint32_t domid, const char* nr_vcpus, int check_host)
         fprintf(stderr, "Error: Invalid argument.\n");
         return 1;
     }
+    if (nr_vcpus == 0) {
+        fprintf(stderr, "Error: Setting number of vcpus to 0 isn't allowed.\n");
+        return 1;
+    }

This message is liable to be confusing when the string passed in represents a non-zero number which, when converted to unsigned int, yields zero. I think more thorough input checking is needed here. main_vcpupin(), for example, deliberately uses a type wider than seemingly necessary, to avoid such an issue.

Quoted 2 lines

I also wonder whether rejecting zero here is really the job of the frontend, rather than libxl.

Yes, this would be better.

As the number ov vcpus is determined by counting the bits in the cpumap, and this value is an int, I guess we should limit the upper bound to INT_MAX.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel