Skip to contentSkip to conversation

libceph: return the handler error from mon_handle_auth_done()

PATCH In review Ilya Dryomov 2 participants 5 messages Dec 31, 2025 – Jan 6 Ceph common code (libceph)

lore
Share & tools
lore

Ilya Dryomov

author maintainer
#0 lore raw

PATCH 1/1 libceph: return the handler error from mon_handle_auth_done()

Currently any error from ceph_auth_handle_reply_done() is propagated via finish_auth() but isn't returned from mon_handle_auth_done(). This results in higher layers learning that (despite the monitor considering us to be successfully authenticated) something went wrong in the authentication phase and reacting accordingly, but msgr2 still trying to proceed with establishing the session in the background. In the case of secure mode this can trigger a WARN in setup_crypto() and later lead to a NULL pointer dereference inside of prepare_auth_signature().

---
 net/ceph/mon_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +1 -1
index c227ececa925..fa8dd2a20f7d 100644
@@ -1417,7 +1417,7 @@ static int mon_handle_auth_done(struct ceph_connection *con,
 	if (!ret)
 		finish_hunting(monc);
 	mutex_unlock(&monc->mutex);
-	return 0;
+	return ret;
 }
 
 static int mon_handle_auth_bad_method(struct ceph_connection *con,
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Ilya Dryomov

Currently any error from ceph_auth_handle_reply_done() is propagated via finish_auth() but isn't returned from mon_handle_auth_done(). This results in higher layers learning that (despite the monitor considering us to be successfully authenticated) something went wrong in the authentication phase and reacting accordingly, but msgr2 still trying to proceed with establishing the session in the background. In the case of secure mode this can trigger a WARN in setup_crypto() and later lead to a NULL pointer dereference inside of prepare_auth_signature().

---
 net/ceph/mon_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +0 -0
index c227ececa925..fa8dd2a20f7d 100644

net/ceph/mon_client.c static int mon_handle_auth_done(struct ceph_connection *con, · line 1423

Quoted 8 lines
net/ceph/mon_client.c +1 -1
@@ -1417,7 +1417,7 @@ static int mon_handle_auth_done(struct ceph_connection *con,
 	if (!ret)
 		finish_hunting(monc);
 	mutex_unlock(&monc->mutex);
-	return 0;
+	return ret;
 }
 
 static int mon_handle_auth_bad_method(struct ceph_connection *con,

Makes sense to me. Looks good.

As far as I can see, we have the same strange implementation pattern in mon_handle_auth_bad_method() [1]:

static int mon_handle_auth_bad_method(struct ceph_connection *con,
int used_proto, int result, const int *allowed_protos, int proto_cnt, const int *allowed_modes, int mode_cnt)

{
	struct ceph_mon_client *monc = con->private;
	bool was_authed;

	mutex_lock(&monc->mutex);
	WARN_ON(!monc->hunting);
	was_authed = ceph_auth_is_authenticated(monc->auth);
	ceph_auth_handle_bad_method(monc->auth, used_proto, result,
				    allowed_protos, proto_cnt,
				    allowed_modes, mode_cnt);
	finish_auth(monc, -EACCES, was_authed);
	mutex_unlock(&monc->mutex);
	return 0;
}

If we don't return error code at all, then why declaration of function expects of error code returning? Should we exchange returning data type on void?

Thanks,
Slava.

[1]
https://elixir.bootlin.com/linux/v6.19-rc4/source/net/ceph/mon_client.c#L1423

author maintainer
#2 lore raw
Quoted 57 lines · Viacheslav Dubeyko
Quoted 20 lines · Ilya Dryomov

Currently any error from ceph_auth_handle_reply_done() is propagated via finish_auth() but isn't returned from mon_handle_auth_done(). This results in higher layers learning that (despite the monitor considering us to be successfully authenticated) something went wrong in the authentication phase and reacting accordingly, but msgr2 still trying to proceed with establishing the session in the background. In the case of secure mode this can trigger a WARN in setup_crypto() and later lead to a NULL pointer dereference inside of prepare_auth_signature().

---
 net/ceph/mon_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +0 -0
index c227ececa925..fa8dd2a20f7d 100644

net/ceph/mon_client.c static int mon_handle_auth_done(struct ceph_connection *con, · line 1423

Quoted 8 lines
net/ceph/mon_client.c +1 -1
@@ -1417,7 +1417,7 @@ static int mon_handle_auth_done(struct ceph_connection *con,
      if (!ret)
              finish_hunting(monc);
      mutex_unlock(&monc->mutex);
-     return 0;
+     return ret;
 }
 
 static int mon_handle_auth_bad_method(struct ceph_connection *con,

Makes sense to me. Looks good.

As far as I can see, we have the same strange implementation pattern in mon_handle_auth_bad_method() [1]:

static int mon_handle_auth_bad_method(struct ceph_connection *con,
int used_proto, int result, const int *allowed_protos, int proto_cnt, const int *allowed_modes, int mode_cnt)

{
        struct ceph_mon_client *monc = con->private;
        bool was_authed;

        mutex_lock(&monc->mutex);
        WARN_ON(!monc->hunting);
        was_authed = ceph_auth_is_authenticated(monc->auth);
        ceph_auth_handle_bad_method(monc->auth, used_proto, result,
                                    allowed_protos, proto_cnt,
                                    allowed_modes, mode_cnt);
        finish_auth(monc, -EACCES, was_authed);
        mutex_unlock(&monc->mutex);
        return 0;
}
Quoted 2 lines

If we don't return error code at all, then why declaration of function expects of error code returning? Should we exchange returning data type on void?

Hi Slava,

mon_handle_auth_bad_method() implements a msgr2 callout, just like mon_handle_auth_done() does. The handler may need to e.g. allocate memory or in general do any number of things that could fail, so the interface must provide a way to signal such failures to the messenger to ensure that it doesn't try to proceed any further with the session. Theoretically the return type could be downgraded to bool, but definitely not to void.

Thanks,

Ilya

#3 lore raw
Quoted 63 lines · Ilya Dryomov
Quoted 57 lines · Viacheslav Dubeyko
Quoted 20 lines · Ilya Dryomov

Currently any error from ceph_auth_handle_reply_done() is propagated via finish_auth() but isn't returned from mon_handle_auth_done(). This results in higher layers learning that (despite the monitor considering us to be successfully authenticated) something went wrong in the authentication phase and reacting accordingly, but msgr2 still trying to proceed with establishing the session in the background. In the case of secure mode this can trigger a WARN in setup_crypto() and later lead to a NULL pointer dereference inside of prepare_auth_signature().

---
 net/ceph/mon_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +0 -0
index c227ececa925..fa8dd2a20f7d 100644

net/ceph/mon_client.c static int mon_handle_auth_done(struct ceph_connection *con, · line 1423

Quoted 8 lines
net/ceph/mon_client.c +1 -1
@@ -1417,7 +1417,7 @@ static int mon_handle_auth_done(struct ceph_connection *con,
      if (!ret)
              finish_hunting(monc);
      mutex_unlock(&monc->mutex);
-     return 0;
+     return ret;
 }
 
 static int mon_handle_auth_bad_method(struct ceph_connection *con,

Makes sense to me. Looks good.

As far as I can see, we have the same strange implementation pattern in mon_handle_auth_bad_method() [1]:

static int mon_handle_auth_bad_method(struct ceph_connection *con,
int used_proto, int result, const int *allowed_protos, int proto_cnt, const int *allowed_modes, int mode_cnt)

{
        struct ceph_mon_client *monc = con->private;
        bool was_authed;

        mutex_lock(&monc->mutex);
        WARN_ON(!monc->hunting);
        was_authed = ceph_auth_is_authenticated(monc->auth);
        ceph_auth_handle_bad_method(monc->auth, used_proto, result,
                                    allowed_protos, proto_cnt,
                                    allowed_modes, mode_cnt);
        finish_auth(monc, -EACCES, was_authed);
        mutex_unlock(&monc->mutex);
        return 0;
}
Quoted 2 lines

If we don't return error code at all, then why declaration of function expects of error code returning? Should we exchange returning data type on void?

Hi Slava,

Quoted 8 lines

mon_handle_auth_bad_method() implements a msgr2 callout, just like mon_handle_auth_done() does. The handler may need to e.g. allocate memory or in general do any number of things that could fail, so the interface must provide a way to signal such failures to the messenger to ensure that it doesn't try to proceed any further with the session. Theoretically the return type could be downgraded to bool, but definitely not to void.

Maybe, do we need to add the comment that explaining all of this?

Thanks,
Slava.

author maintainer
#4 lore raw
Quoted 74 lines · Viacheslav Dubeyko
Quoted 63 lines · Ilya Dryomov
Quoted 57 lines · Viacheslav Dubeyko
Quoted 20 lines · Ilya Dryomov

Currently any error from ceph_auth_handle_reply_done() is propagated via finish_auth() but isn't returned from mon_handle_auth_done(). This results in higher layers learning that (despite the monitor considering us to be successfully authenticated) something went wrong in the authentication phase and reacting accordingly, but msgr2 still trying to proceed with establishing the session in the background. In the case of secure mode this can trigger a WARN in setup_crypto() and later lead to a NULL pointer dereference inside of prepare_auth_signature().

---
 net/ceph/mon_client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ceph/mon_client.c +0 -0
index c227ececa925..fa8dd2a20f7d 100644

net/ceph/mon_client.c static int mon_handle_auth_done(struct ceph_connection *con, · line 1423

Quoted 8 lines
net/ceph/mon_client.c +1 -1
@@ -1417,7 +1417,7 @@ static int mon_handle_auth_done(struct ceph_connection *con,
      if (!ret)
              finish_hunting(monc);
      mutex_unlock(&monc->mutex);
-     return 0;
+     return ret;
 }
 
 static int mon_handle_auth_bad_method(struct ceph_connection *con,

Makes sense to me. Looks good.

As far as I can see, we have the same strange implementation pattern in mon_handle_auth_bad_method() [1]:

static int mon_handle_auth_bad_method(struct ceph_connection *con,
int used_proto, int result, const int *allowed_protos, int proto_cnt, const int *allowed_modes, int mode_cnt)

{
        struct ceph_mon_client *monc = con->private;
        bool was_authed;

        mutex_lock(&monc->mutex);
        WARN_ON(!monc->hunting);
        was_authed = ceph_auth_is_authenticated(monc->auth);
        ceph_auth_handle_bad_method(monc->auth, used_proto, result,
                                    allowed_protos, proto_cnt,
                                    allowed_modes, mode_cnt);
        finish_auth(monc, -EACCES, was_authed);
        mutex_unlock(&monc->mutex);
        return 0;
}
Quoted 2 lines

If we don't return error code at all, then why declaration of function expects of error code returning? Should we exchange returning data type on void?

Hi Slava,

Quoted 8 lines

mon_handle_auth_bad_method() implements a msgr2 callout, just like mon_handle_auth_done() does. The handler may need to e.g. allocate memory or in general do any number of things that could fail, so the interface must provide a way to signal such failures to the messenger to ensure that it doesn't try to proceed any further with the session. Theoretically the return type could be downgraded to bool, but definitely not to void.

Quoted 1 line

Maybe, do we need to add the comment that explaining all of this?

This isn't specific to the messenger, so I don't think so. When one encounters a method with a bunch of parameters or a return value that doesn't immediately make sense, a very common explanation is that the method implements an interface and that the given implementation just happens to not depend on those parameters or always succeed, etc. The interface is usually wired up in the same file and is trivial to look up by searching for the name of the method:

static const struct ceph_connection_operations osd_con_ops = {
...
.get_auth_request = osd_get_auth_request, .handle_auth_reply_more = osd_handle_auth_reply_more, .handle_auth_done = osd_handle_auth_done, .handle_auth_bad_method = osd_handle_auth_bad_method,
};

From there one can check out the interface itself:

/*
* Ceph defines these callbacks for handling connection events.
*/
struct ceph_connection_operations {
...
/* msgr2 authentication exchange */
int (*get_auth_request)(struct ceph_connection *con,
void *buf, int *buf_len,
void **authorizer, int *authorizer_len);
int (*handle_auth_reply_more)(struct ceph_connection *con,
void *reply, int reply_len, void *buf, int *buf_len, void **authorizer, int *authorizer_len);
int (*handle_auth_done)(struct ceph_connection *con,
u64 global_id, void *reply, int reply_len, u8 *session_key, int *session_key_len, u8 *con_secret, int *con_secret_len);
int (*handle_auth_bad_method)(struct ceph_connection *con,
int used_proto, int result, const int *allowed_protos, int proto_cnt, const int *allowed_modes, int mode_cnt);
};

Thanks,

Ilya