From nobody Tue Nov 17 17:02:04 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 4jTWHJ4yt3z71QFR for ; Tue, 17 Nov 2026 17:02:04 +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 4jTWHJ3Fkdz3QKf for ; Tue, 17 Nov 2026 17:02:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934924; 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=Sq6TDmqFbsGoe+9GlKue//5sYZ9HSTMxmnWJQM8cTHI=; b=CcqxS0RMtm4reKL2CMcT0t+mSXAvmkY2LwTujy3fJi1f42GQackzn2RiF2jb31PayR/r3L XmPX6VEqBk54rMXGXUPEp7x7kpu3Z9Rw9zZVGjZOKq/SEHwZdAXdW9OGCvBj2Z0vjL4J7g yUoMmcT0b72jjPka8bCaPl+hVlT8UYtxk9GVgz3QWi5lZ40XzGdqOHfFgdUL4WuzAAXQMZ 7YEsCe4f/edIjpJ3LpNuOmC6UtZB4ruYBdtsphpHSFADpfnWdidANXGzB4dsJVNQ0try/b szn6Pw4IB//JPdJy4zp6VJvYVisGSw1YfF+8n52acVsz5x9U3l1jNXMUrVQHvQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794934924; b=WKwHWh4VNjTjODQcERDcwXS/dfNTRkIEUSNVrOy3moNEk0+YRgnhNWTh5CAGdmVKYW0VcD DunMy4cl3/aTjmDU7rRAlV883RgjbQIi+necFj2uKTrYfbjnJgFnbADj7cDNKt6jBCukmh mkezeZnUrxQwohxvdaNUN7L8U5pk4dbsoCvD33UPyQ77QyvrVyVQEsHqvn9qqhX1RdB5pi z9HKNsHc7OHiMxzj9ORDTbu3aS5C5qBHHjpoEv36kwqLtp7qh+0v+UPmxH1B2f8q71SzP1 /xqKdQ+0FC2CSgsVHOck3J2tsZkLltVR4PF5Qg95waF6DfGedv8KhAvpm6MGZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794934924; 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=Sq6TDmqFbsGoe+9GlKue//5sYZ9HSTMxmnWJQM8cTHI=; b=LfmN5/L+V26V+AGg3S+cuuRtdaRRWO0UukeSFyr/QtsIfrWaLRRk9JfYHrQhF5Gw4+SSwH tdsEzBUDNB3SL7Np7ClE1A0kt4rT3FbCIjmmweKWBhDTcKQAAfEFic83JtHkOU6T4npwH0 2qUc4hjwJgtTtA2ui560UG+teTr8ld7G60aAFmLnNMnInYcaZdMLXhxPqLP4CJW4UQFKK8 pyiEEBL/gPKuGclxEVDLuxmsxxPffAzVRhHBbcSDp5j8G8C+siipDcENnuN3o5BQWcX966 LiqTimysJ46zPTjE2WBPO6IdT+iXdgJMmP+RW7ZI54nnF+Vaz3V/3X8WX4DBwg== 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 4jTWHJ2s5Dzr8D for ; Tue, 17 Nov 2026 17:02:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1e491 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:02:04 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Dag-Erling=?utf-8?Q? Sm=C3=B8rg?=rav From: Mark Johnston Subject: git: 72328112ec2d - main - 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/main X-Git-Reftype: branch X-Git-Commit: 72328112ec2def16a7ebebed1801227fe66cbe81 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:02:04 +0000 Message-Id: <6afc888c.1e491.3035c973@gitrepo.freebsd.org> The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=72328112ec2def16a7ebebed1801227fe66cbe81 commit 72328112ec2def16a7ebebed1801227fe66cbe81 Author: Dag-Erling Smørgrav AuthorDate: 2026-11-13 20:28:38 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 16:57:01 +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 160fd7a9e5a7..95e38c970779 100644 --- a/tests/sys/fs/fdescfs/fdescfs_test.c +++ b/tests/sys/fs/fdescfs/fdescfs_test.c @@ -516,6 +516,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, traverse_dir); @@ -535,5 +606,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()); }