Received: by 10.213.65.68 with SMTP id h4csp2424800imn; Mon, 9 Apr 2018 03:25:01 -0700 (PDT) X-Google-Smtp-Source: AIpwx48pZETKslWn3t+kiYokJpHGhkBLKC4sLb02RMVsD3MIrecGcG34GuMrmuWa/cdKDJPZU2wV X-Received: by 10.99.177.78 with SMTP id g14mr3486036pgp.253.1523269501334; Mon, 09 Apr 2018 03:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523269501; cv=none; d=google.com; s=arc-20160816; b=MgjVtil2x72gYLrQ1iuqzOpMXsuccvRy5fxE39bUeDHbSC22QkBEVVMTwvJQG4BjQ1 y6LKKVFhRHfnP4+Fj1bb6fA/4N4mKktFMFKT8othPt8JFz1kJz00mnoMzbwWrM8ZD8eT bhTA9hkUMeDsxYqgIub3HMh0sEAB8Ntb1DIS+nvKruOwCyd0uJkQTq35ohaYRJNpJDJN zikTQYWYqeOJ7aorJ8G7nicAME3uDABxsCEqeaonhWWUIpiNMQH2nvOq1xalREQuCG+I lbj6h/Ve5sKHMeh+ylxDYsr8bAXEeeF2X6tvbVkt5qBBWZk8V/0fBj4Gjd/KmRcH4TX0 qQTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=QQ/xoy6jw+m16j48leaB4JfydRSyvMaEZcGMQg9N6IE=; b=uq7AEIcMB4mjmZUqWSJyftxUPTc4RsJ7jhmCePOvdnpQsY9OOulhFmyTOdPVR47IDu KNSYNLQ/zxnk9zgBjLgJ4tnFFlZktaX1/KIt7aCDljZWG2s7nu5PLEb3ppLObeEN1YT0 nbDdleKgI9odL0WlTuh/7SLZJhfTyNLnkR556qMgPncsDJ04BNieKei2j4L3Xw84bTfF FjEnT07n88LLwD1N92kakMWfLyaMciBLiJtEZ8rhMCkDRxHx1ZPTMZ6Qv8vpqzkkt2Tx rIEHeiHGy6pzoD5ia4reAehIOhQbSJWea+w9Mwgcj09YuJTpkmpgGmN5XtFcCbHpm6VV QrXQ== 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 be3-v6si31051plb.75.2018.04.09.03.24.24; Mon, 09 Apr 2018 03:25:01 -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 S1751918AbeDIJ7c (ORCPT + 99 others); Mon, 9 Apr 2018 05:59:32 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:41293 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751874AbeDIJ7a (ORCPT ); Mon, 9 Apr 2018 05:59:30 -0400 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1f5TZx-00078G-95; Mon, 09 Apr 2018 11:59:13 +0200 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1f5TZw-0004F5-P6; Mon, 09 Apr 2018 11:59:12 +0200 Date: Mon, 9 Apr 2018 11:59:12 +0200 From: Sascha Hauer To: David Gstir Cc: linux-fscrypt@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mtd@lists.infradead.org, Richard Weinberger , linux-kernel@vger.kernel.org, kernel@pengutronix.de Subject: Re: [RFC] UBIFS authentication Message-ID: <20180409095912.f7d35y7yjdnj2ffz@pengutronix.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 11:47:33 up 108 days, 18:06, 88 users, load average: 0.05, 0.12, 0.15 User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 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 Hi David, On Wed, Jan 17, 2018 at 04:19:14PM +0100, David Gstir wrote: > Hi everybody! > > ### Index Authentication > > Through UBIFS' concept of a wandering tree, it already takes care of only > updating and persisting changed parts from leaf node up to the root node > of the full B+ tree. This enables us to augment the index nodes of the tree > with a hash over each node's child nodes. As a result, the index basically also > a Merkle tree. Since the leaf nodes of the index contain the actual filesystem > data, the hashes of their parent index nodes thus cover all the file contents > and file metadata. When a file changes, the UBIFS index is updated accordingly > from the leaf nodes up to the root node including the master node. This process > can be hooked to recompute the hash only for each changed node at the same time. > Whenever a file is read, UBIFS can verify the hashes from each leaf node up to > the root node to ensure the node's integrity. > > To ensure the authenticity of the whole index, the UBIFS master node stores a > keyed hash (HMAC) over its own contents (which includes the location of the root > node) and the root node of the index tree. As mentioned above, the master node > is always written to the flash whenever the index is persisted (ie. on index > commit). > > Using this approach only UBIFS index nodes and the master node are changed to > include a hash. All other types of nodes will remain unchanged. This reduces > the storage overhead which is precious for users of UBIFS (ie. embedded > devices). > > > HMAC Master Node > | > ' ' ' ' ' ' ' ' ' ' ' ' ' '|' ' > ' +---------------+ o ' > ' | Master Node | ' > ' +---------------+ ' Hash Index Node #1 > ' | ' | > . . . . . . . .'. . . . . . v . . . . . . . . . . . . . . . .|. . . . . > . ' +---------------+ ' o . > . ' | Index Node #1 | ' . > . ' +---------------+ ' . > . ' | ... | (fanout: 8) . > . ' ' ' ' | ' ' ' ' | ' ' ' ' ' . > . +-------+ +------+ . > . | | . > . ' ' ' ' ' v ' ' ' ' ' ' ' ' ' ' ' v ' ' ' ' ' ' ' ' ' ' ' . > . ' +---------------+ ' ' +---------------+ ' . > . ' | Index Node #2 | ' ' | Index Node #3 | ' . > . ' +---------------+ ' ' +---------------+ ' . > . ' | ... ' ' | ... | ' . > . . . ' . v . . . . . . . '. ' . . . v . . . . v . . . . . . . .' . . . > ' +-----------+ ' '+----------+ +-----------+ ' > ' | Data Node | ' '| INO Node | | DENT Node | ' > ' +-----------+ ' '+----------+ +-----------+ ' > ' o ' ' o ' > ' '|' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '|' ' > | | > Hash Index Node #2 Hash Index Node #3 When a hash covers an index node and also its children then of course this is really space efficient, but this also means that in order to read a node we always have to read all of its children. Also adding a new leaf node means rehashing all siblings. Is it really worth paying this price to save a few bytes for more hashes? I would rather suggest to add a hash per child to each index node. Sascha -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |