Patchwork [5/8] vl.c: numa_add(): Validate nodeid before using it

login
register
mail settings
Submitter Eduardo Habkost
Date Feb. 4, 2013, 6:27 p.m.
Message ID <1360002472-17628-6-git-send-email-ehabkost@redhat.com>
Download mbox | patch
Permalink /patch/218026/
State New
Headers show

Comments

Eduardo Habkost - Feb. 4, 2013, 6:27 p.m.
Without this check, QEMU will corrupt memory if a too-large nodeid is
provided in the command-line. e.g.:

  -numa node,mem=...,cpus=...,nodeid=65

This changes nodenr to unsigned long long, to avoid integer conversion
issues when converting the strtoull() result to int.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 vl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Patch

diff --git a/vl.c b/vl.c
index 89de003..4955c29 100644
--- a/vl.c
+++ b/vl.c
@@ -1249,7 +1249,7 @@  static void numa_add(const char *optarg)
     char option[128];
     char *endptr;
     unsigned long long value, endvalue;
-    int nodenr;
+    unsigned long long nodenr;
 
     value = endvalue = 0ULL;
 
@@ -1270,6 +1270,11 @@  static void numa_add(const char *optarg)
             nodenr = strtoull(option, NULL, 10);
         }
 
+        if (nodenr >= MAX_NODES) {
+            fprintf(stderr, "qemu: invalid NUMA nodeid: %llu\n", nodenr);
+            exit(1);
+        }
+
         if (get_param_value(option, 128, "mem", optarg) == 0) {
             node_mem[nodenr] = 0;
         } else {