OSDN Git Service

numa: Fix off-by-one error at MAX_CPUMASK_BITS check
authorEduardo Habkost <ehabkost@redhat.com>
Thu, 12 Feb 2015 17:23:48 +0000 (15:23 -0200)
committerEduardo Habkost <ehabkost@redhat.com>
Thu, 19 Mar 2015 19:01:22 +0000 (16:01 -0300)
Fix the CPU index check to ensure we don't go beyond the size of the
node_cpu bitmap.

CPU index is always less than MAX_CPUMASK_BITS, as documented at
sysemu.h:

> The following shall be true for all CPUs:
>   cpu->cpu_index < max_cpus <= MAX_CPUMASK_BITS

Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
numa.c

diff --git a/numa.c b/numa.c
index ffbec68..13b2f01 100644 (file)
--- a/numa.c
+++ b/numa.c
@@ -76,9 +76,9 @@ static void numa_node_parse(NumaNodeOptions *node, QemuOpts *opts, Error **errp)
     }
 
     for (cpus = node->cpus; cpus; cpus = cpus->next) {
-        if (cpus->value > MAX_CPUMASK_BITS) {
+        if (cpus->value >= MAX_CPUMASK_BITS) {
             error_setg(errp, "CPU number %" PRIu16 " is bigger than %d",
-                       cpus->value, MAX_CPUMASK_BITS);
+                       cpus->value, MAX_CPUMASK_BITS - 1);
             return;
         }
         bitmap_set(numa_info[nodenr].node_cpu, cpus->value, 1);