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@xxxxxxxxxx> --- src/qemu/qemu_agent.c | 3 +++ src/qemu/qemu_process.c | 4 ---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 5f421be6f6..166cfaf485 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -704,7 +704,10 @@ qemuAgentOpen(virDomainObj *vm, goto cleanup; } + virObjectUnlock(vm); agent->fd = qemuAgentOpenUnix(config->data.nix.path); + virObjectLock(vm); + if (agent->fd == -1) goto cleanup; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d5f8a47ac2..d2ea9b55fe 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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); -- 2.32.0