f2fs crypto: do not set encryption policy for non-directory by ioctl
authorChao Yu <chao2.yu@samsung.com>
Wed, 27 May 2015 07:27:49 +0000 (15:27 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 1 Jun 2015 23:21:07 +0000 (16:21 -0700)
Encryption policy should only be set to an empty directory through ioctl,
This patch add a judgement condition to verify type of the target inode
to avoid incorrectly configuring for non-directory.

Additionally, remove unneeded inline data conversion since regular or symlink
file should not be processed here.

Signed-off-by: Chao Yu <chao2.yu@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/crypto_policy.c
fs/f2fs/file.c

index 30b0b73d42000389daead63fd322d1737afecc1e..d4a96af513c22f28ea1242496286d4ff1a606567 100644 (file)
@@ -92,6 +92,9 @@ int f2fs_process_policy(const struct f2fs_encryption_policy *policy,
        if (policy->version != 0)
                return -EINVAL;
 
+       if (!S_ISDIR(inode->i_mode))
+               return -EINVAL;
+
        if (!f2fs_inode_has_encryption_context(inode)) {
                if (!f2fs_empty_dir(inode))
                        return -ENOTEMPTY;
index cb0d6b68020a1610e265daaf6b463aa56bf5a68e..6b4ba7429dbaf206b3fda44c86dc520e927a1f0b 100644 (file)
@@ -1395,12 +1395,6 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
                                sizeof(policy)))
                return -EFAULT;
 
-       if (f2fs_has_inline_data(inode)) {
-               int ret = f2fs_convert_inline_inode(inode);
-               if (ret)
-                       return ret;
-       }
-
        return f2fs_process_policy(&policy, inode);
 #else
        return -EOPNOTSUPP;