Skip to content

Commit

Permalink
btrfs: prop: fix vanished compression property after failed set
Browse files Browse the repository at this point in the history
The compression property resets to NULL, instead of the old value if we
fail to set the new compression parameter.

  $ btrfs prop get /btrfs compression
    compression=lzo
  $ btrfs prop set /btrfs compression zli
    ERROR: failed to set compression for /btrfs: Invalid argument
  $ btrfs prop get /btrfs compression

This is because the compression property ->validate() is successful for
'zli' as the strncmp() used the length passed from the userspace.

Fix it by using the expected string length in strncmp().

Fixes: 6354192 ("Btrfs: add support for inode properties")
Fixes: 5c1aab1 ("btrfs: Add zstd support")
CC: stable@vger.kernel.org # 4.14+
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
asj authored and kdave committed Apr 4, 2019
1 parent 50398fd commit 272e532
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/btrfs/props.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ int btrfs_subvol_inherit_props(struct btrfs_trans_handle *trans,

static int prop_compression_validate(const char *value, size_t len)
{
if (!strncmp("lzo", value, len))
if (!strncmp("lzo", value, 3))
return 0;
else if (!strncmp("zlib", value, len))
else if (!strncmp("zlib", value, 4))
return 0;
else if (!strncmp("zstd", value, len))
else if (!strncmp("zstd", value, 4))
return 0;

return -EINVAL;
Expand Down

0 comments on commit 272e532

Please sign in to comment.