Skip to content

Commit 03af4c7

Browse files
committed
libceph: set global_id as soon as we get an auth ticket
Commit 61ca49a ("libceph: don't set global_id until we get an auth ticket") delayed the setting of global_id too much. It is set only after all tickets are received, but in pre-nautilus clusters an auth ticket and the service tickets are obtained in separate steps (for a total of three MAuth replies). When the service tickets are requested, global_id is used to build an authorizer; if global_id is still 0 we never get them and fail to establish the session. Moving the setting of global_id into protocol implementations. This way global_id can be set exactly when an auth ticket is received, not sooner nor later. Fixes: 61ca49a ("libceph: don't set global_id until we get an auth ticket") Signed-off-by: Ilya Dryomov <[email protected]> Reviewed-by: Jeff Layton <[email protected]>
1 parent 3c0d089 commit 03af4c7

File tree

4 files changed

+16
-15
lines changed

4 files changed

+16
-15
lines changed

include/linux/ceph/auth.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ struct ceph_auth_client_ops {
5050
* another request.
5151
*/
5252
int (*build_request)(struct ceph_auth_client *ac, void *buf, void *end);
53-
int (*handle_reply)(struct ceph_auth_client *ac,
53+
int (*handle_reply)(struct ceph_auth_client *ac, u64 global_id,
5454
void *buf, void *end, u8 *session_key,
5555
int *session_key_len, u8 *con_secret,
5656
int *con_secret_len);
@@ -104,6 +104,8 @@ struct ceph_auth_client {
104104
struct mutex mutex;
105105
};
106106

107+
void ceph_auth_set_global_id(struct ceph_auth_client *ac, u64 global_id);
108+
107109
struct ceph_auth_client *ceph_auth_init(const char *name,
108110
const struct ceph_crypto_key *key,
109111
const int *con_modes);

net/ceph/auth.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static int init_protocol(struct ceph_auth_client *ac, int proto)
3636
}
3737
}
3838

39-
static void set_global_id(struct ceph_auth_client *ac, u64 global_id)
39+
void ceph_auth_set_global_id(struct ceph_auth_client *ac, u64 global_id)
4040
{
4141
dout("%s global_id %llu\n", __func__, global_id);
4242

@@ -267,7 +267,7 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac,
267267
goto out;
268268
}
269269

270-
ret = ac->ops->handle_reply(ac, payload, payload_end,
270+
ret = ac->ops->handle_reply(ac, global_id, payload, payload_end,
271271
NULL, NULL, NULL, NULL);
272272
if (ret == -EAGAIN) {
273273
ret = build_request(ac, true, reply_buf, reply_len);
@@ -276,8 +276,6 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac,
276276
goto out;
277277
}
278278

279-
set_global_id(ac, global_id);
280-
281279
out:
282280
mutex_unlock(&ac->mutex);
283281
return ret;
@@ -485,7 +483,7 @@ int ceph_auth_handle_reply_more(struct ceph_auth_client *ac, void *reply,
485483
int ret;
486484

487485
mutex_lock(&ac->mutex);
488-
ret = ac->ops->handle_reply(ac, reply, reply + reply_len,
486+
ret = ac->ops->handle_reply(ac, 0, reply, reply + reply_len,
489487
NULL, NULL, NULL, NULL);
490488
if (ret == -EAGAIN)
491489
ret = build_request(ac, false, buf, buf_len);
@@ -503,11 +501,10 @@ int ceph_auth_handle_reply_done(struct ceph_auth_client *ac,
503501
int ret;
504502

505503
mutex_lock(&ac->mutex);
506-
ret = ac->ops->handle_reply(ac, reply, reply + reply_len,
504+
ret = ac->ops->handle_reply(ac, global_id, reply, reply + reply_len,
507505
session_key, session_key_len,
508506
con_secret, con_secret_len);
509-
if (!ret)
510-
set_global_id(ac, global_id);
507+
WARN_ON(ret == -EAGAIN || ret > 0);
511508
mutex_unlock(&ac->mutex);
512509
return ret;
513510
}

net/ceph/auth_none.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,15 @@ static int build_request(struct ceph_auth_client *ac, void *buf, void *end)
6969
* the generic auth code decode the global_id, and we carry no actual
7070
* authenticate state, so nothing happens here.
7171
*/
72-
static int handle_reply(struct ceph_auth_client *ac,
72+
static int handle_reply(struct ceph_auth_client *ac, u64 global_id,
7373
void *buf, void *end, u8 *session_key,
7474
int *session_key_len, u8 *con_secret,
7575
int *con_secret_len)
7676
{
7777
struct ceph_auth_none_info *xi = ac->private;
7878

7979
xi->starting = false;
80+
ceph_auth_set_global_id(ac, global_id);
8081
return 0;
8182
}
8283

net/ceph/auth_x.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static int decode_con_secret(void **p, void *end, u8 *con_secret,
597597
return -EINVAL;
598598
}
599599

600-
static int handle_auth_session_key(struct ceph_auth_client *ac,
600+
static int handle_auth_session_key(struct ceph_auth_client *ac, u64 global_id,
601601
void **p, void *end,
602602
u8 *session_key, int *session_key_len,
603603
u8 *con_secret, int *con_secret_len)
@@ -613,6 +613,7 @@ static int handle_auth_session_key(struct ceph_auth_client *ac,
613613
if (ret)
614614
return ret;
615615

616+
ceph_auth_set_global_id(ac, global_id);
616617
if (*p == end) {
617618
/* pre-nautilus (or didn't request service tickets!) */
618619
WARN_ON(session_key || con_secret);
@@ -661,7 +662,7 @@ static int handle_auth_session_key(struct ceph_auth_client *ac,
661662
return -EINVAL;
662663
}
663664

664-
static int ceph_x_handle_reply(struct ceph_auth_client *ac,
665+
static int ceph_x_handle_reply(struct ceph_auth_client *ac, u64 global_id,
665666
void *buf, void *end,
666667
u8 *session_key, int *session_key_len,
667668
u8 *con_secret, int *con_secret_len)
@@ -695,9 +696,9 @@ static int ceph_x_handle_reply(struct ceph_auth_client *ac,
695696
switch (op) {
696697
case CEPHX_GET_AUTH_SESSION_KEY:
697698
/* AUTH ticket + [connection secret] + service tickets */
698-
ret = handle_auth_session_key(ac, &p, end, session_key,
699-
session_key_len, con_secret,
700-
con_secret_len);
699+
ret = handle_auth_session_key(ac, global_id, &p, end,
700+
session_key, session_key_len,
701+
con_secret, con_secret_len);
701702
break;
702703

703704
case CEPHX_GET_PRINCIPAL_SESSION_KEY:

0 commit comments

Comments
 (0)