Linux EXT4 FS development
 help / color / mirror / Atom feed
From: Ding Feng <dingf3ng@gmail.com>
To: "Theodore Ts'o" <tytso@mit.edu>,
	Andreas Dilger <adilger.kernel@dilger.ca>
Cc: Ding Feng <dingf3ng@gmail.com>, Jan Kara <jack@suse.cz>,
	Baokun Li <libaokun@linux.alibaba.com>,
	Ojaswin Mujoo <ojaswin@linux.ibm.com>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Zhang Yi <yi.zhang@huawei.com>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE
Date: Thu,  3 Dec 2026 13:24:48 +0800	[thread overview]
Message-ID: <20261203052448.53714-1-dingf3ng@gmail.com> (raw)

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

             reply	other threads:[~2026-12-03  5:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  5:24 Ding Feng [this message]
2026-12-03  5:31 ` [PATCH] ext4: apply RLIMIT_FSIZE to FALLOC_FL_INSERT_RANGE sashiko-bot
2026-12-03  9:35 ` Christoph Hellwig
2026-12-03 10:21 ` Jan Kara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203052448.53714-1-dingf3ng@gmail.com \
    --to=dingf3ng@gmail.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=libaokun@linux.alibaba.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojaswin@linux.ibm.com \
    --cc=ritesh.list@gmail.com \
    --cc=tytso@mit.edu \
    --cc=yi.zhang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox