]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_agent: Rework domain object locking when opening agent
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 27 Oct 2021 11:38:05 +0000 (13:38 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 12 Nov 2021 13:11:11 +0000 (14:11 +0100)
Just like qemuMonitorOpen(), hold the domain object locked
throughout the whole time of qemuConnectAgent() and unlock it
only for a brief time of actual connect() (because this is the
only part that has a potential of blocking).

The reason is that qemuAgentOpen() does access domain object
(well, its privateData) AND also at least one argument (@context)
depends on domain object. Accessing these without the lock is
potentially dangerous.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1845468#c12
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_agent.c
src/qemu/qemu_process.c

index be9f73a62108338a223239b8a8786bca1d80d8ac..d19a8b983d4e9ee06b1571e1e63a24d689cf345c 100644 (file)
@@ -682,7 +682,10 @@ qemuAgentOpen(virDomainObj *vm,
         goto cleanup;
     }
 
+    virObjectUnlock(vm);
     agent->fd = qemuAgentOpenUnix(config->data.nix.path);
+    virObjectLock(vm);
+
     if (agent->fd == -1)
         goto cleanup;
 
index 173b7d64a4a42ae47cd04ca2caa01d8f343407cc..6e3d3b82e08965fa0b3a6c31ac71d4ec4331b48f 100644 (file)
@@ -238,16 +238,12 @@ qemuConnectAgent(virQEMUDriver *driver, virDomainObj *vm)
      * deleted while the agent is active */
     virObjectRef(vm);
 
-    virObjectUnlock(vm);
-
     agent = qemuAgentOpen(vm,
                           config->source,
                           virEventThreadGetContext(priv->eventThread),
                           &agentCallbacks,
                           virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VSERPORT_CHANGE));
 
-    virObjectLock(vm);
-
     if (agent == NULL)
         virObjectUnref(vm);