From nobody Tue Nov 17 17:08:16 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 4jTWQT2GLYz71SRF for ; Tue, 17 Nov 2026 17:08:17 +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 4jTWQS6SLHz4N0g for ; Tue, 17 Nov 2026 17:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935296; 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=TzyxZWitFOyP6N0SG7nMHZ2GDMNI4AkCiuKWqz/Aurc=; b=Na/2+1p6Rw0c4aVL3Kdhzzhfrt1ISWuATxpUS/spHRmT4pHCSfwrvzxvTXcC33wC7NdUem /mkG3q90SLWrskWZvFgtN8MzoMPz2W6eSscr25vF9Tlr1v3mKko9gvMDChbvyNV0g3RcUf HmVnXUKGd/60jUfLyRHuJ8rF9emr8st/6+pky8A54qpL2N1gQKnapEIGZ+BKSZnDy/wFlC 9bX2xrqgn5Np9cpZh3FGKiZdTqxJ58ZdqehGLEL8EqyRCixQmwowiy9YuQPzje7fPb9GUd 52x5/l0AzCNYPK0CP2vY6OxEvL23Bo7+FYv2zQZWDDZxedKsQwPxcmF3dMI/AA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935296; b=XBPk8jB6aefjRU/P2TVTaEQ9d194kWOXgw24KPqk1saZvIs4hKe9eRCUi1T6n2nXjNhclV i3OWTy158T6R8QZU0Q1Phrhz0+do3zmxAz3sqCCvj9TUFSCRBSh4z50gLbo2fs/nc6poce VT2Shj3xYDohy1I16l+zelzH7YqhO67EV5vUTi72nYrsuJu6DHax+971OEcXk9gIqHHqMe 0DZ1hWI9sEJNNtgNzYdFHN/SZnaVkeYaWp6HIj7y3UUWDqUKVNTvOe5exX4PyqPuYp9so4 6oaZjTRQPhuNqu0Aph9easICyoEGxZZDqTIlcEiiXHvhCFfSzL/6T11xo5LDAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935296; 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=TzyxZWitFOyP6N0SG7nMHZ2GDMNI4AkCiuKWqz/Aurc=; b=Lv2pfZHnUgfn8leS8B2av2bp7sRAMNP6LGe6PmeNuDmFglbDHHPctFCTShnbiTVG53SCEb SwB07f3iiqschISkasu/XLK84lZGxYuXTrRtICc7MvvyAJyLM8GOdXRzwmaMwfsYu4mBWh SdMbNKCViru7udo6kvmF3gvtRBInRbL8Fi90edTjI0IciPuCscXVSr9EllKv+n/WrteLHF IOq6dsMk+B3MP11viaARkpkmyqtfvKOPL8JzrySllQSzo3jPJJIkXhG7rgWXZVgEIjYYCJ wmacbTCtCcPt0w+hgvr3FrmT7uzlQiIoN/LyFFawCKIPI0GBlAVHOOSbujNo5w== 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 4jTWQS5rT7zrvy for ; Tue, 17 Nov 2026 17:08:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:08:16 +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: c0de320f18f0 - releng/15.1 - 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/releng/15.1 X-Git-Reftype: branch X-Git-Commit: c0de320f18f00ac628a2832607fe46e2baa8f17c Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:08:16 +0000 Message-Id: <6afc8a00.1f3.23595b90@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c0de320f18f00ac628a2832607fe46e2baa8f17c commit c0de320f18f00ac628a2832607fe46e2baa8f17c Author: Konstantin Belousov AuthorDate: 2026-11-12 20:00:18 +0000 Commit: Mark Johnston CommitDate: 2026-11-16 21:21:09 +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()); }