From nobody Wed Sep 09 21:24:34 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4hgDN23DDKz6rRHX for ; Wed, 09 Sep 2026 21:24:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "YR2" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4hgDN21GvRz4F4V for ; Wed, 09 Sep 2026 21:24:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788989074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p/2NOloNmEp+51+2PnAGKH9N5/rZKSvzmkiwVCgSkkU=; b=klFyr11xajPKpm4d1+FjFSQylXex3aC3QydAJO4v5zOBBcnIEje4by6cLJcwp/Kt12erf8 VntDYQyZJvr6xRV4bja7KNm9RAkNB6dBBk5beMZFM79OHjWxiDOsvgbbPu0ePQf/TzZVro Bcm+reyXc3t8Ij9HXZVyTP8haTW4dBuAnKXL1Y06Sq28PFhDdgJTk4gN4aztvryja4FJrc oLFEwmb1zaB/NYioOoWCx3TvKXW6kQdQT1NUgqeiO+zo1ytKGru/3cBPX7BlT0Np0cuCy0 xLsFlZxhPUpZf6fR2Zinar3zXM/UHUR6n7TtGzSQ4D5LOM6s/1gaTdC1eIwDww== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1788989074; b=d4n+oT+5iMeLBrpKmf4bLH7rhRw9FikZvU/OHuHnKC4aoGyCJEbtTTexvNmMbiSx4txCMs KliYJoNQp8sqfyQBdQVhaewSKCyiWz0XQiFVFG7+B2gdbFLnB9SKp9AMtSE8Nlu6iuNuJ3 PVmkuox3G7S1fjUw4TtXiAUaKwZBzfmhPSYf04T2OHY7yfCMHT8i3h81nj3QKQ3DL4HcqW avvQK76Im7JVO9shNoIjYBPPWFCGPY34p/iRpXAflQidmeG8RFPmhqHCl55qgQDNgfntfT 8ZmTGnyvWUBmqjzl8/1q9LbficUfunIBciupybj8YSF0gcPzLy3xF/YMnRtRkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1788989074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=p/2NOloNmEp+51+2PnAGKH9N5/rZKSvzmkiwVCgSkkU=; b=h5DDvr6gWdLkEqQs7DVwXtVKViHKV3HJUygRM1sjPzGKjbMf9vPQTAt3Jlp4qQ6Xe2vjPd nY2sjpI59O75a8XshVFNsZYRDswqeuBtQ/xDhjRTerGSwr8M/Kr3RZV7cVaLcBukOi1K/X aLYBQHqcWU/TrwHUd6J1439lM0E+RnwyPJ+QCB0faPfJ3sthFAuNvVsRJ/hUQ6ArLgCPng uDkaSSeCMssvy/waARoQ6hmtPE7pqNXDBhIY0jBANl2UGiDuaguO4zBUtGqr7pQeK12ZGi ZsdYVYSeOQihJeJ2PJnmz6TfmdytHIAot3AB5wCpiejylXl12SzVcZKtvpnStQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4hgDN20KSFz1Cln for ; Wed, 09 Sep 2026 21:24:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 242ff by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 09 Sep 2026 21:24:34 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: b2a270da9fbf - main - libjail: fix fetching mac.label for multiple jails List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b2a270da9fbf0fb58fb7c1bf1006ae675e14a5e3 Auto-Submitted: auto-generated Date: Wed, 09 Sep 2026 21:24:34 +0000 Message-Id: <6aa1ce92.242ff.438d0563@gitrepo.freebsd.org> The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=b2a270da9fbf0fb58fb7c1bf1006ae675e14a5e3 commit b2a270da9fbf0fb58fb7c1bf1006ae675e14a5e3 Author: Kyle Evans AuthorDate: 2026-09-09 21:24:18 +0000 Commit: Kyle Evans CommitDate: 2026-09-09 21:24:18 +0000 libjail: fix fetching mac.label for multiple jails When doing a basic `jls -n`, jls(8) will jailparam_get() the mac.label for every jail on the system using the same set of jailparams, and thus the same jp_value. We only init the mac_t the first time, so the first jail would populate it with `?` from /etc/mac.conf and the resulting jail_get(2) would clobber it with the empty string, then a second jail would try to pass the empty string to the kernel and fail because it must have a non-zero length. Fix it by invoking jps_get() every time. Drop some comments to note that jps_get() will be invoked with zero || garbage from previous call, and be sure that we don't leak our previous mac_t. There aren't any other jps_get implementations at this time, so this shouldn't cause any unexpected problems. Reported by: ivy Reviewed by: jamie Differential Revision: https://reviews.freebsd.org/D57280 --- lib/libjail/jail.c | 31 +++++++++++++++++++++++++------ usr.sbin/jail/tests/jail_basic_test.sh | 5 ++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/libjail/jail.c b/lib/libjail/jail.c index 95ba336b62ce..c180b8533e97 100644 --- a/lib/libjail/jail.c +++ b/lib/libjail/jail.c @@ -746,13 +746,23 @@ jailparam_get(struct jailparam *jp, unsigned njp, int flags) jiov[i].iov_base = jp[j].jp_name; jiov[i].iov_len = strlen(jp[j].jp_name) + 1; i++; - if (jp[j].jp_value == NULL && - !(jp[j].jp_flags & JP_RAWVALUE)) { - jp[j].jp_value = malloc(jp[j].jp_valuelen); + + /* + * We give structured types' jps_get() implementations + * a chance to initialize the value. We'll guarantee + * that the initial value is zeroed out, but they should + * assume on every call that the value may be populated + * by a subsequent jailparam_get(). + */ + if (!(jp[j].jp_flags & JP_RAWVALUE)) { if (jp[j].jp_value == NULL) { - strerror_r(errno, jail_errmsg, - JAIL_ERRMSGLEN); - return (-1); + jp[j].jp_value = calloc(1, + jp[j].jp_valuelen); + if (jp[j].jp_value == NULL) { + strerror_r(errno, jail_errmsg, + JAIL_ERRMSGLEN); + return (-1); + } } /* @@ -1435,6 +1445,15 @@ jps_get_mac_label(struct jailparam *jp, struct iovec *jiov) mac_t *pmac = jp->jp_value; int error; + /* + * Our value is only allocated once and may be reused for many + * jailparam_get() calls; avoid leaking. + */ + if (*pmac != NULL) { + mac_free(*pmac); + *pmac = NULL; + } + error = mac_prepare_type(pmac, "jail"); if (error != 0 && errno == ENOENT) { /* diff --git a/usr.sbin/jail/tests/jail_basic_test.sh b/usr.sbin/jail/tests/jail_basic_test.sh index cb50a94a45e8..c662e44f1a16 100755 --- a/usr.sbin/jail/tests/jail_basic_test.sh +++ b/usr.sbin/jail/tests/jail_basic_test.sh @@ -35,6 +35,9 @@ basic_body() { # Create the jail atf_check -s exit:0 -o ignore jail -c name=basejail persist ip4.addr=192.0.1.1 + # Create a second jail to test `jls -n` in the process for breakage when + # handling some of the non-trivial parameter types. + atf_check -s exit:0 -o ignore jail -c name=basejail2 persist ip4.addr=192.0.1.2 # Check output of jls atf_check -s exit:0 -o ignore jls atf_check -s exit:0 -o ignore jls -v @@ -52,7 +55,7 @@ basic_body() basic_cleanup() { - jail -r basejail + jail -r basejail basejail2 } atf_test_case "list" "cleanup"