public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] generic: test that truncate(2) on fsverity is blocked
@ 2026-01-19  6:24 Christoph Hellwig
  2026-01-21 15:08 ` Zorro Lang
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2026-01-19  6:24 UTC (permalink / raw)
  To: zlang; +Cc: ebiggers, fstests

truncate(2) doesn't go through open and needs special code to block
it on fsverity files.  btrfs was missing this check.

Note that truncate(2) in current core utils uses openat and ftruncate,
so add our own little test program for it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 src/Makefile          |  2 +-
 src/truncate.c        | 17 +++++++++++++++++
 tests/generic/788     | 37 +++++++++++++++++++++++++++++++++++++
 tests/generic/788.out |  4 ++++
 4 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 src/truncate.c
 create mode 100755 tests/generic/788
 create mode 100644 tests/generic/788.out

diff --git a/src/Makefile b/src/Makefile
index d0a4106e6be8..577d816ae859 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,7 +21,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \
 	t_mmap_writev_overlap checkpoint_journal mmap-rw-fault allocstale \
 	t_mmap_cow_memory_failure fake-dump-rootino dio-buf-fault rewinddir-test \
 	readdir-while-renames dio-append-buf-fault dio-write-fsync-same-fd \
-	dio-writeback-race unlink-fsync
+	dio-writeback-race unlink-fsync truncate
 
 LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \
diff --git a/src/truncate.c b/src/truncate.c
new file mode 100644
index 000000000000..4c106d26f29e
--- /dev/null
+++ b/src/truncate.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2026 Christoph Hellwig.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+	if (truncate(argv[1], 0) < 0) {
+		perror("truncate");
+		exit(1);
+	}
+
+	fprintf(stderr, "truncate succeeded\n");
+}
diff --git a/tests/generic/788 b/tests/generic/788
new file mode 100755
index 000000000000..02959037e7c3
--- /dev/null
+++ b/tests/generic/788
@@ -0,0 +1,37 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2026 Christoph Hellwig.
+#
+# FS QA Test 788
+#
+# Test that truncate(2) is blocked on fsverity files.
+#
+. ./common/preamble
+_begin_fstest auto quick verity
+
+_cleanup()
+{
+	cd /
+	_restore_fsverity_signatures
+	rm -f $tmp.*
+}
+
+. ./common/filter
+. ./common/verity
+
+_require_test
+_require_scratch_verity
+_disable_fsverity_signatures
+
+_scratch_mkfs_verity &>> $seqres.full
+_scratch_mount
+
+fsv_file=$SCRATCH_MNT/file.fsv
+
+_fsv_scratch_begin_subtest "Using truncate(2) on a verity file fails"
+_fsv_create_enable_file $fsv_file
+$here/src/truncate $fsv_file
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/788.out b/tests/generic/788.out
new file mode 100644
index 000000000000..11074b71f3eb
--- /dev/null
+++ b/tests/generic/788.out
@@ -0,0 +1,4 @@
+QA output created by 788
+
+# Using truncate(2) on a verity file fails
+truncate: Operation not permitted
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-01-22  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19  6:24 [PATCH] generic: test that truncate(2) on fsverity is blocked Christoph Hellwig
2026-01-21 15:08 ` Zorro Lang
2026-01-22  5:59   ` Christoph Hellwig
2026-01-22  7:23     ` Zorro Lang
2026-01-22  7:25       ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox