* [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE
@ 2026-12-03 5:24 Ding Feng
2026-12-03 5:31 ` sashiko-bot
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ding Feng @ 2026-12-03 5:24 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger
Cc: Ding Feng, Jan Kara, Baokun Li, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, linux-ext4, linux-kernel
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@vger.kernel.org
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
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
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE
2026-12-03 5:24 [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE Ding Feng
@ 2026-12-03 5:31 ` sashiko-bot
2026-12-03 9:35 ` Christoph Hellwig
2026-12-03 10:21 ` Jan Kara
2 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-03 5:31 UTC (permalink / raw)
To: Ding Feng; +Cc: linux-ext4, tytso
> 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@vger.kernel.org
> Signed-off-by: Ding Feng <dingf3ng@gmail.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203052448.53714-1-dingf3ng@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE
2026-12-03 5:24 [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE Ding Feng
2026-12-03 5:31 ` sashiko-bot
@ 2026-12-03 9:35 ` Christoph Hellwig
2026-12-03 10:21 ` Jan Kara
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2026-12-03 9:35 UTC (permalink / raw)
To: Ding Feng
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
Ojaswin Mujoo, Ritesh Harjani (IBM), Zhang Yi, linux-ext4,
linux-kernel
On Thu, Dec 03, 2026 at 01:24:48PM +0800, Ding Feng wrote:
> 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.
Can you add this to xfstests?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE
2026-12-03 5:24 [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE Ding Feng
2026-12-03 5:31 ` sashiko-bot
2026-12-03 9:35 ` Christoph Hellwig
@ 2026-12-03 10:21 ` Jan Kara
2 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2026-12-03 10:21 UTC (permalink / raw)
To: Ding Feng
Cc: Theodore Ts'o, Andreas Dilger, Jan Kara, Baokun Li,
Ojaswin Mujoo, Ritesh Harjani (IBM), Zhang Yi, linux-ext4,
linux-kernel
On Thu 03-12-26 13:24:48, Ding Feng wrote:
> 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@vger.kernel.org
> Signed-off-by: Ding Feng <dingf3ng@gmail.com>
Fix already posted and reviewed here [1].
Honza
[1] https://lore.kernel.org/all/20261116185810.82581-1-dennylin0707@gmail.com/
> ---
> 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
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-03 10:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 5:24 [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE Ding Feng
2026-12-03 5:31 ` sashiko-bot
2026-12-03 9:35 ` Christoph Hellwig
2026-12-03 10:21 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox