diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2019-06-02 14:03:56 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2019-06-02 14:03:56 +0000 |
commit | 067498ed56f6bcf15757a598db45ef374f6b946a (patch) | |
tree | 07f13cf55a6c1b7831624f9cf34cd065aeddf096 /lib/libjail | |
parent | 71259635f77a7b40324c9ceab0a31b212dda2564 (diff) | |
download | src-067498ed56f6bcf15757a598db45ef374f6b946a.tar.gz src-067498ed56f6bcf15757a598db45ef374f6b946a.zip |
jail_getid(3): add special-case immediate return for jid 0
As depicted in the comment: jid 0 always exists, but the lookup will fail as
it does not appear in the kernel's alljails list being a special jail. Some
callers will expect/rely on this, and we have no reason to lie because it
does always exist.
Reported by: Stefan Hegnauer <stefan.hegnauer gmx ch>
MFC after: soon (regression, breaks inspecting jail host bits, partial
revert)
Notes
Notes:
svn path=/head/; revision=348509
Diffstat (limited to 'lib/libjail')
-rw-r--r-- | lib/libjail/jail_getid.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/libjail/jail_getid.c b/lib/libjail/jail_getid.c index f99a175fd398..3700ff0d36cc 100644 --- a/lib/libjail/jail_getid.c +++ b/lib/libjail/jail_getid.c @@ -54,6 +54,15 @@ jail_getid(const char *name) jid = strtoul(name, &ep, 10); if (*name && !*ep) { + /* + * jid == 0 is a special case; it will not appear in the + * kernel's jail list, but naturally processes will be assigned + * to it because it is prison 0. Trivially return this one + * without a trip to the kernel, because it always exists but + * the lookup won't succeed. + */ + if (jid == 0) + return jid; jiov[0].iov_base = __DECONST(char *, "jid"); jiov[0].iov_len = sizeof("jid"); jiov[1].iov_base = &jid; |