render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
b159bb
From 96518d4316b711c72205117f8d5c967d5127bbb6 Mon Sep 17 00:00:00 2001
b159bb
Message-Id: <96518d4316b711c72205117f8d5c967d5127bbb6.1374788370.git.crobinso@redhat.com>
b159bb
From: Alex Jia <ajia@redhat.com>
b159bb
Date: Tue, 16 Jul 2013 17:30:20 +0800
b159bb
Subject: [PATCH] qemu: Prevent crash of libvirtd without guest agent
b159bb
 configuration
b159bb
b159bb
If users haven't configured guest agent then qemuAgentCommand() will
b159bb
dereference a NULL 'mon' pointer, which causes crash of libvirtd when
b159bb
using agent based cpu (un)plug.
b159bb
b159bb
With the patch, when the qemu-ga service isn't running in the guest,
b159bb
a expected error "error: Guest agent is not responding: Guest agent
b159bb
not available for now" will be raised, and the error "error: argument
b159bb
unsupported: QEMU guest agent is not configured" is raised when the
b159bb
guest hasn't configured guest agent.
b159bb
b159bb
GDB backtrace:
b159bb
b159bb
 (gdb) bt
b159bb
 #0  virNetServerFatalSignal (sig=11, siginfo=<value optimized out>, context=<value optimized out>) at rpc/virnetserver.c:326
b159bb
 #1  <signal handler called>
b159bb
 #2  qemuAgentCommand (mon=0x0, cmd=0x7f39300017b0, reply=0x7f394b090910, seconds=-2) at qemu/qemu_agent.c:975
b159bb
 #3  0x00007f39429507f6 in qemuAgentGetVCPUs (mon=0x0, info=0x7f394b0909b8) at qemu/qemu_agent.c:1475
b159bb
 #4  0x00007f39429d9857 in qemuDomainGetVcpusFlags (dom=<value optimized out>, flags=9) at qemu/qemu_driver.c:4849
b159bb
 #5  0x00007f3957dffd8d in virDomainGetVcpusFlags (domain=0x7f39300009c0, flags=8) at libvirt.c:9843
b159bb
b159bb
How to reproduce?
b159bb
b159bb
 # To start a guest without guest agent configuration
b159bb
 # then run the following cmdline
b159bb
b159bb
 # virsh vcpucount foobar --guest
b159bb
 error: End of file while reading data: Input/output error
b159bb
 error: One or more references were leaked after disconnect from the hypervisor
b159bb
 error: Failed to reconnect to the hypervisor
b159bb
b159bb
RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=984821
b159bb
b159bb
Signed-off-by: Alex Jia <ajia@redhat.com>
b159bb
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
b159bb
---
b159bb
 src/qemu/qemu_driver.c | 26 ++++++++++++++++++++++++++
b159bb
 1 file changed, 26 insertions(+)
b159bb
b159bb
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
b159bb
index b4a668a..95dd591 100644
b159bb
--- a/src/qemu/qemu_driver.c
b159bb
+++ b/src/qemu/qemu_driver.c
b159bb
@@ -4122,6 +4122,19 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
b159bb
             goto endjob;
b159bb
         }
b159bb
 
b159bb
+        if (priv->agentError) {
b159bb
+            virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
b159bb
+                           _("QEMU guest agent is not "
b159bb
+                             "available due to an error"));
b159bb
+            goto endjob;
b159bb
+        }
b159bb
+
b159bb
+        if (!priv->agent) {
b159bb
+            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
b159bb
+                           _("QEMU guest agent is not configured"));
b159bb
+            goto endjob;
b159bb
+        }
b159bb
+
b159bb
         qemuDomainObjEnterAgent(vm);
b159bb
         ncpuinfo = qemuAgentGetVCPUs(priv->agent, &cpuinfo);
b159bb
         qemuDomainObjExitAgent(vm);
b159bb
@@ -4839,6 +4852,19 @@ qemuDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
b159bb
         if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
b159bb
             goto cleanup;
b159bb
 
b159bb
+        if (priv->agentError) {
b159bb
+            virReportError(VIR_ERR_AGENT_UNRESPONSIVE, "%s",
b159bb
+                           _("QEMU guest agent is not "
b159bb
+                             "available due to an error"));
b159bb
+            goto endjob;
b159bb
+        }
b159bb
+
b159bb
+        if (!priv->agent) {
b159bb
+            virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
b159bb
+                           _("QEMU guest agent is not configured"));
b159bb
+            goto endjob;
b159bb
+        }
b159bb
+
b159bb
         if (!virDomainObjIsActive(vm)) {
b159bb
             virReportError(VIR_ERR_OPERATION_INVALID, "%s",
b159bb
                            _("domain is not running"));
b159bb
-- 
b159bb
1.8.3.1
b159bb