[PATCH v2 09/36] btrfs: disable various operations on encrypted inodes

2023年10月10日 13:41:26 -0700

From: Omar Sandoval <[email protected]>
Initially, only normal data extents will be encrypted. This change
forbids various other bits:
- allows reflinking only if both inodes have the same encryption status
- disable inline data on encrypted inodes
Signed-off-by: Omar Sandoval <[email protected]>
Signed-off-by: Sweet Tea Dorminy <[email protected]>
Signed-off-by: Josef Bacik <[email protected]>
---
 fs/btrfs/inode.c | 3 ++-
 fs/btrfs/reflink.c | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index c9317c047587..4806ff34224a 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 fabd856e5079..3c66630d87ee 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"
@@ -809,6 +810,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.41.0

Reply via email to