Merge tag 'for-f2fs-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk...
[platform/kernel/linux-starfive.git] / fs / f2fs / namei.c
index 11cabca..98f00a3 100644 (file)
@@ -321,9 +321,9 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
                if (err)
                        goto err_out;
        }
-       if (!IS_ERR(inode) && f2fs_encrypted_inode(dir) &&
-                       (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
-                       !fscrypt_has_permitted_context(dir, inode)) {
+       if (f2fs_encrypted_inode(dir) &&
+           (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)) &&
+           !fscrypt_has_permitted_context(dir, inode)) {
                bool nokey = f2fs_encrypted_inode(inode) &&
                        !fscrypt_has_encryption_key(inode);
                err = nokey ? -ENOKEY : -EPERM;
@@ -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) ||