From nobody Mon May 4 16:51:21 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4g8SMs5Ml7z6brK9 for ; Mon, 04 May 2026 16:51:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g8SMs1wz7z3wJh for ; Mon, 04 May 2026 16:51:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777913481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VyuPBx2qE/1YrhBKhwoRQmO+O3jJwyQi87G9LOJ2P6E=; b=q4X/iPzClwiraVF83wbuz5aNb+YATuwDDg1TbDoh9pBx9A3ztQioNWQVpPLi3yHEHjhYaZ S7U3HsWzcY93kJsgtxnoyuCAmI0JNE95FEZgOX5EoPzWKQHZJe1vl7lz6IrUQXz4nEqKfT WMTYjdHUzmjWrLI3pRwxbaIbnXC4yTbnveTeUd5kaQQ9gzN7wuECZFJqnUuc1HoZ4Jg2EE A3ogxY4Jmgw9sCC+OT1u1xBlALvWHWjHIlxIXLDrIRtyHMZjmXauDDT4CIrzRY7LHlaLfW XsCKRhy9Gnx55thDSlOUhCggxlDkPvf6u8uu7QXzSq+95H2YBPbMeSL8G1xg1g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777913481; a=rsa-sha256; cv=none; b=ISix1widYTSbdii+5q95tOwUX5fsykWm9RbPLizoh/TGA10bgxAsw/0asJ8OaWhZCunYPC BxXAC2OXopAfQyAtw/MM9qY6TfEVROvRpOxMH0zVkJ5MrBS6/EQGZ0ebkcx/AtTX0MgsiQ TIjzECZO9twigqZ8qAO+AVG72WDr/ml19DO399bK65+mrMjQ6yY3RPiYFLhFLMKPqxjAJI c+6pLn6gIlyi/qMEliGfZ77r5QJoebikT6P6/0jJB/ocvdghOcqQFP2ohomIFSGDXxH3aK BpAtuAEp4KMG4BItYAOhzWyMtYzTnzi6L7uxzkPT/nVG5UlJFLBlmU/Bc7+1Rg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777913481; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VyuPBx2qE/1YrhBKhwoRQmO+O3jJwyQi87G9LOJ2P6E=; b=Qk2i1nh/Fp1LLtJ/AI/6BShXaCVxvPLsvIAIgTEGGzUB0YGWYsMofUwBtjmpFTCd6ua+UW ZkGt5pEiBh45TF22AWG3jEhlro58Jm2AjCoiBmBHVU8BRP3zPn1LVNsFN0303z5L3CxfNF z/HFHekfXkpmJMdSTmPk/sWV3GLMsYDEFxToddTwTXxn75KFRecSZPpdQ1yO1OH+0cJD1H 0C0yNP05kiPStid8XHobLBIsQbgKy8RJiHwEI+d1JvjvmUpiQBZo8JC8dlXresqf+zgOko nBgelTGQibmqRs/l1Q/tiO2/BNBMx5N2Zs7JAUUfEjO1qCCHswkB50I1qwovZw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g8SMs1C05zCjp for ; Mon, 04 May 2026 16:51:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 26f63 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 04 May 2026 16:51:21 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 77b8bc06cf73 - stable/14 - ifnet: if_detach(): Fix races with vmove operations List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 77b8bc06cf73c66ed9a4ebb4d88d072056059ff4 Auto-Submitted: auto-generated Date: Mon, 04 May 2026 16:51:21 +0000 Message-Id: <69f8ce89.26f63.77cc04e3@gitrepo.freebsd.org> The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=77b8bc06cf73c66ed9a4ebb4d88d072056059ff4 commit 77b8bc06cf73c66ed9a4ebb4d88d072056059ff4 Author: Zhenlei Huang AuthorDate: 2026-04-25 19:56:07 +0000 Commit: Zhenlei Huang CommitDate: 2026-05-04 16:49:43 +0000 ifnet: if_detach(): Fix races with vmove operations The rationality is that the driver private data holds a strong reference to the interface, and the detach operation shall never fail. Given the vmove operation, if_vmove_loan(), if_vmove_reclaim() or vnet_if_return() is not atomic and spans multiple steps, acquire ifnet_detach_sxlock only for if_detach_internal() and if_vmove() is not sufficient. It is possible that the thread running if_detach() sees stale vnet, or the vmoving is in progress, then if_unlink_ifnet() will fail. Fix that by extending coverage of ifnet_detach_sxlock a bit to also cover if_unlink_ifnet(), so that the entire detach and vmove operation is serialized. Given it is an error when the if_unlink_ifnet() fails, and if_detach() is a public KPI, prefer panic() over assertion on failure, to indicate explicitly that bad thing happens. That shall also prevent potential corrupted status of the interface, which is a bit hard to diagnose. PR: 292993 Reviewed by: glebius MFC after: 5 days Differential Revision: https://reviews.freebsd.org/D56374 (cherry picked from commit ba7f47d47dc1a177e4d8f115f791ec25f3da0eab) (cherry picked from commit 5c4021ca0abe4e17200f5faa2fd71014ef0a5f09) --- sys/net/if.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 0aa1cbbb7b41..b3ab75144460 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -459,6 +459,7 @@ if_unlink_ifnet(struct ifnet *ifp, bool vmove) struct ifnet *iter; int found = 0; + sx_assert(&ifnet_detach_sxlock, SX_XLOCKED); IFNET_WLOCK(); CK_STAILQ_FOREACH(iter, &V_ifnet, if_link) if (iter == ifp) { @@ -1087,14 +1088,23 @@ if_detach(struct ifnet *ifp) { bool found; + /* + * The driver private data holds a strong reference to the ifnet, and + * it is actually the "owner", hence this routine shall never fail. + * + * Ideally we can loop retrying when we lose race with other threads + * those run if_unlink_ifnet(). For simplicity, use ifnet_detach_sxlock + * to serialize all the detach / vmove operations. + */ + sx_xlock(&ifnet_detach_sxlock); CURVNET_SET_QUIET(ifp->if_vnet); found = if_unlink_ifnet(ifp, false); - if (found) { - sx_xlock(&ifnet_detach_sxlock); - if_detach_internal(ifp, false); - sx_xunlock(&ifnet_detach_sxlock); - } + if (! found) + panic("%s: interface is not on the active list", + ifp->if_xname); + if_detach_internal(ifp, false); CURVNET_RESTORE(); + sx_xunlock(&ifnet_detach_sxlock); } /* @@ -1403,13 +1413,14 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid) } /* Get interface back from child jail/vnet. */ + sx_xlock(&ifnet_detach_sxlock); found = if_unlink_ifnet(ifp, true); if (! found) { + sx_xunlock(&ifnet_detach_sxlock); CURVNET_RESTORE(); prison_free(pr); return (ENODEV); } - sx_xlock(&ifnet_detach_sxlock); if_vmove(ifp, vnet_dst); sx_xunlock(&ifnet_detach_sxlock); CURVNET_RESTORE();