All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] f2fs-tools: detect corrupted sit journal
@ 2019-05-24  8:52 Chao Yu
  0 siblings, 0 replies; only message in thread
From: Chao Yu @ 2019-05-24  8:52 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: jaegeuk

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

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mount.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fsck/mount.c b/fsck/mount.c
index a627f1d..909c1f4 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -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);
 
-- 
2.18.0.rc1

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-05-24  8:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24  8:52 [PATCH] f2fs-tools: detect corrupted sit journal Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.