From 8ddd7235fff1396db6ab3c6fc526b3efa9aa490d Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Mon, 3 Jun 2019 15:28:37 +0000 Subject: [PATCH] MFC r348509: 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. Approved by: re (early MFC) --- lib/libjail/jail_getid.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/libjail/jail_getid.c b/lib/libjail/jail_getid.c index f99a175fd39..3700ff0d36c 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; -- 2.45.0