f2fs-tools: detect corrupted sit journal
authorChao Yu <yuchao0@huawei.com>
Fri, 24 May 2019 08:52:41 +0000 (16:52 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 20 Aug 2019 18:23:51 +0000 (11:23 -0700)
Enables to detect corrupted sit journal
a) total count of entries.
b) segment no. in entry.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/mount.c

index 887c9fc..7521f4e 100644 (file)
@@ -1915,8 +1915,25 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
        }
 
        free(sit_blk);
+
+       if (sits_in_cursum(journal) > SIT_JOURNAL_ENTRIES) {
+               MSG(0, "\tError: build_sit_entries truncate n_sits(%u) to "
+                       "SIT_JOURNAL_ENTRIES(%lu)\n",
+                       sits_in_cursum(journal), SIT_JOURNAL_ENTRIES);
+               journal->n_sits = cpu_to_le16(SIT_JOURNAL_ENTRIES);
+               c.fix_on = 1;
+       }
+
        for (i = 0; i < sits_in_cursum(journal); i++) {
                segno = le32_to_cpu(segno_in_journal(journal, i));
+
+               if (segno >= TOTAL_SEGS(sbi)) {
+                       MSG(0, "\tError: build_sit_entries: segno(%u) is invalid!!!\n", segno);
+                       journal->n_sits = cpu_to_le16(i);
+                       c.fix_on = 1;
+                       continue;
+               }
+
                se = &sit_i->sentries[segno];
                sit = sit_in_journal(journal, i);