Skip to contentSkip to conversation

ceph: don't rely on error_string to validate blocklisted session.

PATCH In review [email protected] 2 participants 3 messages Sep 27, 2021 – Oct 1, 2021 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: don't rely on error_string to validate blocklisted session.

From: Kotresh HR <[email protected]>

The "error_string" in the metadata of MClientSession is being parsed by kclient to validate whether the session is blocklisted. The "error_string" is for humans and shouldn't be relied on it. Hence added the flag to MClientsession to indicate the session is blocklisted.

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

---
 fs/ceph/mds_client.c         | 24 +++++++++++++++++++++---
 include/linux/ceph/ceph_fs.h |  2 ++
 2 files changed, 23 insertions(+), 3 deletions(-)
fs/ceph/mds_client.c +21 -3
index 44bc780b2b0e..cc1137468b29 100644
@@ -3396,9 +3396,15 @@ static void handle_session(struct ceph_mds_session *session,
 
 	if (msg_version >= 3) {
 		u32 len;
-		/* version >= 2, metadata */
-		if (__decode_session_metadata(&p, end, &blocklisted) < 0)
-			goto bad;
+		/* version >= 2 and < 5, decode metadata, skip otherwise
+		 * as it's handled via flags.
+		 */
+		if (msg_version >= 5) {
+			ceph_decode_skip_map(&p, end, string, string, bad);
+		} else {
+			if (__decode_session_metadata(&p, end, &blocklisted) < 0)
+				goto bad;
+		}
 		/* version >= 3, feature bits */
 		ceph_decode_32_safe(&p, end, len, bad);
 		if (len) {
@@ -3407,6 +3413,18 @@ static void handle_session(struct ceph_mds_session *session,
 		}
 	}
 
+	if (msg_version >= 5) {
+		u32 flags;
+		/* version >= 4, struct_v, struct_cv, len, metric_spec */
+	        ceph_decode_skip_n(&p, end, 2 + sizeof(u32) * 2, bad);
+		/* version >= 5, flags   */
+                ceph_decode_32_safe(&p, end, flags, bad);
+		if (flags & CEPH_SESSION_BLOCKLISTED) {
+		        pr_warn("mds%d session blocklisted\n", session->s_mds);
+			blocklisted = true;
+		}
+	}
+
 	mutex_lock(&mdsc->mutex);
 	if (op == CEPH_SESSION_CLOSE) {
 		ceph_get_mds_session(session);
include/linux/ceph/ceph_fs.h +2 -0
index bc2699feddbe..7ad6c3d0db7d 100644
@@ -302,6 +302,8 @@ enum {
 	CEPH_SESSION_REQUEST_FLUSH_MDLOG,
 };
 
+#define CEPH_SESSION_BLOCKLISTED	(1 << 0)  /* session blocklisted */
+
 extern const char *ceph_session_op_name(int op);
 
 struct ceph_mds_session_head {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 2 lines · On Mon, 2021-09-27 at 19:22 +0530, [email protected] wrote:

From: Kotresh HR <[email protected]>

This looks good. For future reference, I'd have probably marked this as [PATCH v2]. One minor style nit below, but you don't need to resend for that. I'll fix it up when I merge it if you're OK with it.

Quoted 21 lines

The "error_string" in the metadata of MClientSession is being parsed by kclient to validate whether the session is blocklisted. The "error_string" is for humans and shouldn't be relied on it. Hence added the flag to MClientsession to indicate the session is blocklisted.

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

---
 fs/ceph/mds_client.c         | 24 +++++++++++++++++++++---
 include/linux/ceph/ceph_fs.h |  2 ++
 2 files changed, 23 insertions(+), 3 deletions(-)
fs/ceph/mds_client.c +0 -0
index 44bc780b2b0e..cc1137468b29 100644
@@ -3396,9 +3396,15 @@ static void handle_session(struct ceph_mds_session *session,
 
 	if (msg_version >= 3) {
 		u32 len;

fs/ceph/mds_client.c static void handle_session(struct ceph_mds_session *session, · line 3405

Quoted 10 lines
fs/ceph/mds_client.c +7 -3
-		/* version >= 2, metadata */
-		if (__decode_session_metadata(&p, end, &blocklisted) < 0)
-			goto bad;
+		/* version >= 2 and < 5, decode metadata, skip otherwise
+		 * as it's handled via flags.
+		 */
+		if (msg_version >= 5) {
+			ceph_decode_skip_map(&p, end, string, string, bad);
+		} else {
+			if (__decode_session_metadata(&p, end, &blocklisted) < 0)

We can use an "else if" here and remove a level of indentation. Also, the braces aren't necessary since both just cover a single-line statements.

Quoted 37 lines
fs/ceph/mds_client.c +14 -0
+				goto bad;
+		}
 		/* version >= 3, feature bits */
 		ceph_decode_32_safe(&p, end, len, bad);
 		if (len) {
@@ -3407,6 +3413,18 @@ static void handle_session(struct ceph_mds_session *session,
 		}
 	}
 
+	if (msg_version >= 5) {
+		u32 flags;
+		/* version >= 4, struct_v, struct_cv, len, metric_spec */
+	        ceph_decode_skip_n(&p, end, 2 + sizeof(u32) * 2, bad);
+		/* version >= 5, flags   */
+                ceph_decode_32_safe(&p, end, flags, bad);
+		if (flags & CEPH_SESSION_BLOCKLISTED) {
+		        pr_warn("mds%d session blocklisted\n", session->s_mds);
+			blocklisted = true;
+		}
+	}
+
 	mutex_lock(&mdsc->mutex);
 	if (op == CEPH_SESSION_CLOSE) {
 		ceph_get_mds_session(session);
include/linux/ceph/ceph_fs.h +2 -0
index bc2699feddbe..7ad6c3d0db7d 100644
@@ -302,6 +302,8 @@ enum {
 	CEPH_SESSION_REQUEST_FLUSH_MDLOG,
 };
 
+#define CEPH_SESSION_BLOCKLISTED	(1 << 0)  /* session blocklisted */
+
 extern const char *ceph_session_op_name(int op);
 
 struct ceph_mds_session_head {

A message that is not in the archive (sent off-list or not yet received): CAPgWtC6Y_Bh5TeL_JN8KJ6ftKa=A=6aZmdNtj1Tb=OO_An+tpA@mail.gmail.com

#3 lore raw
Quoted 15 lines · Kotresh Hiremath Ravishankar
Quoted 10 lines · Jeff Layton
Quoted 2 lines · On Mon, 2021-09-27 at 19:22 +0530, [email protected] wrote:

From: Kotresh HR <[email protected]>

This looks good. For future reference, I'd have probably marked this as
[PATCH v2]. One minor style nit below, but you don't need to resend for
that. I'll fix it up when I merge it if you're OK with it.

Quoted 4 lines

I did format it with [PATCH v2], not sure why 'git send-email' didn't pick it up.
Sure, No problem. Thanks Jeff!

Merged. Please take a look when you have time and let me know if you see anything wrong with the final result.

Thanks,
Jeff

Signature · 1 line
Jeff Layton <[email protected]>