add patch return-EFSBADCRC-on-csum-error-in-ext4_find_entry
[ext4-patch-queue.git] / forbid-encrypting-root-directory
blobbbc0eedd5702130e4591431b773852532092605c
1 ext4: forbid encrypting root directory
3 From: Eric Biggers <ebiggers@google.com>
5 Currently it's possible to encrypt all files and directories on an ext4
6 filesystem by deleting everything, including lost+found, then setting an
7 encryption policy on the root directory.  However, this is incompatible
8 with e2fsck because e2fsck expects to find, create, and/or write to
9 lost+found and does not have access to any encryption keys.  Especially
10 problematic is that if e2fsck can't find lost+found, it will create it
11 without regard for whether the root directory is encrypted.  This is
12 wrong for obvious reasons, and it causes a later run of e2fsck to
13 consider the lost+found directory entry to be corrupted.
15 Encrypting the root directory may also be of limited use because it is
16 the "all-or-nothing" use case, for which dm-crypt can be used instead.
17 (By design, encryption policies are inherited and cannot be overridden;
18 so the root directory having an encryption policy implies that all files
19 and directories on the filesystem have that same encryption policy.)
21 In any case, encrypting the root directory is broken currently and must
22 not be allowed; so start returning an error if userspace requests it.
23 For now only do this in ext4, because f2fs and ubifs do not appear to
24 have the lost+found requirement.  We could move it into
25 fscrypt_ioctl_set_policy() later if desired, though.
27 Signed-off-by: Eric Biggers <ebiggers@google.com>
28 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
29 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
30 ---
32 v2: use EPERM instead of EBUSY, and tweak commit message
34  fs/ext4/super.c | 9 +++++++++
35  1 file changed, 9 insertions(+)
37 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
38 index d37c81f327e7..d5b5c80c23f5 100644
39 --- a/fs/ext4/super.c
40 +++ b/fs/ext4/super.c
41 @@ -1145,6 +1145,15 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
42         handle_t *handle = fs_data;
43         int res, res2, retries = 0;
45 +       /*
46 +        * Encrypting the root directory is not allowed because e2fsck expects
47 +        * lost+found to exist and be unencrypted, and encrypting the root
48 +        * directory would imply encrypting the lost+found directory as well as
49 +        * the filename "lost+found" itself.
50 +        */
51 +       if (inode->i_ino == EXT4_ROOT_INO)
52 +               return -EPERM;
54         res = ext4_convert_inline_data(inode);
55         if (res)
56                 return res;
57 -- 
58 2.13.1.518.g3df882009-goog