add patch lock-inode-while-setting-encryption-policy
[ext4-patch-queue.git] / lock-inode-while-setting-encryption-policy
blob6619027b6963328d887daaadc20bcb3bd1af4fe6
1 fscrypto: lock inode while setting encryption policy
3 From: Eric Biggers <ebiggers@google.com>
5 i_rwsem needs to be acquired while setting an encryption policy so that
6 concurrent calls to FS_IOC_SET_ENCRYPTION_POLICY are correctly
7 serialized (especially the ->get_context() + ->set_context() pair), and
8 so that new files cannot be created in the directory during or after the
9 ->empty_dir() check.
11 Signed-off-by: Eric Biggers <ebiggers@google.com>
12 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 Reviewed-by: Richard Weinberger <richard@nod.at>
14 Cc: stable@vger.kernel.org
15 ---
16 Note: to be applied without conflict, this patch needs the changes from
17 v4.8-rc6.
19 ---
20  fs/crypto/policy.c | 4 ++++
21  1 file changed, 4 insertions(+)
23 diff --git a/fs/crypto/policy.c b/fs/crypto/policy.c
24 index ed115ac..6865663 100644
25 --- a/fs/crypto/policy.c
26 +++ b/fs/crypto/policy.c
27 @@ -109,6 +109,8 @@ int fscrypt_process_policy(struct file *filp,
28         if (ret)
29                 return ret;
31 +       inode_lock(inode);
33         if (!inode_has_encryption_context(inode)) {
34                 if (!S_ISDIR(inode->i_mode))
35                         ret = -EINVAL;
36 @@ -127,6 +129,8 @@ int fscrypt_process_policy(struct file *filp,
37                 ret = -EINVAL;
38         }
40 +       inode_unlock(inode);
42         mnt_drop_write_file(filp);
43         return ret;
44  }
45 -- 
46 2.8.0.rc3.226.g39d4020