Skip to contentSkip to conversation

ceph: ensure we return an error when parsing corrupt mdsmap

PATCH In review Jeff Layton 2 participants 2 messages Aug 30, 2021 Ceph client

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: ensure we return an error when parsing corrupt mdsmap

Commit ba5e57de7b20 (ceph: reconnect to the export targets on new mdsmaps) changed ceph_mdsmap_decode to "goto corrupt" when given a bogus mds rank in the export targets. It did not set the err variable however, which caused that function to return a NULL pointer instead of a proper ERR_PTR value for the error.

Fix this by setting err before doing the "goto corrupt".

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

Fixes ba5e57de7b20 ("ceph: reconnect to the export targets on new mdsmaps")
---
 fs/ceph/mdsmap.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

I'll plan to fold this change into the original patch since it hasn't been merged yet. Let me know if you have objections.

fs/ceph/mdsmap.c +3 -1
index d995cb02d30c..61d67cbcb367 100644
@@ -263,8 +263,10 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2)
 				goto nomem;
 			for (j = 0; j < num_export_targets; j++) {
 				target = ceph_decode_32(&pexport_targets);
-				if (target >= m->possible_max_rank)
+				if (target >= m->possible_max_rank) {
+					err = -EIO;
 					goto corrupt;
+				}
 				info->export_targets[j] = target;
 			}
 		} else {
Signature · 1 line
2.31.1
#1 lore raw
Quoted 24 lines · Jeff Layton

Commit ba5e57de7b20 (ceph: reconnect to the export targets on new mdsmaps) changed ceph_mdsmap_decode to "goto corrupt" when given a bogus mds rank in the export targets. It did not set the err variable however, which caused that function to return a NULL pointer instead of a proper ERR_PTR value for the error.

Fix this by setting err before doing the "goto corrupt".

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

Fixes ba5e57de7b20 ("ceph: reconnect to the export targets on new mdsmaps")
---
  fs/ceph/mdsmap.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

I'll plan to fold this change into the original patch since it hasn't been merged yet. Let me know if you have objections.

fs/ceph/mdsmap.c +0 -0
index d995cb02d30c..61d67cbcb367 100644
@@ -263,8 +263,10 @@ struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2)
  				goto nomem;

fs/ceph/mdsmap.c struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end, bool msgr2) · line 272

Quoted 10 lines
fs/ceph/mdsmap.c +3 -1
  			for (j = 0; j < num_export_targets; j++) {
  				target = ceph_decode_32(&pexport_targets);
-				if (target >= m->possible_max_rank)
+				if (target >= m->possible_max_rank) {
+					err = -EIO;
  					goto corrupt;
+				}
  				info->export_targets[j] = target;
  			}
  		} else {

Make sense and LGTM.