Skip to contentSkip to conversation

fsck.f2fs: check validity of nid from journal

PATCH Superseded Chao Yu 1 participant 1 message Jan 9, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 fsck.f2fs: check validity of nid from journal

As reported by Aravind:

I built f2fs tools from source (at tag v1.12.0) and was able to get this backtrace in gdb:

Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7f8eb54 in f2fs_set_bit (nr=1041170432,

    addr=0x7fffff621010 <error: Cannot access memory at address 0x7fffff621010>) at libf2fs.c:312
312        mask = 1 << (7 - (nr & 0x07));
(gdb) where
    addr=0x7fffff621010 <error: Cannot access memory at address 0x7fffff621010>) at libf2fs.c:312

nid recorded in journal may be corrupted, let's do sanity check on them, and skip loading invalid ones during build_node_manager().

---
 fsck/mount.c | 4 ++++
 1 file changed, 4 insertions(+)
fsck/mount.c +4 -0
index ea70306b0895..e0d4db245a9e 100644
@@ -1071,6 +1071,10 @@ static int f2fs_init_nid_bitmap(struct f2fs_sb_info *sbi)
 
 		addr = le32_to_cpu(nat_in_journal(journal, i).block_addr);
 		nid = le32_to_cpu(nid_in_journal(journal, i));
+		if (!IS_VALID_NID(sbi, nid)) {
+			MSG(0, "\tError: f2fs_init_nid_bitmap: nid(%u) is invalid!!!\n", nid);
+			continue;
+		}
 		if (addr != NULL_ADDR)
 			f2fs_set_bit(nid, nm_i->nid_bitmap);
 	}
Signature · 1 line
2.18.0.rc1