diff options
author | Eric Biggers <ebiggers@google.com> | 2017-06-23 00:10:36 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2017-06-23 00:10:36 -0400 |
commit | 9ce0151a47f6fa8e4b3b35785aac0d51adbb06ca (patch) | |
tree | 53453aa170bba3595458bd1c16e949cb6ae9c6dc /fs/ext4 | |
parent | a015434480dcdbfdc188df9b3633348af745e1b1 (diff) | |
download | op-kernel-dev-9ce0151a47f6fa8e4b3b35785aac0d51adbb06ca.zip op-kernel-dev-9ce0151a47f6fa8e4b3b35785aac0d51adbb06ca.tar.gz |
ext4: forbid encrypting root directory
Currently it's possible to encrypt all files and directories on an ext4
filesystem by deleting everything, including lost+found, then setting an
encryption policy on the root directory. However, this is incompatible
with e2fsck because e2fsck expects to find, create, and/or write to
lost+found and does not have access to any encryption keys. Especially
problematic is that if e2fsck can't find lost+found, it will create it
without regard for whether the root directory is encrypted. This is
wrong for obvious reasons, and it causes a later run of e2fsck to
consider the lost+found directory entry to be corrupted.
Encrypting the root directory may also be of limited use because it is
the "all-or-nothing" use case, for which dm-crypt can be used instead.
(By design, encryption policies are inherited and cannot be overridden;
so the root directory having an encryption policy implies that all files
and directories on the filesystem have that same encryption policy.)
In any case, encrypting the root directory is broken currently and must
not be allowed; so start returning an error if userspace requests it.
For now only do this in ext4, because f2fs and ubifs do not appear to
have the lost+found requirement. We could move it into
fscrypt_ioctl_set_policy() later if desired, though.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/super.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/fs/ext4/super.c b/fs/ext4/super.c index cb9af5d..56c9718 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -1152,6 +1152,15 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len, handle_t *handle = fs_data; int res, res2, credits, retries = 0; + /* + * Encrypting the root directory is not allowed because e2fsck expects + * lost+found to exist and be unencrypted, and encrypting the root + * directory would imply encrypting the lost+found directory as well as + * the filename "lost+found" itself. + */ + if (inode->i_ino == EXT4_ROOT_INO) + return -EPERM; + res = ext4_convert_inline_data(inode); if (res) return res; |