Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 27 Dec 2020 04:50:19 GMT
From:      Jamie Gritton <jamie@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 7f4e724829e5 - main - jail: add a missing lock around an osd_jail_call().
Message-ID:  <202012270450.0BR4oJoq020846@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by jamie:

URL: https://cgit.FreeBSD.org/src/commit/?id=7f4e724829e556fc646056669c2af3551b7e8724

commit 7f4e724829e556fc646056669c2af3551b7e8724
Author:     Jamie Gritton <jamie@FreeBSD.org>
AuthorDate: 2020-12-27 04:49:30 +0000
Commit:     Jamie Gritton <jamie@FreeBSD.org>
CommitDate: 2020-12-27 04:49:30 +0000

    jail: add a missing lock around an osd_jail_call().
    
    allprison_lock should be at least held shared when jail OSD methods
    are called.  Add a shared lock around one such call where that wasn't
    the case.
    
    In another such call, change an exclusive lock grab to be shared in
    what is likely the more common case.
---
 sys/kern/kern_jail.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c
index a140b6f537d1..fb77cf87126d 100644
--- a/sys/kern/kern_jail.c
+++ b/sys/kern/kern_jail.c
@@ -2498,8 +2498,9 @@ do_jail_attach(struct thread *td, struct prison *pr)
 	VOP_UNLOCK(pr->pr_root);
  e_revert_osd:
 	/* Tell modules this thread is still in its old jail after all. */
+	sx_slock(&allprison_lock);
 	(void)osd_jail_call(td->td_ucred->cr_prison, PR_METHOD_ATTACH, td);
-	prison_deref(pr, PD_DEREF | PD_DEUREF);
+	prison_deref(pr, PD_DEREF | PD_DEUREF | PD_LIST_SLOCKED);
 	return (error);
 }
 
@@ -2687,8 +2688,13 @@ prison_deref(struct prison *pr, int flags)
 		 */
 		if (lasturef) {
 			if (!(flags & (PD_LIST_SLOCKED | PD_LIST_XLOCKED))) {
-				sx_xlock(&allprison_lock);
-				flags |= PD_LIST_XLOCKED;
+				if (ref > 1) {
+					sx_slock(&allprison_lock);
+					flags |= PD_LIST_SLOCKED;
+				} else {
+					sx_xlock(&allprison_lock);
+					flags |= PD_LIST_XLOCKED;
+				}
 			}
 			(void)osd_jail_call(pr, PR_METHOD_REMOVE, NULL);
 			mtx_lock(&pr->pr_mtx);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202012270450.0BR4oJoq020846>