From nobody Tue Nov 17 17:09:41 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 4jTWS71DPZz71SsV for ; Tue, 17 Nov 2026 17:09:43 +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 4jTWS55HMTz4QDc for ; Tue, 17 Nov 2026 17:09:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935381; 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=YMmGXU1VD5Ga2Op/GECDgbWMKh5LatzxBi8MwpX6r0M=; b=XPaj/q4Mr4a4IlINpr4f0gwk7abI1NUA1QL9Zfit/F+1NGpma8/+bBSZtHjMPWSt36K/hK Bb6+4kV6S5deiSBHmDsY/vZfGFZe0gw3cs8q7oRm5GodRdIqOWBjxwpYLZ8K8+tKLYhfuX 4ywKrViiSe+6rDM+DdRxF7JZHC9UN1ARgIWYAmPqliEbOaTLnsBKdXKhnARTzbE60/ib35 ORDYTu/A2Pzcm0mCu818O5qCHmEn2YTz5APtSGIpSKTLbi2UaCBIjiE4XKRnO1CEAIQk5o e/Bus8lsv7BbCebXUMZ5QoMmUkNFHraOuCkUNbjqrEvUxm+TkaanrEFCfrs6CQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935381; b=jzOktY6ASZGUjewxNTDhBtMIu2nbE0GDLB8JwDJIAHJFYtCQgUWr7Gz5uXH2Y9HmrLU/Ci pIIfutCqqgePEs0IJbrt68EVgSb+NhGYG+pM1ypeNpwUQ2ViGAG328s9GrYK11nTXlnE8X WfpQk4a1oGdYRsEP6mN3LbHepWSBzjtzLWgnBTiQZTklNk77UDfQPY9QS14l2A1Rxc3i9P 4RVTe9H4ZsJ19+U0uISOjLQ/DfWBFQNWJmuKEL/YnIALIg+nbHJoT1bBEYferzCpSP+tBA evQRA+FdUC/X/RPFy3mzY9p9PZMM6xhoF4Xk//dygxKLsY6+1icd+dUwW51PQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935381; 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=YMmGXU1VD5Ga2Op/GECDgbWMKh5LatzxBi8MwpX6r0M=; b=I95HyE2U9yuZxWrJWXVchXWNvP3RiIJ5C7zCY6+Es3AUgQenZSb+Rwh0JiXUTrWcsHwB+Q flwVcrqCFdbtlQDJ6VbdOW28PjYvTsbpmcAzNL28x/E937LcdCA87aaGmhu2lsDffF+2lk HCyLOEoQvmM2GGaemSewysESHGJh3EnibvYJWn/ENiOOLWT2Qhh+F32T5nOPTgvHjMYytE 0UytyAmS58PwZgTcHlvGR4kOemqw4cu0azkYZVhtPETuBQf7/oOGuvdsnWBrit9OSu8/W6 geXfRu0uUo6ktavZhOHfojPn6YeCmJjJcMYRkBFig8DgqGPrzys8WDrHXsvfuQ== 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 4jTWS54JQdzs1p for ; Tue, 17 Nov 2026 17:09:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1d17c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:09:41 +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: 0ffc20130b70 - releng/15.2 - 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.2 X-Git-Reftype: branch X-Git-Commit: 0ffc20130b70f2ce9ab9c37b945dde42aa58574d Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:09:41 +0000 Message-Id: <6afc8a55.1d17c.39a86e95@gitrepo.freebsd.org> The branch releng/15.2 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=0ffc20130b70f2ce9ab9c37b945dde42aa58574d commit 0ffc20130b70f2ce9ab9c37b945dde42aa58574d Author: Konstantin Belousov AuthorDate: 2026-11-12 20:00:18 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 13:35:12 +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: re (cperciva) 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()); }