]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.5.7/btrfs-add-write-protection-to-set_features-ioctl.patch
Linux 4.14.95
[thirdparty/kernel/stable-queue.git] / releases / 4.5.7 / btrfs-add-write-protection-to-set_features-ioctl.patch
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
5
6 From: David Sterba <dsterba@suse.cz>
7
8 commit 7ab19625a911f7568ec85302e3aa7a64186006c8 upstream.
9
10 Perform the want_write check if we get far enough to do any writes.
11
12 Signed-off-by: David Sterba <dsterba@suse.com>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
14
15 ---
16 fs/btrfs/ioctl.c | 16 +++++++++++++---
17 1 file changed, 13 insertions(+), 3 deletions(-)
18
19 --- a/fs/btrfs/ioctl.c
20 +++ b/fs/btrfs/ioctl.c
21 @@ -5397,9 +5397,15 @@ static int btrfs_ioctl_set_features(stru
22 if (ret)
23 return ret;
24
25 + ret = mnt_want_write_file(file);
26 + if (ret)
27 + return ret;
28 +
29 trans = btrfs_start_transaction(root, 0);
30 - if (IS_ERR(trans))
31 - return PTR_ERR(trans);
32 + if (IS_ERR(trans)) {
33 + ret = PTR_ERR(trans);
34 + goto out_drop_write;
35 + }
36
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);
42
43 - return btrfs_commit_transaction(trans, root);
44 + ret = btrfs_commit_transaction(trans, root);
45 +out_drop_write:
46 + mnt_drop_write_file(file);
47 +
48 + return ret;
49 }
50
51 long btrfs_ioctl(struct file *file, unsigned int