public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] [JFFS2] check xattr data integrity during the scan.
@ 2012-04-11 20:23 Jean-Christophe DUBOIS
  2012-04-22 13:04 ` Artem Bityutskiy
  2012-04-22 13:15 ` Artem Bityutskiy
  0 siblings, 2 replies; 5+ messages in thread
From: Jean-Christophe DUBOIS @ 2012-04-11 20:23 UTC (permalink / raw)
  To: linux-mtd; +Cc: Jean-Christophe DUBOIS

If the system was powered off while JFFS2 was creating or moving
(GC) an extended attribute node, it might happen at next reboot
that the node CRC is OK but the data (name and value) might be
incomplete and therefore corrupted.

During the mount scan we need to check the xattr data integrity to
weed out bad ones and keep good ones (whith an earlier version).

Whitout this check the xattr data integrity problem was detected
a lot later and was not cured automatically (-EIO was returned).

Signed-off-by: Jean-Christophe DUBOIS <jcd@tribudubois.net>
---
 fs/jffs2/scan.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index 7654e87..91f44d7 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -354,6 +354,16 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
 		return 0;
 	}
 
+	/* we also need to check the xattr data integrity to weed out bad ones */
+	crc = crc32(0, &rx->data[0], rx->name_len + 1 + je16_to_cpu(rx->value_len));
+	if (crc != je32_to_cpu(rx->data_crc)) {
+		JFFS2_WARNING("xattr data CRC failed at %#08x, read=%#08x, calc=%#08x\n",
+			      ofs, je32_to_cpu(rx->data_crc), crc);
+		if ((err = jffs2_scan_dirty_space(c, jeb, je32_to_cpu(rx->totlen))))
+			return err;
+		return 0;
+	}
+
 	xd = jffs2_setup_xattr_datum(c, xid, version);
 	if (IS_ERR(xd))
 		return PTR_ERR(xd);
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-25 13:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-11 20:23 [PATCH] [JFFS2] check xattr data integrity during the scan Jean-Christophe DUBOIS
2012-04-22 13:04 ` Artem Bityutskiy
2012-04-22 13:15 ` Artem Bityutskiy
2012-04-22 16:17   ` Jean-Christophe DUBOIS
2012-04-25 13:55     ` Artem Bityutskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox