From mboxrd@z Thu Jan 1 00:00:00 1970 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 E1159606A32D for ; Sat, 5 Dec 2026 00:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=lists1p-gnu-org header.b=qMmAIB3b; dkim=pass (2048-bit key, unprotected) header.d=gnu.org header.i=@gnu.org header.a=rsa-sha256 header.s=fencepost-gnu-org header.b=C4ILd5ng DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=lists1p-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From:Date ; bh=kw+l4OZKfyGLq6AYSyIe2vunOPg9OxDwkUGQikiEcmo=; b=qMmAIB3bNP3rvt8Oqp71DKE8 lxSvpDbJjvI57jgk9657Wg3PNlRII/nd0HGd3n+SWieq22FXST6lYH34ctvCAZfGdRQmyjGmK0fqM gpY68/SZNUzX7Wfoig2HBWR4A/075QNr+2tVdQW+IUI4KK4q4Hb40GlJNsIqzZ5ssBKK/GaMdGJyh htkGUbe6zicA5FkiNKIUSIdy1alLUcqqjVFe6LYj8DDSQF3DG0gd2vI0lvdqiZCh1KiEfCl1Jqz0B bdSY0C3hG1y31HMLW5tAQinCMWfpsp4sLKwC7MDZN1vE5oCCCuP31V/KIJjU0C+iAzigFeenNVqcU v3lG6eD1rw==; Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xZdpM-0000AU-PR; Fri, 04 Dec 2026 19:40:36 -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 1xZdpK-0000A9-Fg; Fri, 04 Dec 2026 19:40:34 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xZdpI-0005SU-LJ; Fri, 04 Dec 2026 19:40:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From: Date; bh=kw+l4OZKfyGLq6AYSyIe2vunOPg9OxDwkUGQikiEcmo=; b=C4ILd5ngdQz7j6JYb+g7 09gFvF2IdEZLz6lF8S9rGR6UHOIDyUEQYBheRNpIcZcQBoMqD3HcQH4noBRJaywPcXNDGjk10MKKx A98UKgCIqPshX/exHnBpwraTmHfuMFqKsdwiO37ZnDQcbKhbW59qBoM1cimu+nP04k/CXy/pCq8X0 yvZJYUZrtYgkFXUA0jIE9nQ4YKwAqJAs76ubFQAFYs6bqv2PAAixiDyjRdrdtuBA0zZDQgJG0SYXe 08nNKjzEWFdCsDUzJIBBtCxKtH3BKohHlSDl4BHJ+rAi6tQ1vG/IbYJtberB+5WXiSGR2g6HFefVT EmD6D57LoPinFw==; Date: Sat, 5 Dec 2026 01:40:30 +0100 From: Samuel Thibault To: David Woodhouse Cc: qemu-devel@nongnu.org, Jason Wang , "Michael S . Tsirkin" , Stefano Garzarella , qemu-stable@nongnu.org, David Woodhouse Subject: Re: [PATCH 1/5] net: Make slirp cleanup idempotent Message-ID: References: <20261204104345.3422972-1-dwmw2@infradead.org> <20261204104345.3422972-2-dwmw2@infradead.org> X-Archived-By: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="ta7qxtpN8ktEodVK" Content-Disposition: inline In-Reply-To: <20261204104345.3422972-2-dwmw2@infradead.org> Organization: I am not organized 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=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS 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 --ta7qxtpN8ktEodVK Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable David Woodhouse, le ven. 04 d=C3=A9c. 2026 10:43:41 +0000, a ecrit: > From: David Woodhouse >=20 > Since commit e7891c575fb2 ("net: move backend cleanup to NIC cleanup"), > a backend whose peer NIC has taken ownership of it (nic->peer_deleted) > has its cleanup callback invoked from both net_cleanup() and > qemu_del_nic(). Normally only one of those runs, but the xen-net-device > NIC is deleted from the XenDevice exit notifier, after net_cleanup(): > the backend is cleaned up twice. >=20 > For slirp the second invocation frees the Slirp state again, and glibc > aborts with "double free or corruption (!prev)". Trivially reproducible > with: >=20 > qemu-system-x86_64 -accel kvm,xen-version=3D0x4000a,kernel-irqchip=3Dsp= lit \ > -netdev user,id=3Dn0 -device xen-net-device,netdev=3Dn0 >=20 > and quitting. >=20 > Most cleanup callbacks are already idempotent. Document that NetCleanup, > like a GObject dispose method, must cope with being invoked more than > once, and make slirp bail out if s->slirp is already NULL. Also guard > net_slirp_receive(): the NIC owns the client beyond cleanup, and a > packet delivered in that window was a use-after-free. (Slirp's timers > all fire from the main loop and slirp_cleanup() deletes them, so none > can fire after the first cleanup.) >=20 > The remaining non-idempotent backends will be fixed in subsequent > patches, in roughly decreasing order of reachability. >=20 > Verified with valgrind that runtime deletion (device_del and netdev_del, > in both orders, for e1000 and xen-net-device) still cleans up exactly > once, and that the reproducer now exits cleanly. >=20 > Fixes: e7891c575fb2 ("net: move backend cleanup to NIC cleanup") > Cc: qemu-stable@nongnu.org > Signed-off-by: David Woodhouse Reviewed-by: Samuel Thibault Thanks! Samuel > --- > include/net/net.h | 8 ++++++++ > net/slirp.c | 20 +++++++++++++++++++- > 2 files changed, 27 insertions(+), 1 deletion(-) >=20 > diff --git a/include/net/net.h b/include/net/net.h > index c2fd451f17..6394df827f 100644 > --- a/include/net/net.h > +++ b/include/net/net.h > @@ -62,6 +62,14 @@ typedef int (NetLoad)(NetClientState *); > typedef void (NetStop)(NetClientState *); > typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); > typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, = int); > +/* > + * NetCleanup may be invoked more than once on the same client; like a > + * GObject dispose method it must be idempotent. In particular, a NIC > + * which has taken ownership of its deleted peer (nic->peer_deleted) > + * cleans the peer up from both net_cleanup() and qemu_del_nic(), and > + * for the xen-net-device NIC the latter runs from an exit notifier > + * after net_cleanup() has already done so. > + */ > typedef void (NetCleanup) (NetClientState *); > typedef void (LinkStatusChanged)(NetClientState *); > typedef void (NetClientDestructor)(NetClientState *); > diff --git a/net/slirp.c b/net/slirp.c > index eea12e7981..bf59639120 100644 > --- a/net/slirp.c > +++ b/net/slirp.c > @@ -128,7 +128,10 @@ static ssize_t net_slirp_receive(NetClientState *nc,= const uint8_t *buf, size_t > { > SlirpState *s =3D DO_UPCAST(SlirpState, nc, nc); > =20 > - slirp_input(s->slirp, buf, size); > + /* The client may live on after cleanup, owned by its peer NIC. */ > + if (s->slirp) { > + slirp_input(s->slirp, buf, size); > + } > =20 > return size; > } > @@ -151,12 +154,27 @@ static void net_slirp_cleanup(NetClientState *nc) > { > SlirpState *s =3D DO_UPCAST(SlirpState, nc, nc); > =20 > + /* > + * A NIC which has taken ownership of its deleted peer > + * (nic->peer_deleted) cleans the peer up both from net_cleanup() > + * and from qemu_del_nic(); for the xen-net-device NIC the latter > + * happens in an exit notifier after net_cleanup() has already run. > + * Like a GObject dispose method, cleanup must therefore cope with > + * being invoked more than once. > + */ > + if (!s->slirp) { > + return; > + } > + > g_slist_free_full(s->fwd, slirp_free_fwd); > + s->fwd =3D NULL; > main_loop_poll_remove_notifier(&s->poll_notifier); > unregister_savevm(NULL, "slirp", s->slirp); > slirp_cleanup(s->slirp); > + s->slirp =3D NULL; > if (s->exit_notifier.notify) { > qemu_remove_exit_notifier(&s->exit_notifier); > + s->exit_notifier.notify =3D NULL; > } > slirp_smb_cleanup(s); > QTAILQ_REMOVE(&slirp_stacks, s, entry); > --=20 > 2.43.0 >=20 --=20 Samuel xlnt comme sujet de stage je peux essayer de donner une description for= melle de automake -+- #ens-mim -+- --ta7qxtpN8ktEodVK Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEDHkkXhaQVdLZstA3O2TU75284AwFAmsTXXoACgkQO2TU7528 4Ay8uxAAglcgw8SFDSEG+eWbRXfiNf5pZOJjHTCKkCEeW5HS2juQt9ufffvejBxL ODQdfUmnWACOI6K0hunitM4IxoiFVgpqnGa/130mkU4Myl7oOvbJFIUcoCdS8txW 7uPwKy+yaR6+BmRpC/kJpJlzPrIbEI29lj1q0yx/Z7rWe12mc+40LpDXKgY//ozt Yt1JWcJeHumolRn8wV8KR5ZcLT0pXZ/wqc+k2TjNZDRpGvvwdKdOTmWddkvVRTgC kQYgF/otKY4/3DByEEAgAOiJoc6egYN95jCjMfzRVhj7UtWIt2JYepl5HHDhMHYf Znx2NQSmU1pgfUL1D1Pu8YbLR+l8zL55RQ4OXLf/PhbmH+rk7YwncGAdMfXNDQsx E0s7trUqPKTOeT6++KkwV5Fg86rjTrf+wrkOexm/RBvzKYPZgi+doxGYm9iID9/X C1gzsdelD4/qw/vLsYJOHir1uHDvAApLPhmElsX/L5wKSlhZXWsCrhjBNCKbdA5A x6awmP+AtgqUZcP4PU54/FO6Hqkg018nWmEHdLenCbpf7u/qDilTXxvrLajd6I/C HgYu6EcwfZ/U0O/2Qr4RWJpLB6BkJJe8BPUnxr0xIT2m1F+++9l2agl92a9M1h1D iboYe7e2dPipiWGVds92yXpdwXir6W7esr832EdFtCVbaeGZ4fo= =NFxX -----END PGP SIGNATURE----- --ta7qxtpN8ktEodVK--