ceph: use correct index when encoding client supported features
PATCH 1/1 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.
--- fs/ceph/mds_client.c | 7 +++++-- fs/ceph/mds_client.h | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-)
I hope I got this code right. I found this issue when trying to add an extra feature bit that would go beyond bit 15 and that wasn't showing up on the MDS side.
fs/ceph/mds_client.c +5 -2
@@ -1220,14 +1220,17 @@ static int encode_supported_features(void **p, void *end)if (count >0 ) {size_t i;size_t size =FEATURE_BYTES (count); +unsigned long bit;if (WARN_ON_ONCE (*p +4 + size > end))return -ERANGE ;ceph_encode_32 (p, size);memset (*p,0 , size); -for (i =0 ; i < count; i++) - ((unsigned char *)(*p))[i /8 ] |=BIT (feature_bits[i] %8 ); +for (i =0 ; i < count; i++) { + bit = feature_bits[i]; + ((unsigned char *)(*p))[bit /8 ] |=BIT (bit %8 ); + } *p += size; }else {if (WARN_ON_ONCE (*p +4 > end))
fs/ceph/mds_client.h +0 -2
@@ -45,8 +45,6 @@ enum ceph_feature_type {CEPHFS_FEATURE_MULTI_RECONNECT , \CEPHFS_FEATURE_DELEG_INO , \CEPHFS_FEATURE_METRIC_COLLECT , \ - \ -CEPHFS_FEATURE_MAX , \ } #define CEPHFS_FEATURES_CLIENT_REQUIRED {}
Quoted 27 lines · Luís Henriques
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.Fixes 9ba1e224538a ("ceph: allocate the correct amount of extra bytes for the session features")Signed-off-by Luís Henriques <[email protected]>--- fs/ceph/mds_client.c | 7 +++++-- fs/ceph/mds_client.h | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-)I hope I got this code right. I found this issue when trying to add an extra feature bit that would go beyond bit 15 and that wasn't showing up on the MDS side.
fs/ceph/mds_client.c +1
-0@@ -1220,14 +1220,17 @@ static int encode_supported_features(void **p, void *end)if (count >0 ) {size_t i;size_t size =FEATURE_BYTES (count); +unsigned long bit;if (WARN_ON_ONCE (*p +4 + size > end))
fs/ceph/mds_client.c static int encode_supported_features(void **p, void *end) · line 1233
Quoted 10 lines
fs/ceph/mds_client.c +4
-2return -ERANGE ;ceph_encode_32 (p, size);memset (*p,0 , size); -for (i =0 ; i < count; i++) - ((unsigned char *)(*p))[i /8 ] |=BIT (feature_bits[i] %8 ); +for (i =0 ; i < count; i++) { + bit = feature_bits[i]; + ((unsigned char *)(*p))[bit /8 ] |=BIT (bit %8 ); + }
I wish we could just use __set_bit/__clear_bit here. It would be a lot easier to reason this out. Your logic looks correct to me though.
Quoted 8 lines
fs/ceph/mds_client.c +0
-0*p += size; }else {if (WARN_ON_ONCE (*p +4 > end))fs/ceph/mds_client.h +0
-0
fs/ceph/mds_client.h enum ceph_feature_type { · line 50
Quoted 8 lines
fs/ceph/mds_client.h +0
-2@@ -45,8 +45,6 @@ enum ceph_feature_type {CEPHFS_FEATURE_MULTI_RECONNECT , \CEPHFS_FEATURE_DELEG_INO , \CEPHFS_FEATURE_METRIC_COLLECT , \ - \ -CEPHFS_FEATURE_MAX , \ } #define CEPHFS_FEATURES_CLIENT_REQUIRED {}
Quoted 45 lines · Luís Henriques
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.Fixes 9ba1e224538a ("ceph: allocate the correct amount of extra bytes for the session features")Signed-off-by Luís Henriques <[email protected]>--- fs/ceph/mds_client.c | 7 +++++-- fs/ceph/mds_client.h | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-)I hope I got this code right. I found this issue when trying to add an extra feature bit that would go beyond bit 15 and that wasn't showing up on the MDS side.
fs/ceph/mds_client.c +5
-2@@ -1220,14 +1220,17 @@ static int encode_supported_features(void **p, void *end)if (count >0 ) {size_t i;size_t size =FEATURE_BYTES (count); +unsigned long bit;if (WARN_ON_ONCE (*p +4 + size > end))return -ERANGE ;ceph_encode_32 (p, size);memset (*p,0 , size); -for (i =0 ; i < count; i++) - ((unsigned char *)(*p))[i /8 ] |=BIT (feature_bits[i] %8 ); +for (i =0 ; i < count; i++) { + bit = feature_bits[i]; + ((unsigned char *)(*p))[bit /8 ] |=BIT (bit %8 ); + } *p += size; }else {if (WARN_ON_ONCE (*p +4 > end))fs/ceph/mds_client.h +0
-0
fs/ceph/mds_client.h enum ceph_feature_type { · line 50
Quoted 8 lines
fs/ceph/mds_client.h +0
-2@@ -45,8 +45,6 @@ enum ceph_feature_type {CEPHFS_FEATURE_MULTI_RECONNECT , \CEPHFS_FEATURE_DELEG_INO , \CEPHFS_FEATURE_METRIC_COLLECT , \ - \ -CEPHFS_FEATURE_MAX , \ } #define CEPHFS_FEATURES_CLIENT_REQUIRED {}
LGTM. Just one small fix in the comment, since you have removed the 'CEPHFS_FEATURE_MAX', which makes no sense any more:
fs/ceph/mds_client.h +0 -0
@@ -33,10 +33,6 @@ enum ceph_feature_type {
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 { \
0, 1, 2, 3, 4, 5, 6, 7, \
CEPHFS_FEATURE_MIMIC, \
Merged into the testing branch.
Thanks Luis.
-- Xiubo
Quoted 49 lines · Xiubo Li
Quoted 48 lines · Luís Henriques
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.Fixes 9ba1e224538a ("ceph: allocate the correct amount of extra bytes for the session features")Signed-off-by Luís Henriques <[email protected]>--- fs/ceph/mds_client.c | 7 +++++-- fs/ceph/mds_client.h | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-)I hope I got this code right. I found this issue when trying to add an extra feature bit that would go beyond bit 15 and that wasn't showing up on the MDS side.
fs/ceph/mds_client.c +5
-2@@ -1220,14 +1220,17 @@ static int encode_supported_features(void **p, void *end)if (count >0 ) {size_t i;size_t size =FEATURE_BYTES (count); +unsigned long bit;if (WARN_ON_ONCE (*p +4 + size > end))return -ERANGE ;ceph_encode_32 (p, size);memset (*p,0 , size); -for (i =0 ; i < count; i++) - ((unsigned char *)(*p))[i /8 ] |=BIT (feature_bits[i] %8 ); +for (i =0 ; i < count; i++) { + bit = feature_bits[i]; + ((unsigned char *)(*p))[bit /8 ] |=BIT (bit %8 ); + } *p += size; }else {if (WARN_ON_ONCE (*p +4 > end))fs/ceph/mds_client.h +0
-0@@ -45,8 +45,6 @@ enum ceph_feature_type {CEPHFS_FEATURE_MULTI_RECONNECT , \CEPHFS_FEATURE_DELEG_INO , \ CEPHFS_FEATURE_METRIC_COLLECT, \
Quoted 8 lines
fs/ceph/mds_client.h enum ceph_feature_type { · line 50
Quoted 5 lines
fs/ceph/mds_client.h +0
-2- \ - CEPHFS_FEATURE_MAX, \ }#define CEPHFS_FEATURES_CLIENT_REQUIRED {}LGTM. Just one small fix in the comment, since you have removed the '
CEPHFS_FEATURE_MAX', which makes no sense any more:
Ah, yeah. I missed that. Thanks!
Cheers,
Signature · 1 line
Luís
Quoted 22 lines
fs/ceph/mds_client.h +0
-4@@ -33,10 +33,6 @@ enum ceph_feature_type { 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 { \ 0, 1, 2, 3, 4, 5, 6, 7, \ CEPHFS_FEATURE_MIMIC, \Merged into the testing branch.
Thanks Luis.
-- Xiubo