Skip to contentSkip to conversation

ceph: fix incorrectly assigning random values to peer's members

PATCH In review Xiubo Li 3 participants 4 messages Jun 6, 2022 Ceph client

lore
Share & tools
lore

Xiubo Li

author
#0 lore raw

PATCH 1/1 ceph: fix incorrectly assigning random values to peer's members

For export the peer is empty in ceph.

URL: https://tracker.ceph.com/issues/55857

---
 fs/ceph/caps.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
fs/ceph/caps.c +5 -10
index 0a48bf829671..8efa46ff4282 100644
@@ -4127,16 +4127,11 @@ void ceph_handle_caps(struct ceph_mds_session *session,
 		p += flock_len;
 	}
 
-	if (msg_version >= 3) {
-		if (op == CEPH_CAP_OP_IMPORT) {
-			if (p + sizeof(*peer) > end)
-				goto bad;
-			peer = p;
-			p += sizeof(*peer);
-		} else if (op == CEPH_CAP_OP_EXPORT) {
-			/* recorded in unused fields */
-			peer = (void *)&h->size;
-		}
+	if (msg_version >= 3 && op == CEPH_CAP_OP_IMPORT) {
+		if (p + sizeof(*peer) > end)
+			goto bad;
+		peer = p;
+		p += sizeof(*peer);
 	}
 
 	if (msg_version >= 4) {
Signature · 1 line
2.36.0.rc1
#1 lore raw
Quoted 38 lines · Xiubo Li

For export the peer is empty in ceph.

URL: https://tracker.ceph.com/issues/55857

---
 fs/ceph/caps.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
fs/ceph/caps.c +5 -10
index 0a48bf829671..8efa46ff4282 100644
@@ -4127,16 +4127,11 @@ void ceph_handle_caps(struct ceph_mds_session *session,
 		p += flock_len;
 	}
 
-	if (msg_version >= 3) {
-		if (op == CEPH_CAP_OP_IMPORT) {
-			if (p + sizeof(*peer) > end)
-				goto bad;
-			peer = p;
-			p += sizeof(*peer);
-		} else if (op == CEPH_CAP_OP_EXPORT) {
-			/* recorded in unused fields */
-			peer = (void *)&h->size;
-		}
+	if (msg_version >= 3 && op == CEPH_CAP_OP_IMPORT) {
+		if (p + sizeof(*peer) > end)
+			goto bad;
+		peer = p;
+		p += sizeof(*peer);
 	}
 
 	if (msg_version >= 4) {
Signature · 1 line
2.36.0.rc1

Are you sure this isn't breaking anything? Looking at MClientCaps.h, it seems to be doing something similar, i.e. for the CAP_OP_EXPORT, the 'peer' is encoded where the 'size', 'max_size', 'truncate_size',... are for the CAP_OP_IMPORT. This is definitely confusing and messy, but not sure if your change isn't breaking something.

Cheers,

Signature · 1 line
Luís
#2 lore raw
In reply to Xiubo Li
Quoted 24 lines · Xiubo Li

For export the peer is empty in ceph.

URL: https://tracker.ceph.com/issues/55857

---
 fs/ceph/caps.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)
fs/ceph/caps.c +0 -8
index 0a48bf829671..8efa46ff4282 100644
@@ -4127,16 +4127,11 @@ void ceph_handle_caps(struct ceph_mds_session *session,
 		p += flock_len;
 	}
 
-	if (msg_version >= 3) {
-		if (op == CEPH_CAP_OP_IMPORT) {
-			if (p + sizeof(*peer) > end)
-				goto bad;
-			peer = p;
-			p += sizeof(*peer);
-		} else if (op == CEPH_CAP_OP_EXPORT) {
-			/* recorded in unused fields */

fs/ceph/caps.c void ceph_handle_caps(struct ceph_mds_session *session, · line 4137

Quoted 10 lines
fs/ceph/caps.c +5 -2
-			peer = (void *)&h->size;
-		}
+	if (msg_version >= 3 && op == CEPH_CAP_OP_IMPORT) {
+		if (p + sizeof(*peer) > end)
+			goto bad;
+		peer = p;
+		p += sizeof(*peer);
 	}
 
 	if (msg_version >= 4) {

This was added in commit 11df2dfb61 (ceph: add imported caps when handling cap export message). If peer should always be NULL on an export, I wonder what he was thinking by adding this in the first place? Zheng, could you take a look here?

If this does turn out to be correct, then I think there is some further cleanup you can do here, as you should be able to drop the peer argument from handle_cap_export. That should also collapse some of the code down in that function as well since lot of the target fields end up being 0s.

Signature · 1 line
Jeff Layton <[email protected]>
author
#3 lore raw
Quoted 40 lines · Jeff Layton
Quoted 24 lines · Xiubo Li

For export the peer is empty in ceph.

URL: https://tracker.ceph.com/issues/55857

---
  fs/ceph/caps.c | 15 +++++----------
  1 file changed, 5 insertions(+), 10 deletions(-)
fs/ceph/caps.c +0 -8
index 0a48bf829671..8efa46ff4282 100644
@@ -4127,16 +4127,11 @@ void ceph_handle_caps(struct ceph_mds_session *session,
  		p += flock_len;
  	}
 
-	if (msg_version >= 3) {
-		if (op == CEPH_CAP_OP_IMPORT) {
-			if (p + sizeof(*peer) > end)
-				goto bad;
-			peer = p;
-			p += sizeof(*peer);
-		} else if (op == CEPH_CAP_OP_EXPORT) {
-			/* recorded in unused fields */

fs/ceph/caps.c void ceph_handle_caps(struct ceph_mds_session *session, · line 4137

Quoted 10 lines
fs/ceph/caps.c +5 -2
-			peer = (void *)&h->size;
-		}
+	if (msg_version >= 3 && op == CEPH_CAP_OP_IMPORT) {
+		if (p + sizeof(*peer) > end)
+			goto bad;
+		peer = p;
+		p += sizeof(*peer);
  	}
 
  	if (msg_version >= 4) {

This was added in commit 11df2dfb61 (ceph: add imported caps when handling cap export message). If peer should always be NULL on an export, I wonder what he was thinking by adding this in the first place? Zheng, could you take a look here?

Quoted 4 lines

If this does turn out to be correct, then I think there is some further cleanup you can do here, as you should be able to drop the peer argument from handle_cap_export. That should also collapse some of the code down in that function as well since lot of the target fields end up being 0s.

Okay, will drop this. The head structs are different in ceph and kernel.

-- Xiubo