From nobody Tue Nov 17 17:06:00 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 4jTWMs2pCtz71RmZ for ; Tue, 17 Nov 2026 17:06:01 +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 4jTWMr4dspz4JKg for ; Tue, 17 Nov 2026 17:06:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935160; 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=mnkqW2AU7I9k/3EJqyn1RJXny+Ws07SwBKGZuF+VGC4=; b=XkrN1meavtlxx9GpPRGUi4n+PigbPx8kMZDLxxL1Qt3GvxTQHK6F8/B5s/bewLyyS0S1hn svmszkMf9A3vadDgAaK1phdD34yWa0GudXproor/URbpt/+mUBAeivFU+LFgoOTxoS5NG0 wCT4rBinGkFI0LUXGXYf9iyFlozIrNQ0JWguHw3eVzhRBKWhY6wBNVWZy3C+scBITg8l86 zh1Q+DCDb2H1gvn2smm6tgIqurmdZxeUrub5JRiQpSG4LbLe6z+9hYLQkVATPKH0csvE4Y +kR33DxxnM/emAcg7A5nktVAG9b1dBL3P7NuQRIW/I5Kl8vdvZMgQdTcUk3+pQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935160; b=epxNbeZ7UGH1OQTEPcH0TqhirZlmXwcuX23ww9tmrNkOwLeKCTYYL2sgPHwOXzLaSW+8TG UJRnWzqgfL6KKiXFYwabpqJGD4phvZbFLzV61UGN3TyuZzCMSlVGkJInw0qM9AjQ3eXce0 8KBDuNIVNnn5RtFJqucBdWywjqvVkYWSwOwwF3LZS4BjOv5o4NgQFt1c8gy7lwD5dwM+rs bTDjBDryHhppcpoXbzgb8tgBFKzcfX6Z7SVEmJ2Ahx1jyykWZfCwqiLVRKuafL/NMAjwUW 5sCWPxpQonJiYB1VZL14oYBtW5e5IlDHhZLTaC24OnDwoC2OhXNJpnOBtmRd5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935160; 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=mnkqW2AU7I9k/3EJqyn1RJXny+Ws07SwBKGZuF+VGC4=; b=m9AnvPqAoAzTusncYK7OJZhtzGPpLIasIrMbMqFvag8yIY/am8Dsv80yo9SZzsplBIFC0H 6zj3SkK3wx5gS3OckgWTBIGpBCWXw+NUYffuIiPZ5DlZd4Mme4vcK84XcgQ/iT8EKoXL/6 84gRdL8PJjmbJ+mHsZ3l/YzLcLQqCLej2CsxRE9qnj8fMTgp0OYW7f92hMS2+SEjqmnzs5 m5/31mVami/99kOoDDeoGFiFzB+r1EI9DGAHk8iXeDDpHb+FmDb5OCQgQIhloBebuOXQsb ZWEM//50hYEnF6LEPnRUdp3R407t1qstfs4rDQJO8O+7ysF1YG4Ds7y7mucv+Q== 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 4jTWMr41b0zrVt for ; Tue, 17 Nov 2026 17:06:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1fb9d by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:06:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Konstantin Belousov From: Mark Johnston Subject: git: 9b7c7bcebd4d - stable/15 - lookup_cap_dotdot test: check symlink escape below a union mount root List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 9b7c7bcebd4d8b85212fed84daeae54a0522c00c Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:06:00 +0000 Message-Id: <6afc8978.1fb9d.5aa96baa@gitrepo.freebsd.org> The branch stable/15 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=9b7c7bcebd4d8b85212fed84daeae54a0522c00c commit 9b7c7bcebd4d8b85212fed84daeae54a0522c00c Author: Konstantin Belousov AuthorDate: 2026-11-12 20:00:18 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:22 +0000 lookup_cap_dotdot test: check symlink escape below a union mount root Let mount_tmpfs() add the union option, and leave creating the mount point to the callers, so that the covered directory can be populated before the mount. Approved by: so Security: FreeBSD-SA-26:81.vfs Sponsored by: The FreeBSD Foundation --- tests/sys/vfs/lookup_cap_dotdot.c | 84 ++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/tests/sys/vfs/lookup_cap_dotdot.c b/tests/sys/vfs/lookup_cap_dotdot.c index 08c3f81b0d57..1fde0f13834c 100644 --- a/tests/sys/vfs/lookup_cap_dotdot.c +++ b/tests/sys/vfs/lookup_cap_dotdot.c @@ -263,15 +263,16 @@ ATF_TC_BODY(lookup_cap_dotdot__root, tc) */ static char mntpath[MAXPATHLEN]; +/* Mount tmpfs over the existing directory "mnt". */ static void -mount_tmpfs(void) +mount_tmpfs(bool unionmnt) { - struct iovec iov[4]; + struct iovec iov[6]; char cwd[MAXPATHLEN]; + u_int iovlen; ATF_REQUIRE(getcwd(cwd, sizeof(cwd)) != NULL); snprintf(mntpath, sizeof(mntpath), "%s/mnt", cwd); - ATF_REQUIRE(mkdir(mntpath, 0777) == 0); iov[0].iov_base = __DECONST(char *, "fstype"); iov[0].iov_len = sizeof("fstype"); iov[1].iov_base = __DECONST(char *, "tmpfs"); @@ -280,10 +281,29 @@ mount_tmpfs(void) iov[2].iov_len = sizeof("fspath"); iov[3].iov_base = mntpath; iov[3].iov_len = strlen(mntpath) + 1; - ATF_REQUIRE_MSG(nmount(iov, nitems(iov), 0) == 0, "nmount: %s", + iovlen = 4; + if (unionmnt) { + iov[4].iov_base = __DECONST(char *, "union"); + iov[4].iov_len = sizeof("union"); + iov[5].iov_base = NULL; + iov[5].iov_len = 0; + iovlen = 6; + } + ATF_REQUIRE_MSG(nmount(iov, iovlen, 0) == 0, "nmount: %s", strerror(errno)); } +static void +unmount_tmpfs(void) +{ + char cwd[MAXPATHLEN]; + + if (getcwd(cwd, sizeof(cwd)) == NULL) + return; + snprintf(mntpath, sizeof(mntpath), "%s/mnt", cwd); + (void)unmount(mntpath, MNT_FORCE); +} + ATF_TC_WITH_CLEANUP(lookup_cap_dotdot__mountroot); ATF_TC_HEAD(lookup_cap_dotdot__mountroot, tc) { @@ -297,7 +317,8 @@ ATF_TC_BODY(lookup_cap_dotdot__mountroot, tc) int dfd; check_capsicum(); - mount_tmpfs(); + ATF_REQUIRE(mkdir("mnt", 0777) == 0); + mount_tmpfs(false); ATF_REQUIRE((dfd = open(mntpath, O_RDONLY | O_DIRECTORY)) >= 0); ATF_REQUIRE(mkdirat(dfd, "sub", 0777) == 0); @@ -317,12 +338,54 @@ ATF_TC_BODY(lookup_cap_dotdot__mountroot, tc) ATF_TC_CLEANUP(lookup_cap_dotdot__mountroot, tc) { - char cwd[MAXPATHLEN]; + unmount_tmpfs(); +} - if (getcwd(cwd, sizeof(cwd)) == NULL) - return; - snprintf(mntpath, sizeof(mntpath), "%s/mnt", cwd); - (void)unmount(mntpath, MNT_FORCE); +/* + * A name missing from the root of a union mount is looked up in the + * covered directory. A relative symlink found there is resolved from + * the covered directory, and its ".." must not leave the starting + * directory either. + */ +ATF_TC_WITH_CLEANUP(lookup_cap_dotdot__union); +ATF_TC_HEAD(lookup_cap_dotdot__union, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Validate that symlinks below a union mount root stay beneath it"); + atf_tc_set_md_var(tc, "require.user", "root"); +} + +ATF_TC_BODY(lookup_cap_dotdot__union, tc) +{ + int dfd; + + check_capsicum(); + touchat(AT_FDCWD, "outside"); + ATF_REQUIRE(mkdir("mnt", 0777) == 0); + touchat(AT_FDCWD, "mnt/lower"); + ATF_REQUIRE(symlink("lower", "mnt/lnklower") == 0); + ATF_REQUIRE(symlink("../outside", "mnt/lnkout") == 0); + mount_tmpfs(true); + + ATF_REQUIRE((dfd = open(mntpath, O_RDONLY | O_DIRECTORY)) >= 0); + + /* Entries of the covered directory are still found. */ + ATF_REQUIRE_MSG(openat(dfd, "lower", O_RDONLY | + O_RESOLVE_BENEATH) >= 0, "%s", strerror(errno)); + ATF_REQUIRE_MSG(openat(dfd, "lnklower", O_RDONLY | + O_RESOLVE_BENEATH) >= 0, "%s", strerror(errno)); + + ATF_REQUIRE_ERRNO(ENOTCAPABLE, openat(dfd, "lnkout", O_RDONLY | + O_RESOLVE_BENEATH) < 0); + + ATF_REQUIRE(cap_enter() >= 0); + + ATF_REQUIRE_ERRNO(ENOTCAPABLE, openat(dfd, "lnkout", O_RDONLY) < 0); +} + +ATF_TC_CLEANUP(lookup_cap_dotdot__union, tc) +{ + unmount_tmpfs(); } ATF_TP_ADD_TCS(tp) @@ -338,6 +401,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, lookup_cap_dotdot__negative); ATF_TP_ADD_TC(tp, lookup_cap_dotdot__root); ATF_TP_ADD_TC(tp, lookup_cap_dotdot__mountroot); + ATF_TP_ADD_TC(tp, lookup_cap_dotdot__union); return (atf_no_error()); }