Skip to content

Commit 1dc9348

Browse files
osandovkdave
authored andcommitted
btrfs: disable various operations on encrypted inodes
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 Note: The patch was taken from v5 of fscrypt patchset (https://lore.kernel.org/linux-btrfs/cover.1706116485.git.josef@toxicpanda.com/) which was handled over time by various people: Omar Sandoval, Sweet Tea Dorminy, Josef Bacik. Signed-off-by: Omar Sandoval <osandov@osandov.com> Signed-off-by: Daniel Vacek <neelx@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> [ add note ] Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 93b057a commit 1dc9348

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

fs/btrfs/inode.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,10 @@ static bool can_cow_file_range_inline(struct btrfs_inode *inode,
592592
if (size < i_size_read(&inode->vfs_inode))
593593
return false;
594594

595+
/* Encrypted file cannot be inlined. */
596+
if (IS_ENCRYPTED(&inode->vfs_inode))
597+
return false;
598+
595599
return true;
596600
}
597601

fs/btrfs/reflink.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include <linux/blkdev.h>
4+
#include <linux/fscrypt.h>
45
#include <linux/iversion.h>
56
#include "ctree.h"
67
#include "fs.h"
@@ -789,6 +790,10 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,
789790
ASSERT(inode_in->vfs_inode.i_sb == inode_out->vfs_inode.i_sb);
790791
}
791792

793+
/* Can only reflink encrypted files if both files are encrypted. */
794+
if (IS_ENCRYPTED(&inode_in->vfs_inode) != IS_ENCRYPTED(&inode_out->vfs_inode))
795+
return -EINVAL;
796+
792797
/* Don't make the dst file partly checksummed */
793798
if ((inode_in->flags & BTRFS_INODE_NODATASUM) !=
794799
(inode_out->flags & BTRFS_INODE_NODATASUM)) {

0 commit comments

Comments
 (0)