Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp1440405pxu; Thu, 8 Oct 2020 11:30:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqG4T1Y5FygSXj0Hh5WUVwKyArVnIq7YCwHH7PMKPIb8/QWUnryaS0Vg/DI/5pMWyhrUzb X-Received: by 2002:a17:906:649a:: with SMTP id e26mr10502217ejm.415.1602181825177; Thu, 08 Oct 2020 11:30:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602181825; cv=none; d=google.com; s=arc-20160816; b=AKa81RyQpZ6b7X6LhqVCNzA1t4XRW/6PeCvuK5wVT5hFfeX30wlRa3U6ksr4nOENFG LlW8qbX9SqsGyCfLZNJHwlHGFkfQpUnPFTHW+qRwJ8bgAoNWSOpKCXP54sqCA5OKPHwd jwn6phaSYHj+Ia4Pk9Rjl0SycEjcQJ/33SLrChIO89c069EYVyDdXABC/ptl/YcYpdqy Zs8BzDkNKVkNmP4sNcwg+gHJv7v2wghLE3TFbpHtc+6c6QYIrqFcJIlg8s56ejxKDi3M GCwk06DUdGsZAVj5o1H8SjU0qH0Q082p3Uu0KdLRSZjEM17kK52wHr9KX88EHh/xFfqL 5fBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Y0Y5ANEHX4O2TK0JPgz3k8ynUBSSnrN/f8R94XC0hzI=; b=Z92exkWQ5TaJpfjCY5Vf0Of2IWJCEoF/13hGgXVKWzUqYkiHsXW7hhn2YVJe0L3UC4 8WPbKI7rqB2Cij/1NhdHu7LKkug1HPTGwMx1OPy48UM17tDXSLtUMRx0jOnSwd7ZTVvH s8DbLixQL6JBTxtaQcBuxGj21U6R6cDa3cX4leL8cLD2/tatItxvwHfnTkZZXreqrdsk icklVwD7jt/WLHkDh/s4VbHgIT9OFYc5TCXgb5EdNmUkn0RZEIDGR4OCVO7FXxrUwccr c0RZXVRrfKpsBVITb9hOOM3H1XoODauelGjFU0S99oxgq1Irzy6Z3XCDYTHGc1N/nmer 9Q7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PwrHuqX4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si4323530ejf.306.2020.10.08.11.29.59; Thu, 08 Oct 2020 11:30:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PwrHuqX4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729649AbgJHRBq (ORCPT + 99 others); Thu, 8 Oct 2020 13:01:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:33808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728014AbgJHRBq (ORCPT ); Thu, 8 Oct 2020 13:01:46 -0400 Received: from gmail.com (unknown [104.132.1.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8145D21D7D; Thu, 8 Oct 2020 17:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602176505; bh=IPIHUhKQTR3oZFKgHCq4nhhn7A6xUIlzms8OzsEuF28=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PwrHuqX4aQSTqSAKewP9aeFPjJKYJek1v/w0zHl5hesP93nf3Qq/+9wpPpItYfTVT TywQzt6+BOMyVmqgM67Juk77N/liRX2fjSxNRftNvRQoOG94cVzvYcIo6pgq96Z/Ff zqzPxj3RQDPuMVNOFqyaD7D55D1P5KvjrNxM8oEs= Date: Thu, 8 Oct 2020 10:01:43 -0700 From: Eric Biggers To: Satya Tangirala Cc: "Theodore Y . Ts'o" , Jaegeuk Kim , Chao Yu , linux-kernel@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH 0/3] add support for metadata encryption to F2FS Message-ID: <20201008170143.GA1869638@gmail.com> References: <20201005073606.1949772-1-satyat@google.com> <20201007210040.GB1530638@gmail.com> <20201007220500.GA2544297@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201007220500.GA2544297@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 07, 2020 at 10:05:00PM +0000, Satya Tangirala wrote: > > I notice this is missing the step I suggested to include the metadata encryption > > key in the HKDF application-specific info string when deriving subkeys from the > > fscrypt master keys. > > > > The same effect could also be achieved by adding an additional level to the key > > hierarchy: each HKDF key would be derived from a fscrypt master key and the > > metadata encryption key. > > > > We need one of those, to guarantee that the file contents encryption is at least > > as strong as the "metadata encryption". > > > Yes - I didn't get around to that in the first version, but I'll add > that too in the next version. I was going to go with the first approach > before I saw your comment - is there one method you'd recommend going > with over the other? I'm not entirely sure, but I'm now leaning towards the second approach because it would avoid adding additional work (another SHA-512 block) to all later key derivations. Also it would avoid having to add a super_block argument to fscrypt_hkdf_expand(). But please ask Paul Crowley for his suggestion too. Here's a quick untested patch to consider: diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index dca254590a70..67f8ba3098d3 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -319,6 +319,7 @@ int fscrypt_init_hkdf(struct fscrypt_hkdf *hkdf, const u8 *master_key, #define HKDF_CONTEXT_DIRHASH_KEY 5 /* info=file_nonce */ #define HKDF_CONTEXT_IV_INO_LBLK_32_KEY 6 /* info=mode_num||fs_uuid */ #define HKDF_CONTEXT_INODE_HASH_KEY 7 /* info= */ +#define HKDF_CONTEXT_MIX_METADATA_KEY 8 /* info=metadata_key */ int fscrypt_hkdf_expand(const struct fscrypt_hkdf *hkdf, u8 context, const u8 *info, unsigned int infolen, @@ -600,6 +601,20 @@ int fscrypt_setup_v1_file_key(struct fscrypt_info *ci, int fscrypt_setup_v1_file_key_via_subscribed_keyrings(struct fscrypt_info *ci); +/* metadata_crypt.c */ + +#ifdef CONFIG_FS_ENCRYPTION_METADATA +int fscrypt_mix_in_metadata_key(struct super_block *sb, + struct fscrypt_master_key_secret *secret); +#else +static inline int +fscrypt_mix_in_metadata_key(struct super_block *sb, + struct fscrypt_master_key_secret *secret) +{ + return 0; +} +#endif + /* policy.c */ bool fscrypt_policies_equal(const union fscrypt_policy *policy1, diff --git a/fs/crypto/hkdf.c b/fs/crypto/hkdf.c index 0cba7928446d..61d1f0aa802e 100644 --- a/fs/crypto/hkdf.c +++ b/fs/crypto/hkdf.c @@ -174,4 +174,5 @@ int fscrypt_hkdf_expand(const struct fscrypt_hkdf *hkdf, u8 context, void fscrypt_destroy_hkdf(struct fscrypt_hkdf *hkdf) { crypto_free_shash(hkdf->hmac_tfm); + hkdf->hmac_tfm = NULL; } diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c index e74f239c4428..43453a7f77b1 100644 --- a/fs/crypto/keyring.c +++ b/fs/crypto/keyring.c @@ -494,6 +494,10 @@ static int add_master_key(struct super_block *sb, */ memzero_explicit(secret->raw, secret->size); + err = fscrypt_mix_in_metadata_key(sb, secret); + if (err) + return err; + /* Calculate the key identifier */ err = fscrypt_hkdf_expand(&secret->hkdf, HKDF_CONTEXT_KEY_IDENTIFIER, NULL, 0, diff --git a/fs/crypto/metadata_crypt.c b/fs/crypto/metadata_crypt.c index 5e16df130509..233e68c35504 100644 --- a/fs/crypto/metadata_crypt.c +++ b/fs/crypto/metadata_crypt.c @@ -13,6 +13,32 @@ #include "fscrypt_private.h" +/* TODO: add comment */ +int fscrypt_mix_in_metadata_key(struct super_block *sb, + struct fscrypt_master_key_secret *secret) +{ + u8 real_key[FSCRYPT_MAX_KEY_SIZE]; + int err; + + if (WARN_ON(secret->size > sizeof(real_key))) + return -EINVAL; + + if (!sb->s_metadata_key) + return 0; + + err = fscrypt_hkdf_expand(&secret->hkdf, HKDF_CONTEXT_MIX_METADATA_KEY, + sb->s_metadata_key->raw, + sb->s_metadata_key->size, + real_key, secret->size); + if (err) + return err; + + fscrypt_destroy_hkdf(&secret->hkdf); + err = fscrypt_init_hkdf(&secret->hkdf, real_key, secret->size); + memzero_explicit(real_key, secret->size); + return err; +} + /* TODO: mostly copied from keysetup_v1.c - maybe refactor this function */ static int fscrypt_metadata_get_key_from_id(const char *prefix, char *descriptor_hex,