From nobody Tue Nov 17 17:05:26 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 4jTWMC0tHZz71RZQ for ; Tue, 17 Nov 2026 17:05:27 +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 4jTWMB5wclz4HFQ for ; Tue, 17 Nov 2026 17:05:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935126; 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=+/Jzpu10iOfximlt71/BhMumCo3HdciGAruwfRwxW+g=; b=alyieZhPTRPexuH34qx9jYq+xndpAWfB+v9yJGBNieoPIRXWVuqU48l3s8iyvD8G+XevX6 8FqULpXPvd7qtbFrDzXREboHYLvp02j/roeQISiHGKwAu/17D3OfjBqCDS3eIZEJHQwC0u pxBwSG8U1jGOmzHzwDHgsUf183eGvS6i3YY4YKbwJgQcZ1H13PKgWqbntoJG2wFvCwIh1C jFtxd5mNJD57lIdmMme7swDeeN6U5GSqKv/2C88S+D/7jF4yNYE4c7mmVTD6CK0wDmchpU tQ55uiiGYbz684FpdV9+GUGGCXsHiAFM4yhnYd5vzZZkev2/cWPHBEdjwnpBVA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935126; b=rTZQjgDggwrFE5vJAy3AX+4ERnvOlDvVYCJWbt+qU69+4iAixyQJIQisM7RaWUmbT3twWj uDIcYJeLXmoI0gHumqzLHDIZI8NWoUaQOjFq/GOvIgqgEjXOzKhfsLyn0owBAex31Hhq34 UJxhCnx+wvr+BPt/8jt2on4/ZJryQL+lmgHlK/2ei0GJ2UH+xdXjsENc4Rv/uK72Is0+aL orr6jAe2OD51HftgAx1dzIpBErCMAhMM6EhrBy/WEUdTOF0dmApi901XGTyrXhnOZLEIxW jsc1THtQieQOXdTMJi0ybcnARs6n1mOASVljAPFnhYw5JkTfAZFfBqhClcdIcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935126; 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=+/Jzpu10iOfximlt71/BhMumCo3HdciGAruwfRwxW+g=; b=mIM3Q13RWMUK8QQenwDPril2zSsRz+OpExK37xYExHw6qN0taSC4r2J9RQsQm4cFUBKYha Z24jPCCaCpvCMFQrA2FBho9ruiAf4IyvNL5ck88D/J8XszVlT+ugxdxj95SJCpaNqPuPZw WMg1sDIroT2x3QNo+4U6eZSxZuHhUA42fb7T0FAmp3RCe23ZuuLNEswKm0J0LsEYnsRefk /ZZD6QzTxJqQvSkvmOl5AO0B6tP9f3Lwt5DbN+Dgqz7YjylB+8i4v4zFzmrGRctztCNAxZ YV9bFVYC/YPirY9gTeRZ54MimEIVmVGnJ80owQZzaP3RoYdSgPa3WjYRN0a0ag== 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 4jTWMB5ZynzrmG for ; Tue, 17 Nov 2026 17:05:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1f6fc by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:05:26 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Cc: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav From: Mark Johnston Subject: git: 1e1ab955789a - releng/14.5 - tests: Add test for fdescfs truncation bug 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/14.5 X-Git-Reftype: branch X-Git-Commit: 1e1ab955789a01782487addfb3a9ae25382eaf97 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:05:26 +0000 Message-Id: <6afc8956.1f6fc.501e6d9c@gitrepo.freebsd.org> The branch releng/14.5 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1e1ab955789a01782487addfb3a9ae25382eaf97 commit 1e1ab955789a01782487addfb3a9ae25382eaf97 Author: Dag-Erling Smørgrav AuthorDate: 2026-11-13 20:28:38 +0000 Commit: Mark Johnston CommitDate: 2026-11-16 21:17:13 +0000 tests: Add test for fdescfs truncation bug Add a test case that verifies that it is not possible to truncate a file opened read-only through fdescfs in default mode, and another that verifies that it is possible when fdescfs was mounted in nodup mode. Approved by: so Security: FreeBSD-SA-26:91.fdescfs Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D61236 --- tests/sys/fs/fdescfs/fdescfs_test.c | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/sys/fs/fdescfs/fdescfs_test.c b/tests/sys/fs/fdescfs/fdescfs_test.c index 558714026c5d..2d45a4ee9bf2 100644 --- a/tests/sys/fs/fdescfs/fdescfs_test.c +++ b/tests/sys/fs/fdescfs/fdescfs_test.c @@ -261,6 +261,77 @@ ATF_TC_BODY(nodup_ioctl_cap_intersection, tc) ATF_REQUIRE_EQ(0, unmount("mnt", 0)); } +#define TEXT "Hello, world!\n" +#define LEN 14 + +FDESCFS_TC(truncate_ro, + "disallow truncating read-only files (plain)"); +ATF_TC_BODY(truncate_ro, tc) +{ + struct stat sb; + char fd_path[16]; + int fd; + + /* create read-only target file */ + ATF_REQUIRE((fd = open("file", O_RDWR | O_CREAT, 0400)) >= 0); + ATF_REQUIRE_EQ(LEN, write(fd, TEXT, LEN)); + ATF_REQUIRE_EQ(0, close(fd)); + + /* reopen the file read-only */ + ATF_REQUIRE((fd = open("file", O_RDONLY)) >= 0); + + /* mount fdescfs */ + mount_fdescfs(NULL); + + /* construct and stat path */ + snprintf(fd_path, sizeof(fd_path), "mnt/%d", fd); + ATF_REQUIRE_EQ(0, stat(fd_path, &sb)); + ATF_CHECK_EQ(S_IFCHR, sb.st_mode & S_IFMT); + ATF_CHECK_EQ(0555, sb.st_mode & ALLPERMS); + ATF_CHECK_EQ(0, sb.st_size); + + /* attempt to truncate */ + ATF_CHECK(truncate(fd_path, 0) < 0); + ATF_CHECK_EQ(LEN, lseek(fd, 0, SEEK_END)); + + /* done */ + ATF_CHECK_EQ(0, close(fd)); +} + +FDESCFS_TC(nodup_truncate_ro, + "allow truncating read-only files (nodup)"); +ATF_TC_BODY(nodup_truncate_ro, tc) +{ + struct stat sb; + char fd_path[16]; + int fd; + + /* create read-only target file */ + ATF_REQUIRE((fd = open("file", O_RDWR | O_CREAT, 0400)) >= 0); + ATF_REQUIRE_EQ(LEN, write(fd, TEXT, LEN)); + ATF_REQUIRE_EQ(0, close(fd)); + + /* reopen the file read-only */ + ATF_REQUIRE((fd = open("file", O_RDONLY)) >= 0); + + /* mount fdescfs */ + mount_fdescfs(nodup); + + /* construct and stat path */ + snprintf(fd_path, sizeof(fd_path), "mnt/%d", fd); + ATF_REQUIRE_EQ(0, stat(fd_path, &sb)); + ATF_CHECK_EQ(S_IFREG, sb.st_mode & S_IFMT); + ATF_CHECK_EQ(0400, sb.st_mode & ALLPERMS); + ATF_CHECK_EQ(LEN, sb.st_size); + + /* attempt to truncate */ + ATF_CHECK(truncate(fd_path, LEN / 2) == 0); + ATF_CHECK_EQ(LEN / 2, lseek(fd, 0, SEEK_END)); + + /* done */ + ATF_CHECK_EQ(0, close(fd)); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, cap_rights); @@ -270,5 +341,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, ioctl_caps); ATF_TP_ADD_TC(tp, nodup_ioctl_caps); ATF_TP_ADD_TC(tp, nodup_ioctl_cap_intersection); + ATF_TP_ADD_TC(tp, truncate_ro); + ATF_TP_ADD_TC(tp, nodup_truncate_ro); return (atf_no_error()); }