From owner-freebsd-jail@freebsd.org Mon Jun 3 19:34:29 2019 Return-Path: Delivered-To: freebsd-jail@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E36BF15BBAE5 for ; Mon, 3 Jun 2019 19:34:28 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mailman.ysv.freebsd.org (mailman.ysv.freebsd.org [IPv6:2001:1900:2254:206a::50:5]) by mx1.freebsd.org (Postfix) with ESMTP id 6452B6BC02 for ; Mon, 3 Jun 2019 19:34:28 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mailman.ysv.freebsd.org (Postfix) id 21D0615BBAE3; Mon, 3 Jun 2019 19:34:28 +0000 (UTC) Delivered-To: jail@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EE9E315BBAE1 for ; Mon, 3 Jun 2019 19:34:27 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 598016BC00; Mon, 3 Jun 2019 19:34:27 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com [209.85.167.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) (Authenticated sender: kevans) by smtp.freebsd.org (Postfix) with ESMTPSA id 0DAE21648E; Mon, 3 Jun 2019 19:34:27 +0000 (UTC) (envelope-from kevans@freebsd.org) Received: by mail-lf1-f48.google.com with SMTP id b11so14535491lfa.5; Mon, 03 Jun 2019 12:34:26 -0700 (PDT) X-Gm-Message-State: APjAAAV96aS1xhmRBJ68Kd0VT2034o8wFJai0RHoLgxWmDGyNyTcTYrW 2VIFYZlYHzrhv6XESALImpgnwifdpOGg+NXWEbE= X-Google-Smtp-Source: APXvYqxfoySMnZSBd/4eY1gXaENkrPUfw8Gc3wWRt/KcdOlBbbvMNb71MKx964cPZAV/4vK1C3VO1hsSTfsBVgwtTR0= X-Received: by 2002:ac2:5449:: with SMTP id d9mr15695527lfn.126.1559590465567; Mon, 03 Jun 2019 12:34:25 -0700 (PDT) MIME-Version: 1.0 References: <201906021403.x52E3v0x067698@repo.freebsd.org> In-Reply-To: <201906021403.x52E3v0x067698@repo.freebsd.org> From: Kyle Evans Date: Mon, 3 Jun 2019 14:33:47 -0500 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r348509 - head/lib/libjail To: jail@freebsd.org, James Gritton Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 598016BC00 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.98 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.98)[-0.979,0]; ASN(0.00)[asn:11403, ipnet:96.47.64.0/20, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: freebsd-jail@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Discussion about FreeBSD jail\(8\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jun 2019 19:34:29 -0000 (Resend to get the list address right- sorry Jamie!) On Sun, Jun 2, 2019 at 9:04 AM Kyle Evans wrote: > > Author: kevans > Date: Sun Jun 2 14:03:56 2019 > New Revision: 348509 > URL: https://svnweb.freebsd.org/changeset/base/348509 > > Log: > 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 > MFC after: soon (regression, breaks inspecting jail host bits, partial > revert) > > Modified: > head/lib/libjail/jail_getid.c > > Modified: head/lib/libjail/jail_getid.c > ============================================================================== > --- head/lib/libjail/jail_getid.c Sun Jun 2 09:28:50 2019 (r348508) > +++ head/lib/libjail/jail_getid.c Sun Jun 2 14:03:56 2019 (r348509) > @@ -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; > On a related note- do we have a good reason for not exposing jid 0 via jail_get(2) if that's what's requested and we're operating in prison0? I have no historical context here, so it's not clear to me what issues that might expose other than the issue of exposing a prison that's not all that interesting. Thanks, Kyle Evans