f2fs crypto: sync ext4_lookup and ext4_file_open
authorJaegeuk Kim <jaegeuk@kernel.org>
Tue, 23 Feb 2016 17:21:37 +0000 (09:21 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 18 Mar 2016 04:19:42 +0000 (21:19 -0700)
This patch tries to catch up with lookup and open policies in ext4.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/dir.c
fs/f2fs/file.c
fs/f2fs/namei.c

index f82e28b121a84845f4778fb536412a961e2c47bb..479467e442ea44127fd9b84dd70347df01c9f049 100644 (file)
@@ -855,7 +855,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx)
 
        if (f2fs_encrypted_inode(inode)) {
                err = fscrypt_get_encryption_info(inode);
-               if (err)
+               if (err && err != -ENOKEY)
                        return err;
 
                err = fscrypt_fname_alloc_buffer(inode, F2FS_NAME_LEN, &fstr);
index 04ab1e4fc1dfe79de8c73f5308d9dadc2df2eb19..b41c3579ea9e859bd692127e30c1b998e4346fb9 100644 (file)
@@ -441,6 +441,7 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
 static int f2fs_file_open(struct inode *inode, struct file *filp)
 {
        int ret = generic_file_open(inode, filp);
+       struct inode *dir = filp->f_path.dentry->d_parent->d_inode;
 
        if (!ret && f2fs_encrypted_inode(inode)) {
                ret = fscrypt_get_encryption_info(inode);
@@ -449,6 +450,9 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
                if (!fscrypt_has_encryption_key(inode))
                        return -ENOKEY;
        }
+       if (f2fs_encrypted_inode(dir) &&
+                       !fscrypt_has_permitted_context(dir, inode))
+               return -EPERM;
        return ret;
 }
 
index 3bddd9f657e5517285750eca3b223b1361fdb0f3..7b07a4799952093e7ce21dd5feecee017b9bfba2 100644 (file)
@@ -262,6 +262,21 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
        int err = 0;
        unsigned int root_ino = F2FS_ROOT_INO(F2FS_I_SB(dir));
 
+       if (f2fs_encrypted_inode(dir)) {
+               int res = fscrypt_get_encryption_info(dir);
+
+               /*
+                * DCACHE_ENCRYPTED_WITH_KEY is set if the dentry is
+                * created while the directory was encrypted and we
+                * don't have access to the key.
+                */
+               if (fscrypt_has_encryption_key(dir))
+                       fscrypt_set_encrypted_dentry(dentry);
+               fscrypt_set_d_op(dentry);
+               if (res && res != -ENOKEY)
+                       return ERR_PTR(res);
+       }
+
        if (dentry->d_name.len > F2FS_NAME_LEN)
                return ERR_PTR(-ENAMETOOLONG);
 
@@ -288,6 +303,14 @@ 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)) {
+               bool nokey = f2fs_encrypted_inode(inode) &&
+                       !fscrypt_has_encryption_key(inode);
+               iput(inode);
+               return nokey ? ERR_PTR(-ENOKEY) : ERR_PTR(-EPERM);
+       }
        return d_splice_alias(inode, dentry);
 
 err_out:
This page took 0.033561 seconds and 5 git commands to generate.