f2fs: don't allow encrypted operations without keys
authorJaegeuk Kim <jaegeuk@kernel.org>
Thu, 29 Dec 2016 01:31:15 +0000 (17:31 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 29 Jan 2017 03:46:01 +0000 (12:46 +0900)
This patch fixes the renaming bug on encrypted filenames, which was pointed by

 (ext4: don't allow encrypted operations without keys)

Cc: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/namei.c

index 290a9d7060efef7c11148f46738215777c12a04e..0eda02253ffb434af611c1a037355914fb944d61 100644 (file)
@@ -663,6 +663,12 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
        bool is_old_inline = f2fs_has_inline_dentry(old_dir);
        int err = -ENOENT;
 
+       if ((f2fs_encrypted_inode(old_dir) &&
+                       !fscrypt_has_encryption_key(old_dir)) ||
+                       (f2fs_encrypted_inode(new_dir) &&
+                       !fscrypt_has_encryption_key(new_dir)))
+               return -ENOKEY;
+
        if ((old_dir != new_dir) && f2fs_encrypted_inode(new_dir) &&
                        !fscrypt_has_permitted_context(new_dir, old_inode)) {
                err = -EPERM;
@@ -843,6 +849,12 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
        int old_nlink = 0, new_nlink = 0;
        int err = -ENOENT;
 
+       if ((f2fs_encrypted_inode(old_dir) &&
+                       !fscrypt_has_encryption_key(old_dir)) ||
+                       (f2fs_encrypted_inode(new_dir) &&
+                       !fscrypt_has_encryption_key(new_dir)))
+               return -ENOKEY;
+
        if ((f2fs_encrypted_inode(old_dir) || f2fs_encrypted_inode(new_dir)) &&
                        (old_dir != new_dir) &&
                        (!fscrypt_has_permitted_context(new_dir, old_inode) ||