From nobody Mon Mar 30 16:02:12 2026 X-Original-To: dev-commits-src-main@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 4fkwxJ4td2z6WhVF for ; Mon, 30 Mar 2026 16:02:12 +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 "R12" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4fkwxJ41xvz47GV for ; Mon, 30 Mar 2026 16:02:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1774886532; 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=g863N5nPu3sdp8yoWgaapcFfuXv8W4PyiaKyuRJXXto=; b=Zh4bQvxc6PfLbfFLJlNy4noBTHYD1/ykKzoX6bufKywF0ID5czfkqSxa1OLX3igMRscbuc V3cbNaT2MCE4C3xmqgeziZKIb23rVQvPRYM9V8lJkAYA1pGcPi/yL1yaqE2B1zJxILN00u +KFBQ2BFLMQ9Bc4xXvYZUR0AtEHmEw5Zj6NYLAz6eQG+O7iDEoNLLu+QI4mJvojBIEBD11 bFItvjPq6FPAX7GtorGCkEOsIsSpbtJhW8OUnmE8fwJlhiZ8ey9yQsrRQbjrkpIM9qEMyc XkmmbzVmafjQlsYckwzUD02bDrBN6m1EESin3lbo7Y5NBEKRQPImLGEISZhMEQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1774886532; a=rsa-sha256; cv=none; b=uorq2uxQi3WMbUCEtZyJEtL9NsxyZpOwmmEVYnxUgnKp877rlJG0ysLqXuXc1K2RTP1TPw yLkkYWLQkGdGut4SbEEiXGoROXwbXL/mx+JyDRLTUZcuiWl333ru0ktYtVpRlfXQnIN+a6 mNGe8FuTJ2phM2mOGnn3bwqOd5PtM0bNFs3g3d62SkZ+vHSALhDfoAnH8v3IsfmwWws80M Nr97005Wgn0gCmscIczCOdGakf2QjGeZqqhvyIIz59BK3Uyci/+wJAlO2GMMRlskkqgSO7 vrClh0WG1Ybhm8l6A3X61uq6KynijJ8ProW+1xKkHkhspBi+E4IY+udr0q1W8g== 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=1774886532; 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=g863N5nPu3sdp8yoWgaapcFfuXv8W4PyiaKyuRJXXto=; b=kWMYm3KmSapUS/qVdldlhePu8VbEfITu7NZ0eUCoHX+p3CxTwyLv8CyYF5wZ2OxNAyQJLE SsIsaKGCpmqI7MA+O5FLbQEpJKHBkNOKw/P+mtNAriYJI3myt+ok4qA7NhTW7tEopKS2WZ /ws7Qroa9zOyS5HbeCNLHvOdvsRaK8JtTsy2au3NxU3daHtZiEVw3nI2UvtXi+1hmhllo3 dMiRxg5lKHn8RewrCFr1iM/utfK85PW33391xOcmkUKZPG9+crXXbx/FIDmyujJ/norJBx AJ0ukNchXTmOaJUTvk0nLBS8vz/CSkfzPQsyMjYrbllvc39QO1Zgd82DVPPFZQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fkwxJ3YgrzqLV for ; Mon, 30 Mar 2026 16:02:12 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 39858 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 30 Mar 2026 16:02:12 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: ee9456ce3753 - main - ifnet: Fix races in if_vmove_reclaim() List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org 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/main X-Git-Reftype: branch X-Git-Commit: ee9456ce37539da5b651945eea18502f290eb133 Auto-Submitted: auto-generated Date: Mon, 30 Mar 2026 16:02:12 +0000 Message-Id: <69ca9e84.39858.1a21c3c1@gitrepo.freebsd.org> The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=ee9456ce37539da5b651945eea18502f290eb133 commit ee9456ce37539da5b651945eea18502f290eb133 Author: Zhenlei Huang AuthorDate: 2026-03-30 16:00:01 +0000 Commit: Zhenlei Huang CommitDate: 2026-03-30 16:00:01 +0000 ifnet: Fix races in if_vmove_reclaim() The thread running if_vmove_reclaim() may race with other threads those running if_detach(), if_vmove_loan() or if_vmove_reclaim(). In case the current thread loses race, two issues arise, 1. It is unstable and unsafe to access ifp->if_vnet, 2. The interface is removed from "active" list, hence if_unlink_ifnet() can fail. For the first case, check against source prison's vnet instead, given the interface is obtained from that vnet. For the second one, return ENODEV to indicate the interface was on the list but the current thread loses race, to distinguish from ENXIO, which means the interface or child prison is not found. This is the same with if_vmove_loan(). Reviewed by: kp, pouria Fixes: a779388f8bb3 if: Protect V_ifnet in vnet_if_return() MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55997 --- sys/net/if.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 41084ecf0516..bdb5671c1afb 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1242,7 +1242,7 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid) struct prison *pr; struct vnet *vnet_dst; struct ifnet *ifp; - int found __diagused; + int found; /* Try to find the prison within our visibility. */ sx_slock(&allprison_lock); @@ -1255,16 +1255,16 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid) /* Make sure the named iface exists in the source prison/vnet. */ CURVNET_SET(pr->pr_vnet); - ifp = ifunit(ifname); /* XXX Lock to avoid races. */ + ifp = ifunit(ifname); if (ifp == NULL) { CURVNET_RESTORE(); prison_free(pr); return (ENXIO); } - /* Do not try to move the iface from and to the same prison. */ + /* Do not try to move the iface from and to the same vnet. */ vnet_dst = TD_TO_VNET(td); - if (vnet_dst == ifp->if_vnet) { + if (vnet_dst == pr->pr_vnet) { CURVNET_RESTORE(); prison_free(pr); return (EEXIST); @@ -1272,7 +1272,11 @@ if_vmove_reclaim(struct thread *td, char *ifname, int jid) /* Get interface back from child jail/vnet. */ found = if_unlink_ifnet(ifp, true); - MPASS(found); + if (! found) { + CURVNET_RESTORE(); + prison_free(pr); + return (ENODEV); + } sx_xlock(&ifnet_detach_sxlock); if_vmove(ifp, vnet_dst); sx_xunlock(&ifnet_detach_sxlock);