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

Configure Feed

Select the types of activity you want to include in your feed.

f2fs: fix to detect potential corrupted nid in free_nid_list

As reported, on-disk footer.ino and footer.nid is the same and
out-of-range, let's add sanity check on f2fs_alloc_nid() to detect
any potential corruption in free_nid_list.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>

authored by

Chao Yu and committed by
Jaegeuk Kim
8fc6056d 2e8f4c2b

+17 -1
+16 -1
fs/f2fs/node.c
··· 27 27 static struct kmem_cache *nat_entry_set_slab; 28 28 static struct kmem_cache *fsync_node_entry_slab; 29 29 30 + static inline bool is_invalid_nid(struct f2fs_sb_info *sbi, nid_t nid) 31 + { 32 + return nid < F2FS_ROOT_INO(sbi) || nid >= NM_I(sbi)->max_nid; 33 + } 34 + 30 35 /* 31 36 * Check whether the given nid is within node id range. 32 37 */ 33 38 int f2fs_check_nid_range(struct f2fs_sb_info *sbi, nid_t nid) 34 39 { 35 - if (unlikely(nid < F2FS_ROOT_INO(sbi) || nid >= NM_I(sbi)->max_nid)) { 40 + if (unlikely(is_invalid_nid(sbi, nid))) { 36 41 set_sbi_flag(sbi, SBI_NEED_FSCK); 37 42 f2fs_warn(sbi, "%s: out-of-range nid=%x, run fsck to fix.", 38 43 __func__, nid); ··· 2639 2634 f2fs_bug_on(sbi, list_empty(&nm_i->free_nid_list)); 2640 2635 i = list_first_entry(&nm_i->free_nid_list, 2641 2636 struct free_nid, list); 2637 + 2638 + if (unlikely(is_invalid_nid(sbi, i->nid))) { 2639 + spin_unlock(&nm_i->nid_list_lock); 2640 + f2fs_err(sbi, "Corrupted nid %u in free_nid_list", 2641 + i->nid); 2642 + f2fs_stop_checkpoint(sbi, false, 2643 + STOP_CP_REASON_CORRUPTED_NID); 2644 + return false; 2645 + } 2646 + 2642 2647 *nid = i->nid; 2643 2648 2644 2649 __move_free_nid(sbi, i, FREE_NID, PREALLOC_NID);
+1
include/linux/f2fs_fs.h
··· 79 79 STOP_CP_REASON_FLUSH_FAIL, 80 80 STOP_CP_REASON_NO_SEGMENT, 81 81 STOP_CP_REASON_CORRUPTED_FREE_BITMAP, 82 + STOP_CP_REASON_CORRUPTED_NID, 82 83 STOP_CP_REASON_MAX, 83 84 }; 84 85