* [PATCH] ext4: reserve inode write access before unlinking entry
@ 2026-10-27 10:53 Alan
2026-10-27 11:05 ` sashiko-bot
2026-11-16 7:35 ` Alan
0 siblings, 2 replies; 6+ messages in thread
From: Alan @ 2026-10-27 10:53 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: linux-ext4, Alan, stable
__ext4_unlink() removes the directory entry and dirties the parent inode
before it updates the target inode's link count. If the inode write access
operation fails after the directory entry has been removed, unlink returns
without decrementing the target inode's link count. With errors=continue,
the directory update can still be committed.
Reserve write access to the parent and target inode-table buffers before
removing the directory entry. This makes inode-location and journal-access
errors fail before the namespace changes. Keep the existing namespace and
link-count update order, and release the inode-location references on all
exits. Fast-commit replay can skip the parent update when the directory
entry no longer matches the target inode, so reserve only the target inode
in that case.
The source-derived fault injector reproduced this window by returning EIO
from the real journal write-access boundary in ext4_reserve_inode_write().
Before this change, after a normal unmount, e2fsck reported inode 13 as
unattached, debugfs showed Links: 1, and the parent directory no longer
contained the file. With this change, the same error is returned before the
directory entry is changed; the file remains present with Links: 1 and
e2fsck -fn passes.
The failure injection and the repaired run were performed on Linux 6.12.1
with errors=continue and an ordinary sync/unmount; no forced-shutdown ioctl
was used. The repaired change also builds in the current mainline tree with
make O=/tmp/linux-mainline-d135ab-build ARCH=x86 W=1 -j8 fs/ext4/namei.o.
Fixes: 4209ae12b122 ("ext4: handle ext4_mark_inode_dirty errors")
Cc: stable@vger.kernel.org
Signed-off-by: Alan <3164729207@qq.com>
---
fs/ext4/namei.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 354fc2d22df1a..312ff0b682123 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3233,6 +3233,7 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
int retval = -ENOENT;
struct buffer_head *bh;
struct ext4_dir_entry_2 *de = NULL;
+ struct ext4_iloc dir_iloc, inode_iloc;
handle_t *handle;
int skip_remove_dentry = 0;
@@ -3269,6 +3270,22 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
if (IS_DIRSYNC(dir))
ext4_handle_sync(handle);
+ /*
+ * Get the inode-table buffers and journal write access before removing
+ * the directory entry. Otherwise, an error while updating either inode
+ * can leave the name removed but the link count unchanged.
+ */
+ dir_iloc.bh = NULL;
+ inode_iloc.bh = NULL;
+ if (!skip_remove_dentry) {
+ retval = ext4_reserve_inode_write(handle, dir, &dir_iloc);
+ if (retval)
+ goto out_handle;
+ }
+ retval = ext4_reserve_inode_write(handle, inode, &inode_iloc);
+ if (retval)
+ goto out_handle;
+
if (!skip_remove_dentry) {
retval = ext4_delete_entry(handle, dir, de, bh);
if (retval)
@@ -3293,6 +3310,10 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
if (dentry && !retval)
ext4_fc_track_unlink(handle, dentry);
out_handle:
+ if (dir_iloc.bh)
+ brelse(dir_iloc.bh);
+ if (inode_iloc.bh)
+ brelse(inode_iloc.bh);
ext4_journal_stop(handle);
out_bh:
brelse(bh);
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: reserve inode write access before unlinking entry
2026-10-27 10:53 [PATCH] ext4: reserve inode write access before unlinking entry Alan
@ 2026-10-27 11:05 ` sashiko-bot
2026-11-16 7:35 ` Alan
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-10-27 11:05 UTC (permalink / raw)
To: Alan; +Cc: linux-ext4, tytso
> __ext4_unlink() removes the directory entry and dirties the parent inode
> before it updates the target inode's link count. If the inode write access
> operation fails after the directory entry has been removed, unlink returns
> without decrementing the target inode's link count. With errors=continue,
> the directory update can still be committed.
>
> Reserve write access to the parent and target inode-table buffers before
> removing the directory entry. This makes inode-location and journal-access
> errors fail before the namespace changes. Keep the existing namespace and
> link-count update order, and release the inode-location references on all
> exits. Fast-commit replay can skip the parent update when the directory
> entry no longer matches the target inode, so reserve only the target inode
> in that case.
>
> The source-derived fault injector reproduced this window by returning EIO
> from the real journal write-access boundary in ext4_reserve_inode_write().
> Before this change, after a normal unmount, e2fsck reported inode 13 as
> unattached, debugfs showed Links: 1, and the parent directory no longer
> contained the file. With this change, the same error is returned before the
> directory entry is changed; the file remains present with Links: 1 and
> e2fsck -fn passes.
>
> The failure injection and the repaired run were performed on Linux 6.12.1
> with errors=continue and an ordinary sync/unmount; no forced-shutdown ioctl
> was used. The repaired change also builds in the current mainline tree with
> make O=/tmp/linux-mainline-d135ab-build ARCH=x86 W=1 -j8 fs/ext4/namei.o.
>
> Fixes: 4209ae12b122 ("ext4: handle ext4_mark_inode_dirty errors")
> Cc: stable@vger.kernel.org
> Signed-off-by: Alan <3164729207@qq.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_D60E766CE07D3A1847B81DE9BC37B4466908@qq.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: reserve inode write access before unlinking entry
2026-10-27 10:53 [PATCH] ext4: reserve inode write access before unlinking entry Alan
2026-10-27 11:05 ` sashiko-bot
@ 2026-11-16 7:35 ` Alan
2026-11-16 12:48 ` Jan Kara
1 sibling, 1 reply; 6+ messages in thread
From: Alan @ 2026-11-16 7:35 UTC (permalink / raw)
To: tytso
Cc: adilger.kernel, libaokun, jack, ojaswin, ritesh.list, yi.zhang,
harshadshirwadkar, linux-ext4, linux-kernel, stable
Hi Ted, Jan and ext4 reviewers,
A gentle ping on this patch from October 27. Are there any comments on the
approach?
I have additional validation from November 2 using QEMU blkdebug to fail an
actual guest block READ. These results supplement the source-derived fault
injection described in the original mail.
On the unpatched Linux 6.12.1 test kernel, with errors=continue, the failed
read was at sector 2312, in the parent inode-table block (block 289, parent
inode 13). The kernel reported:
I/O error, dev vda, sector 2312 op 0x0:(READ)
ext4_get_inode_loc:4554: inode #13: block 289: unable to read itable block
__ext4_unlink:3469: inode #13: mark_inode_dirty error
unlink returned EIO. After normal unmount, /p/file was absent, but raw
inode 2064 still had Links: 1. e2fsck -fn reported:
Unattached inode 2064
In this case the inode-table read fails in ext4_get_inode_loc(), before the
journal write-access call. A separate run of the same block-read failure
traced JBD2 through unlink, sync and normal unmount:
jbd2_journal_abort() probe hits: 0
unlink handle at jbd2_journal_stop(): TID 7, T_RUNNING
h_err=0, h_aborted=0, j_errno=0, journal JBD2_ABORT flag clear
jbd2_journal_stop() return value: 0
jbd2_start_commit: transaction 7
jbd2_end_commit: transaction 7
The offline filesystem check still reported the unattached inode. This
demonstrates that this read-error path can commit the directory change
without a journal abort when mounted with errors=continue.
With the fix, the same clean input and block-read error failed before the
directory entry was removed. After normal unmount, /p/file remained present,
inode 2064 still had Links: 1, and e2fsck -fn completed without diagnostics.
Thanks,
Alan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ext4: reserve inode write access before unlinking entry
2026-11-16 7:35 ` Alan
@ 2026-11-16 12:48 ` Jan Kara
2026-11-17 3:39 ` [PATCH v2] " Alan
0 siblings, 1 reply; 6+ messages in thread
From: Jan Kara @ 2026-11-16 12:48 UTC (permalink / raw)
To: Alan
Cc: tytso, adilger.kernel, libaokun, jack, ojaswin, ritesh.list,
yi.zhang, harshadshirwadkar, linux-ext4, linux-kernel, stable
Hi!
On Mon 16-11-26 15:35:19, Alan wrote:
> Hi Ted, Jan and ext4 reviewers,
>
> A gentle ping on this patch from October 27. Are there any comments on the
> approach?
So for me it is unclear whether this needs addressing at all. Because
realistically the only reason why getting write access to inode bh can fail
is due to aborted journal in which case no transaction will get committed
anyway. So this looks mostly like a problem specific to this error
injection testing...
Honza
>
> I have additional validation from November 2 using QEMU blkdebug to fail an
> actual guest block READ. These results supplement the source-derived fault
> injection described in the original mail.
>
> On the unpatched Linux 6.12.1 test kernel, with errors=continue, the failed
> read was at sector 2312, in the parent inode-table block (block 289, parent
> inode 13). The kernel reported:
>
> I/O error, dev vda, sector 2312 op 0x0:(READ)
> ext4_get_inode_loc:4554: inode #13: block 289: unable to read itable block
> __ext4_unlink:3469: inode #13: mark_inode_dirty error
>
> unlink returned EIO. After normal unmount, /p/file was absent, but raw
> inode 2064 still had Links: 1. e2fsck -fn reported:
>
> Unattached inode 2064
>
> In this case the inode-table read fails in ext4_get_inode_loc(), before the
> journal write-access call. A separate run of the same block-read failure
> traced JBD2 through unlink, sync and normal unmount:
>
> jbd2_journal_abort() probe hits: 0
> unlink handle at jbd2_journal_stop(): TID 7, T_RUNNING
> h_err=0, h_aborted=0, j_errno=0, journal JBD2_ABORT flag clear
> jbd2_journal_stop() return value: 0
> jbd2_start_commit: transaction 7
> jbd2_end_commit: transaction 7
>
> The offline filesystem check still reported the unattached inode. This
> demonstrates that this read-error path can commit the directory change
> without a journal abort when mounted with errors=continue.
>
> With the fix, the same clean input and block-read error failed before the
> directory entry was removed. After normal unmount, /p/file remained present,
> inode 2064 still had Links: 1, and e2fsck -fn completed without diagnostics.
>
> Thanks,
> Alan
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] ext4: reserve inode write access before unlinking entry
2026-11-16 12:48 ` Jan Kara
@ 2026-11-17 3:39 ` Alan
2026-11-17 3:51 ` sashiko-bot
0 siblings, 1 reply; 6+ messages in thread
From: Alan @ 2026-11-17 3:39 UTC (permalink / raw)
To: tytso
Cc: adilger.kernel, libaokun, jack, ojaswin, ritesh.list, yi.zhang,
harshadshirwadkar, linux-ext4, linux-kernel, stable
__ext4_unlink() removes the directory entry before decrementing the target
inode's link count. It then dirties the parent inode. If the parent
inode-table block cannot be read, parent inode dirtying fails after the
entry has been removed, and unlink returns without dropping the target
inode's link count. With errors=continue, this read error need not abort
the journal transaction, so the directory update can be committed without
the corresponding link-count update.
Reserve the inode locations and journal write access for the parent and
target inodes before removing the directory entry. This makes inode-table
read and access errors fail before the namespace is changed. Keep the
existing namespace and link-count update order, and release the inode
location references on every exit path. Fast-commit replay can skip the
parent update when the directory entry does not match the target inode, so
reserve only the target inode in that case.
The original source-derived injection at the journal write-access boundary
is not evidence for a committed inconsistency: an error after the journal
has already aborted cannot establish a committed transaction. The relevant
failure is an actual inode-table READ EIO before journal write access.
Tested on Linux 7.4-rc3 (torvalds/linux commit
aebb7274476403040d582c61478df8f4a7bf9cd3) with QEMU blkdebug and
errors=continue. On the unpatched kernel, the READ EIO leaves the directory
entry removed with Links: 1 after normal unmount; the JBD2 trace shows no
journal abort and records the transaction commit, and e2fsck -fn reports
an unattached inode. With this patch, the same error is returned before the
directory entry is removed; the file remains present with Links: 1 and
e2fsck -fn passes. No-fault controls pass on both kernels. Also built
fs/ext4/namei.o with W=1.
Fixes: 4209ae12b122 ("ext4: handle ext4_mark_inode_dirty errors")
Link: https://lore.kernel.org/linux-ext4/tencent_D60E766CE07D3A1847B81DE9BC37B4466908@qq.com/
Cc: stable@vger.kernel.org
Signed-off-by: Alan <3164729207@qq.com>
---
fs/ext4/namei.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
v2:
- Clarify that the committed inconsistency is reproduced by an inode-table
READ EIO before journal write access, not by an already-aborted journal.
- Revalidate the unmodified and fixed paths on current Linux 7.4-rc3 mainline.
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 354fc2d22df1aa..4c16aa9ad78176 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -3233,6 +3233,7 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
int retval = -ENOENT;
struct buffer_head *bh;
struct ext4_dir_entry_2 *de = NULL;
+ struct ext4_iloc dir_iloc, inode_iloc;
handle_t *handle;
int skip_remove_dentry = 0;
@@ -3269,6 +3270,22 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
if (IS_DIRSYNC(dir))
ext4_handle_sync(handle);
+ /*
+ * Read the inode-table blocks and get journal write access before
+ * removing the directory entry. Otherwise, a read error while updating
+ * either inode can leave the name removed but the link count unchanged.
+ */
+ dir_iloc.bh = NULL;
+ inode_iloc.bh = NULL;
+ if (!skip_remove_dentry) {
+ retval = ext4_reserve_inode_write(handle, dir, &dir_iloc);
+ if (retval)
+ goto out_handle;
+ }
+ retval = ext4_reserve_inode_write(handle, inode, &inode_iloc);
+ if (retval)
+ goto out_handle;
+
if (!skip_remove_dentry) {
retval = ext4_delete_entry(handle, dir, de, bh);
if (retval)
@@ -3293,6 +3310,10 @@ int __ext4_unlink(struct inode *dir, const struct qstr *d_name,
if (dentry && !retval)
ext4_fc_track_unlink(handle, dentry);
out_handle:
+ if (dir_iloc.bh)
+ brelse(dir_iloc.bh);
+ if (inode_iloc.bh)
+ brelse(inode_iloc.bh);
ext4_journal_stop(handle);
out_bh:
brelse(bh);
base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e
--
2.53.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] ext4: reserve inode write access before unlinking entry
2026-11-17 3:39 ` [PATCH v2] " Alan
@ 2026-11-17 3:51 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-17 3:51 UTC (permalink / raw)
To: Alan; +Cc: linux-ext4, tytso
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] ext4: single-word name in Signed-off-by trailer of commit
message
--
commit 5832893d419ac26f89a042ffd66a0050e8ae1910
Author: Alan <3164729207@qq.com>
> ext4: reserve inode write access before unlinking entry
>
> __ext4_unlink() removes the directory entry before decrementing the target
> inode's link count. It then dirties the parent inode. If the parent
> inode-table block cannot be read, parent inode dirtying fails after the
> entry has been removed, and unlink returns without dropping the target
> inode's link count. With errors=continue, this read error need not abort
> the journal transaction, so the directory update can be committed without
> the corresponding link-count update.
>
> Reserve the inode locations and journal write access for the parent and
> target inodes before removing the directory entry. This makes inode-table
> read and access errors fail before the namespace is changed. Keep the
> existing namespace and link-count update order, and release the inode
> location references on every exit path. Fast-commit replay can skip the
> parent update when the directory entry does not match the target inode, so
> reserve only the target inode in that case.
>
> The original source-derived injection at the journal write-access boundary
> is not evidence for a committed inconsistency: an error after the journal
> has already aborted cannot establish a committed transaction. The relevant
> failure is an actual inode-table READ EIO before journal write access.
>
> Tested on Linux 7.4-rc3 (torvalds/linux commit
> aebb7274476403040d582c61478df8f4a7bf9cd3) with QEMU blkdebug and
> errors=continue. On the unpatched kernel, the READ EIO leaves the directory
> entry removed with Links: 1 after normal unmount; the JBD2 trace shows no
> journal abort and records the transaction commit, and e2fsck -fn reports
> an unattached inode. With this patch, the same error is returned before the
> directory entry is removed; the file remains present with Links: 1 and
> e2fsck -fn passes. No-fault controls pass on both kernels. Also built
> fs/ext4/namei.o with W=1.
>
> Fixes: 4209ae12b122 ("ext4: handle ext4_mark_inode_dirty errors")
> Link: https://lore.kernel.org/linux-ext4/tencent_D60E766CE07D3A1847B81DE9BC37B4466908@qq.com/
> Cc: stable@vger.kernel.org
> Signed-off-by: Alan <3164729207@qq.com>
[Severity: High]
The Signed-off-by trailer and Author header use a single-word name ("Alan"),
whereas Documentation/process/submitting-patches.rst requires a full real
name for the Developer's Certificate of Origin.
--
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_58D8BEFB60308A7011D26F6F7E8C941C2A09@qq.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-17 3:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 10:53 [PATCH] ext4: reserve inode write access before unlinking entry Alan
2026-10-27 11:05 ` sashiko-bot
2026-11-16 7:35 ` Alan
2026-11-16 12:48 ` Jan Kara
2026-11-17 3:39 ` [PATCH v2] " Alan
2026-11-17 3:51 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).