ext4: don't allow encrypted operations without keys
authorTheodore Ts'o <tytso@mit.edu>
Wed, 28 Dec 2016 05:22:52 +0000 (00:22 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 8 Jan 2017 05:58:23 +0000 (00:58 -0500)
While we allow deletes without the key, the following should not be
permitted:

# cd /vdc/encrypted-dir-without-key
# ls -l
total 4
-rw-r--r-- 1 root root   0 Dec 27 22:35 6,LKNRJsp209FbXoSvJWzB
-rw-r--r-- 1 root root 286 Dec 27 22:35 uRJ5vJh9gE7vcomYMqTAyD
# mv uRJ5vJh9gE7vcomYMqTAyD  6,LKNRJsp209FbXoSvJWzB

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
fs/ext4/namei.c

index 80b8afa4a8f9917343b22844341a2d07d361361c..bb880c326191f21d276758ec00edf709edd066cb 100644 (file)
@@ -3527,6 +3527,12 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
                        EXT4_I(old_dentry->d_inode)->i_projid)))
                return -EXDEV;
 
+       if ((ext4_encrypted_inode(old_dir) &&
+            !fscrypt_has_encryption_key(old_dir)) ||
+           (ext4_encrypted_inode(new_dir) &&
+            !fscrypt_has_encryption_key(new_dir)))
+               return -ENOKEY;
+
        retval = dquot_initialize(old.dir);
        if (retval)
                return retval;
@@ -3727,6 +3733,12 @@ static int ext4_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
        int retval;
        struct timespec ctime;
 
+       if ((ext4_encrypted_inode(old_dir) &&
+            !fscrypt_has_encryption_key(old_dir)) ||
+           (ext4_encrypted_inode(new_dir) &&
+            !fscrypt_has_encryption_key(new_dir)))
+               return -ENOKEY;
+
        if ((ext4_encrypted_inode(old_dir) ||
             ext4_encrypted_inode(new_dir)) &&
            (old_dir != new_dir) &&