]> git.proxmox.com Git - qemu.git/commitdiff
pc: Fix crash when attempting to hotplug CPU with negative ID
authorIgor Mammedov <imammedo@redhat.com>
Thu, 30 May 2013 15:09:34 +0000 (17:09 +0200)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Mon, 17 Jun 2013 23:01:42 +0000 (18:01 -0500)
QMP command "{ 'execute': 'cpu-add', 'arguments': { 'id': -1 }}" may cause
QEMU SIGSEGV at:
 piix4_cpu_hotplug_req ()
    ...
    g->sts[cpu_id / 8] |= (1 << (cpu_id % 8));
    ...

Since for PC in current implementation id should be in range [0...maxcpus)
and maxcpus is already checked, add check for lower bound and error out
on incorrect value.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
(cherry picked from commit 8de433cb0820dc1f387a2d580d255744aacd60cc)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
hw/i386/pc.c

index 197d218715fdad9270ac0d65c3b9cdb409331b17..e2c44f888201af087586ed4466a14787c2758b3c 100644 (file)
@@ -927,6 +927,11 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
     DeviceState *icc_bridge;
     int64_t apic_id = x86_cpu_apic_id_from_index(id);
 
+    if (id < 0) {
+        error_setg(errp, "Invalid CPU id: %" PRIi64, id);
+        return;
+    }
+
     if (cpu_exists(apic_id)) {
         error_setg(errp, "Unable to add CPU: %" PRIi64
                    ", it already exists", id);