From: Ryusuke Konishi <konishi.ryusuke@gmail.com>
To: Viacheslav Dubeyko <slava@dubeyko.com>
Cc: Wang Jianjian <wangjianjian3@huawei.com>,
linux-nilfs <linux-nilfs@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
Zheng Zheng <fengaojigui88@gmail.com>,
Joshua Crofts <joshua.crofts1@gmail.com>
Subject: [PATCH 1/8] nilfs2: fix leak of gc inodes on error
Date: Fri, 27 Nov 2026 13:40:54 +0900 [thread overview]
Message-ID: <20261127044231.37630-2-konishi.ryusuke@gmail.com> (raw)
In-Reply-To: <20261127044231.37630-1-konishi.ryusuke@gmail.com>
From: Wang Jianjian <wangjianjian3@huawei.com>
Zhengzheng reported below syz problems:
NILFS (loop5): disposed unprocessed dirty file(s) when stopping log writer
VFS: Busy inodes after unmount of loop5 (nilfs2)
The reproducer called ioctl clean_segments on a corrupted image. It's
first argument is { ino = 8, cno = 0xffffffffffffffff, vd_vblocknr = 34,
vd_period = [0x30000000000000, 0x10), vd_blocknr = 6, vd_offset =
7,...}.
nilfs_ioctl_clean_segments
nilfs_ioctl_move_blocks // gc iget 8, get one inode reference
nilfs_clean_segments
nilfs->ns_gc_inodes move to sci->sc_gc_inodes
nilfs_segctor_construct
nilfs_segctor_do_construct
nilfs_segctor_assign
nilfs_segctor_update_payload_blocknr
nilfs_bmap_assign
nilfs_btree_assign_gc
nilfs_dat_move
// since there is no dat entry for vblknr 34
// (entry->de_blocknr == 0), return -EINVAL
// fs will be remounted to readonly
// clean segments loop will be break because readonly fs
nilfs_remove_all_gcinodes
// since nilfs->ns_gc_inodes empty, it
// clean nothing
ioctl_clean_segment will get one extra reference of inode 8 and when
segments construct do GC move vblock 34 and do bmap assign, it lookup
DAT table and get de_blocknr = 0, so it return -EINVAL. And since
nilfs->ns_gc_inodes is empty, nilfs_remove_all_gcinodes will do nothing
and the extra inode reference won't be released.
To fix this, splice sci->sc_gc_inodes back to nilfs->ns_gc_inodes when
got error.
Note that, when normal files add to nilfs dirty list by
nilfs_set_file_dirty, it will got one reference and when
nilfs_bmap_assign got error, nilfs_segctor_do_construct() also doesn't
put the inode, but as a last resort, nilfs_segctor_destroy will do
it(however, it doesn't clean sci->sc_gc_inodes).
Fixes: ce5a5ad1a833 ("nilfs2: fix infinite loop in nilfs_clean_segments()")
Signed-off-by: Wang Jianjian <wangjianjian3@huawei.com>
Reported-by: fengaojigui88@gmail.com
Closes: https://lore.kernel.org/linux-nilfs/CAO-4RZ2=4okHYZ-xCkpV-ekj-aSqKLnYGOsRM9A2dD8R4Ozzeg@mail.gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
---
fs/nilfs2/segment.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index 68b640a7aa5b..4c2d51f6550c 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -2586,6 +2586,7 @@ int nilfs_clean_segments(struct super_block *sb, struct nilfs_argv *argv,
out_unlock:
sci->sc_freesegs = NULL;
sci->sc_nfreesegs = 0;
+ list_splice_tail_init(&sci->sc_gc_inodes, &nilfs->ns_gc_inodes);
nilfs_mdt_clear_shadow_map(nilfs->ns_dat);
bail_unlock:
nilfs_transaction_unlock(sb);
--
2.53.0
next prev parent reply other threads:[~2026-11-27 4:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 4:40 [PATCH 0/8] nilfs2: support GC error rollback and avoid infinite retry hangs Ryusuke Konishi
2026-11-27 4:40 ` Ryusuke Konishi [this message]
2026-11-27 4:40 ` [PATCH 2/8] nilfs2: cancel the relocation of GC-targeted blocks if log writing fails Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 3/8] nilfs2: restore segment usage from the save buffer when aborting GC Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 4/8] nilfs2: drop redirected buffer flag from DAT when clearing shadow map Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 5/8] nilfs2: save DAT entry blocks to shadow mapping before freeing Ryusuke Konishi
2026-11-27 4:40 ` [PATCH 6/8] nilfs2: restore removed DAT entries when aborting GC Ryusuke Konishi
2026-11-27 4:41 ` [PATCH 7/8] nilfs2: free virtual block numbers just before collecting DAT changes Ryusuke Konishi
2026-11-27 4:41 ` [PATCH 8/8] nilfs2: avoid infinite retry loop on GC failure Ryusuke Konishi
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=20261127044231.37630-2-konishi.ryusuke@gmail.com \
--to=konishi.ryusuke@gmail.com \
--cc=fengaojigui88@gmail.com \
--cc=joshua.crofts1@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nilfs@vger.kernel.org \
--cc=slava@dubeyko.com \
--cc=wangjianjian3@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
all inboxes | Powered by JetHome®