From nobody Mon Jul 28 16:19:48 2025 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 4brNwj0Ggkz63FP3; Mon, 28 Jul 2025 16:19:49 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4brNwh57klz3YxV; Mon, 28 Jul 2025 16:19:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753719588; 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=sUucQDaXFfdgvFpFXNf0PnTXkpcnYlbHa3wdSxYEv+4=; b=A9hDd/jQaGo2lHSh0TTuUWQKQ1PB/rBc9DROoQTwSFW3hsvGw3dif9MlQfbYKk+MwSbHdC XN+2qO+eKTOQxkdevHaRC9B/TxXYxCaOgwmTlbEKrCchXTRn2js0XCcVqOld+ozza8omZE IVu6DCjt5msau7gcOp7gBVDHWHK0QzpNgqtIu0d452I7ObubPfVia81j9sgq5zlSYnzpd0 QOIJ7DyH/AsbyumbcmZQ53eQiFOOyOWBul0N0Y8YuAEGUhU9fEqAwAy7flXKDF8Fc9flkj CceyabmCngjmoGJjMNKBprqsKca7mHwEZzSWoyRmyOcU1aQaD3f4aUSlCtUGZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1753719588; 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=sUucQDaXFfdgvFpFXNf0PnTXkpcnYlbHa3wdSxYEv+4=; b=lnEPxlvOpCbnZEYru4q5sPOUVhWOlmNp/U7Pqqz0f3H1weGqeHdyZg5ICS+0OriOFef79M fH93w7xllQJPYN7Pey0idEBBmqRvQn0tUZtt4Vefcu4mllKELyq1pky8NKGdNnvxDHGYeo uVyAbOfZv9Q1i9J5nYwrGX9/dO+BiBAN1/LKh6ek94eceaqZHtIIWCaqIf+QpFdLSjFaZK g7e99MLwjuL1nqBOYS7CNBsehLZh4sIuWotNb99q2jOb/LJ1V40Ar5nLQzCBYZcYfzO7Z4 qkd0VDe41xD6Uu/Pk7+rjsxMNTWycpkfBEENs20Yh7TDU1MOVw2zDEVNgqNaVg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1753719588; a=rsa-sha256; cv=none; b=MVBRT1Tb9Xqn06b8q/0Fx+U/IC+TLnm/t092Oxbk28OB1D8hg6aMms5+WnzDUjg43gkvz1 CjV5vF6beD2qtZwnQ/witr7MrviCeLk6TzuvoiX84/xLY5f5jX1wY1z1X538YlIrZR1bBj UxoGSIhi/tPEbVk2/KTjPuchgmDNaWIl7sMRe2K5W3rBiJIsRxJv6H79NGg+hKwky1soM5 FmtDQn35teO5BrzsnYYS2wn8J8V5xnnA2pkNqR9YpmiLltXsKHO/7O9rvgIQmRthhtAnIw rqNh1ymiayA5z6DmXE7sspd/pw6REfPBKTb6PXuyTjgMHfxSEHWhR5Fg6cCZeg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4brNwh3KLVzsf0; Mon, 28 Jul 2025 16:19:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 56SGJm6U091663; Mon, 28 Jul 2025 16:19:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 56SGJm34091660; Mon, 28 Jul 2025 16:19:48 GMT (envelope-from git) Date: Mon, 28 Jul 2025 16:19:48 GMT Message-Id: <202507281619.56SGJm34091660@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 96b29c7f0cff - main - if_ovpn: Destroy cloned interfaces via a prison removal callback 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 96b29c7f0cffd377a757ad8ccc0cdd8fcb96d0dd Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=96b29c7f0cffd377a757ad8ccc0cdd8fcb96d0dd commit 96b29c7f0cffd377a757ad8ccc0cdd8fcb96d0dd Author: Mark Johnston AuthorDate: 2025-07-28 15:46:37 +0000 Commit: Mark Johnston CommitDate: 2025-07-28 16:19:38 +0000 if_ovpn: Destroy cloned interfaces via a prison removal callback A if_ovpn interface carries a reference to a socket, which has a credential reference, which holds a reference on the containing prison and prevents SYSUNINITs from being invoked. So, register a PR_METHOD_REMOVE callback and destroy the cloner from there instead, since that mechanism doesn't require the prison refcount to drop to zero first. This fixes a bug where jails get left stuck in the DYING state after running if_ovpn regression tests. Reviewed by: kp MFC after: 2 weeks Sponsored by: Stormshield Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D51526 --- sys/net/if_ovpn.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/sys/net/if_ovpn.c b/sys/net/if_ovpn.c index fdbf70465338..fe3e7bbd7fff 100644 --- a/sys/net/if_ovpn.c +++ b/sys/net/if_ovpn.c @@ -34,11 +34,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -2784,23 +2786,53 @@ vnet_ovpn_init(const void *unused __unused) VNET_SYSINIT(vnet_ovpn_init, SI_SUB_PSEUDO, SI_ORDER_ANY, vnet_ovpn_init, NULL); -static void -vnet_ovpn_uninit(const void *unused __unused) +static int +ovpn_prison_remove(void *obj, void *data __unused) { - if_clone_detach(V_ovpn_cloner); +#ifdef VIMAGE + struct prison *pr; + + pr = obj; + if (prison_owns_vnet(pr)) { + CURVNET_SET(pr->pr_vnet); + if (V_ovpn_cloner != NULL) { + ifc_detach_cloner(V_ovpn_cloner); + V_ovpn_cloner = NULL; + } + CURVNET_RESTORE(); + } +#endif + return (0); } -VNET_SYSUNINIT(vnet_ovpn_uninit, SI_SUB_PSEUDO, SI_ORDER_ANY, - vnet_ovpn_uninit, NULL); static int ovpnmodevent(module_t mod, int type, void *data) { + static int ovpn_osd_jail_slot; + switch (type) { - case MOD_LOAD: - /* Done in vnet_ovpn_init() */ + case MOD_LOAD: { + /* + * Registration is handled in vnet_ovpn_init(), but cloned + * interfaces must be destroyed via PR_METHOD_REMOVE since they + * hold a reference to the prison via the UDP socket, which + * prevents the prison from being destroyed. + */ + osd_method_t methods[PR_MAXMETHOD] = { + [PR_METHOD_REMOVE] = ovpn_prison_remove, + }; + ovpn_osd_jail_slot = osd_jail_register(NULL, methods); break; + } case MOD_UNLOAD: - /* Done in vnet_ovpn_uninit() */ + if (ovpn_osd_jail_slot != 0) + osd_jail_deregister(ovpn_osd_jail_slot); + CURVNET_SET(vnet0); + if (V_ovpn_cloner != NULL) { + ifc_detach_cloner(V_ovpn_cloner); + V_ovpn_cloner = NULL; + } + CURVNET_RESTORE(); break; default: return (EOPNOTSUPP);