From patchwork Sun May 20 12:28:07 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Reardon X-Patchwork-Id: 160257 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 217CDB6FB7 for ; Sun, 20 May 2012 22:30:12 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SW5F6-0002CR-DB; Sun, 20 May 2012 12:28:12 +0000 Received: from [78.46.68.141] (helo=eristoteles.iwoars.net) by merlin.infradead.org with smtp (Exim 4.76 #1 (Red Hat Linux)) id 1SW5F3-0002CD-Hf for linux-mtd@lists.infradead.org; Sun, 20 May 2012 12:28:10 +0000 Received: (qmail 27633 invoked by uid 5144); 20 May 2012 14:28:07 +0200 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 20 May 2012 14:28:07 +0200 Date: Sun, 20 May 2012 14:28:07 +0200 (CEST) From: Joel Reardon X-X-Sender: joel@eristoteles.iwoars.net To: Artem Bityutskiy Subject: [PATCH] UBIFS: add ksa_pos to replay buds, read when replaying Message-ID: User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) MIME-Version: 1.0 X-Spam-Note: CRM114 invocation failed X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.8 RDNS_NONE Delivered to internal network by a host with no rDNS 0.3 FROM_12LTRDOM From a 12-letter domain Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org 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: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch read the ksa_pos from data nodes to the replay buds when performing a replay after unclean commit. This is critical for the correctness of the key state map, because the keys that are assigned to uncommited data nodes will be considered "unused" after mounting but will be considered "used" after replaying. The ksa_pos values stored in the replay bud are passed to the TNC using ubifs_tnc_add. This was tested by assigning distinct ksa_pos values and disabling commiting. Data was written and then the drive was remounted. The ksa_pos values were read from the journal and outputted while replaying. When the file was later read, it was confirmed that the ksa_pos values were already loaded into the TNC. Signed-off-by: Joel Reardon --- fs/ubifs/replay.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c index 1fec6e2..1f02829 100644 --- a/fs/ubifs/replay.c +++ b/fs/ubifs/replay.c @@ -47,6 +47,7 @@ * @nm: directory entry name * @old_size: truncation old size * @new_size: truncation new size + * @ksa_pos: the node's cryptographic key's position in the KSA * * The replay process first scans all buds and builds the replay list, then * sorts the replay list in nodes sequence number order, and then inserts all @@ -67,6 +68,7 @@ struct replay_entry { loff_t new_size; }; }; + long long ksa_pos; }; /** @@ -251,7 +253,7 @@ static int apply_replay_entry(struct ubifs_info *c, struct replay_entry *r) } else err = ubifs_tnc_add(c, &r->key, r->lnum, r->offs, - r->len, 0); + r->len, r->ksa_pos); if (err) return err; @@ -345,6 +347,7 @@ static void destroy_replay_list(struct ubifs_info *c) * @used: number of bytes in use in a LEB * @old_size: truncation old size * @new_size: truncation new size + * @ksa_pos: the node's cryptographic key's position in the KSA * * This function inserts a scanned non-direntry node to the replay list. The * replay list contains @struct replay_entry elements, and we sort this list in @@ -356,7 +359,7 @@ static void destroy_replay_list(struct ubifs_info *c) static int insert_node(struct ubifs_info *c, int lnum, int offs, int len, union ubifs_key *key, unsigned long long sqnum, int deletion, int *used, loff_t old_size, - loff_t new_size) + loff_t new_size, long long ksa_pos) { struct replay_entry *r; @@ -371,6 +374,7 @@ static int insert_node(struct ubifs_info *c, int lnum, int offs, int len, if (!deletion) *used += ALIGN(len, 8); + r->ksa_pos = ksa_pos; r->lnum = lnum; r->offs = offs; r->len = len; @@ -606,7 +610,7 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b) deletion = 1; err = insert_node(c, lnum, snod->offs, snod->len, &snod->key, snod->sqnum, deletion, - &used, 0, new_size); + &used, 0, new_size, 0); break; } case UBIFS_DATA_NODE: @@ -618,7 +622,8 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b) err = insert_node(c, lnum, snod->offs, snod->len, &snod->key, snod->sqnum, deletion, - &used, 0, new_size); + &used, 0, new_size, + le64_to_cpu(dn->ksa_pos)); break; } case UBIFS_DENT_NODE: @@ -658,7 +663,7 @@ static int replay_bud(struct ubifs_info *c, struct bud_entry *b) trun_key_init(c, &key, le32_to_cpu(trun->inum)); err = insert_node(c, lnum, snod->offs, snod->len, &key, snod->sqnum, 1, &used, - old_size, new_size); + old_size, new_size, 0); break; } default: