]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/btrfs-prop-fix-vanished-compression-property-after-failed-set.patch
Linux 4.14.112
[thirdparty/kernel/stable-queue.git] / queue-4.19 / btrfs-prop-fix-vanished-compression-property-after-failed-set.patch
1 From 272e5326c7837697882ce3162029ba893059b616 Mon Sep 17 00:00:00 2001
2 From: Anand Jain <anand.jain@oracle.com>
3 Date: Tue, 2 Apr 2019 18:07:40 +0800
4 Subject: btrfs: prop: fix vanished compression property after failed set
5
6 From: Anand Jain <anand.jain@oracle.com>
7
8 commit 272e5326c7837697882ce3162029ba893059b616 upstream.
9
10 The compression property resets to NULL, instead of the old value if we
11 fail to set the new compression parameter.
12
13 $ btrfs prop get /btrfs compression
14 compression=lzo
15 $ btrfs prop set /btrfs compression zli
16 ERROR: failed to set compression for /btrfs: Invalid argument
17 $ btrfs prop get /btrfs compression
18
19 This is because the compression property ->validate() is successful for
20 'zli' as the strncmp() used the length passed from the userspace.
21
22 Fix it by using the expected string length in strncmp().
23
24 Fixes: 63541927c8d1 ("Btrfs: add support for inode properties")
25 Fixes: 5c1aab1dd544 ("btrfs: Add zstd support")
26 CC: stable@vger.kernel.org # 4.14+
27 Reviewed-by: Nikolay Borisov <nborisov@suse.com>
28 Signed-off-by: Anand Jain <anand.jain@oracle.com>
29 Reviewed-by: David Sterba <dsterba@suse.com>
30 Signed-off-by: David Sterba <dsterba@suse.com>
31 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
32
33 ---
34 fs/btrfs/props.c | 6 +++---
35 1 file changed, 3 insertions(+), 3 deletions(-)
36
37 --- a/fs/btrfs/props.c
38 +++ b/fs/btrfs/props.c
39 @@ -366,11 +366,11 @@ int btrfs_subvol_inherit_props(struct bt
40
41 static int prop_compression_validate(const char *value, size_t len)
42 {
43 - if (!strncmp("lzo", value, len))
44 + if (!strncmp("lzo", value, 3))
45 return 0;
46 - else if (!strncmp("zlib", value, len))
47 + else if (!strncmp("zlib", value, 4))
48 return 0;
49 - else if (!strncmp("zstd", value, len))
50 + else if (!strncmp("zstd", value, 4))
51 return 0;
52
53 return -EINVAL;