Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1774822imm; Fri, 7 Sep 2018 06:04:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZUKh+FwmRRfHppA0bMB6VcmxDbi3OnaVkGxkpCVg7KU/UD1DA+YV1UoLx5lqyhr9sS797O X-Received: by 2002:a63:10c:: with SMTP id 12-v6mr7997136pgb.62.1536325473782; Fri, 07 Sep 2018 06:04:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536325473; cv=none; d=google.com; s=arc-20160816; b=R5u6Ptf8iaXDYxS9VGQGSdR4ERVoP8WNPplMKePsUr1/d1mI0pB0ekpIapQreVNlbD kDi4gilaOTXp985RO4f443t3XoOrWWpAWjk72RB5IJdq5fbbfXaBUOGlGLhDIGNdIHkZ GOXkUNS1QR/N0I7SUJIb54nvZIhEXy/jw1hT01D44+d+QraVpSjVu+pzp8r1LmUJTY5S zAK+62emgO+9PI9VrqXzAaF76ISsyBmcEmUrOXzGcF8QnotppJZCz70lQRtVj0PE1s08 vHUXxtYol0TCBHJCTGuHLph3TjKEp1z1ldNekip3R2/LPYKKvkuhf5viY3pYcYi2s/lr EjNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=3+lmwTjwh1fB74FuT5Vut4wzcRS8Lnh1S51XspsAp/4=; b=OuhVDe/Qu5WOaMTdhugrb1LRxA7TrO9RDq8msOeYXFcokCBAJzPV0sEc9UT2Thlbeg 2HHPD/Q9i/S3PugGKpMEd0MReJX0toUGnQNlaIxWFVlxpOlOrzfZIYte6xFz6NkSEzkp hu1tdmweBl82L+XNu1jPDyHahDvPZuPIyzGudQFi+fOKslasuB44pE2VEHEKtHyZq8H6 y2bPs6Dv3iOBf8408F9KrzZzF9OUJHOC2X/ssECxUgduAmyIUhiPW3ItmUhjmzfzZM18 VXKml28OIVdHe3vZSjBPHK6L/h3a/Sndiupw0hlQrdMUcPYrzoEhc8V+s5n0zOGBpif8 cFVA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c31-v6si8435608pgl.126.2018.09.07.06.04.17; Fri, 07 Sep 2018 06:04:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729373AbeIGRTk (ORCPT + 99 others); Fri, 7 Sep 2018 13:19:40 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:42567 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729363AbeIGRTj (ORCPT ); Fri, 7 Sep 2018 13:19:39 -0400 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fyG27-0007c7-Tv; Fri, 07 Sep 2018 14:38:43 +0200 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.91) (envelope-from ) id 1fyG26-00062g-KO; Fri, 07 Sep 2018 14:38:42 +0200 From: Sascha Hauer To: linux-mtd@lists.infradead.org Cc: David Gstir , Richard Weinberger , kernel@pengutronix.de, linux-kernel@vger.kernel.org, Sascha Hauer Subject: [PATCH 22/25] ubifs: Add hashes and HMACs to default filesystem Date: Fri, 7 Sep 2018 14:36:43 +0200 Message-Id: <20180907123646.12688-23-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907123646.12688-1-s.hauer@pengutronix.de> References: <20180907123646.12688-1-s.hauer@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch calculates the necessary hashes and HMACs for the default filesystem so that the dynamically created default fs can be authenticated. Signed-off-by: Sascha Hauer --- fs/ubifs/sb.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c index 7f0967771c9f..ac1ed5ad126d 100644 --- a/fs/ubifs/sb.c +++ b/fs/ubifs/sb.c @@ -87,6 +87,7 @@ static int create_default_filesystem(struct ubifs_info *c) __le64 tmp_le64; __le32 tmp_le32; struct timespec64 ts; + u8 hash[UBIFS_HASH_ARR_SZ]; u8 hash_lpt[UBIFS_HASH_ARR_SZ]; /* Some functions called from here depend on the @c->key_len filed */ @@ -177,6 +178,16 @@ static int create_default_filesystem(struct ubifs_info *c) sup_flags |= UBIFS_FLG_BIGLPT; sup_flags |= UBIFS_FLG_DOUBLE_HASH; + if (ubifs_authenticated(c)) { + sup_flags |= UBIFS_FLG_AUTHENTICATION; + sup->hash_algo = cpu_to_le16(c->auth_hash_algo); + err = ubifs_hmac_wkm(c, sup->hmac_wkm); + if (err) + goto out; + } else { + sup->hash_algo = 0xffff; + } + sup->ch.node_type = UBIFS_SB_NODE; sup->key_hash = UBIFS_KEY_HASH_R5; sup->flags = cpu_to_le32(sup_flags); @@ -235,6 +246,7 @@ static int create_default_filesystem(struct ubifs_info *c) mst->empty_lebs = cpu_to_le32(main_lebs - 2); mst->idx_lebs = cpu_to_le32(1); mst->leb_cnt = cpu_to_le32(c->leb_cnt); + ubifs_copy_hash(c, hash_lpt, mst->hash_lpt); /* Calculate lprops statistics */ tmp64 = main_bytes; @@ -307,25 +319,33 @@ static int create_default_filesystem(struct ubifs_info *c) cs->ch.node_type = UBIFS_CS_NODE; - err = ubifs_write_node(c, sup, UBIFS_SB_NODE_SZ, 0, 0); + err = ubifs_write_node_hmac(c, sup, UBIFS_SB_NODE_SZ, 0, 0, + offsetof(struct ubifs_sb_node, hmac)); if (err) goto out; - err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0); + err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, + main_first + DEFAULT_DATA_LEB, 0); if (err) goto out; - err = ubifs_write_node(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, - 0); + ubifs_node_calc_hash(c, ino, hash); + ubifs_copy_hash(c, hash, ubifs_branch_hash(c, br)); + + err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0); if (err) goto out; - err = ubifs_write_node(c, idx, idx_node_size, main_first + DEFAULT_IDX_LEB, 0); + ubifs_node_calc_hash(c, idx, hash); + ubifs_copy_hash(c, hash, mst->hash_root_idx); + + err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM, 0, + offsetof(struct ubifs_mst_node, hmac)); if (err) goto out; - err = ubifs_write_node(c, ino, UBIFS_INO_NODE_SZ, - main_first + DEFAULT_DATA_LEB, 0); + err = ubifs_write_node_hmac(c, mst, UBIFS_MST_NODE_SZ, UBIFS_MST_LNUM + 1, + 0, offsetof(struct ubifs_mst_node, hmac)); if (err) goto out; -- 2.18.0