From nobody Thu Apr 30 09:53:23 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 4g5qHR5jN3z6bWRP for ; Thu, 30 Apr 2026 09:53:23 +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 4g5qHR16dCz3DQQ for ; Thu, 30 Apr 2026 09:53:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777542803; 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=VJhRhN79vJR7JVBj4/N0GloQCv5leS6ED6uBQbUXyRU=; b=kYVKd6YRfp0b/OjdKFA7JuKBJX0myLK/zyGmcaI5kwlyA7xv53RHMGO+w4TXN0HEcI/0KE UZANDOOPcxZgSwLTidr9wv/V3pChI7YDSwfKCDWVCd2iTsC93QnaHZWYBktzDnxT7NX7N6 OafuhKRZ6VGz6LVecq+TBeP6TwInb/txwiWbtimnEuRRjPHigO5/51dIbaibhN4FefuTRd N6aX4xD8hTpBX3smiIvotmw5rSUCcTCZzeuNn9ZdyFyJaF4luLnZVLVn46Hgltj+H2IDit 5rjqOXgSCs+ZFUJKvlAe4rU1iC4wEQzKWPub3GLpu1chDfWudYOL0aaaYZQQsw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777542803; a=rsa-sha256; cv=none; b=LHAL2cGe99qrq8MHM/9GbTwHlAc4V2GJMpucXyK8PB8HEFXm/eUenvkbhaE0I0W8tzMZPN cncaIAL5bHCH5qlVq3hX00UC0T0qrSoZRhNcvn99X/FukZycw7900ZC7GRc128H1mgmC6S 2TUuFoBDZVCw/tcm8gUxkYIN9rWQk9FtzCqjKcCan9GCAMEtMv1HNWrw1S58DIN2KgFCXx DIpwx/JhlmrCwpBHgpfchRzQwkOl6tcS07/20C/XSTKHLgVyiyHKUpl4tUO5hKcPJ3lNJe WYHtK2msZSH6w+so+S5t7C/gqyBA4jvGSDEzs9bWdpMntVYCycrMNZboZbuaKQ== 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=1777542803; 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=VJhRhN79vJR7JVBj4/N0GloQCv5leS6ED6uBQbUXyRU=; b=M9gP/l3DEYKW20IIVef2/e+304/XsNUQuxLMJlh0Bx59RL/x6ZwEWjnxnMWceZbh1rmb1x zK5PBBKHVP/yN5ezocT6Sz6hP2j7g3pHghG02YMTdAizUXnMhNDpC5/s2kjLNrllTrqyMo 7nIJedfcL+t/sReunwhsJ3Fwh9CjWK9kXFkSOJf7+EXjnjQdwKrJxis3txh82w3i1LhjtM cb6Pcn+scvwDHE0HXmAl/F8+/afaxxqId7SMEwurubzOWU+C59eV733/QHvVH0RBlo0scS /WbqywLf/+4Gd6S1uL8Cca4IBlTAhLw6yGBEhT1RJrWh9bOlt3AAc/mrIgdKIQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g5qHR0hlFz1LcW for ; Thu, 30 Apr 2026 09:53:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 466f8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 30 Apr 2026 09:53:23 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: 477c3ba36731 - stable/15 - ifnet: Move SIOCSIFVNET from ifhwioctl() to ifioctl() 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 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/15 X-Git-Reftype: branch X-Git-Commit: 477c3ba3673152e88ec5c50d8f45db24102bdf07 Auto-Submitted: auto-generated Date: Thu, 30 Apr 2026 09:53:23 +0000 Message-Id: <69f32693.466f8.39cf56ab@gitrepo.freebsd.org> The branch stable/15 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=477c3ba3673152e88ec5c50d8f45db24102bdf07 commit 477c3ba3673152e88ec5c50d8f45db24102bdf07 Author: Zhenlei Huang AuthorDate: 2026-04-13 04:38:44 +0000 Commit: Zhenlei Huang CommitDate: 2026-04-30 09:52:00 +0000 ifnet: Move SIOCSIFVNET from ifhwioctl() to ifioctl() SIOCSIFVNET is not a hardware ioctl. Move it to where it belongs. Where here, rewrite the logic of checking whether we are moving the interface from and to the same vnet or not, since it is obviously not stable to access the interface's vnet, given the current thread may race with other threads those running if_vmove(). MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D55880 (cherry picked from commit 38bd7ef62f318f791e232e217855307a9d75efa0) --- sys/net/if.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/sys/net/if.c b/sys/net/if.c index 7424da5ccf6d..2da0afbeabc9 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1300,26 +1300,39 @@ if_vmove(struct ifnet *ifp, struct vnet *new_vnet) * Move an ifnet to or from another child prison/vnet, specified by the jail id. */ static int -if_vmove_loan(struct thread *td, struct ifnet *ifp, char *ifname, int jid) +if_vmove_loan(struct thread *td, char *ifname, int jid) { struct prison *pr; - struct ifnet *difp; + struct ifnet *ifp, *difp; bool found; + MPASS(curthread == td); + MPASS(curvnet == TD_TO_VNET(td)); + + /* + * We check the existence of the interface, and will later try to + * unlink it from the "active" list, so it is sufficient to only + * hold a weak reference to it. + * Be aware that it is unsafe to access any member of it, until it + * is proven to be safe to ( say it was on the "active" list ). + */ + ifp = ifunit(ifname); + if (ifp == NULL) + return (ENXIO); + /* Try to find the prison within our visibility. */ sx_slock(&allprison_lock); pr = prison_find_child(td->td_ucred->cr_prison, jid); sx_sunlock(&allprison_lock); if (pr == NULL) return (ENXIO); - prison_hold_locked(pr); - mtx_unlock(&pr->pr_mtx); - - /* Do not try to move the iface from and to the same prison. */ - if (pr->pr_vnet == ifp->if_vnet) { - prison_free(pr); + /* Do not try to move the iface from and to the same vnet. */ + if (pr->pr_vnet == TD_TO_VNET(td)) { + mtx_unlock(&pr->pr_mtx); return (EEXIST); } + prison_hold_locked(pr); + mtx_unlock(&pr->pr_mtx); /* Make sure the named iface does not exists in the dst. prison/vnet. */ /* XXX Lock interfaces to avoid races. */ @@ -2693,15 +2706,6 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) error = if_rename(ifp, new_name); break; -#ifdef VIMAGE - case SIOCSIFVNET: - error = priv_check(td, PRIV_NET_SETIFVNET); - if (error) - return (error); - error = if_vmove_loan(td, ifp, ifr->ifr_name, ifr->ifr_jid); - break; -#endif - case SIOCSIFMETRIC: error = priv_check(td, PRIV_NET_SETIFMETRIC); if (error) @@ -2989,6 +2993,12 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) ifr = (struct ifreq *)data; switch (cmd) { #ifdef VIMAGE + case SIOCSIFVNET: + error = priv_check(td, PRIV_NET_SETIFVNET); + if (error == 0) + error = if_vmove_loan(td, ifr->ifr_name, ifr->ifr_jid); + goto out_noref; + case SIOCSIFRVNET: error = priv_check(td, PRIV_NET_SETIFVNET); if (error == 0)