Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D6497606A31C for ; Thu, 12 Nov 2026 05:05:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=EI8VcxUD Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xRMzo-0002ZB-Ix; Thu, 12 Nov 2026 00:05:14 -0500 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 1xRMzb-0002Y4-WA for qemu-devel@nongnu.org; Thu, 12 Nov 2026 00:05:02 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xRMzZ-0007l1-IJ for qemu-devel@nongnu.org; Thu, 12 Nov 2026 00:04:59 -0500 Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6AC2iaMv2796426; Thu, 12 Nov 2026 05:04:46 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=NJu5mn 4+5mJU35Gq6U3XltoNo23+X9g3hhXMnBpdwZE=; b=EI8VcxUD8vCbC7fAoE+QhR hK1FAFZvTfyi0q2o3EjMNapQ2otZFsVUL4eBPYP2yaMICzoFYreld2AEaUrh5Rko HEOL3gTjZNzzAd8SO/+8CFlKxM/dS5VA/ium78cJv619BGym035hlB4qtFy1/XTA kS2GuBf6JqzJeQL+MI6pCExqnmczXw0yzY55V+CHNhN3cihrjSKaMpHHTgcJocmC ITANm5ysrNqlh69e3XqE9U9LFggRaamtI3Zw5QMNZIozQkbMkseKhgmjoanC0Thd s4ko02h2EBVJNRi7sh5+B1QIHjqZTCitkgDyXNhpBmtNYi5kXHr2sb+eFjSX91qA == Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4hssdkwfnx-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 12 Nov 2026 05:04:46 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6AC2pRd3098417; Thu, 12 Nov 2026 05:04:45 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4hvkq0uxs7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Nov 2026 05:04:45 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6AC54iKv37618350 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 12 Nov 2026 05:04:44 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E6D758059; Thu, 12 Nov 2026 05:04:44 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F3FC658017; Thu, 12 Nov 2026 05:04:41 +0000 (GMT) Received: from [9.61.119.48] (unknown [9.61.119.48]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Thu, 12 Nov 2026 05:04:41 +0000 (GMT) Message-ID: Date: Thu, 12 Nov 2026 00:04:41 -0500 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v16 01/22] migration/cpr: forbid saving duplicate CprFds into hash table From: Eric Farman To: Omar Elghoul , Andrey Drobyshev , qemu-devel@nongnu.org Cc: odaki@rsg.ci.i.u-tokyo.ac.jp, bchaney@akamai.com, mst@redhat.com, maciej.szmigiero@oracle.com, sgarzare@redhat.com, mark.kanda@oracle.com, vsementsov@yandex-team.ru, clg@redhat.com, den@openvz.org, dongli.zhang@oracle.com, farosas@suse.de, peterx@redhat.com, dwmw2@infradead.org, philmd@oss.qualcomm.com, Christian Borntraeger , Matthew Rosato , Yi Liu , Eric Auger , Zhenzhong Duan References: <20261012-up-vsock-vhost-v5-v16-0-36c38bd15ffc@virtuozzo.com> <20261012-up-vsock-vhost-v5-v16-1-36c38bd15ffc@virtuozzo.com> <5b08d2f3-7edc-4525-95e4-ee6719acaf5b@linux.ibm.com> Content-Language: en-US Autocrypt: addr=farman@linux.ibm.com; keydata= xsFNBF7EiEwBEADGG0EtNKnjp+kQfEVqlqxXoBHjnaQptFpMgxNlz2GtqOujY6nzEWnybIXY 63XUTmMS/tWUf2DTbNCNoWwumGM/I2Gj1uGyMnc4Q477BQlL/e2/9MRaut11rwHsi4zmWylc jO0eFTSLFA8yFBj9osT3uZzk5TwWkD8sf+rD916fFVk0G39uYEd5sjEzjeOf9/dwXyZpjJY6 api1pUHEw7weRvOnllJAfIKFz+KoR6d7ezvMF9zOYHF73FGeSVIYoIEUhA5Cdg60rSlTtHb2 cftex3/cEapvY5bK3CKJ33BVVK10Bht9XfVaA/AOcg/3o5ZbhSIwz4xScGsEVf/Yr368YMdr 3VkCZrmN2ppmVRz/RvAmCyItnmzoVDlSREA6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bilT7bmpcq8B8/3yb0kmy6gXLcQAp OnomV3sQBmm050amiO3tvxMNv8J71AvNdTG/rojTDKUl2Nw4f+aw4nVw874m2XpEe9JGRw54 5d2dN8k3GpzcTBe9fCQPOFHOGkQ1CgptDkQuQVD3DIeNzQjXf6xehEymIKnLOkukT2smV0zh fj08z7eiv+dsmnBsbhdM6DKU8qIgkTu77TfHUKjjOY/Mj0YHPuH/J4b1AZFxBhGP0BTKiB2W CR6/49XVKvY1jHxgadSSNCD+f7tEqUNBlVl+P0emMJaYpK1+gy88ma4g3nvyOVe/VzDPjGDC 4HX/6RAR4Dbzry6/epWTTji+7ApzePzmJzPcuzD31ICsgT2dJ6ydxyxxXikBFJqx6BPOF+u+ 1BtKcTz1ek3I2sWvBM1V5CKaFw7iNXxS6HgS2scuAT2awKq+BQlt778/GfBWpXonfqixMvit y8m0x6unNti2MZIUMy0m2gcE In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=POqaavqC c=1 sm=1 tr=0 ts=6af548ee cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=A3H8OfN2AAAA:8 a=20KFwNOVAAAA:8 a=TYBLyS7eAAAA:8 a=liYQOHb4cClhrTlgu2sA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=hKFNpMRl0UUYlmJlzFdh:22 a=zvYvwCWiE4KgVXXeO06c:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTEyMDAxOCBTYWx0ZWRfX4sUIWibOyd7G gT3F8LlbtEhURQ8goQqU6xky6E7A0LHLFxvSkgRpUMOk5c8HOjUUgPKPxb/+gGjBgoSYUlQVaHc NXeA67mUnniZgA6pbIuHkZF14Pmed9wQcZ/FBolOqmvQ0hr1d3vN9Aq8aRUjynwd8OL8/CSw4KE PyvxyrzB6IrWinHYD5uIw2yNHTHBYJdLieqSuYd44hFbh0/3KHuKseRItR7R8E3zk8e6E7hDblv V67fR8uCXgXdUUTkkhyNRbNIw1Esde7HZn0wjFKoeWFwGd+nQqrEvzhWDozn5pe2luoJRtjc1p5 NZDNAr1wk87hmmeFaB89wyJOTkdBbrmfvDoLek1sFPUB1lQTE/XEcqRr7w/4oIFdUbdupc/QYyy ymi/DB9L1DCnv2rjM5udH0a8UBz6SSRBdqmhMCLYWBYY7wGlcCEIlctwCRl/RFKCyRbLqNs9MNO h86+2j2K9KUoPrDUcvg== X-Proofpoint-Spam-Info: AW1haW4tMjYxMTEyMDAxOCBTYWx0ZWRfX4DpCY2T/+pH8 +94Q7SHNimiyvkZ6oSuWOTuygaOIyp3Oxwee6fy7YD6QaOwnyFapNfgfTzpKOGpPvfIrr63gLyu F/ZDjFFERm88ClMG0Ps37nV4pxcMkBM= X-Proofpoint-ORIG-GUID: 4Bumm2g9juqN8YMssEef8vvTwv7uU8Xq X-Proofpoint-GUID: 4Bumm2g9juqN8YMssEef8vvTwv7uU8Xq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-12_01,2026-11-11_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 impostorscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 spamscore=0 clxscore=1011 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611120018 Received-SPF: pass client-ip=148.163.158.5; envelope-from=farman@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-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-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 +cc iommufd maintainers On 11/11/26 11:52 PM, Eric Farman wrote: > > > On 11/10/26 3:51 PM, Omar Elghoul wrote: >> On 10/12/26 6:28 AM, Andrey Drobyshev wrote: >>> In its current form, the mechanism for saving CPR FDs into hash table >>> has flaws. >>> >>> The CPR fd hash table uses the same CprFd for both key and value, and >>> is created with a key destroy function.  Inserting a second element >>> with the same (name, id) key leads to a use after free.  According to >>> GLib docs [1], g_hash_table_insert() keeps the old key, replaces the >>> value with the new element, and destroys the new key.  Thus when >>> inserting 2 CprFd elements fd1 and fd2 with equal keys we get: >>> >>>    g_hash_table_insert(table, fd1, fd1);  /* table has fd1 -> fd1 */ >>>    g_hash_table_insert(table, fd2, fd2);  /* table has fd1 -> fd2, >>> fd2 freed */ >>> >>> Any subsequent cpr_find_fd() for that key then returns freed memory. >>> >>> This is reachable whenever two CPR-aware objects register fds under the >>> same name, and it happens long before an actual CPR, since cpr_save_fd() >>> is typically called from .realize(), i.e. at boot time. >>> >>> Apart from the UAF itself, when the user decides to perform CPR >>> migration, >>> on CPR target we'd get corrupted FD from the hash table and fail >>> somewhere >>> in .realize() for affected devices. >>> >>> As a solution, let's altogether prohibit adding CprFds with duplicate >>> keys.  Since FDs are being registered for a subsequent CPR right at the >>> startup in .realize(), that'll allow us to error out and exit QEMU (or >>> fail a device hotplug op) gracefully instead of delaying potential >>> problems for later.  To do so, let's make cpr_save_fd() return 'bool' >>> instead of 'void' and provide an 'errp' argument to it.  That way caller >>> becomes responsible for checking the return value and propagating the >>> error. >>> >>> Also update all the callers to use the adjusted interface to keep things >>> compilable and bisectable. >>> >>> [1] https://docs.gtk.org/glib/type_func.HashTable.insert.html >>> >>> Fixes: a181df93bb3 ("migration/cpr: use hashtable for cpr fds") >>> Reviewed-by: Peter Xu >>> Reviewed-by: Cédric Le Goater >>> Signed-off-by: Andrey Drobyshev >> >> Hi everyone, FYI we've recently run into a regression on s390x where if >> we have a KVM guest with a PCI passthrough device using iommufd and we >> hot-unplug the device, the guest becomes fully unresponsive. In the host >> dmesg, we can see this message right when the hang begins: >> >> [ 1618.849602] vfio-pci 0001:00:00.0: No device request channel >> registered, blocked until released by user > > It's worth pointing out that the new error message in this commit does > indeed show up in the logs, and points to the problematic device fd: > > virtqemud[1172]: internal error: unable to execute QEMU command 'object- > add': cpr fd 'iommufd0' id 0 is already registered > virtqemud[1172]: internal error: unable to execute QEMU command > 'closefd': File descriptor named 'iommufd' not found > kernel: mlx5_vfio_pci 0004:00:00.0: No device request channel > registered, blocked until released by user > > >> >> Bisecting qemu leads us to this patch: >> >> de80025348925ba9f56070ce4ec0a5a0c512d450 is the first 'bad' commit >> commit de80025348925ba9f56070ce4ec0a5a0c512d450 >> Author: Andrey Drobyshev >> Date:   Mon Oct 12 13:28:09 2026 +0300 >> >>      migration/cpr: forbid saving duplicate CprFds into hash table >> >> We tried to revert the commit to confirm the root cause, but then the >> master branch no longer compiles, so unfortunately we were not able to >> confirm that, at least without making many changes. >> >> We're wondering if you might have any ideas what's going on there, or >> what we could do to try and resolve this issue. Any thoughts would be >> much appreciated and I'd be happy to share more info if needed. > > > Since the routine that unregisters such an fd is cpr_delete_fd(), but > that gets skipped as soon as we go through the _set_fd() path, I wonder > if the solution starts as something like the following? > > diff --git a/backends/iommufd.c b/backends/iommufd.c > index ecf4caee1a..d708948357 100644 > --- a/backends/iommufd.c > +++ b/backends/iommufd.c > @@ -161,8 +161,8 @@ void iommufd_backend_disconnect(IOMMUFDBackend *be) >      be->users--; >      if (!be->users) { >          vfio_iommufd_cpr_unregister_iommufd(be); > +        cpr_delete_fd(iommufd_fd_name(be), 0); >          if (be->owned) { > -            cpr_delete_fd(iommufd_fd_name(be), 0); >              close(be->fd); >              be->fd = -1; >          } > > What that means for the prepare_delete/finalize paths and/or the failure > path in _connect is something else to ponder... Neither of those call > cpr_delete_fd() themselves despite closing the fd if it owns the thing. > >> >> Thanks in advance! >> >> [...] >