Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

f2fs: fix to handle looped node chain during recovery

There is no checksum in node block now, so bit-transition from hardware
can make node_footer.next_blkaddr being corrupted w/o any detection,
result in node chain becoming looped one.

For this condition, during recovery, in order to avoid running into dead
loop, let's detect it and just skip out.

Signed-off-by: Yunlei He <heyunlei@huawei.com>
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Chao Yu and committed by
Jaegeuk Kim
fb0e72c8 0f9ec2a8

+14
+14
fs/f2fs/recovery.c
··· 242 242 struct curseg_info *curseg; 243 243 struct page *page = NULL; 244 244 block_t blkaddr; 245 + unsigned int loop_cnt = 0; 246 + unsigned int free_blocks = sbi->user_block_count - 247 + valid_user_blocks(sbi); 245 248 int err = 0; 246 249 247 250 /* get node pages in the current segment */ ··· 297 294 if (IS_INODE(page) && is_dent_dnode(page)) 298 295 entry->last_dentry = blkaddr; 299 296 next: 297 + /* sanity check in order to detect looped node chain */ 298 + if (++loop_cnt >= free_blocks || 299 + blkaddr == next_blkaddr_of_node(page)) { 300 + f2fs_msg(sbi->sb, KERN_NOTICE, 301 + "%s: detect looped node chain, " 302 + "blkaddr:%u, next:%u", 303 + __func__, blkaddr, next_blkaddr_of_node(page)); 304 + err = -EINVAL; 305 + break; 306 + } 307 + 300 308 /* check next segment */ 301 309 blkaddr = next_blkaddr_of_node(page); 302 310 f2fs_put_page(page, 1);