aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/uipc_mqueue.c
diff options
context:
space:
mode:
authorJamie Gritton <jamie@FreeBSD.org>2021-01-18 18:56:20 +0000
committerJamie Gritton <jamie@FreeBSD.org>2021-01-18 18:56:20 +0000
commit76ad42abf9d46c7a86c9e727603fe62e8b62a37b (patch)
treef68d95d80d378a4960fc71860f806c8369604e46 /sys/kern/uipc_mqueue.c
parentefa9c21bca9873af9c9660f5aeffda9d5ae1dfb7 (diff)
downloadsrc-76ad42abf9d46c7a86c9e727603fe62e8b62a37b.tar.gz
src-76ad42abf9d46c7a86c9e727603fe62e8b62a37b.zip
jail: Add prison_isvalid() and prison_isalive()
prison_isvalid() checks if a prison record can be used at all, i.e. pr_ref > 0. This filters out prisons that aren't fully created, and those that are either in the process of being dismantled, or will be at the next opportunity. While the check for pr_ref > 0 is simple enough to make without a convenience function, this prepares the way for other measures of prison validity. prison_isalive() checks not only validity as far as the useablity of the prison structure, but also whether the prison is visible to user space. It replaces a test for pr_uref > 0, which is currently only used within kern_jail.c, and not often there. Both of these functions also assert that either the prison mutex or allprison_lock is held, since it's generally the case that unlocked prisons aren't guaranteed to remain useable for any length of time. This isn't entirely true, for example a thread can assume its own prison is good, but most exceptions will exist inside of kern_jail.c.
Diffstat (limited to 'sys/kern/uipc_mqueue.c')
-rw-r--r--sys/kern/uipc_mqueue.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/kern/uipc_mqueue.c b/sys/kern/uipc_mqueue.c
index 309fa3423fbd..dc94ce213d08 100644
--- a/sys/kern/uipc_mqueue.c
+++ b/sys/kern/uipc_mqueue.c
@@ -1569,7 +1569,8 @@ mqfs_prison_remove(void *obj, void *data __unused)
found = 0;
TAILQ_FOREACH(tpr, &allprison, pr_list) {
prison_lock(tpr);
- if (tpr->pr_root == pr->pr_root && tpr != pr && tpr->pr_ref > 0)
+ if (tpr != pr && prison_isvalid(tpr) &&
+ tpr->pr_root == pr->pr_root)
found = 1;
prison_unlock(tpr);
}