1 From 7ab19625a911f7568ec85302e3aa7a64186006c8 Mon Sep 17 00:00:00 2001
2 From: David Sterba <dsterba@suse.cz>
3 Date: Wed, 4 May 2016 11:32:00 +0200
4 Subject: btrfs: add write protection to SET_FEATURES ioctl
6 From: David Sterba <dsterba@suse.cz>
8 commit 7ab19625a911f7568ec85302e3aa7a64186006c8 upstream.
10 Perform the want_write check if we get far enough to do any writes.
12 Signed-off-by: David Sterba <dsterba@suse.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 fs/btrfs/ioctl.c | 16 +++++++++++++---
17 1 file changed, 13 insertions(+), 3 deletions(-)
19 --- a/fs/btrfs/ioctl.c
20 +++ b/fs/btrfs/ioctl.c
21 @@ -5397,9 +5397,15 @@ static int btrfs_ioctl_set_features(stru
25 + ret = mnt_want_write_file(file);
29 trans = btrfs_start_transaction(root, 0);
31 - return PTR_ERR(trans);
32 + if (IS_ERR(trans)) {
33 + ret = PTR_ERR(trans);
34 + goto out_drop_write;
37 spin_lock(&root->fs_info->super_lock);
38 newflags = btrfs_super_compat_flags(super_block);
39 @@ -5418,7 +5424,11 @@ static int btrfs_ioctl_set_features(stru
40 btrfs_set_super_incompat_flags(super_block, newflags);
41 spin_unlock(&root->fs_info->super_lock);
43 - return btrfs_commit_transaction(trans, root);
44 + ret = btrfs_commit_transaction(trans, root);
46 + mnt_drop_write_file(file);
51 long btrfs_ioctl(struct file *file, unsigned int