Skip to contentSkip to conversation

f2fs-tools: detect corrupted sit journal

PATCH New Chao Yu 1 participant 1 message May 24, 2019

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs-tools: detect corrupted sit journal

Enables to detect corrupted sit journal
a) total count of entries.
b) segment no. in entry.

---
 fsck/mount.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
fsck/mount.c +17 -0
index a627f1d..909c1f4 100644
@@ -1912,8 +1912,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);
 
Signature · 1 line
2.18.0.rc1