qemu_agent: Rework domain object locking when opening agent

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>
This commit is contained in:
Michal Privoznik 2021-10-27 13:38:05 +02:00
parent 831f541582
commit 108e131a3d
2 changed files with 3 additions and 4 deletions

View File

@ -682,7 +682,10 @@ qemuAgentOpen(virDomainObj *vm,
goto cleanup; goto cleanup;
} }
virObjectUnlock(vm);
agent->fd = qemuAgentOpenUnix(config->data.nix.path); agent->fd = qemuAgentOpenUnix(config->data.nix.path);
virObjectLock(vm);
if (agent->fd == -1) if (agent->fd == -1)
goto cleanup; goto cleanup;

View File

@ -238,16 +238,12 @@ qemuConnectAgent(virQEMUDriver *driver, virDomainObj *vm)
* deleted while the agent is active */ * deleted while the agent is active */
virObjectRef(vm); virObjectRef(vm);
virObjectUnlock(vm);
agent = qemuAgentOpen(vm, agent = qemuAgentOpen(vm,
config->source, config->source,
virEventThreadGetContext(priv->eventThread), virEventThreadGetContext(priv->eventThread),
&agentCallbacks, &agentCallbacks,
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VSERPORT_CHANGE)); virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_VSERPORT_CHANGE));
virObjectLock(vm);
if (agent == NULL) if (agent == NULL)
virObjectUnref(vm); virObjectUnref(vm);