linux-fscrypt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Cc: "Theodore Y. Ts'o" <tytso@mit.edu>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Eric Biggers <ebiggers@kernel.org>, Chris Mason <clm@fb.com>,
	David Sterba <dsterba@suse.com>,
	linux-fscrypt@vger.kernel.org, linux-btrfs@vger.kernel.org,
	kernel-team@meta.com
Subject: Re: [PATCH v2 10/14] fscrypt: revamp key removal for extent encryption
Date: Mon, 17 Jul 2023 11:18:18 -0400	[thread overview]
Message-ID: <20230717151818.GE691303@perftesting> (raw)
In-Reply-To: <c17187f7c9bb9a995ec8b428508bd62728b8de30.1688927487.git.sweettea-kernel@dorminy.me>

On Sun, Jul 09, 2023 at 02:53:43PM -0400, Sweet Tea Dorminy wrote:
> Currently, for inode encryption, once an inode is open IO will not fail
> due to lack of key until the inode is closed. Even if the key is
> removed, open inodes will continue to use the key.
> 
> For extent encryption, it's a little harder, since the extent may not be
> createdi/loaded until well after the REMOVE_KEY ioctl is called. To be
> as similar to inode based encryption as plausible, this changes key
> removal to be 'soft' for extent-based encryption, allowing new extents
> to use keys which were in use by open inodes at the time of removal;
> this hopefully follows the discussion at [1].
> 
> [1] https://lore.kernel.org/linux-fscrypt/248eac32-96cc-eb2e-85da-422a8d75a376@dorminy.me/T/#m48f43837cf98e0212de2e70aa6435320e3532d6e
> 
> Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
> ---
>  fs/crypto/fscrypt_private.h | 37 ++++++++++++++++++++++++++++-----
>  fs/crypto/keyring.c         | 41 ++++++++++++++++++++++++++++---------
>  fs/crypto/keysetup.c        | 32 ++++++++++++++++++++++++++++-
>  3 files changed, 94 insertions(+), 16 deletions(-)
> 
> diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h
> index 8bf27ceeecd1..926531597e7b 100644
> --- a/fs/crypto/fscrypt_private.h
> +++ b/fs/crypto/fscrypt_private.h
> @@ -332,6 +332,21 @@ static inline bool fscrypt_uses_extent_encryption(const struct inode *inode)
>  	return false;
>  }
>  
> +/**
> + * fscrypt_fs_uses_extent_encryption() -- whether a filesystem uses per-extent
> + *				          encryption
> + *
> + * @sb: the superblock of the filesystem in question
> + *
> + * Return: true if the fs uses per-extent fscrypt_infos, false otherwise
> + */
> +static inline bool
> +fscrypt_fs_uses_extent_encryption(const struct super_block *sb)
> +{
> +	// No filesystems currently use per-extent infos
> +	return false;

Wrong comment format.

> +}
> +
>  /**
>   * fscrypt_get_info_ino() - get the ino or ino equivalent for an info
>   *
> @@ -556,11 +571,14 @@ struct fscrypt_master_key {
>  
>  	/*
>  	 * The secret key material.  After FS_IOC_REMOVE_ENCRYPTION_KEY is
> -	 * executed, this is wiped and no new inodes can be unlocked with this
> -	 * key; however, there may still be inodes in ->mk_decrypted_inodes
> -	 * which could not be evicted.  As long as some inodes still remain,
> -	 * FS_IOC_REMOVE_ENCRYPTION_KEY can be retried, or
> -	 * FS_IOC_ADD_ENCRYPTION_KEY can add the secret again.
> +	 * executed, no new inodes can be unlocked with this key; however,
> +	 * there may still be inodes in ->mk_decrypted_inodes which could not
> +	 * be evicted. For inode-based encryption, the secret is wiped; for
> +	 * extent-based encryption, the secret is preserved while inodes still
> +	 * reference it, as they may need to create new extents using the
> +	 * secret to service IO; @soft_deleted is set to true then. As long as
> +	 * some inodes still remain, FS_IOC_REMOVE_ENCRYPTION_KEY can be
> +	 * retried, or FS_IOC_ADD_ENCRYPTION_KEY can add the secret again.
>  	 *
>  	 * While ->mk_secret is present, one ref in ->mk_active_refs is held.
>  	 *
> @@ -599,6 +617,13 @@ struct fscrypt_master_key {
>  	struct list_head	mk_decrypted_inodes;
>  	spinlock_t		mk_decrypted_inodes_lock;
>  
> +	/*
> +	 * Whether the key is unavailable to new inodes, but still available
> +	 * to new extents within decrypted inodes. Protected by
> +	 * ->mk_decrypted_inodes_lock.
> +	 */
> +	bool			mk_soft_deleted;
> +

You say this is protected by mk_decrypted_inodes_lock, but you only ever take it
when you set it to false.  It looks like it's more used to gate behavior, so the
locking is sort of inconsistent and doesn't appear to be needed?  Can you just
do READ_ONCE()/WRITE_ONCE() and it's fine?  If not you need to wrap it in the
lock where you're accessing it.  Thanks,

Josef

  reply	other threads:[~2023-07-17 15:18 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-09 18:53 [PATCH v2 00/14] fscrypt: add extent encryption Sweet Tea Dorminy
2023-07-09 18:53 ` [PATCH v2 01/14] fscrypt: factor helper for locking master key Sweet Tea Dorminy
2023-07-09 18:53 ` [PATCH v2 02/14] fscrypt: factor getting info for a specific block Sweet Tea Dorminy
2023-07-09 18:53 ` [PATCH v2 03/14] fscrypt: adjust effective lblks based on extents Sweet Tea Dorminy
2023-07-14 18:13   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 04/14] fscrypt: add a super_block pointer to fscrypt_info Sweet Tea Dorminy
2023-07-09 18:53 ` [PATCH v2 05/14] fscrypt: setup leaf inodes for extent encryption Sweet Tea Dorminy
2023-07-14 18:16   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 06/14] fscrypt: allow infos to be owned by extents Sweet Tea Dorminy
2023-07-09 18:53 ` [PATCH v2 07/14] fscrypt: notify per-extent infos if master key vanishes Sweet Tea Dorminy
2023-07-17 14:54   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 08/14] fscrypt: use an optional ino equivalent for per-extent infos Sweet Tea Dorminy
2023-07-09 18:53 ` [PATCH v2 09/14] fscrypt: move function call warning of busy inodes Sweet Tea Dorminy
2023-07-17 14:59   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 10/14] fscrypt: revamp key removal for extent encryption Sweet Tea Dorminy
2023-07-17 15:18   ` Josef Bacik [this message]
2023-07-09 18:53 ` [PATCH v2 11/14] fscrypt: add creation/usage/freeing of per-extent infos Sweet Tea Dorminy
2023-07-17 15:21   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 12/14] fscrypt: allow load/save of extent contexts Sweet Tea Dorminy
2023-07-17 15:23   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 13/14] fscrypt: save session key credentials for extent infos Sweet Tea Dorminy
2023-07-17 14:31   ` Josef Bacik
2023-07-09 18:53 ` [PATCH v2 14/14] fscrypt: update documentation for per-extent keys Sweet Tea Dorminy

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=20230717151818.GE691303@perftesting \
    --to=josef@toxicpanda.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=ebiggers@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=kernel-team@meta.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    --cc=sweettea-kernel@dorminy.me \
    --cc=tytso@mit.edu \
    /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).