* [PATCH] ext4: do not report interrupted truncate as filesystem error
@ 2026-11-29 4:37 Christopher Lusk via B4 Relay
2026-11-29 4:54 ` sashiko-bot
0 siblings, 1 reply; 4+ messages in thread
From: Christopher Lusk via B4 Relay @ 2026-11-29 4:37 UTC (permalink / raw)
To: Theodore Ts'o
Cc: Andreas Dilger, Baokun Li, Jan Kara, Ojaswin Mujoo,
Ritesh Harjani (IBM), Zhang Yi, linux-ext4, Christopher Lusk
From: Christopher Lusk <clusk@northecho.dev>
A fatal signal can interrupt the buffered iomap truncate-up path with
-EINTR. ext4_setattr() then routes that transient error through
ext4_std_error(), which sets the filesystem error flag and can remount
a healthy filesystem read-only with errors=remount-ro.
Ignore the interrupted error only while a fatal signal is pending, so
real -EINTR errors are still reported.
Found by LLM-driven ext4 concurrency testing.
Fixes: 68738d77ce86 ("ext4: implement partial block zero range path using iomap")
Signed-off-by: Christopher Lusk <clusk@northecho.dev>
---
Tested in a 2-CPU network-less KVM lab on v7.4-rc4, both KASAN and
non-KASAN. The stock kernel reproduced ext4_setattr:7161 with error 4
and an emergency read-only remount in 3/3 runs; the patched kernel was
clean in 3/3 runs. e2fsck was not rerun after the fixed validation, and
no other buffered_iomap configurations were tested.
Drafted with LLM assistance; I reviewed, tested and edited it.
---
fs/ext4/super.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 880f664d6c04..112dfae7a738 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -43,6 +43,7 @@
#include <linux/iversion.h>
#include <linux/unicode.h>
#include <linux/part_stat.h>
+#include <linux/sched/signal.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include <linux/fsnotify.h>
@@ -1022,6 +1023,9 @@ void __ext4_std_error(struct super_block *sb, const char *function,
if (errno == -EROFS && journal_current_handle() == NULL && sb_rdonly(sb))
return;
+ if (errno == -EINTR && fatal_signal_pending(current))
+ return;
+
if (ext4_error_ratelimit(sb)) {
errstr = ext4_decode_error(sb, errno, nbuf);
printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
---
base-commit: aceadbccd428fb8e6593b27a3091d961f80225d1
change-id: 20261128-b4-ext4-eintr-d876d9f48256
Best regards,
--
Christopher Lusk <clusk@northecho.dev>
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: do not report interrupted truncate as filesystem error
2026-11-29 4:37 [PATCH] ext4: do not report interrupted truncate as filesystem error Christopher Lusk via B4 Relay
@ 2026-11-29 4:54 ` sashiko-bot
2026-11-29 13:48 ` Christopher Lusk
0 siblings, 1 reply; 4+ messages in thread
From: sashiko-bot @ 2026-11-29 4:54 UTC (permalink / raw)
To: Christopher Lusk; +Cc: linux-ext4, tytso
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] ext4: incomplete truncate-down and orphan corruption in
__ext4_std_error()
- [High] ext4: infinite loop in ext4_orphan_cleanup() on -EINTR in
__ext4_std_error()
--
commit 58e5e8252974ec4aca8d6342e1b1e890589567bb
Author: Christopher Lusk <clusk@northecho.dev>
ext4: do not report interrupted truncate as filesystem error
This commit ignores -EINTR in __ext4_std_error() when a fatal signal is
pending on current.
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 880f664d6c04b..112dfae7a7386 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
[ ... ]
> @@ -1022,6 +1023,9 @@ void __ext4_std_error(struct super_block *sb, const char *function,
> if (errno == -EROFS && journal_current_handle() == NULL && sb_rdonly(sb))
> return;
>
> + if (errno == -EINTR && fatal_signal_pending(current))
> + return;
[Severity: High]
Can ignoring -EINTR here leave a file half-truncated and leak its on-disk
orphan entry when a shrinking truncate is interrupted?
Unlike ext4_truncate_up(), ext4_truncate_down() first commits a transaction
that adds the inode to the on-disk orphan list and shrinks i_size and
i_disksize, and only then calls ext4_truncate(). On buffered_iomap, when
the new size is not block-aligned, ext4_truncate() calls
ext4_block_zero_eof() -> ... -> iomap_write_begin(), which returns -EINTR
if a fatal signal is pending, aborting before freeing blocks past EOF or
removing the on-disk orphan entry:
fs/ext4/inode.c:ext4_truncate_down() {
...
if (ext4_handle_valid(handle)) {
ret = ext4_orphan_add(handle, inode);
*orphan = 1;
...
i_size_write(inode, newsize);
__ext4_set_i_disksize(inode, newsize);
up_write(&EXT4_I(inode)->i_data_sem);
ret = ext4_mark_inode_dirty(handle, inode);
ext4_journal_stop(handle);
...
truncate_pagecache(inode, newsize);
return ext4_truncate(inode);
}
ext4_setattr() then runs ext4_orphan_del(NULL, inode), which clears only
the in-memory orphan state and relies on ext4_std_error() to mark the
filesystem in error. Returning early from __ext4_std_error() leaves the
filesystem read-write with blocks still allocated past i_disksize, an
unzeroed tail block, and a leaked on-disk orphan slot (causing a later
read-only remount or freeze to fail with EFSCORRUPTED in
ext4_mark_recovery_complete()).
[Severity: High]
Could returning early here also cause an infinite loop in
ext4_orphan_cleanup() if the mount or remount task has a fatal signal
pending?
When recovering a linked orphan (inode->i_nlink > 0) with a
non-block-aligned i_size on the superblock orphan list,
ext4_process_orphan() calls ext4_truncate(), which fails with -EINTR in
ext4_block_zero_eof() before updating es->s_last_orphan:
fs/ext4/orphan.c:ext4_process_orphan() {
...
ret = ext4_truncate(inode);
if (ret) {
ext4_orphan_del(NULL, inode);
ext4_std_error(inode->i_sb, ret);
}
...
}
ext4_orphan_del(NULL, inode) only unlinks the in-memory list entry, and
the while (es->s_last_orphan) loop in ext4_orphan_cleanup() relies on
EXT4_ERROR_FS being set by ext4_std_error() to break out. Without
EXT4_ERROR_FS, es->s_last_orphan never advances and the loop spins
forever on the same inode.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-ext4-eintr-v1-1-dc38ab39d1e7@northecho.dev?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: do not report interrupted truncate as filesystem error
2026-11-29 4:54 ` sashiko-bot
@ 2026-11-29 13:48 ` Christopher Lusk
2026-11-29 14:37 ` Christopher Lusk
0 siblings, 1 reply; 4+ messages in thread
From: Christopher Lusk @ 2026-11-29 13:48 UTC (permalink / raw)
To: sashiko-reviews
Cc: linux-ext4, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang
Subject: Re: [PATCH] ext4: do not report interrupted truncate as
filesystem error
On Sun, Nov 29, 2026 at 04:54 UTC, sashiko-bot wrote:
> - [High] ext4: incomplete truncate-down and orphan corruption in
> __ext4_std_error()
> - [High] ext4: infinite loop in ext4_orphan_cleanup() on -EINTR in
> __ext4_std_error()
Both points are correct, so please don't apply this patch.
Suppressing the error in __ext4_std_error() hides it from callers that
rely on EXT4_ERROR_FS. ext4_orphan_cleanup() can then loop forever, and
an interrupted truncate-down leaves the filesystem writable with its
orphan entry leaked.
The test claim in the notes was also too strong. The validator stopped
after the first kill without confirming that iomap_write_begin()
returned -EINTR, so "clean in 3/3 runs" does not show the path was
exercised.
v2 will handle the error at the caller. Truncate-up fails before
anything is committed, so ext4_setattr() can simply return -EINTR
there. Truncate-down zeroes the tail only after the new size and the
orphan entry are committed. I think the zeroing should move before
that point, as ext4_truncate_up() already does. Zhang Yi, does that
match what you intended for the iomap path, or would you prefer a
different approach?
Thanks,
Christopher
On Sat, Nov 28, 2026 at 11:54 PM <sashiko-bot@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [High] ext4: incomplete truncate-down and orphan corruption in
> __ext4_std_error()
> - [High] ext4: infinite loop in ext4_orphan_cleanup() on -EINTR in
> __ext4_std_error()
> --
>
> commit 58e5e8252974ec4aca8d6342e1b1e890589567bb
> Author: Christopher Lusk <clusk@northecho.dev>
>
> ext4: do not report interrupted truncate as filesystem error
>
> This commit ignores -EINTR in __ext4_std_error() when a fatal signal is
> pending on current.
>
> > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > index 880f664d6c04b..112dfae7a7386 100644
> > --- a/fs/ext4/super.c
> > +++ b/fs/ext4/super.c
>
> [ ... ]
>
> > @@ -1022,6 +1023,9 @@ void __ext4_std_error(struct super_block *sb, const char *function,
> > if (errno == -EROFS && journal_current_handle() == NULL && sb_rdonly(sb))
> > return;
> >
> > + if (errno == -EINTR && fatal_signal_pending(current))
> > + return;
>
> [Severity: High]
> Can ignoring -EINTR here leave a file half-truncated and leak its on-disk
> orphan entry when a shrinking truncate is interrupted?
>
> Unlike ext4_truncate_up(), ext4_truncate_down() first commits a transaction
> that adds the inode to the on-disk orphan list and shrinks i_size and
> i_disksize, and only then calls ext4_truncate(). On buffered_iomap, when
> the new size is not block-aligned, ext4_truncate() calls
> ext4_block_zero_eof() -> ... -> iomap_write_begin(), which returns -EINTR
> if a fatal signal is pending, aborting before freeing blocks past EOF or
> removing the on-disk orphan entry:
>
> fs/ext4/inode.c:ext4_truncate_down() {
> ...
> if (ext4_handle_valid(handle)) {
> ret = ext4_orphan_add(handle, inode);
> *orphan = 1;
> ...
> i_size_write(inode, newsize);
> __ext4_set_i_disksize(inode, newsize);
> up_write(&EXT4_I(inode)->i_data_sem);
>
> ret = ext4_mark_inode_dirty(handle, inode);
> ext4_journal_stop(handle);
> ...
> truncate_pagecache(inode, newsize);
> return ext4_truncate(inode);
> }
>
> ext4_setattr() then runs ext4_orphan_del(NULL, inode), which clears only
> the in-memory orphan state and relies on ext4_std_error() to mark the
> filesystem in error. Returning early from __ext4_std_error() leaves the
> filesystem read-write with blocks still allocated past i_disksize, an
> unzeroed tail block, and a leaked on-disk orphan slot (causing a later
> read-only remount or freeze to fail with EFSCORRUPTED in
> ext4_mark_recovery_complete()).
>
> [Severity: High]
> Could returning early here also cause an infinite loop in
> ext4_orphan_cleanup() if the mount or remount task has a fatal signal
> pending?
>
> When recovering a linked orphan (inode->i_nlink > 0) with a
> non-block-aligned i_size on the superblock orphan list,
> ext4_process_orphan() calls ext4_truncate(), which fails with -EINTR in
> ext4_block_zero_eof() before updating es->s_last_orphan:
>
> fs/ext4/orphan.c:ext4_process_orphan() {
> ...
> ret = ext4_truncate(inode);
> if (ret) {
> ext4_orphan_del(NULL, inode);
> ext4_std_error(inode->i_sb, ret);
> }
> ...
> }
>
> ext4_orphan_del(NULL, inode) only unlinks the in-memory list entry, and
> the while (es->s_last_orphan) loop in ext4_orphan_cleanup() relies on
> EXT4_ERROR_FS being set by ext4_std_error() to break out. Without
> EXT4_ERROR_FS, es->s_last_orphan never advances and the loop spins
> forever on the same inode.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-ext4-eintr-v1-1-dc38ab39d1e7@northecho.dev?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: do not report interrupted truncate as filesystem error
2026-11-29 13:48 ` Christopher Lusk
@ 2026-11-29 14:37 ` Christopher Lusk
0 siblings, 0 replies; 4+ messages in thread
From: Christopher Lusk @ 2026-11-29 14:37 UTC (permalink / raw)
To: sashiko-reviews
Cc: linux-ext4, tytso, adilger.kernel, libaokun, jack, ojaswin,
ritesh.list, yi.zhang
On Sun, Nov 29, 2026 at 8:48 AM Christopher Lusk wrote:
> I think the zeroing should move before that point, as
> ext4_truncate_up() already does. Zhang Yi, does that match what you
> intended for the iomap path, or would you prefer a different approach?
Some lab data on the two options. Each result is three runs in which a
kernel probe confirmed that ext4_block_zero_eof() returned -EINTR. Every
hit was a truncate-down, not the truncate-up that v1 described. The base
was the ext4 dev tree at aceadbccd428, mounted with buffered_iomap.
Returning -EINTR from ext4_setattr() without ext4_std_error(), leaving
the orphan record for the next mount:
- orphan_file: a later remount,ro logs "Orphan file not empty on
read-only fs"; deleting the file and remounting logs "bad orphan
inode". Both leave the filesystem read-only.
- ^orphan_file: remount,rw after a remount,ro is refused ("unprocessed
orphan inode list"); deleting the file and remounting fails the mount
with "bad orphan inode", although e2fsck -fn reports the filesystem
clean.
Zeroing the new EOF block in ext4_truncate_down() before the orphan
record and the new size are committed, and skipping the second zeroing
in ext4_truncate() for that caller: the interrupted shrink leaves the
file unchanged, with no errors, clean remounts and a clean e2fsck, for
both orphan formats.
That change also affects the non-iomap path, so I'll run xfstests on it
before sending anything. I can post it as an RFC if the direction looks
right.
Thanks,
Christopher
On Sun, Nov 29, 2026 at 8:48 AM Christopher Lusk <clusk@northecho.dev> wrote:
>
> Subject: Re: [PATCH] ext4: do not report interrupted truncate as
> filesystem error
>
> On Sun, Nov 29, 2026 at 04:54 UTC, sashiko-bot wrote:
> > - [High] ext4: incomplete truncate-down and orphan corruption in
> > __ext4_std_error()
> > - [High] ext4: infinite loop in ext4_orphan_cleanup() on -EINTR in
> > __ext4_std_error()
>
> Both points are correct, so please don't apply this patch.
>
> Suppressing the error in __ext4_std_error() hides it from callers that
> rely on EXT4_ERROR_FS. ext4_orphan_cleanup() can then loop forever, and
> an interrupted truncate-down leaves the filesystem writable with its
> orphan entry leaked.
>
> The test claim in the notes was also too strong. The validator stopped
> after the first kill without confirming that iomap_write_begin()
> returned -EINTR, so "clean in 3/3 runs" does not show the path was
> exercised.
>
> v2 will handle the error at the caller. Truncate-up fails before
> anything is committed, so ext4_setattr() can simply return -EINTR
> there. Truncate-down zeroes the tail only after the new size and the
> orphan entry are committed. I think the zeroing should move before
> that point, as ext4_truncate_up() already does. Zhang Yi, does that
> match what you intended for the iomap path, or would you prefer a
> different approach?
>
> Thanks,
> Christopher
>
> On Sat, Nov 28, 2026 at 11:54 PM <sashiko-bot@kernel.org> wrote:
> >
> > Thank you for your contribution! Sashiko AI review found 2 potential
> > issues to consider:
> > - [High] ext4: incomplete truncate-down and orphan corruption in
> > __ext4_std_error()
> > - [High] ext4: infinite loop in ext4_orphan_cleanup() on -EINTR in
> > __ext4_std_error()
> > --
> >
> > commit 58e5e8252974ec4aca8d6342e1b1e890589567bb
> > Author: Christopher Lusk <clusk@northecho.dev>
> >
> > ext4: do not report interrupted truncate as filesystem error
> >
> > This commit ignores -EINTR in __ext4_std_error() when a fatal signal is
> > pending on current.
> >
> > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > > index 880f664d6c04b..112dfae7a7386 100644
> > > --- a/fs/ext4/super.c
> > > +++ b/fs/ext4/super.c
> >
> > [ ... ]
> >
> > > @@ -1022,6 +1023,9 @@ void __ext4_std_error(struct super_block *sb, const char *function,
> > > if (errno == -EROFS && journal_current_handle() == NULL && sb_rdonly(sb))
> > > return;
> > >
> > > + if (errno == -EINTR && fatal_signal_pending(current))
> > > + return;
> >
> > [Severity: High]
> > Can ignoring -EINTR here leave a file half-truncated and leak its on-disk
> > orphan entry when a shrinking truncate is interrupted?
> >
> > Unlike ext4_truncate_up(), ext4_truncate_down() first commits a transaction
> > that adds the inode to the on-disk orphan list and shrinks i_size and
> > i_disksize, and only then calls ext4_truncate(). On buffered_iomap, when
> > the new size is not block-aligned, ext4_truncate() calls
> > ext4_block_zero_eof() -> ... -> iomap_write_begin(), which returns -EINTR
> > if a fatal signal is pending, aborting before freeing blocks past EOF or
> > removing the on-disk orphan entry:
> >
> > fs/ext4/inode.c:ext4_truncate_down() {
> > ...
> > if (ext4_handle_valid(handle)) {
> > ret = ext4_orphan_add(handle, inode);
> > *orphan = 1;
> > ...
> > i_size_write(inode, newsize);
> > __ext4_set_i_disksize(inode, newsize);
> > up_write(&EXT4_I(inode)->i_data_sem);
> >
> > ret = ext4_mark_inode_dirty(handle, inode);
> > ext4_journal_stop(handle);
> > ...
> > truncate_pagecache(inode, newsize);
> > return ext4_truncate(inode);
> > }
> >
> > ext4_setattr() then runs ext4_orphan_del(NULL, inode), which clears only
> > the in-memory orphan state and relies on ext4_std_error() to mark the
> > filesystem in error. Returning early from __ext4_std_error() leaves the
> > filesystem read-write with blocks still allocated past i_disksize, an
> > unzeroed tail block, and a leaked on-disk orphan slot (causing a later
> > read-only remount or freeze to fail with EFSCORRUPTED in
> > ext4_mark_recovery_complete()).
> >
> > [Severity: High]
> > Could returning early here also cause an infinite loop in
> > ext4_orphan_cleanup() if the mount or remount task has a fatal signal
> > pending?
> >
> > When recovering a linked orphan (inode->i_nlink > 0) with a
> > non-block-aligned i_size on the superblock orphan list,
> > ext4_process_orphan() calls ext4_truncate(), which fails with -EINTR in
> > ext4_block_zero_eof() before updating es->s_last_orphan:
> >
> > fs/ext4/orphan.c:ext4_process_orphan() {
> > ...
> > ret = ext4_truncate(inode);
> > if (ret) {
> > ext4_orphan_del(NULL, inode);
> > ext4_std_error(inode->i_sb, ret);
> > }
> > ...
> > }
> >
> > ext4_orphan_del(NULL, inode) only unlinks the in-memory list entry, and
> > the while (es->s_last_orphan) loop in ext4_orphan_cleanup() relies on
> > EXT4_ERROR_FS being set by ext4_std_error() to break out. Without
> > EXT4_ERROR_FS, es->s_last_orphan never advances and the loop spins
> > forever on the same inode.
> >
> > --
> > Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-ext4-eintr-v1-1-dc38ab39d1e7@northecho.dev?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-29 14:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 4:37 [PATCH] ext4: do not report interrupted truncate as filesystem error Christopher Lusk via B4 Relay
2026-11-29 4:54 ` sashiko-bot
2026-11-29 13:48 ` Christopher Lusk
2026-11-29 14:37 ` Christopher Lusk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox