linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH v3 02/34] fscrypt: conditionally don't wipe mk secret until the last active user is done
Date: Mon, 16 Oct 2023 14:21:09 -0400	[thread overview]
Message-ID: <ec8bcd516777519ae25c23e66aae79a93e8c7e5e.1697480198.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1697480198.git.josef@toxicpanda.com>

Previously we were wiping the master key secret when we do
FS_IOC_REMOVE_ENCRYPTION_KEY, and then using the fact that it was
cleared as the mechanism from keeping new users from being setup.  This
works with inode based encryption, as the per-inode key is derived at
setup time, so the secret disappearing doesn't affect any currently open
files from being able to continue working.

However for extent based encryption we do our key derivation at page
writeout and readpage time, which means we need the master key secret to
be available while we still have our file open.

Since the master key lifetime is controlled by a flag, move the clearing
of the secret to the mk_active_users cleanup stage if we have extent
based encryption enabled on this super block.  This counter represents
the actively open files that still exist on the file system, and thus
should still be able to operate normally.  Once the last user is closed
we can clear the secret.  Until then no new users are allowed, and this
allows currently open files to continue to operate until they're closed.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/crypto/keyring.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c
index f34a9b0b9e92..acf5e7b3196d 100644
--- a/fs/crypto/keyring.c
+++ b/fs/crypto/keyring.c
@@ -105,6 +105,14 @@ void fscrypt_put_master_key_activeref(struct super_block *sb,
 	WARN_ON_ONCE(mk->mk_present);
 	WARN_ON_ONCE(!list_empty(&mk->mk_decrypted_inodes));
 
+	/* We can't wipe the master key secret until the last activeref is
+	 * dropped on the master key with per-extent encryption since the key
+	 * derivation continues to happen as long as there are active refs.
+	 * Wipe it here now that we're done using it.
+	 */
+	if (sb->s_cop->has_per_extent_encryption)
+		wipe_master_key_secret(&mk->mk_secret);
+
 	for (i = 0; i <= FSCRYPT_MODE_MAX; i++) {
 		fscrypt_destroy_prepared_key(
 				sb, &mk->mk_direct_keys[i]);
@@ -129,7 +137,15 @@ static void fscrypt_initiate_key_removal(struct super_block *sb,
 					 struct fscrypt_master_key *mk)
 {
 	WRITE_ONCE(mk->mk_present, false);
-	wipe_master_key_secret(&mk->mk_secret);
+
+	/*
+	 * Per-extent encryption requires the master key to stick around until
+	 * writeout has completed as we derive the per-extent keys at writeout
+	 * time.  Once the activeref drops to 0 we'll wipe the master secret
+	 * key.
+	 */
+	if (!sb->s_cop->has_per_extent_encryption)
+		wipe_master_key_secret(&mk->mk_secret);
 	fscrypt_put_master_key_activeref(sb, mk);
 }
 
-- 
2.41.0


  parent reply	other threads:[~2023-10-16 18:22 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-16 18:21 [PATCH v3 00/34] btrfs: add fscrypt support Josef Bacik
2023-10-16 18:21 ` [PATCH v3 01/34] fscrypt: add per-extent encryption support Josef Bacik
2023-10-16 18:21 ` Josef Bacik [this message]
2023-10-16 18:21 ` [PATCH v3 03/34] blk-crypto: add a process bio callback Josef Bacik
2023-10-16 18:21 ` [PATCH v3 04/34] fscrypt: expose fscrypt_nokey_name Josef Bacik
2023-10-16 18:21 ` [PATCH v3 05/34] fscrypt: add documentation about extent encryption Josef Bacik
2023-10-16 18:21 ` [PATCH v3 06/34] btrfs: add infrastructure for safe em freeing Josef Bacik
2023-10-16 18:21 ` [PATCH v3 07/34] btrfs: disable various operations on encrypted inodes Josef Bacik
2023-10-16 18:21 ` [PATCH v3 08/34] btrfs: disable verity " Josef Bacik
2023-10-16 18:21 ` [PATCH v3 09/34] btrfs: start using fscrypt hooks Josef Bacik
2023-10-16 18:21 ` [PATCH v3 10/34] btrfs: add inode encryption contexts Josef Bacik
2023-10-16 18:21 ` [PATCH v3 11/34] btrfs: add new FEATURE_INCOMPAT_ENCRYPT flag Josef Bacik
2023-10-16 18:21 ` [PATCH v3 12/34] btrfs: adapt readdir for encrypted and nokey names Josef Bacik
2023-10-16 18:21 ` [PATCH v3 13/34] btrfs: handle " Josef Bacik
2023-10-16 18:21 ` [PATCH v3 14/34] btrfs: implement fscrypt ioctls Josef Bacik
2023-10-16 18:21 ` [PATCH v3 15/34] btrfs: add encryption to CONFIG_BTRFS_DEBUG Josef Bacik
2023-10-16 18:21 ` [PATCH v3 16/34] btrfs: add get_devices hook for fscrypt Josef Bacik
2023-10-16 18:21 ` [PATCH v3 17/34] btrfs: turn on inlinecrypt mount option for encrypt Josef Bacik
2023-10-16 18:21 ` [PATCH v3 18/34] btrfs: set file extent encryption excplicitly Josef Bacik
2023-10-16 18:21 ` [PATCH v3 19/34] btrfs: add fscrypt_info and encryption_type to extent_map Josef Bacik
2023-10-16 18:21 ` [PATCH v3 20/34] btrfs: add fscrypt_info and encryption_type to ordered_extent Josef Bacik
2023-10-16 18:21 ` [PATCH v3 21/34] btrfs: plumb through setting the fscrypt_info for ordered extents Josef Bacik
2023-10-16 18:21 ` [PATCH v3 22/34] btrfs: populate the ordered_extent with the fscrypt context Josef Bacik
2023-10-16 18:21 ` [PATCH v3 23/34] btrfs: keep track of fscrypt info and orig_start for dio reads Josef Bacik
2023-10-16 18:21 ` [PATCH v3 24/34] btrfs: add an optional encryption context to the end of file extents Josef Bacik
2023-10-16 18:21 ` [PATCH v3 25/34] btrfs: explicitly track file extent length for replace and drop Josef Bacik
2023-10-16 18:21 ` [PATCH v3 26/34] btrfs: pass through fscrypt_extent_info to the file extent helpers Josef Bacik
2023-10-16 18:21 ` [PATCH v3 27/34] btrfs: pass the fscrypt_info through the replace extent infrastructure Josef Bacik
2023-10-16 18:21 ` [PATCH v3 28/34] btrfs: implement the fscrypt extent encryption hooks Josef Bacik
2023-10-16 18:21 ` [PATCH v3 29/34] btrfs: setup fscrypt_extent_info for new extents Josef Bacik
2023-10-16 18:21 ` [PATCH v3 30/34] btrfs: populate ordered_extent with the orig offset Josef Bacik
2023-10-16 18:21 ` [PATCH v3 31/34] btrfs: set the bio fscrypt context when applicable Josef Bacik
2023-10-16 18:21 ` [PATCH v3 32/34] btrfs: add a bio argument to btrfs_csum_one_bio Josef Bacik
2023-10-16 18:21 ` [PATCH v3 33/34] btrfs: add orig_logical to btrfs_bio Josef Bacik
2023-10-16 18:21 ` [PATCH v3 34/34] btrfs: implement process_bio cb for fscrypt Josef Bacik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ec8bcd516777519ae25c23e66aae79a93e8c7e5e.1697480198.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).