Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Btrfs: send, use the right limits for xattr names and values

We were limiting the sum of the xattr name and value lengths to PATH_MAX,
which is not correct, specially on filesystems created with btrfs-progs
v3.12 or higher, where the default leaf size is max(16384, PAGE_SIZE), or
systems with page sizes larger than 4096 bytes.

Xattrs have their own specific maximum name and value lengths, which depend
on the leaf size, therefore use these limits to be able to send xattrs with
sizes larger than PATH_MAX.

A test case for xfstests follows.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <clm@fb.com>

authored by

Filipe Manana and committed by
Chris Mason
7e3ae33e 1af56070

+23 -7
+23 -7
fs/btrfs/send.c
··· 975 975 struct btrfs_dir_item *di; 976 976 struct btrfs_key di_key; 977 977 char *buf = NULL; 978 - const int buf_len = PATH_MAX; 978 + int buf_len; 979 979 u32 name_len; 980 980 u32 data_len; 981 981 u32 cur; ··· 984 984 int slot; 985 985 int num; 986 986 u8 type; 987 + 988 + if (found_key->type == BTRFS_XATTR_ITEM_KEY) 989 + buf_len = BTRFS_MAX_XATTR_SIZE(root); 990 + else 991 + buf_len = PATH_MAX; 987 992 988 993 buf = kmalloc(buf_len, GFP_NOFS); 989 994 if (!buf) { ··· 1011 1006 type = btrfs_dir_type(eb, di); 1012 1007 btrfs_dir_item_key_to_cpu(eb, di, &di_key); 1013 1008 1014 - /* 1015 - * Path too long 1016 - */ 1017 - if (name_len + data_len > buf_len) { 1018 - ret = -ENAMETOOLONG; 1019 - goto out; 1009 + if (type == BTRFS_FT_XATTR) { 1010 + if (name_len > XATTR_NAME_MAX) { 1011 + ret = -ENAMETOOLONG; 1012 + goto out; 1013 + } 1014 + if (name_len + data_len > buf_len) { 1015 + ret = -E2BIG; 1016 + goto out; 1017 + } 1018 + } else { 1019 + /* 1020 + * Path too long 1021 + */ 1022 + if (name_len + data_len > buf_len) { 1023 + ret = -ENAMETOOLONG; 1024 + goto out; 1025 + } 1020 1026 } 1021 1027 1022 1028 read_extent_buffer(eb, buf, (unsigned long)(di + 1),