From nobody Mon Apr 13 04:39:47 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 4fvF7S10HCz6YG4P for ; Mon, 13 Apr 2026 04:39:48 +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 4fvF7R5XJNz438x for ; Mon, 13 Apr 2026 04:39:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1776055187; 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=irZa2tS7gFPtViwYTc00zG66V4W+yFfmULZskqL9y5s=; b=RykKHFKuzRcBarBhWliJl2XXpBM/KU8Z5FQYM4slOd4ySASzDmWGqNC+AnKLcwBSLiCQKL 3EV1HNEGYqNxQiRB3BJGg2JDf8JpIxL/LlKUFDr7wV7k9UFlf7Ayl+guYpLUH4LHMOlFKV 3qX6/NCFytiPfLdL+Ow12o9Ox244XkeqHzyHlS9E1l7cB53GMgThIDYrbBdASUaNEAsW8k 0IMWxUZ4V+mO3c+X4p3eo6cxXTCGmrPzlLDIHwnj0iimuaw3oweRiJiNCCOG1CL2mSy6T1 7KfPaGTJ07bswUI4OklT36woFjx0086jU5Xw343tq2pNW6xrxUz2gYphGuZcrg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1776055187; a=rsa-sha256; cv=none; b=JtxdnsVGcCloM3tHHOOXqVUeLdOiViPIawRsb5UawpDqOVS8Vq2gRkMtmJwhuoNiEfC83W Yx9rBs4EUYsDRTgL1tTVOrpTRjf9oQaUQmn3GcYTJvediVUTch6EW4mZrrmH5zrIe5m17u +EH9kEXeWcEEJTmvgfSpC2XJrrX/CKYLVdSrxVqyaBKwj5j2kNWILRlQ70Y9l5s+VkuwKH vORBmvXrvkCRp8BDc7iue+LqRVr0gHW+LtfI4k6ynK76l2gMswHHTOt3SXp+LIUyeiXF80 ZUbkiu7mYQ8qH/JU5CrLDED+UEU40pKengQl1Yz3E0QvW/QxyDEm38dPqbMI3w== 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=1776055187; 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=irZa2tS7gFPtViwYTc00zG66V4W+yFfmULZskqL9y5s=; b=JV9Fa4BVYJ08EJszlepQuls+AbVLYEKy4eiZCd5n6VzAA1oeGxwOoXxB661QV8G5Ap2ur+ moSQvMubCic3jY8xtex2csO3NajDD7sDkGbWXVK0pO4oR0uEoohugdkXLsoAxdPJqj6NTh CMcbOtMPJJqBfbqjYAlh1mPIwqGdKL3BJ8oigGw1jhmL7NvHjFRbUWVAuY0q+sOAT8EXfD YIYH2tQ9i8KkQOK/V0azqd3SNck4bpzBUgDGV/aNaxMSL9UtqutJNB6hSXp47E+bO0s3RD fIb+xBovw6qItRqcC15Fk/k/xnk7YnGiNaPgNBoQwSqO+5TCGVWqUqWZzrqW2Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4fvF7R4vzjzptd for ; Mon, 13 Apr 2026 04:39:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 21c2b by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 13 Apr 2026 04:39:47 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Zhenlei Huang Subject: git: 38bd7ef62f31 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 38bd7ef62f318f791e232e217855307a9d75efa0 Auto-Submitted: auto-generated Date: Mon, 13 Apr 2026 04:39:47 +0000 Message-Id: <69dc7393.21c2b.5635f87@gitrepo.freebsd.org> The branch main has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=38bd7ef62f318f791e232e217855307a9d75efa0 commit 38bd7ef62f318f791e232e217855307a9d75efa0 Author: Zhenlei Huang AuthorDate: 2026-04-13 04:38:44 +0000 Commit: Zhenlei Huang CommitDate: 2026-04-13 04:38:44 +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 --- 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 73138716cf46..1d73c55aa69f 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -1191,26 +1191,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. */ @@ -2580,15 +2593,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) @@ -2876,6 +2880,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)