From nobody Fri Oct 30 21:53:24 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 4jGZbm2FDfz6xd6p for ; Fri, 30 Oct 2026 21:53:24 +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) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jGZbm1Zbsz4VPc for ; Fri, 30 Oct 2026 21:53:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793397204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=84amzcK/VnYfZDUr0E1GsmZ/hIMg5f1lz/Ttay/vRJ4=; b=bv7aq28jZcoGkwe4WM6wHIo/j2++MmJiBPXd3WoYT0amypE/g/U8gIG+o2Lemej6soHsSn 5c9cNTkNxYY7wn+bkl0AokncP+mfk0iNqAR8B4f1LCkn3NTxWnL+MN8w9mQPK0T+++8rgf sm5QciTJfam7LbngDMJukAKL1VVR0IFVjn6INxbjMDIj8osrBlU7Bnvx1s4i5vQINHsU+d i7kFwnD4Dn6JfhVP1+xuldccfZwXZh2SvE2pkUPYySXZSgtpkTDH+Xmg3dJNljhzwCALxg QLzcjs7ZNkxNK1ZS0dBQc24mTqcrPOTui0eL8Sza0WXlGFl2FH+Op+7mL62VqA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793397204; b=FLTJuYrWHOPQdRgCJ3t5Lvaw/uVv8xUqKgpDisRRLNmSl6Ljm+DvOAn411kqXN5vfWpBSK L9hLcZifrXzMFd/OSPagVMhUXCREiWT11Wv5eKCNpJtLc5z/4hzXZzL66hJ2OQGe8Cgbee sKAZV3w/QhWF6GUROcOGmj7QOMRxYSV9feZ1GF/S5vw6s5OQuUb3M644SExmeAPbqCtKg/ Q8U/4XxtJzVgiODRQ+FAQ3zfuCbiDv1FRjCvUQ+HoU/bAZRO09VRcQw/m+Z9i+zxe/OGcY is00kF3V3zE5Z3ogYvejj5a7S0FkEJf1byLaRb1qPL1+kfPPsV+AxFy+FZbriQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793397204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=84amzcK/VnYfZDUr0E1GsmZ/hIMg5f1lz/Ttay/vRJ4=; b=ftmsZKt1Wz4VTUhOnKFGyKTVI7LrWEVvRmNSp9sYiDx3y924Qors+HYJGPcaDiNZmbYnKO Mzb4nhLp1Fjaq/eOy1c1KZDC4s8pH/B90AEzuJOk/dcpyllpMGka2mJpDhyxrZxwZ7FOg9 oF7fNa0ujR19UIf6W6Xk2XzFFt9M3xFiSz7Vok9tT+olsmH41Woup5yDXRFpcp6IJXaxlR uJVnSH8o5hQFJ4p7/lnblxu3qIjsoZ9LqTJ6Q5LJbfg0FROrY1PwzSmLNvsraFdhWzNIIF 4Ln1NCleTfc4k9qMtgP04b1hH/m77HXSwSrCI+IC8cchpmOm6ndRXn1kji7wCg== 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 4jGZbm1DdHzmnb for ; Fri, 30 Oct 2026 21:53:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 35f20 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 30 Oct 2026 21:53:24 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Yura Tkachenko From: Igor Ostapenko Subject: git: d1a465f02b14 - main - jailmeta: reject empty keys in metadata lookups List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository 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: igoro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d1a465f02b14c9eed8a87c31092bb9251dc053c1 Auto-Submitted: auto-generated Date: Fri, 30 Oct 2026 21:53:24 +0000 Message-Id: <6ae511d4.35f20.55b09f96@gitrepo.freebsd.org> The branch main has been updated by igoro: URL: https://cgit.FreeBSD.org/src/commit/?id=d1a465f02b14c9eed8a87c31092bb9251dc053c1 commit d1a465f02b14c9eed8a87c31092bb9251dc053c1 Author: Yura Tkachenko AuthorDate: 2026-10-30 20:20:24 +0000 Commit: Igor Ostapenko CommitDate: 2026-10-30 21:45:43 +0000 jailmeta: reject empty keys in metadata lookups Reject empty keys in metadata lookups with EINVAL to prevent an infinite loop while holding allprison_lock and pr_mtx. Add tests for empty-key reads and writes with empty and populated meta/env buffers, trailing newlines, and empty final values. Reviewed by: igoro, jamie MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D61025 --- sys/kern/kern_jailmeta.c | 4 ++++ tests/sys/kern/jailmeta.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/sys/kern/kern_jailmeta.c b/sys/kern/kern_jailmeta.c index 91bb7155820d..83d773ca6caa 100644 --- a/sys/kern/kern_jailmeta.c +++ b/sys/kern/kern_jailmeta.c @@ -436,6 +436,10 @@ jm_osd_method_get(void *obj, void *data, const struct meta *meta) p = osd; key = opt->name + strlen(meta->name) + 1; keylen = strlen(key); + if (keylen < 1) { + error = EINVAL; + break; + } while ((p = strstr(p, key)) != NULL) { if ((p == osd || *(p - 1) == '\n') && p[keylen] == '=') { diff --git a/tests/sys/kern/jailmeta.sh b/tests/sys/kern/jailmeta.sh index f030e44b14c3..236690ffddcb 100644 --- a/tests/sys/kern/jailmeta.sh +++ b/tests/sys/kern/jailmeta.sh @@ -397,12 +397,28 @@ keyvalue_generic() atf_check -sexit:0 -oinline:'""\n' jls -jj $meta + # Reject empty keys even when the metadata buffer is empty. + atf_check -s exit:1 -o empty -e match:'Invalid argument' \ + jls -jj "${meta}." + atf_check -s exit:1 -o empty -e match:'Invalid argument' \ + jail -m name=j "${meta}.=value" + atf_check -s exit:0 -o inline:'""\n' jls -jj "$meta" + # Note: each sub-case depends on the results of the previous ones # Should be able to extract a key added manually atf_check -sexit:0 jail -m name=j $meta="a=1" atf_check -sexit:0 -oinline:'a=1\n' jls -jj $meta atf_check -sexit:0 -oinline:'1\n' jls -jj $meta.a + + # Reject empty keys with populated metadata; failed writes preserve it. + atf_check -s exit:1 -o empty -e match:'Invalid argument' \ + jls -jj "${meta}." + atf_check -s exit:1 -o empty -e match:'Invalid argument' \ + jail -m name=j "${meta}.=value" + atf_check -s exit:0 -o inline:'a=1\n' jls -jj "$meta" + atf_check -s exit:0 -o inline:'1\n' jls -jj "${meta}.a" + atf_check -sexit:0 jail -m name=j $meta="$(printf 'a=2\nb=3')" atf_check -sexit:0 -oinline:'a=2\nb=3\n' jls -jj $meta atf_check -sexit:0 -oinline:'2\n' jls -jj $meta.a @@ -492,6 +508,18 @@ keyvalue_generic() # Should respectively support "jls -s" for a missing key atf_check -sexit:0 -oinline:''$meta'.missing\n' jls -jj -s $meta.missing + + # Preserve the trailing newline despite command substitution. + local value + value=$(printf 'a=1\nb=2\n.') + value=${value%.} + atf_check -s exit:0 jail -m name=j "${meta}=$value" + atf_check -s exit:0 -o inline:'1\n' jls -jj "${meta}.a" + atf_check -s exit:0 -o inline:'2\n' jls -jj "${meta}.b" + + # An empty value on the final line needs only its terminating NUL. + atf_check -s exit:0 jail -m name=j "${meta}=a=" + atf_check -s exit:0 -o inline:'""\n' jls -jj "${meta}.a" } keyvalue_body() {