From nobody Tue Nov 17 17:01:47 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 4jTWH01t9yz71QYX for ; Tue, 17 Nov 2026 17:01:48 +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 4jTWGz4Y14z3PSr for ; Tue, 17 Nov 2026 17:01:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934907; 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=jSC2XGU2JyO8aRw4e6b0f0jgWyyOpok6FA6Y5QXejbQ=; b=bqH1TRh5eFFJ93kQDecsRfQO6eX4/8GNEbvl+20TFLUTTNwgtuu58t5D1ArZJiLdHiERr4 51HnosV7l8Ch62qVLCe48vFyRRk2zxLt1yAg07rEJO6eu2dXXfAB1lp44/PLe8Fc2n1jS8 WvmkyV32MHGPUPwybHW+ehLCWm+CeDt1sNfNcIcTGZMMIrgs3zgPI08u84/PWvbp73g9Oy i0+RGPDPZwEypnlbESafqUnR3IJvxZk5pyqgLuUGSr2Wr3BhYQlKg8y/K5I7BcAvB/E0rp 7v9b1aoaM/PKPx6kyyRot62bpG7SGPx2he+op+dP9DkZDvsOD7MVpyBIKzDhdA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794934907; b=YnLJGu3C3lnBb3wWVC7VV3t5cEgRSsZWk4BXqPiU2fx4K7jtqn572V3vtep7CQzCTqOARs HZBHdpEK9lIjEafk67oI/qUj/1x2J1KkyWVtEq2Tj6+is3BKcSeEt0Z78ocxZXdc/wpySr DFlHyRZ+T1u5tryWh/ya6iCtQ3Mf3V5lGNMLn7+IMZw4gtX4eEt4w0APlaw/F0E+R1x3mc pZTRJo0VA5Rsksh8xSnb5yWMQY2i84fvpNiF1RgQTUHEyutkAvYgoL1gHEUdQMqf562gAl u8LGVGQ60RiswGHsKcVoCTuoSqo34HX3Uw1+9+TT2rDH0Q2aFxOM/TRYl8eSNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934907; 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=jSC2XGU2JyO8aRw4e6b0f0jgWyyOpok6FA6Y5QXejbQ=; b=aMRNnW38MOumxmi/MdfHEuyjoWsPp9uvDDQeiDahgbaQxcuu514OwkI3jO6Ai32qUFeg7k wd774ivHsFSfdBYINNfl1g45QxknD+L8yGYW2FjGj2YYNFCtWD3/0jEf0S5cTQmuQT+dnq ji5ayR2utfaw1B6pjoJbOyVV2JoLCUb2ArEM8MgLPfkntdBXlUL2GFyyKBGNJUjgKLRIPN ROA/WISrwn2rj0yKa3e+9T+ZAP9yWiH/qOr8jlp8ZBBMVrEnTz3lV2zphIfAntYfC62KyF BOW+FDhrriDj192hMP0n58GMeq6eOw/vR2zQinmdWMtzzf1g34m6VoWeo1xbGA== 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 4jTWGz4CQJzrf1 for ; Tue, 17 Nov 2026 17:01:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1e7d8 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:01:47 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Konstantin Belousov From: Mark Johnston Subject: git: b20fea1fa9d9 - main - 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/main X-Git-Reftype: branch X-Git-Commit: b20fea1fa9d939da78453da2918ba34f0520b928 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:01:47 +0000 Message-Id: <6afc887b.1e7d8.1c3ce195@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=b20fea1fa9d939da78453da2918ba34f0520b928 commit b20fea1fa9d939da78453da2918ba34f0520b928 Author: Konstantin Belousov AuthorDate: 2026-11-12 20:00:18 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:00 +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()); }