Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jun 2019 16:47:51 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r348546 - stable/11/lib/libjail
Message-ID:  <201906031647.x53GlpX1014727@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Jun  3 16:47:51 2019
New Revision: 348546
URL: https://svnweb.freebsd.org/changeset/base/348546

Log:
  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 (gjb)

Modified:
  stable/11/lib/libjail/jail_getid.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libjail/jail_getid.c
==============================================================================
--- stable/11/lib/libjail/jail_getid.c	Mon Jun  3 16:47:00 2019	(r348545)
+++ stable/11/lib/libjail/jail_getid.c	Mon Jun  3 16:47:51 2019	(r348546)
@@ -52,6 +52,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;



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