* [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX
@ 2026-11-19 3:10 Ding Feng
2026-11-19 3:10 ` [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits() Ding Feng
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ding Feng @ 2026-11-19 3:10 UTC (permalink / raw)
To: Christian Brauner, Damien Le Moal
Cc: Ding Feng, Alexander Viro, Jan Kara, Naohiro Aota,
Johannes Thumshirn, linux-fsdevel, linux-kernel
generic_write_check_limits() and its zonefs copy store
rlimit(RLIMIT_FSIZE), an unsigned long, in a loff_t. A soft limit
between 2^63 and RLIM_INFINITY turns negative, and every write then
fails with -EFBIG and SIGXFSZ:
$ bash -c 'ulimit -f 9007199254740992; echo hi > /tmp/f'
File size limit exceeded
Patch 1 fixes the VFS helper (write, pwrite, writev and copy_file_range
paths). Patch 2 applies the same fix to zonefs.
Changes in v2:
- Hold the limit in a u64 instead of an unsigned long. On 32-bit,
"limit <= LLONG_MAX" was always true and clang W=1 warned, as the
kernel test robot reported and Damien pointed out.
- v1 patch 1 was applied to vfs-7.5.misc as bc0dc4379463; v2 patch 1
replaces it.
v1: https://lore.kernel.org/linux-fsdevel/20261117173129.61028-1-dingf3ng@gmail.com/
Tested on v7.4-rc3 (20eef29b7c84), arm64 tinyconfig in QEMU, with a
static test program that sets the soft RLIMIT_FSIZE, writes 2 bytes
and copies 10 bytes with copy_file_range():
soft limit unpatched patched
1024, 2^63-1 ok ok
2^63, 2^63+4096,
2^64-2 EFBIG (both) ok (both)
1 short write, then EFBIG (both kernels)
Built fs/read_write.o and fs/zonefs/file.o with clang 19 and W=1 for
arm (multi_v7_defconfig) and arm64 (defconfig): v1 gives the robot's
warning on arm, v2 gives none. The zonefs change is compile-tested only.
Jun-ichi Takimoto reported this in 2020 [1]; no fix followed. It came up
again while proving pwrite(2) against POSIX with Frama-C/WP.
[1] https://lore.kernel.org/linux-fsdevel/8F9EB913-3AC3-4D89-9DA3-427029F6D211@kba.biglobe.ne.jp/
Ding Feng (2):
fs: ignore RLIMIT_FSIZE above LLONG_MAX in
generic_write_check_limits()
zonefs: ignore RLIMIT_FSIZE above LLONG_MAX in
zonefs_write_check_limits()
fs/read_write.c | 9 +++++----
fs/zonefs/file.c | 9 +++++----
2 files changed, 10 insertions(+), 8 deletions(-)
--
2.55.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits()
2026-11-19 3:10 [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Ding Feng
@ 2026-11-19 3:10 ` Ding Feng
2026-11-19 3:28 ` Ding Feng
2026-11-19 10:01 ` Jan Kara
2026-11-19 3:10 ` [PATCH v2 2/2] zonefs: ignore RLIMIT_FSIZE above LLONG_MAX in zonefs_write_check_limits() Ding Feng
2026-11-19 19:07 ` (subset) [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Christian Brauner
2 siblings, 2 replies; 6+ messages in thread
From: Ding Feng @ 2026-11-19 3:10 UTC (permalink / raw)
To: Christian Brauner, Damien Le Moal
Cc: Ding Feng, Alexander Viro, Jan Kara, Naohiro Aota,
Johannes Thumshirn, linux-fsdevel, linux-kernel,
Jun-ichi Takimoto, stable
generic_write_check_limits() stores rlimit(RLIMIT_FSIZE), an unsigned
long, in a loff_t. A soft limit between 2^63 and RLIM_INFINITY becomes
negative there, so "pos >= limit" holds for every position: each write
through generic_write_checks() or copy_file_range() fails with -EFBIG
and raises SIGXFSZ, although no file position can reach such a limit.
Reproducer (bash counts ulimit -f in 1024-byte blocks, so 2^53 blocks
is 2^63 bytes):
$ bash -c 'ulimit -f 9007199254740991; echo hi > /tmp/f'; echo $?
0
$ bash -c 'ulimit -f 9007199254740992; echo hi > /tmp/f'; echo $?
File size limit exceeded
153
Before commit 9fd91a90cb98 ("vfs: strengthen checking of file range
inputs to generic_remap_checks") the limit was an unsigned long in
generic_write_checks(), and such limits had no effect.
Keep the limit unsigned and apply it only when it is at most LLONG_MAX.
Smaller limits keep the existing loff_t arithmetic, so their behaviour,
including for negative positions, is unchanged.
Fixes: 9fd91a90cb98 ("vfs: strengthen checking of file range inputs to generic_remap_checks")
Reported-by: Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
Closes: https://lore.kernel.org/linux-fsdevel/8F9EB913-3AC3-4D89-9DA3-427029F6D211@kba.biglobe.ne.jp/
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5 Frama-C
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
Notes:
v2: hold the limit in a u64. As an unsigned long, "limit <= LLONG_MAX" is
always true on 32-bit, and clang W=1 warns (kernel test robot, Damien).
v1 was applied to vfs-7.5.misc as bc0dc4379463; this version replaces it.
fs/read_write.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/read_write.c b/fs/read_write.c
index b15522c..9786dfc 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1693,14 +1693,15 @@ int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count)
{
struct inode *inode = file->f_mapping->host;
loff_t max_size = inode->i_sb->s_maxbytes;
- loff_t limit = rlimit(RLIMIT_FSIZE);
+ u64 limit = rlimit(RLIMIT_FSIZE);
- if (limit != RLIM_INFINITY) {
- if (pos >= limit) {
+ /* No file position reaches a limit above LLONG_MAX. */
+ if (limit != RLIM_INFINITY && limit <= LLONG_MAX) {
+ if (pos >= (loff_t)limit) {
send_sig(SIGXFSZ, current, 0);
return -EFBIG;
}
- *count = min(*count, limit - pos);
+ *count = min(*count, (loff_t)limit - pos);
}
if (!(file->f_flags & O_LARGEFILE))
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] zonefs: ignore RLIMIT_FSIZE above LLONG_MAX in zonefs_write_check_limits()
2026-11-19 3:10 [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Ding Feng
2026-11-19 3:10 ` [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits() Ding Feng
@ 2026-11-19 3:10 ` Ding Feng
2026-11-19 19:07 ` (subset) [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Christian Brauner
2 siblings, 0 replies; 6+ messages in thread
From: Ding Feng @ 2026-11-19 3:10 UTC (permalink / raw)
To: Christian Brauner, Damien Le Moal
Cc: Ding Feng, Alexander Viro, Jan Kara, Naohiro Aota,
Johannes Thumshirn, linux-fsdevel, linux-kernel, stable
zonefs_write_check_limits() follows generic_write_check_limits() and
has the same problem: it stores rlimit(RLIMIT_FSIZE), an unsigned long,
in a loff_t, so a soft limit between 2^63 and RLIM_INFINITY is negative
and every write fails with -EFBIG and raises SIGXFSZ.
Keep the limit unsigned and apply it only when it is at most LLONG_MAX,
as the generic helper now does.
Fixes: ebfd68cd0c1e ("zonefs: Fix O_APPEND async write handling")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5 Frama-C
Signed-off-by: Ding Feng <dingf3ng@gmail.com>
---
Notes:
v2: hold the limit in a u64, as in patch 1.
fs/zonefs/file.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/zonefs/file.c b/fs/zonefs/file.c
index 319d950..c9293e3 100644
--- a/fs/zonefs/file.c
+++ b/fs/zonefs/file.c
@@ -399,15 +399,16 @@ static loff_t zonefs_write_check_limits(struct file *file, loff_t pos,
{
struct inode *inode = file_inode(file);
struct zonefs_zone *z = zonefs_inode_zone(inode);
- loff_t limit = rlimit(RLIMIT_FSIZE);
+ u64 limit = rlimit(RLIMIT_FSIZE);
loff_t max_size = z->z_capacity;
- if (limit != RLIM_INFINITY) {
- if (pos >= limit) {
+ /* No file position reaches a limit above LLONG_MAX. */
+ if (limit != RLIM_INFINITY && limit <= LLONG_MAX) {
+ if (pos >= (loff_t)limit) {
send_sig(SIGXFSZ, current, 0);
return -EFBIG;
}
- count = min(count, limit - pos);
+ count = min(count, (loff_t)limit - pos);
}
if (!(file->f_flags & O_LARGEFILE))
--
2.55.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits()
2026-11-19 3:10 ` [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits() Ding Feng
@ 2026-11-19 3:28 ` Ding Feng
2026-11-19 10:01 ` Jan Kara
1 sibling, 0 replies; 6+ messages in thread
From: Ding Feng @ 2026-11-19 3:28 UTC (permalink / raw)
To: Christian Brauner; +Cc: Jan Kara, Damien Le Moal, linux-fsdevel, linux-kernel
Jan reviewed v1 of this patch after I had prepared v2:
https://lore.kernel.org/linux-fsdevel/hwwtflqzbga65oxvo7bw44xuhpbqseyfww62kyzko5az4gdnxy@4wxsl465nvp5/
The only change in v2 is the type of the limit (u64 instead of
unsigned long).
Thanks,
Ding Feng
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits()
2026-11-19 3:10 ` [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits() Ding Feng
2026-11-19 3:28 ` Ding Feng
@ 2026-11-19 10:01 ` Jan Kara
1 sibling, 0 replies; 6+ messages in thread
From: Jan Kara @ 2026-11-19 10:01 UTC (permalink / raw)
To: Ding Feng
Cc: Christian Brauner, Damien Le Moal, Alexander Viro, Jan Kara,
Naohiro Aota, Johannes Thumshirn, linux-fsdevel, linux-kernel,
Jun-ichi Takimoto, stable
On Thu 19-11-26 11:10:25, Ding Feng wrote:
> generic_write_check_limits() stores rlimit(RLIMIT_FSIZE), an unsigned
> long, in a loff_t. A soft limit between 2^63 and RLIM_INFINITY becomes
> negative there, so "pos >= limit" holds for every position: each write
> through generic_write_checks() or copy_file_range() fails with -EFBIG
> and raises SIGXFSZ, although no file position can reach such a limit.
>
> Reproducer (bash counts ulimit -f in 1024-byte blocks, so 2^53 blocks
> is 2^63 bytes):
>
> $ bash -c 'ulimit -f 9007199254740991; echo hi > /tmp/f'; echo $?
> 0
> $ bash -c 'ulimit -f 9007199254740992; echo hi > /tmp/f'; echo $?
> File size limit exceeded
> 153
>
> Before commit 9fd91a90cb98 ("vfs: strengthen checking of file range
> inputs to generic_remap_checks") the limit was an unsigned long in
> generic_write_checks(), and such limits had no effect.
>
> Keep the limit unsigned and apply it only when it is at most LLONG_MAX.
> Smaller limits keep the existing loff_t arithmetic, so their behaviour,
> including for negative positions, is unchanged.
>
> Fixes: 9fd91a90cb98 ("vfs: strengthen checking of file range inputs to generic_remap_checks")
> Reported-by: Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
> Closes: https://lore.kernel.org/linux-fsdevel/8F9EB913-3AC3-4D89-9DA3-427029F6D211@kba.biglobe.ne.jp/
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5-5 Frama-C
> Signed-off-by: Ding Feng <dingf3ng@gmail.com>
Still looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
>
> Notes:
> v2: hold the limit in a u64. As an unsigned long, "limit <= LLONG_MAX" is
> always true on 32-bit, and clang W=1 warns (kernel test robot, Damien).
> v1 was applied to vfs-7.5.misc as bc0dc4379463; this version replaces it.
>
> fs/read_write.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/fs/read_write.c b/fs/read_write.c
> index b15522c..9786dfc 100644
> --- a/fs/read_write.c
> +++ b/fs/read_write.c
> @@ -1693,14 +1693,15 @@ int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count)
> {
> struct inode *inode = file->f_mapping->host;
> loff_t max_size = inode->i_sb->s_maxbytes;
> - loff_t limit = rlimit(RLIMIT_FSIZE);
> + u64 limit = rlimit(RLIMIT_FSIZE);
>
> - if (limit != RLIM_INFINITY) {
> - if (pos >= limit) {
> + /* No file position reaches a limit above LLONG_MAX. */
> + if (limit != RLIM_INFINITY && limit <= LLONG_MAX) {
> + if (pos >= (loff_t)limit) {
> send_sig(SIGXFSZ, current, 0);
> return -EFBIG;
> }
> - *count = min(*count, limit - pos);
> + *count = min(*count, (loff_t)limit - pos);
> }
>
> if (!(file->f_flags & O_LARGEFILE))
> --
> 2.55.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: (subset) [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX
2026-11-19 3:10 [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Ding Feng
2026-11-19 3:10 ` [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits() Ding Feng
2026-11-19 3:10 ` [PATCH v2 2/2] zonefs: ignore RLIMIT_FSIZE above LLONG_MAX in zonefs_write_check_limits() Ding Feng
@ 2026-11-19 19:07 ` Christian Brauner
2 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2026-11-19 19:07 UTC (permalink / raw)
To: Damien Le Moal, Ding Feng
Cc: Alexander Viro, Jan Kara, Naohiro Aota, Johannes Thumshirn,
linux-fsdevel, linux-kernel
On Thu, 19 Nov 2026 11:10:24 +0800, Ding Feng wrote:
> generic_write_check_limits() and its zonefs copy store
> rlimit(RLIMIT_FSIZE), an unsigned long, in a loff_t. A soft limit
> between 2^63 and RLIM_INFINITY turns negative, and every write then
> fails with -EFBIG and SIGXFSZ:
>
> $ bash -c 'ulimit -f 9007199254740992; echo hi > /tmp/f'
> File size limit exceeded
>
> [...]
Applied to the vfs-7.5.misc branch of the vfs/vfs.git tree.
Patches in the vfs-7.5.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs-7.5.misc
[1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits()
https://git.kernel.org/vfs/vfs/c/3f6eaa87ab42
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-19 19:07 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 3:10 [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Ding Feng
2026-11-19 3:10 ` [PATCH v2 1/2] fs: ignore RLIMIT_FSIZE above LLONG_MAX in generic_write_check_limits() Ding Feng
2026-11-19 3:28 ` Ding Feng
2026-11-19 10:01 ` Jan Kara
2026-11-19 3:10 ` [PATCH v2 2/2] zonefs: ignore RLIMIT_FSIZE above LLONG_MAX in zonefs_write_check_limits() Ding Feng
2026-11-19 19:07 ` (subset) [PATCH v2 0/2] fs, zonefs: ignore RLIMIT_FSIZE values above LLONG_MAX Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox