From nobody Tue Nov 17 17:08:34 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 4jTWQq1R08z71SVj for ; Tue, 17 Nov 2026 17:08:35 +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 4jTWQp5VpWz4NDW for ; Tue, 17 Nov 2026 17:08:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935314; 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=tNR/CL0s5CoJ/MnLJ04F295mWGH7X6aCS1U8YWGeZEk=; b=KQekioWG/SPylP6SvqwAjxcJ2Efl7jyAHB3A8zPlEkhXhniTUf3vFQ9eft2yA8nDGMcI2u YQAdjQzDe7VBzZysGqNteiDyu1diUBLoB8HPUfgkYKxFLcxceJH3zj9a3Nhr5RfguspP02 eVd7fsTkSidfHW/grj5546rb5yeEuItQBdpZzG7dcKgbEQMTQpkIdFqooXUwxlep8bH0yG rjq6jr1eApMVmuQZ+Xk8YhaUF6eIuO7e5WPAyp+pgo15QbSYfAhH3G3AkssyMg7tXw4xmJ NMl+GyilSDryDoK+NgrXbv+KbKA6ZlmMXw/ulBJ47xThqc+GMIWZPH5a/XDEEQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935314; b=DwXa7Mxx1GWrejMouvjC/moGPTMKCTkHmTshJgZaqTTyJ1qArs6M6aViXth2cKsBCh0CJb qrmTpCwaxxDPKhnBXq/ODxYvyjKdeGc7Hz2ttLAN10JpwiGzegO9yHfenLgQJz3PU8rSdx FyXUl+wX3RcBINuk3+Y8ki72uJq2cS00C2yixNvagjl/HoabQn+wiI0nnGzbPIDOCmdxsu KIhCD3g88AsrDJ8D09NadQElLQjrHFVNnBTRHtTMfYRGQSmPyzCDYU1tvPbie9rvq5EVKK ywULIRZ9w3bfPqVrdhvR34V+76cxJrFfi3ntywyIsaMe40LnPTR/lx6K2H+LmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935314; 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=tNR/CL0s5CoJ/MnLJ04F295mWGH7X6aCS1U8YWGeZEk=; b=Lux8QuwISpwSvrTmTkhmWaBVl0/nA/FsbLh7cpA59LSA+IFTubS7+S1lUmJh8a2fZrcpia GGk2eOtJZISoMg4NTrP/a22mmLy9TRNgf14hADpBAZ4UrRE0QixYQoVJiLTgVn78f3sX/t uod3hzpJDse6zLrRKdAoR0w9XSAvI17HewnM2LwVasr02Ms+Dyj9BOvy4FaIr5pSglwYyB IBPegXzwh1kllX8E1IJ31cDbwWi5SlfIjf3/HRpG4domeDKaJr9JoYkbcrncQFw6Vjr0VH F32CiDgYezVOq6Dbw55GokQPMEsgLDSengbhzYnbN56kbJFBJvz/Qppps8pwbw== 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 4jTWQp58yMzrnR for ; Tue, 17 Nov 2026 17:08:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id a06 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:08:34 +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: 1a5557e16105 - releng/15.1 - 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/15.1 X-Git-Reftype: branch X-Git-Commit: 1a5557e16105818fa1e5337d5b2a5596e9002090 Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:08:34 +0000 Message-Id: <6afc8a12.a06.3c90ff6a@gitrepo.freebsd.org> The branch releng/15.1 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=1a5557e16105818fa1e5337d5b2a5596e9002090 commit 1a5557e16105818fa1e5337d5b2a5596e9002090 Author: Dag-Erling Smørgrav AuthorDate: 2026-11-13 20:28:38 +0000 Commit: Mark Johnston CommitDate: 2026-11-16 21:25:06 +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 f80d335108e6..4f1151f7d221 100644 --- a/tests/sys/fs/fdescfs/fdescfs_test.c +++ b/tests/sys/fs/fdescfs/fdescfs_test.c @@ -223,6 +223,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); @@ -232,5 +303,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()); }