From owner-dev-commits-src-all@freebsd.org Thu Feb 4 23:15:59 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C9B60532C99; Thu, 4 Feb 2021 23:15:59 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DWvYV6sRzz3Lf7; Thu, 4 Feb 2021 23:15:58 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 DD03D14555; Thu, 4 Feb 2021 23:15:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 114NFwPr061550; Thu, 4 Feb 2021 23:15:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 114NFwvS061549; Thu, 4 Feb 2021 23:15:58 GMT (envelope-from git) Date: Thu, 4 Feb 2021 23:15:58 GMT Message-Id: <202102042315.114NFwvS061549@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Jamie Gritton Subject: git: 4c44dbde5491 - stable/13 - MFC jail: Handle a parent jail when a child is added to it MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jamie X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4c44dbde5491516eba8725dc51d39c1dcc817472 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Feb 2021 23:15:59 -0000 The branch stable/13 has been updated by jamie: URL: https://cgit.FreeBSD.org/src/commit/?id=4c44dbde5491516eba8725dc51d39c1dcc817472 commit 4c44dbde5491516eba8725dc51d39c1dcc817472 Author: Jamie Gritton AuthorDate: 2021-01-29 05:51:09 +0000 Commit: Jamie Gritton CommitDate: 2021-02-04 23:13:54 +0000 MFC jail: Handle a parent jail when a child is added to it It's possible when adding a jail that its dying parent comes back to life. Only allow that to happen when JAIL_DYING is specified. And if it does happen, call PR_METHOD_CREATE on it. (cherry picked from commit c050ea803eaa1087313b86628b5d486c0e59e41b) --- sys/kern/kern_jail.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 064f1afa4133..ece0aa33e642 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -1105,6 +1105,14 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags) "jail \"%s\" not found", name); goto done_deref; } + if (!(flags & JAIL_DYING) && + !prison_isalive(ppr)) { + mtx_unlock(&ppr->pr_mtx); + error = ENOENT; + vfs_opterror(opts, + "jail \"%s\" is dying", name); + goto done_deref; + } mtx_unlock(&ppr->pr_mtx); *namelc = '.'; } @@ -1200,8 +1208,18 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags) goto done_deref; } prison_hold(ppr); - refcount_acquire(&ppr->pr_uref); - mtx_unlock(&ppr->pr_mtx); + if (refcount_acquire(&ppr->pr_uref)) + mtx_unlock(&ppr->pr_mtx); + else { + /* This brings the parent back to life. */ + mtx_unlock(&ppr->pr_mtx); + error = osd_jail_call(ppr, PR_METHOD_CREATE, opts); + if (error) { + pr = ppr; + drflags |= PD_DEREF | PD_DEUREF; + goto done_deref; + } + } if (jid == 0 && (jid = get_next_prid(&inspr)) == 0) { error = EAGAIN;