From nobody Wed Nov 04 17:27:09 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 4jKXSM1dLnz6yYYp for ; Wed, 04 Nov 2026 17:27:15 +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 4jKXSL6BN3z4xY0 for ; Wed, 04 Nov 2026 17:27:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793813234; 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=e1jUvsdI+rtT3C24MGuAfFisMHdf6UC+3VAJ33KBYgI=; b=wVfyQZ9LTdT9hNFWJnN9lJm9NXcQddsZSQDHWflfE5EYCeQNO2JiTUV8OuOd/MLMNOXVKL WSrHjVMrLZLpsfWbx84mxaBXF9P/GeUqGDGaGZxixSfeQRa82LmN2RnWYyatTT/MVzF6IJ XHZjCov3ndDz0n1M4pOOzYE25XsOwTCso+ANWXpNgqEBatGSDNnYocIOkQIib4okQRO8Da 9ERFs3LfYD92j/LO13Y08Gr98ycq/9cR7eeyofLSMTXTmw6oL0abIREPn/BiUfRT64AcAg PSEl8CB2q7X2hCPgbkuT3I3XL9abG8GZHLUIQn1lwxdxCFb1d6mHstyZK+YMWg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793813234; b=NQKV/O2mEziY2/ien8iWtXKtWKjKoCOnKOK1iF2XuIY5q1Un67OkEyWuz8jKiji2iIny78 MQiSYoAdxNeMo0H1S1fpZaFbyKcWew/eSrJuqQAJtS7LrB7oVPIVqHw8Dc0xjBENBDCpob SqDSV+2PRBqsni99z3KrX/uW5nvyEUPuHnrMpPFBcFOYWGjq+Pw9h+0T3+JbeigG1D/0XJ NE8wghK6S1AMUwuZGkQ3DGOyX5OqWxORCmWk40giWGSjr5Jf1n7pmkarjzB+usYDYmfKah ou8ZrklEr1M6ImgEMnnWjDf3qLuhV9aPEMCZwjWZpfSNHZ4iUmYMKC/fcBGQBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793813234; 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=e1jUvsdI+rtT3C24MGuAfFisMHdf6UC+3VAJ33KBYgI=; b=lN73hhWPYsgkZCW2sMLpCz67T4MEfyWAavb3QQQwvAPAZFNlAfxlMSXP6jAZ7qVtYjjIn+ QrjPPlamWT++c73lN3taq/+AgQ8H1LHnQj6qFCt/lqzSEWfE6UIhd+tRZ2Y69qm6idwh9P F52hifNqWNW3RoDorRv7+REaLhEfMBVno0i03NnvBhfeRaX8tPEEPlwckSYUxy495LXnxw fxAUkOFApJpMCH5kYbxDmnGlmxdeaSqSii2QCvqqAv0k/odL+ywIqBp4Y1c8HbPlEQPaY2 As5jSk67qTicARvJ287CWeTqVt+7lVNZhb2do/1Wbi+SnUZvu+hAyI03Cw3J2A== 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 4jKXSL5YFzz1BXH for ; Wed, 04 Nov 2026 17:27:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 25f15 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Wed, 04 Nov 2026 17:27:09 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Yura Tkachenko From: Igor Ostapenko Subject: git: 646a485c3b2f - stable/15 - 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/stable/15 X-Git-Reftype: branch X-Git-Commit: 646a485c3b2f08906b3a75da656da3466438e758 Auto-Submitted: auto-generated Date: Wed, 04 Nov 2026 17:27:09 +0000 Message-Id: <6aeb6aed.25f15.bbc24a@gitrepo.freebsd.org> The branch stable/15 has been updated by igoro: URL: https://cgit.FreeBSD.org/src/commit/?id=646a485c3b2f08906b3a75da656da3466438e758 commit 646a485c3b2f08906b3a75da656da3466438e758 Author: Yura Tkachenko AuthorDate: 2026-10-30 20:20:24 +0000 Commit: Igor Ostapenko CommitDate: 2026-11-04 01:13:03 +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 (cherry picked from commit d1a465f02b14c9eed8a87c31092bb9251dc053c1) --- 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() {