From nobody Sat May 30 17:46:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1779433080961814.1987063281364; Thu, 21 May 2026 23:58:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wQJoo-0003a0-TI; Fri, 22 May 2026 02:57:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQJoj-0003Zj-5p for qemu-devel@nongnu.org; Fri, 22 May 2026 02:57:09 -0400 Received: from mailgw.kylinos.cn ([124.126.103.232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wQJoa-0002bk-Bf for qemu-devel@nongnu.org; Fri, 22 May 2026 02:57:08 -0400 Received: from zgh-vmware-virtual-platform.localdomain [(120.228.139.200)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1187487065; Fri, 22 May 2026 14:56:40 +0800 X-UUID: 62b9b8a055ab11f1aa26b74ffac11d73-20260522 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12, REQID:9ed5d12c-2b50-4b28-9a0d-9e64015464d3, IP:10, URL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:5 X-CID-INFO: VERSION:1.3.12, REQID:9ed5d12c-2b50-4b28-9a0d-9e64015464d3, IP:10, UR L:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:5 X-CID-META: VersionHash:e7bac3a, CLOUDID:89db9ce744bbf1d67ca5204198459ad3, BulkI D:260522145641448ATRFU,BulkQuantity:0,Recheck:0,SF:10|38|66|78|102|123|127 |865|898,TC:nil,Content:0|15|50,EDM:-3,IP:-2,URL:0,File:nil,RT:nil,Bulk:ni l,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE :0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 62b9b8a055ab11f1aa26b74ffac11d73-20260522 X-User: zhaoguohan@kylinos.cn From: zhaoguohan@kylinos.cn To: John Levon , Thanos Makatos , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Cc: qemu-devel@nongnu.org Subject: [PATCH] vfio-user: disconnect container when device info query fails Date: Fri, 22 May 2026 14:56:37 +0800 Message-ID: <20260522065637.4109499-1-zhaoguohan@kylinos.cn> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=124.126.103.232; envelope-from=zhaoguohan@kylinos.cn; helo=mailgw.kylinos.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01, UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1779433083937158500 Content-Type: text/plain; charset="utf-8" From: GuoHan Zhao 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 listene= r, RAM discard state, object reference and address space reference are released on this error path. Signed-off-by: GuoHan Zhao Reviewed-by: John Levon --- hw/vfio-user/container.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c index 796289a46903..dc23b06eebf1 100644 --- a/hw/vfio-user/container.c +++ b/hw/vfio-user/container.c @@ -309,7 +309,12 @@ static bool vfio_user_device_attach(const char *name, = VFIODevice *vbasedev, return false; } =20 - return vfio_user_device_get(container, vbasedev, errp); + if (!vfio_user_device_get(container, vbasedev, errp)) { + vfio_user_container_disconnect(container); + return false; + } + + return true; } =20 static void vfio_user_device_detach(VFIODevice *vbasedev) --=20 2.43.0