Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1779461imm; Fri, 7 Sep 2018 06:07:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaXnSSg3Hz4i1+rhOpyu9kyYZbp7hqgrba3sPZIWCoRxjYap0eGnkKxBUoGHZcrsUk//hEf X-Received: by 2002:a17:902:6b89:: with SMTP id p9-v6mr7791684plk.272.1536325673437; Fri, 07 Sep 2018 06:07:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536325673; cv=none; d=google.com; s=arc-20160816; b=jmLXUb/Vfeizs/N6vbk/LeM2DrWw/nv8HA1FFDWbsntwzK36deh8zGFoD5HiEVrltt FxqeLRUrKc8VhqQodxlk9eqHtTkidZIJL8lCnBlGN93jxQfOPSmL9CqMW/G/mu1Vg3n8 BpfoVyiKadZiRSwVLtQf4CFZ1LJ+JCDoV4cvicRYDrzs6siUuOGtHUSRLtTrqyyF1Ote 5JTJvr8QpNhHzIJLXMsBMtmvNdASDRzpHppvQZ7jByU2fGT+DWqFuUsmwaxRAIC706Tm YyXlpX7IgGL8EzDWNeARXpqgdAHlJTYogELJNcF7rN4GPfKPlSWtWTjqhGz9ExlZvNUh 6CYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=xVbKEE1hdDTsRN3z2jwF28dG/eEeKiII3NLBZK6Zixg=; b=gwliWv1BLnof3w9rR2vLBwmn6JglcLPcP1AyWKMxoDqB7FgFjoz1OfFm9zeao02Cvn JYrxIL9LaGEw8z7lql0jIEQerykscuvzWGQ9MIFQAsUn3iLTrrRScrCsj91iVqxjjwJK jwdmeWm+b44/rkgfAFtT0+d/O3GEUW94J4jm1WsDjcsKttbwABsl7/8a4F6hQEptO6pQ 4PN7NsF2gFzpB5PE61X48Z0MgdPdkQBefYNHRC323/UcRG9wkzd7tA05wieVeshqebbB jIC6zzKlXUlGaFGFZS/bwVLU/1wqt7eTyv4CyIn1hWmq6gNqn3gbOPa0oU87tqIAgdn9 iEQg== 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 s65-v6si8519319pfb.271.2018.09.07.06.07.38; Fri, 07 Sep 2018 06:07:53 -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 S1729525AbeIGRV4 (ORCPT + 99 others); Fri, 7 Sep 2018 13:21:56 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:57939 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728103AbeIGRTc (ORCPT ); Fri, 7 Sep 2018 13:19:32 -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-0007bl-79; 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-00061W-9r; 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 v2 00/25] UBIFS authentication support Date: Fri, 7 Sep 2018 14:36:21 +0200 Message-Id: <20180907123646.12688-1-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.18.0 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 Hi all, This patchset introduces UBIFS authentication support. With authentication enabled UBIFS is fully protected against offline changes. This is done by hashing the different parts of UBIFS and protecting the toplevel hashes with HMACs. The parts that are protected are: * the index tree * the journal * the LPT * the master nodes * the superblock node A detailed overview how the different parts are authenticated can be found here: https://github.com/sigma-star/ubifs-authentication/blob/master/ubifs-authentication-whitepaper.md However, some details still had to be changed, so an updated version of that document is part of this patchset. Usage: ====== First add an authentication key to the kernel keyring. It must be of type 'logon'. The description can be freely chosen, it must be passed as mount option later: # keyctl add logon ubifs:foo 12345678901234567890123456789012 @s Attach the UBI device and mount with auth_key=$description and auth_hash_name=$algo: # mount -t ubifs /dev/ubi0_0 -o auth_key=ubifs:foo,auth_hash_name=sha256 /mnt/ This mounts the UBIFS in authenticated mode. The hash algorithm can be freely chosen from include/uapi/linux/hash_info.h as long as the digest is at maximum 64 bytes which is the space we reserved in the UBIFS structures. We always use the same algorithms for creating HMACs, so using sha256 for hashing means that we also use hmac(sha256) for creating authentication data. When the authentication_key mount option is given, a UBIFS image which can be authenticated with that key is mandatory, no unauthenticated image will be accepted. Likewise, when the option is not given, no authenticated image can be accepted since that couldn't be authenticated. We could skip authentication in this case, but we couldn't create any valid HMACs when writing new data. We could make it an option to mount in readonly mode for debugging purposes when we do not have a key (or we already know that parts of the UBIFS image are corrupted), but that is not implemented yet. Offline signed images ===================== Currently UBIFS authentication is only supported on the default filesystem the kernel creates when an empty UBI volume is found. Support for offline signed images is in the makings. Preliminary patches for the Kernel and mtd-utils are ready and can be shared on request, otherwise I'll continue on them once this basic patchset is ready and merged. Testing ======= I've gone through various tests including powercut tests over the weekend and running xfstests. It is tested on real hardware (i.MX6 based) on a 2k page NAND and in nandsim on a simulated 512b page NAND in big LPT mode. Basic testing has been done with all chk_* ubifs flags set to 1, lockdep enabled. This patchset is based on v4.19-rc2 and can be obtained here: git://git.pengutronix.de/sha/linux ubifs-authentication-v2 Changes since v1: - rebase onto v4.19-rc2 - Add missing ubifs_copy_hash() in make_idx_node to make in-the-gaps method work with authentication - Return error codes from all crypto related functions and forward error - Remove VLAs - rename c->superblock to c->sup_node - use UBIFS_HASH_ARR_SZ for array sizes. UBIFS_HASH_ARR_SZ is set to 0 for non authenticated fs and to UBIFS_MAX_HASH_LEN for authenticated fs - Add common bad-hash report handler - fix various comments - Add missing ubifs_add_dirt() in the garbage collectors move_nodes() function - add ubifs_add_auth_dirt() to add dirt for an authentication node /Sascha Sascha Hauer (25): ARM: imx_v6_v7_defconfig: update ubifs: refactor create_default_filesystem() ubifs: pass ubifs_zbranch to try_read_node() ubifs: pass ubifs_zbranch to read_znode() ubifs: export pnode_lookup as ubifs_pnode_lookup ubifs: implement ubifs_lpt_lookup using ubifs_pnode_lookup ubifs: drop write_node ubifs: Store read superblock node ubifs: Format changes for authentication support ubifs: add separate functions to init/crc a node ubifs: add helper functions for authentication support ubifs: Create functions to embed a HMAC in a node ubifs: Add hashes to the tree node cache ubifs: authentication: Add hashes to index nodes ubifs: Add authentication nodes to journal ubifs: Add auth nodes to garbage collector journal head ubifs: authenticate replayed journal ubifs: authentication: authenticate LPT ubfis: authentication: authenticate master node ubifs: Create hash for default LPT ubifs: authentication: Authenticate super block node ubifs: Add hashes and HMACs to default filesystem ubifs: do not update inode size in-place in authenticated mode ubifs: Enable authentication support Documentation: ubifs: Add authentication whitepaper .../filesystems/ubifs-authentication.md | 426 +++++++++++++++ Documentation/filesystems/ubifs.txt | 7 + arch/arm/configs/imx_v6_v7_defconfig | 15 +- fs/ubifs/Kconfig | 11 + fs/ubifs/Makefile | 1 + fs/ubifs/auth.c | 502 ++++++++++++++++++ fs/ubifs/debug.c | 6 + fs/ubifs/gc.c | 49 +- fs/ubifs/io.c | 110 +++- fs/ubifs/journal.c | 289 +++++++--- fs/ubifs/log.c | 24 + fs/ubifs/lpt.c | 184 ++++++- fs/ubifs/lpt_commit.c | 44 +- fs/ubifs/master.c | 64 ++- fs/ubifs/misc.h | 5 +- fs/ubifs/recovery.c | 120 +++-- fs/ubifs/replay.c | 177 +++++- fs/ubifs/sb.c | 207 +++++--- fs/ubifs/super.c | 91 +++- fs/ubifs/tnc.c | 36 +- fs/ubifs/tnc_commit.c | 27 + fs/ubifs/tnc_misc.c | 26 +- fs/ubifs/ubifs-media.h | 46 +- fs/ubifs/ubifs.h | 253 ++++++++- 24 files changed, 2422 insertions(+), 298 deletions(-) create mode 100644 Documentation/filesystems/ubifs-authentication.md create mode 100644 fs/ubifs/auth.c -- 2.18.0