[PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE
From: Ding Feng
Date: Thu Dec 03 2026 - 00:25:03 EST
ext4_insert_range() grows i_size by len but checks the new size only
against s_maxbytes, so an insert can take a file past the caller's
RLIMIT_FSIZE. On the same file, ftruncate() and an extending fallocate()
fail with EFBIG and SIGXFSZ, and XFS refuses the insert.
With a 4096-byte file and RLIMIT_FSIZE 4096, on v7.4-rc5 (x86_64, QEMU):
ext4 FALLOC_FL_INSERT_RANGE(0, 4096) -> 0, size 8192
xfs FALLOC_FL_INSERT_RANGE(0, 4096) -> EFBIG, size 4096
The same gap in the SMB client was fixed as CVE-2026-98127 ("smb/client:
validate new EOF for insert range").
Check the new size with inode_newsize_ok(), which sends SIGXFSZ and
returns -EFBIG when it exceeds RLIMIT_FSIZE.
Fixes: 331573febb6a ("ext4: Add support FALLOC_FL_INSERT_RANGE for fallocate")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ding Feng <dingf3ng@xxxxxxxxx>
---
Reproducer, run as ./insert_range /mnt/ext4/file. With this patch ext4
gives EFBIG and keeps the size at 4096, like XFS; an insert with no
limit still succeeds.
/* A 4096-byte file under RLIMIT_FSIZE 4096: FALLOC_FL_INSERT_RANGE of 4096 bytes at 0. */
#define _GNU_SOURCE
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char **argv)
{
struct rlimit rl = { 4096, RLIM_INFINITY };
char buf[4096];
struct stat st;
int fd;
fd = open(argc > 1 ? argv[1] : "file", O_CREAT | O_RDWR | O_TRUNC, 0644);
memset(buf, 'a', sizeof(buf));
pwrite(fd, buf, sizeof(buf), 0);
signal(SIGXFSZ, SIG_IGN);
setrlimit(RLIMIT_FSIZE, &rl);
if (fallocate(fd, FALLOC_FL_INSERT_RANGE, 0, 4096))
perror("INSERT_RANGE");
fstat(fd, &st);
printf("%s: size %lld\n", argv[1], (long long)st.st_size);
return 0;
}
fs/ext4/extents.c | 4 ++++
1 file changed, 4 insertions(+)
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -5875,6 +5875,10 @@ static int ext4_insert_range(struct file
/* Check whether the maximum file size would be exceeded */
if (len > inode->i_sb->s_maxbytes - inode->i_size)
return -EFBIG;
+ /* The insert grows the file by len, so RLIMIT_FSIZE applies */
+ ret = inode_newsize_ok(inode, inode->i_size + len);
+ if (ret)
+ return ret;
/*
* Persist the pending zeroed EOF block to ensure i_disksize