@samitouri / QOSamiQemu / commits / 5a5ba01f2c

vfio-user: disconnect container when device info query fails

vfio_user_device_attach() connects the vfio-user container before querying VFIO_USER_DEVICE_GET_INFO. If the device info query fails, vfio_device_prepare() has not run yet, so vbasedev->bcontainer is still NULL and the later vfio_device_detach() cleanup path cannot reach the new container. Disconnect the container before returning the attach failure so the listener, RAM discard state, object reference and address space reference are released on this error path. Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn> Reviewed-by: John Levon <john.levon@nutanix.com> Link: https://lore.kernel.org/qemu-devel/20260522065637.4109499-1-zhaoguohan@kylinos.cn Signed-off-by: Cédric Le Goater <clg@redhat.com>

GuoHan Zhao committed May 22, 2026 at 14:56 UTC 5a5ba01f2ce2e9199593f57ddd833f9599c07a92
1 file changed +6 -1
hw/vfio-user/container.c
+6 -1
@@ -309,7 +309,12 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
309 return false;
310 }
311
312 - return vfio_user_device_get(container, vbasedev, errp);
312 + if (!vfio_user_device_get(container, vbasedev, errp)) {
313 + vfio_user_container_disconnect(container);
314 + return false;
315 + }
316 +
317 + return true;
318 }
319
320 static void vfio_user_device_detach(VFIODevice *vbasedev)