From: Boris Burkov <boris@bur.io>
To: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
Eric Biggers <ebiggers@kernel.org>,
"Theodore Y. Ts'o" <tytso@mit.edu>,
Jaegeuk Kim <jaegeuk@kernel.org>,
kernel-team@meta.com, linux-btrfs@vger.kernel.org,
linux-fscrypt@vger.kernel.org,
Omar Sandoval <osandov@osandov.com>
Subject: Re: [PATCH v1 01/17] btrfs: disable various operations on encrypted inodes
Date: Fri, 7 Jul 2023 16:36:05 -0700 [thread overview]
Message-ID: <20230707233605.GB2579580@zen> (raw)
In-Reply-To: <e7785ffe237e581a7ba7e45d2724fca4d8fa1470.1687988380.git.sweettea-kernel@dorminy.me>
On Wed, Jun 28, 2023 at 08:35:24PM -0400, Sweet Tea Dorminy wrote:
> From: Omar Sandoval <osandov@osandov.com>
>
> Initially, only normal data extents, using the normal (non-direct) IO
> path, will be encrypted. This change forbids various other bits:
> - allows reflinking only if both inodes have the same encryption status
> - disables direct IO on encrypted inodes
> - disable inline data on encrypted inodes
>
> Signed-off-by: Omar Sandoval <osandov@osandov.com>
> Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>
> ---
> fs/btrfs/file.c | 4 ++--
> fs/btrfs/inode.c | 3 ++-
> fs/btrfs/reflink.c | 7 +++++++
> 3 files changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
> index 392bc7d512a0..354962a7dd72 100644
> --- a/fs/btrfs/file.c
> +++ b/fs/btrfs/file.c
> @@ -1502,7 +1502,7 @@ static ssize_t btrfs_direct_write(struct kiocb *iocb, struct iov_iter *from)
> goto relock;
> }
>
> - if (check_direct_IO(fs_info, from, pos)) {
> + if (IS_ENCRYPTED(inode) || check_direct_IO(fs_info, from, pos)) {
> btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
> goto buffered;
> }
> @@ -3741,7 +3741,7 @@ static ssize_t btrfs_direct_read(struct kiocb *iocb, struct iov_iter *to)
> ssize_t read = 0;
> ssize_t ret;
>
> - if (fsverity_active(inode))
> + if (IS_ENCRYPTED(inode) || fsverity_active(inode))
What's different about fscrypt vs fsverity that makes the inode flag a
good check for encryption while verity relies on the presence of the
extra context metadata?
Is the enable model not subject to the same race where S_VERITY gets set
ahead of actually storing the verity info/item?
I think it's fine for these "skip" cases, but I imagine if we have cases
of "I want a fully ready encrypted file" the verity-style check could be
better?
> return 0;
>
> if (check_direct_read(btrfs_sb(inode->i_sb), to, iocb->ki_pos))
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index dbbb67293e34..48eadc4f187f 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -630,7 +630,8 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 size,
> * compressed) data fits in a leaf and the configured maximum inline
> * size.
> */
> - if (size < i_size_read(&inode->vfs_inode) ||
> + if (IS_ENCRYPTED(&inode->vfs_inode) ||
> + size < i_size_read(&inode->vfs_inode) ||
> size > fs_info->sectorsize ||
> data_len > BTRFS_MAX_INLINE_DATA_SIZE(fs_info) ||
> data_len > fs_info->max_inline)
> diff --git a/fs/btrfs/reflink.c b/fs/btrfs/reflink.c
> index 0474bbe39da7..ad722f495c9b 100644
> --- a/fs/btrfs/reflink.c
> +++ b/fs/btrfs/reflink.c
> @@ -1,6 +1,7 @@
> // SPDX-License-Identifier: GPL-2.0
>
> #include <linux/blkdev.h>
> +#include <linux/fscrypt.h>
> #include <linux/iversion.h>
> #include "ctree.h"
> #include "fs.h"
> @@ -811,6 +812,12 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,
> ASSERT(inode_in->i_sb == inode_out->i_sb);
> }
>
> + /*
> + * Can only reflink encrypted files if both files are encrypted.
> + */
> + if (IS_ENCRYPTED(inode_in) != IS_ENCRYPTED(inode_out))
> + return -EINVAL;
> +
> /* Don't make the dst file partly checksummed */
> if ((BTRFS_I(inode_in)->flags & BTRFS_INODE_NODATASUM) !=
> (BTRFS_I(inode_out)->flags & BTRFS_INODE_NODATASUM)) {
> --
> 2.40.1
>
next prev parent reply other threads:[~2023-07-07 23:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 0:35 [PATCH v1 00/17] btrfs: add encryption feature Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 01/17] btrfs: disable various operations on encrypted inodes Sweet Tea Dorminy
2023-07-07 23:36 ` Boris Burkov [this message]
2023-07-17 1:42 ` Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 02/17] btrfs: disable verity " Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 03/17] fscrypt: expose fscrypt_nokey_name Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 04/17] btrfs: start using fscrypt hooks Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 05/17] btrfs: add inode encryption contexts Sweet Tea Dorminy
2023-07-07 23:32 ` Boris Burkov
2023-07-17 1:43 ` Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 06/17] btrfs: add new FEATURE_INCOMPAT_ENCRYPT flag Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 07/17] btrfs: adapt readdir for encrypted and nokey names Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 08/17] btrfs: use correct name hash for " Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 09/17] btrfs: implement fscrypt ioctls Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 10/17] btrfs: add encryption to CONFIG_BTRFS_DEBUG Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 11/17] btrfs: add get_devices hook for fscrypt Sweet Tea Dorminy
2023-06-29 13:20 ` Luís Henriques
2023-06-29 0:35 ` [PATCH v1 12/17] btrfs: turn on inlinecrypt mount option for encrypt Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 13/17] btrfs: turn on the encryption ioctls Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 14/17] btrfs: create and free extent fscrypt_infos Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 15/17] btrfs: start tracking extent encryption context info Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 16/17] btrfs: explicitly track file extent length and encryption Sweet Tea Dorminy
2023-06-29 0:35 ` [PATCH v1 17/17] btrfs: save and load fscrypt extent contexts 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=20230707233605.GB2579580@zen \
--to=boris@bur.io \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=ebiggers@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kernel-team@meta.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fscrypt@vger.kernel.org \
--cc=osandov@osandov.com \
--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