f2fs: don't BUG_ON an inconsistent node ino in roll-forward recovery
Subsystems (2)
PATCH 1/1 f2fs: don't BUG_ON an inconsistent node ino in roll-forward recovery
From: Zhan Xusheng <[email protected]>
do_recover_data() asserts that the ino in the NAT entry of the node it recovers into matches the ino in the footer of the fsynced node block. Both are read from disk and nothing checks one against the other before, so mounting an image with a wrong ino in that NAT entry hits the f2fs_bug_on(): a kernel BUG with CONFIG_F2FS_CHECK_FS, and without it a warning, after which the NAT ino is written into the footer of the recovered node.
To reproduce, create a file, sync, write and fsync it, crash, and change the ino of the file's entry in the NAT journal of the checkpoint pack. The next mount gives:
kernel BUG at fs/f2fs/recovery.c:698!
Fail the recovery with -EFSCORRUPTED instead, as the ofs_of_node check right after it does.
---
Tested on f2fs/dev b61a029304bb with CONFIG_F2FS_CHECK_FS and KASAN. With the ino of the victim's NAT journal entry changed from 4 to 5:
unfixed kernel BUG at fs/f2fs/recovery.c:698
fixed "Inconsistent ino_of_node, nid:4, ino:5, 4", recovery fails
with -EFSCORRUPTED, the mount is retried without roll-forward and succeeds, and fsck.f2fs reports the same mismatch for nid 4
The unmodified image recovers the same way with and without the patch.
fs/f2fs/recovery.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/f2fs/recovery.c +8 -1
@@ -695,7 +695,14 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode,if (err) goto err; -f2fs_bug_on (sbi, ni.ino !=ino_of_node (sbi, entry)); +if (ni.ino !=ino_of_node (sbi, entry)) { +f2fs_warn (sbi,"Inconsistent ino_of_node, nid:%u, ino:%u, %u" , + dn.nid, ni.ino,ino_of_node (sbi, entry)); + err = -EFSCORRUPTED ; +f2fs_handle_error (sbi,ERROR_INCONSISTENT_FOOTER ); +fserror_report_file_metadata (dn.inode, err,GFP_NOFS ); + goto err; + }if (ofs_of_node (sbi, dn.node_entry) !=ofs_of_node (sbi, entry)) { f2fs_warn(sbi, "Inconsistent ofs_of_node, ino:%llu, ofs:%u, %u",
Signature · 1 line
2.43.0