From patchwork Wed Apr 11 20:23:36 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe Dubois X-Patchwork-Id: 151872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE236B706B for ; Thu, 12 Apr 2012 06:25:45 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SI45g-0008VQ-6M; Wed, 11 Apr 2012 20:24:32 +0000 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SI45Z-0008Sf-DG for linux-mtd@lists.infradead.org; Wed, 11 Apr 2012 20:24:27 +0000 Received: from localhost.localdomain (unknown [78.235.240.156]) by smtp4-g21.free.fr (Postfix) with ESMTP id B9EBD4C8046; Wed, 11 Apr 2012 22:24:18 +0200 (CEST) From: Jean-Christophe DUBOIS To: linux-mtd@lists.infradead.org Subject: [PATCH] [JFFS2] check xattr data integrity during the scan. Date: Wed, 11 Apr 2012 22:23:36 +0200 Message-Id: <1334175816-20688-1-git-send-email-jcd@tribudubois.net> X-Mailer: git-send-email 1.7.5.4 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Jean-Christophe DUBOIS X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 --- 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);