FALLOC_FL_INSERT_RANGE grows a file by the length of the range, so it must fail with EFBIG once the new size would exceed RLIMIT_FSIZE, as truncate and extending fallocate do (generic/394, generic/228). XFS refuses such an insert; ext4 checks only s_maxbytes and grows the file past the limit. Start from a 2-block file: inserting one block under a 2-block limit must fail and leave the size unchanged, and the same insert under a 3-block limit must succeed. Suggested-by: Christoph Hellwig Signed-off-by: Ding Feng --- Tested on v7.4-rc5, x86_64 under QEMU: ext4 fails: the insert under the 2-block limit succeeds, size 3 ext4 with "ext4: check RLIMIT_FSIZE in insert range" [1] passes xfs passes, with and without that patch [1] https://lore.kernel.org/all/20261116185810.82581-1-dennylin0707@gmail.com/ tests/generic/810 | 46 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/810.out | 6 ++++++ 2 files changed, 52 insertions(+) create mode 100755 tests/generic/810 create mode 100644 tests/generic/810.out diff --git a/tests/generic/810 b/tests/generic/810 new file mode 100755 index 00000000..25f5ece4 --- /dev/null +++ b/tests/generic/810 @@ -0,0 +1,46 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 Ding Feng. All Rights Reserved. +# +# FS QA Test No. 810 +# +# Check that FALLOC_FL_INSERT_RANGE respects RLIMIT_FSIZE: an insert range +# grows the file by its length, so it must fail with EFBIG when the new size +# exceeds the limit, and leave the file size unchanged. +# +. ./common/preamble +_begin_fstest auto quick insert prealloc + +_fixed_by_fs_commit ext4 xxxxxxxxxxxx \ + "ext4: check RLIMIT_FSIZE in insert range" + +_require_test +_require_xfs_io_command "finsert" + +file=$TEST_DIR/$seq.file + +# Insert range works in whole file blocks, and ulimit -f in 1 KiB units. +unit=$(_get_file_block_size $TEST_DIR) +[ $unit -lt 4096 ] && unit=4096 + +# Run "finsert 0 $unit" on $file under an FSIZE limit of $1 units. SIGXFSZ is +# ignored so that the call fails with EFBIG instead of killing xfs_io. +insert_under_limit() +{ + bash -c "ulimit -f $(($1 * unit / 1024)); trap '' SIGXFSZ; \ + $XFS_IO_PROG -c 'finsert 0 $unit' $file" + echo "size: $(($(stat -c %s $file) / unit)) units" +} + +rm -f $file +$XFS_IO_PROG -f -c "pwrite -S 0x61 0 $((2 * unit))" $file >> $seqres.full + +echo "Insert one unit into a 2-unit file under a 2-unit limit. This should fail." +insert_under_limit 2 + +echo "Insert one unit into a 2-unit file under a 3-unit limit. This should succeed." +insert_under_limit 3 + +# success, all done +status=0 +exit diff --git a/tests/generic/810.out b/tests/generic/810.out new file mode 100644 index 00000000..7542704d --- /dev/null +++ b/tests/generic/810.out @@ -0,0 +1,6 @@ +QA output created by 810 +Insert one unit into a 2-unit file under a 2-unit limit. This should fail. +fallocate: File too large +size: 2 units +Insert one unit into a 2-unit file under a 3-unit limit. This should succeed. +size: 3 units -- 2.55.0