Skip to content

Commit 6b67737

Browse files
Jaegeuk Kimgregkh
authored andcommitted
f2fs: handle errors of f2fs_get_meta_page_nofail
[ Upstream commit 86f3360 ] First problem is we hit BUG_ON() in f2fs_get_sum_page given EIO on f2fs_get_meta_page_nofail(). Quick fix was not to give any error with infinite loop, but syzbot caught a case where it goes to that loop from fuzzed image. In turned out we abused f2fs_get_meta_page_nofail() like in the below call stack. - f2fs_fill_super - f2fs_build_segment_manager - build_sit_entries - get_current_sit_page INFO: task syz-executor178:6870 can't die for more than 143 seconds. task:syz-executor178 state:R stack:26960 pid: 6870 ppid: 6869 flags:0x00004006 Call Trace: Showing all locks held in the system: 1 lock held by khungtaskd/1179: #0: ffffffff8a554da0 (rcu_read_lock){....}-{1:2}, at: debug_show_all_locks+0x53/0x260 kernel/locking/lockdep.c:6242 1 lock held by systemd-journal/3920: 1 lock held by in:imklog/6769: #0: ffff88809eebc130 (&f->f_pos_lock){+.+.}-{3:3}, at: __fdget_pos+0xe9/0x100 fs/file.c:930 1 lock held by syz-executor178/6870: #0: ffff8880925120e0 (&type->s_umount_key#47/1){+.+.}-{3:3}, at: alloc_super+0x201/0xaf0 fs/super.c:229 Actually, we didn't have to use _nofail in this case, since we could return error to mount(2) already with the error handler. As a result, this patch tries to 1) remove _nofail callers as much as possible, 2) deal with error case in last remaining caller, f2fs_get_sum_page(). Reported-by: syzbot+ee250ac8137be41d7b13@syzkaller.appspotmail.com Reviewed-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent dba295d commit 6b67737

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index)
107107
return __get_meta_page(sbi, index, true);
108108
}
109109

110-
struct page *f2fs_get_meta_page_nofail(struct f2fs_sb_info *sbi, pgoff_t index)
110+
struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index)
111111
{
112112
struct page *page;
113113
int count = 0;

fs/f2fs/f2fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3385,7 +3385,7 @@ enum rw_hint f2fs_io_type_to_rw_hint(struct f2fs_sb_info *sbi,
33853385
void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io);
33863386
struct page *f2fs_grab_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
33873387
struct page *f2fs_get_meta_page(struct f2fs_sb_info *sbi, pgoff_t index);
3388-
struct page *f2fs_get_meta_page_nofail(struct f2fs_sb_info *sbi, pgoff_t index);
3388+
struct page *f2fs_get_meta_page_retry(struct f2fs_sb_info *sbi, pgoff_t index);
33893389
struct page *f2fs_get_tmp_page(struct f2fs_sb_info *sbi, pgoff_t index);
33903390
bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
33913391
block_t blkaddr, int type);

fs/f2fs/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ static void clear_node_page_dirty(struct page *page)
109109

110110
static struct page *get_current_nat_page(struct f2fs_sb_info *sbi, nid_t nid)
111111
{
112-
return f2fs_get_meta_page_nofail(sbi, current_nat_addr(sbi, nid));
112+
return f2fs_get_meta_page(sbi, current_nat_addr(sbi, nid));
113113
}
114114

115115
static struct page *get_next_nat_page(struct f2fs_sb_info *sbi, nid_t nid)

fs/f2fs/segment.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,7 +2344,9 @@ int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra)
23442344
*/
23452345
struct page *f2fs_get_sum_page(struct f2fs_sb_info *sbi, unsigned int segno)
23462346
{
2347-
return f2fs_get_meta_page_nofail(sbi, GET_SUM_BLOCK(sbi, segno));
2347+
if (unlikely(f2fs_cp_error(sbi)))
2348+
return ERR_PTR(-EIO);
2349+
return f2fs_get_meta_page_retry(sbi, GET_SUM_BLOCK(sbi, segno));
23482350
}
23492351

23502352
void f2fs_update_meta_page(struct f2fs_sb_info *sbi,
@@ -2616,7 +2618,11 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type)
26162618
__next_free_blkoff(sbi, curseg, 0);
26172619

26182620
sum_page = f2fs_get_sum_page(sbi, new_segno);
2619-
f2fs_bug_on(sbi, IS_ERR(sum_page));
2621+
if (IS_ERR(sum_page)) {
2622+
/* GC won't be able to use stale summary pages by cp_error */
2623+
memset(curseg->sum_blk, 0, SUM_ENTRY_SIZE);
2624+
return;
2625+
}
26202626
sum_node = (struct f2fs_summary_block *)page_address(sum_page);
26212627
memcpy(curseg->sum_blk, sum_node, SUM_ENTRY_SIZE);
26222628
f2fs_put_page(sum_page, 1);
@@ -3781,7 +3787,7 @@ int f2fs_lookup_journal_in_cursum(struct f2fs_journal *journal, int type,
37813787
static struct page *get_current_sit_page(struct f2fs_sb_info *sbi,
37823788
unsigned int segno)
37833789
{
3784-
return f2fs_get_meta_page_nofail(sbi, current_sit_addr(sbi, segno));
3790+
return f2fs_get_meta_page(sbi, current_sit_addr(sbi, segno));
37853791
}
37863792

37873793
static struct page *get_next_sit_page(struct f2fs_sb_info *sbi,

0 commit comments

Comments
 (0)