Commit fea013e0 authored by Luís Henriques's avatar Luís Henriques Committed by Ilya Dryomov

ceph: use correct index when encoding client supported features

Feature bits have to be encoded into the correct locations.  This hasn't
been an issue so far because the only hole in the feature bits was in bit
10 (CEPHFS_FEATURE_RECLAIM_CLIENT), which is located in the 2nd byte.  When
adding more bits that go beyond the this 2nd byte, the bug will show up.

[xiubli: remove incorrect comment for CEPHFS_FEATURES_CLIENT_SUPPORTED]

Fixes: 9ba1e224 ("ceph: allocate the correct amount of extra bytes for the session features")
Signed-off-by: default avatarLuís Henriques <lhenriques@suse.de>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarXiubo Li <xiubli@redhat.com>
Signed-off-by: default avatarIlya Dryomov <idryomov@gmail.com>
parent 637fa738
...@@ -1220,14 +1220,17 @@ static int encode_supported_features(void **p, void *end) ...@@ -1220,14 +1220,17 @@ static int encode_supported_features(void **p, void *end)
if (count > 0) { if (count > 0) {
size_t i; size_t i;
size_t size = FEATURE_BYTES(count); size_t size = FEATURE_BYTES(count);
unsigned long bit;
if (WARN_ON_ONCE(*p + 4 + size > end)) if (WARN_ON_ONCE(*p + 4 + size > end))
return -ERANGE; return -ERANGE;
ceph_encode_32(p, size); ceph_encode_32(p, size);
memset(*p, 0, size); memset(*p, 0, size);
for (i = 0; i < count; i++) for (i = 0; i < count; i++) {
((unsigned char*)(*p))[i / 8] |= BIT(feature_bits[i] % 8); bit = feature_bits[i];
((unsigned char *)(*p))[bit / 8] |= BIT(bit % 8);
}
*p += size; *p += size;
} else { } else {
if (WARN_ON_ONCE(*p + 4 > end)) if (WARN_ON_ONCE(*p + 4 > end))
......
...@@ -33,10 +33,6 @@ enum ceph_feature_type { ...@@ -33,10 +33,6 @@ enum ceph_feature_type {
CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_METRIC_COLLECT, CEPHFS_FEATURE_MAX = CEPHFS_FEATURE_METRIC_COLLECT,
}; };
/*
* This will always have the highest feature bit value
* as the last element of the array.
*/
#define CEPHFS_FEATURES_CLIENT_SUPPORTED { \ #define CEPHFS_FEATURES_CLIENT_SUPPORTED { \
0, 1, 2, 3, 4, 5, 6, 7, \ 0, 1, 2, 3, 4, 5, 6, 7, \
CEPHFS_FEATURE_MIMIC, \ CEPHFS_FEATURE_MIMIC, \
...@@ -45,8 +41,6 @@ enum ceph_feature_type { ...@@ -45,8 +41,6 @@ enum ceph_feature_type {
CEPHFS_FEATURE_MULTI_RECONNECT, \ CEPHFS_FEATURE_MULTI_RECONNECT, \
CEPHFS_FEATURE_DELEG_INO, \ CEPHFS_FEATURE_DELEG_INO, \
CEPHFS_FEATURE_METRIC_COLLECT, \ CEPHFS_FEATURE_METRIC_COLLECT, \
\
CEPHFS_FEATURE_MAX, \
} }
#define CEPHFS_FEATURES_CLIENT_REQUIRED {} #define CEPHFS_FEATURES_CLIENT_REQUIRED {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment