Commit 2d0ebb08 authored by Eric Biggers's avatar Eric Biggers Committed by Thadeu Lima de Souza Cascardo

fscrypto: require write access to mount to set encryption policy

BugLink: http://bugs.launchpad.net/bugs/1729107

commit ba63f23d upstream.

[Please apply to 4.4-stable.  Note: this was already backported, but
only to ext4; it was missed that it should go to f2fs as well.  This is
needed to make xfstest generic/395 pass on f2fs.]

Since setting an encryption policy requires writing metadata to the
filesystem, it should be guarded by mnt_want_write/mnt_drop_write.
Otherwise, a user could cause a write to a frozen or readonly
filesystem.  This was handled correctly by f2fs but not by ext4.  Make
fscrypt_process_policy() handle it rather than relying on the filesystem
to get it right.
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Acked-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent cc759ca5
...@@ -1541,12 +1541,18 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg) ...@@ -1541,12 +1541,18 @@ static int f2fs_ioc_set_encryption_policy(struct file *filp, unsigned long arg)
sizeof(policy))) sizeof(policy)))
return -EFAULT; return -EFAULT;
err = mnt_want_write_file(filp);
if (err)
return err;
mutex_lock(&inode->i_mutex); mutex_lock(&inode->i_mutex);
err = f2fs_process_policy(&policy, inode); err = f2fs_process_policy(&policy, inode);
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
mnt_drop_write_file(filp);
return err; return err;
#else #else
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment