From nobody Tue Nov 17 17:09:58 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 4jTWSR1k7hz71Sxr for ; Tue, 17 Nov 2026 17:09:59 +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 4jTWSQ5nj6z4Qnl for ; Tue, 17 Nov 2026 17:09:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935398; 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=UtDkZMtReY5RfyxIWQMbgeBYZKaV13LYuw0wNyqO7Tc=; b=kgYs5a2O7UAOm4BATu8aaDf/uD0jcfcW5Ks1D/tzLJjHrqXo39A+/TA5ku5sUQpHPixZJC hlnQ5ymghj4f+P+PLRJdrPi+lI+pupXS3Khn9PuEeaucR5jIT6cSTO+NpThitHnWU+2lIr ydqTEMNytKzxD37E0mM1557xc7npF/nhT9JlvwwL2H90Tw8+VHRmibDsYbntl70yt+njzO fhz2iC4TnH2C/+I2Eg8fmpYjn3ku448EbiK90ejU2os6WXiuE0XxdI82PA8h3ytdtoZ7nz EKlsr0AFt1dM8XZNlQhIXEu/AylMvTtaGsz/9EVsgkD8+K+/bML28ZUKxyZE9A== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794935398; b=Vxmo7hbYoSJi8RAuRWVf+BfjzBQ0DtIQ9PpzpPkYCOW2DTRIvIDp8dc4i7QhlZQnNjQ8rR gPm6XaBQVfBxLOYNbOXK5v4WTlsE8SjEItwtvntz25NvkphG2w/WfP08FSoDRld7Tmp6pD /MhtIyzfEczfbUD3eqB9nJpjZnCdqiCbaO3WzSbPYofBuPcDSqpwQBlxi2lB0KbhlQ0Ps7 izQhBH3yStD45kQSqqF4TB8QVFL2IbIAwN2meshuk6Iiw0nRumXreDUMEbmGIj+L0CgNQX VdTOJmJJQgfhlR3t6v7eA+g1PCIoYm44fEevPZWddi+7u5paYJm6pwODBa6plw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794935398; 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=UtDkZMtReY5RfyxIWQMbgeBYZKaV13LYuw0wNyqO7Tc=; b=IPiqhNgwQivh0gzzfPtdcdYiyjXqOroVh5qDNKONIKyDQSXw++TTjmvZGvEIYf7CEL0sLM YN/4myXRmFvgo1czryIA38XY6fVWMyn6g7I6bBPYO/fspYeHMsgH7OG+3K23K+5/vOiFnD w1tUbPq5q9kQ7uQEHsLmexVgaMIubiC9uNZwnIXpz3VrFA+uEpppAblOFSjyQLgwEB9DfR qHuG9AFGvOqY49R3crmdM4Q0mBO8zECiB7WfAyVNFEGKNprchQ/swJpwuclrzAun+A6srn GJ60K+0a+hrGoJDZB1JV/mY4dFdIFgniS+oDgSS6EGX4BuaJOMx7faC1UISnag== 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 4jTWSQ3KLGzryG for ; Tue, 17 Nov 2026 17:09:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id e82 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 17 Nov 2026 17:09:58 +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: e0dbb0341970 - releng/15.2 - 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.2 X-Git-Reftype: branch X-Git-Commit: e0dbb03419701617f43a0541cea1cdc83f80942d Auto-Submitted: auto-generated Date: Tue, 17 Nov 2026 17:09:58 +0000 Message-Id: <6afc8a66.e82.5e3b9278@gitrepo.freebsd.org> The branch releng/15.2 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=e0dbb03419701617f43a0541cea1cdc83f80942d commit e0dbb03419701617f43a0541cea1cdc83f80942d Author: Dag-Erling Smørgrav AuthorDate: 2026-11-13 20:28:38 +0000 Commit: Mark Johnston CommitDate: 2026-11-17 13:37:00 +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: re (cperciva) 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()); }