Skip to content

Commit 3a19419

Browse files
ebiggersgregkh
authored andcommitted
fscrypto: lock inode while setting encryption policy
commit 8906a8223ad4909b391c5628f7991ebceda30e52 upstream. i_rwsem needs to be acquired while setting an encryption policy so that concurrent calls to FS_IOC_SET_ENCRYPTION_POLICY are correctly serialized (especially the ->get_context() + ->set_context() pair), and so that new files cannot be created in the directory during or after the ->empty_dir() check. Signed-off-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Richard Weinberger <richard@nod.at> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fd74e8d commit 3a19419

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

fs/ext4/ioctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,12 @@ long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
633633
if (err)
634634
goto encryption_policy_out;
635635

636+
mutex_lock(&inode->i_mutex);
637+
636638
err = ext4_process_policy(&policy, inode);
637639

640+
mutex_unlock(&inode->i_mutex);
641+
638642
mnt_drop_write_file(filp);
639643
encryption_policy_out:
640644
return err;

fs/f2fs/file.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1535,12 +1535,19 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
15351535
#ifdef CONFIG_F2FS_FS_ENCRYPTION
15361536
struct f2fs_encryption_policy policy;
15371537
struct inode *inode = file_inode(filp);
1538+
int err;
15381539

15391540
if (copy_from_user(&policy, (struct f2fs_encryption_policy __user *)arg,
15401541
sizeof(policy)))
15411542
return -EFAULT;
15421543

1543-
return f2fs_process_policy(&policy, inode);
1544+
mutex_lock(&inode->i_mutex);
1545+
1546+
err = f2fs_process_policy(&policy, inode);
1547+
1548+
mutex_unlock(&inode->i_mutex);
1549+
1550+
return err;
15441551
#else
15451552
return -EOPNOTSUPP;
15461553
#endif

0 commit comments

Comments
 (0)