ceph: fix up endian bug in managing feature bits
PATCH 1/1 ceph: fix up endian bug in managing feature bits
From: Eduard Shishkin <[email protected]>
In the function handle_session() variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right in encode_supported_features().
However, test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.
This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ceph/mds_client.c +2 -2
@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;
@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)
Signature · 1 line
1.8.3.1
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;
fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)
(cc'ing Zheng since he did the original patches here)
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
How about this patch instead?
--------------------------8<-----------------------------
ceph: fix endianness bug when handling MDS session feature bits
Eduard reported a problem mounting cephfs on s390 arch. The feature mask sent by the MDS is little-endian, so we need to convert it before storing and testing against it.
--- fs/ceph/mds_client.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
fs/ceph/mds_client.c +3 -5
@@ -3260,8 +3260,7 @@ static void handle_session(struct ceph_mds_session *session,void *end = p + msg->front.iov_len;struct ceph_mds_session_head *h;u32 op; -u64 seq; -unsigned long features =0 ; +u64 seq, features =0 ;int wake =0 ;bool blacklisted = false;
@@ -3280,9 +3279,8 @@ static void handle_session(struct ceph_mds_session *session, goto bad;/* version >= 3, feature bits */ ceph_decode_32_safe (&p, end, len, bad); -ceph_decode_need (&p, end, len, bad); -memcpy (&features, p,min_t (size_t, len,sizeof (features))); - p += len; +ceph_decode_64_safe (&p, end, features, bad); + p += len -sizeof (features); }mutex_lock (&mdsc->mutex);
Signature · 1 line
2.26.1
Yan, Zheng
Reviewed-byQuoted 85 lines · Jeff Layton
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)(cc'ing Zheng since he did the original patches here)
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
How about this patch instead?
--------------------------8<-----------------------------
ceph: fix endianness bug when handling MDS session feature bits
Eduard reported a problem mounting cephfs on s390 arch. The feature mask sent by the MDS is little-endian, so we need to convert it before storing and testing against it.
Reported-by Eduard Shishkin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/mds_client.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)fs/ceph/mds_client.c +1
-2@@ -3260,8 +3260,7 @@ static void handle_session(struct ceph_mds_session *session,void *end = p + msg->front.iov_len;struct ceph_mds_session_head *h;u32 op; -u64 seq; -unsigned long features =0 ; +u64 seq, features =0 ;int wake =0 ;bool blacklisted = false;
fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3284
Quoted 9 lines
fs/ceph/mds_client.c +2
-3@@ -3280,9 +3279,8 @@ static void handle_session(struct ceph_mds_session *session, goto bad;/* version >= 3, feature bits */ ceph_decode_32_safe (&p, end, len, bad); -ceph_decode_need (&p, end, len, bad); -memcpy (&features, p,min_t (size_t, len,sizeof (features))); - p += len; +ceph_decode_64_safe (&p, end, features, bad); + p += len -sizeof (features); }
this one looks better.
Quoted 6 lines
fs/ceph/mds_client.c +0
-1mutex_lock (&mdsc->mutex); --2.26.1
Quoted 46 lines · Jeff Layton
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)(cc'ing Zheng since he did the original patches here)
Quoted 8 lines
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
How about this patch instead?
Hi Jeff,
This also works. Please, apply.
Thanks,
Eduard.
Quoted 42 lines
--------------------------8<-----------------------------
ceph: fix endianness bug when handling MDS session feature bits
Eduard reported a problem mounting cephfs on s390 arch. The feature mask sent by the MDS is little-endian, so we need to convert it before storing and testing against it.
Reported-by Eduard Shishkin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/mds_client.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)fs/ceph/mds_client.c +3
-5@@ -3260,8 +3260,7 @@ static void handle_session(struct ceph_mds_session *session,void *end = p + msg->front.iov_len;struct ceph_mds_session_head *h;u32 op; -u64 seq; -unsigned long features =0 ; +u64 seq, features =0 ;int wake =0 ;bool blacklisted = false;@@ -3280,9 +3279,8 @@ static void handle_session(struct ceph_mds_session *session, goto bad;/* version >= 3, feature bits */ ceph_decode_32_safe (&p, end, len, bad); -ceph_decode_need (&p, end, len, bad); -memcpy (&features, p,min_t (size_t, len,sizeof (features))); - p += len; +ceph_decode_64_safe (&p, end, features, bad); + p += len -sizeof (features); }mutex_lock (&mdsc->mutex);
Quoted 54 lines · Eduard Shishkin
Quoted 53 lines · Jeff Layton
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)(cc'ing Zheng since he did the original patches here)
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
Quoted 9 lines
Quoted 1 line
How about this patch instead?
Hi Jeff,
This also works. Please, apply.
Thanks,
Eduard.
Thanks. Merged into ceph-client/testing branch, and should make v5.8.
Quoted 41 lines
Quoted 41 lines
--------------------------8<-----------------------------
ceph: fix endianness bug when handling MDS session feature bits
Eduard reported a problem mounting cephfs on s390 arch. The feature mask sent by the MDS is little-endian, so we need to convert it before storing and testing against it.
Reported-by Eduard Shishkin <[email protected]>Signed-off-by Jeff Layton <[email protected]>--- fs/ceph/mds_client.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)fs/ceph/mds_client.c +3
-5@@ -3260,8 +3260,7 @@ static void handle_session(struct ceph_mds_session *session,void *end = p + msg->front.iov_len;struct ceph_mds_session_head *h;u32 op; -u64 seq; -unsigned long features =0 ; +u64 seq, features =0 ;int wake =0 ;bool blacklisted = false;@@ -3280,9 +3279,8 @@ static void handle_session(struct ceph_mds_session *session, goto bad;/* version >= 3, feature bits */ ceph_decode_32_safe (&p, end, len, bad); -ceph_decode_need (&p, end, len, bad); -memcpy (&features, p,min_t (size_t, len,sizeof (features))); - p += len; +ceph_decode_64_safe (&p, end, features, bad); + p += len -sizeof (features); }mutex_lock (&mdsc->mutex);
Signature · 1 line
Jeff Layton <[email protected]>
Ilya Dryomov
maintainerQuoted 60 lines · Jeff Layton
Quoted 58 lines · Eduard Shishkin
Quoted 46 lines · Jeff Layton
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)(cc'ing Zheng since he did the original patches here)
Quoted 8 lines
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
How about this patch instead?
Hi Jeff,
Quoted 7 lines
Quoted 5 lines
This also works. Please, apply.
Thanks,
Eduard.Thanks. Merged into ceph-client/testing branch, and should make v5.8.
I think this is stable material. I'll tag it and get it queued up for 5.7-rc.
Thanks,
Ilya
Quoted 66 lines · Ilya Dryomov
Quoted 65 lines · Jeff Layton
Quoted 63 lines · Eduard Shishkin
Quoted 46 lines · Jeff Layton
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)(cc'ing Zheng since he did the original patches here)
Quoted 8 lines
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
How about this patch instead?
Hi Jeff,
This also works. Please, apply.
Thanks,
Eduard.
Quoted 6 lines
Quoted 1 line
Thanks. Merged into ceph-client/testing branch, and should make v5.8.
I think this is stable material. I'll tag it and get it queued up for 5.7-rc.
Thanks,
Yeah, that sounds reasonable.
If you're going to send up another PR, then we might want to add these bugfixes currently in the testing branch to it as well:
445645c8be5f fs/ceph:fix special error code in ceph_try_get_caps() 591681748b56 fs/ceph:fix double unlock in handle_cap_export() 0e84a1ebe161 ceph: ceph_kick_flushing_caps needs the s_mutex
I'm not sure that any of them need to go to stable though. We might also want this one though:
7b3facb61440 ceph: reset i_requested_max_size if file write is not wanted
...but it'll probably need to be reworked due to merge conflicts if we move it ahead of some of the cap handling cleanup patches (or we could just pull those in too).
Zheng, do you have an opinion here? Should 7b3facb61440 go to stable?
Thanks,
--
Jeff Layton <[email protected]>
Ilya Dryomov
maintainerQuoted 87 lines · Jeff Layton
Quoted 66 lines · Ilya Dryomov
Quoted 65 lines · Jeff Layton
Quoted 63 lines · Eduard Shishkin
Quoted 46 lines · Jeff Layton
Quoted 34 lines · On Mon, 2020-04-27 at 23:46 +0200, [email protected] wrote:
From: Eduard Shishkin <[email protected]>
In the function
handle_session()variable @features always contains little endian order of bytes. Just because the feature bits are packed bytewise from left to right inencode_supported_features().However,
test_bit(), called to check features availability, assumes the host order of bytes in that variable. This leads to problems on big endian architectures. Specifically it is impossible to mount ceph volume on s390.This patch adds conversion from little endian to the host order of bytes, thus fixing the problem.
Signed-off-by Eduard Shishkin <[email protected]>--- fs/ceph/mds_client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/ceph/mds_client.c +1
-1@@ -3252,7 +3252,7 @@ static void handle_session(struct ceph_mds_session *session,struct ceph_mds_session_head *h;u32 op;u64 seq; -unsigned long features =0 ; +__le64 features =0 ;int wake =0 ;bool blacklisted = false;fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3307
Quoted 8 lines
fs/ceph/mds_client.c +1
-1@@ -3301,7 +3301,7 @@ static void handle_session(struct ceph_mds_session *session,if (session->s_state ==CEPH_MDS_SESSION_RECONNECTING )pr_info ("mds%d reconnect success\n" , session->s_mds); session->s_state =CEPH_MDS_SESSION_OPEN ; - session->s_features = features; + session->s_features =le64_to_cpu (features);renewed_caps (mdsc, session,0 ); wake =1 ;if (mdsc->stopping)(cc'ing Zheng since he did the original patches here)
Quoted 8 lines
Thanks Eduard. The problem is real, but I think we can just do the conversion during the decode.
The feature mask words sent by the MDS are 64 bits, so if it's smaller we can assume that it's malformed. So, I don't think we need to handle the case where it's smaller than 8 bytes.
How about this patch instead?
Hi Jeff,
This also works. Please, apply.
Thanks,
Eduard.Quoted 6 lines
Quoted 1 line
Thanks. Merged into ceph-client/testing branch, and should make v5.8.
I think this is stable material. I'll tag it and get it queued up for 5.7-rc.
Thanks,
Yeah, that sounds reasonable.
If you're going to send up another PR, then we might want to add these bugfixes currently in the testing branch to it as well:
445645c8be5ffs/ceph:fix special error code inceph_try_get_caps()591681748b56fs/ceph:fix double unlock inhandle_cap_export()0e84a1ebe161ceph:ceph_kick_flushing_capsneeds thes_mutexI'm not sure that any of them need to go to stable though. We might also want this one though:
Quoted 7 lines
7b3facb61440ceph: reseti_requested_max_sizeif file write is not wanted...but it'll probably need to be reworked due to merge conflicts if we move it ahead of some of the cap handling cleanup patches (or we could just pull those in too).
Zheng, do you have an opinion here? Should
7b3facb61440go to stable?
(dropping IBM folks)
"ceph: ceph_kick_flushing_caps needs the s_mutex" doesn't apply either because cap_dirty list was moved. I don't see the urgency on these TBH.
The endianness fix and two error handling fixups from Wu are now queued up.
Thanks,
Ilya