Skip to content

Commit 61ca49a

Browse files
committed
libceph: don't set global_id until we get an auth ticket
With the introduction of enforcing mode, setting global_id as soon as we get it in the first MAuth reply will result in EACCES if the connection is reset before we get the second MAuth reply containing an auth ticket -- because on retry we would attempt to reclaim that global_id with no auth ticket at hand. Neither ceph_auth_client nor ceph_mon_client depend on global_id being set ealy, so just delay the setting until we get and process the second MAuth reply. While at it, complain if the monitor sends a zero global_id or changes our global_id as the session is likely to fail after that. Cc: [email protected] # needs backporting for < 5.11 Signed-off-by: Ilya Dryomov <[email protected]> Reviewed-by: Sage Weil <[email protected]>
1 parent 7807daf commit 61ca49a

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

net/ceph/auth.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ 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)
40+
{
41+
dout("%s global_id %llu\n", __func__, global_id);
42+
43+
if (!global_id)
44+
pr_err("got zero global_id\n");
45+
46+
if (ac->global_id && global_id != ac->global_id)
47+
pr_err("global_id changed from %llu to %llu\n", ac->global_id,
48+
global_id);
49+
50+
ac->global_id = global_id;
51+
}
52+
3953
/*
4054
* setup, teardown.
4155
*/
@@ -222,11 +236,6 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac,
222236

223237
payload_end = payload + payload_len;
224238

225-
if (global_id && ac->global_id != global_id) {
226-
dout(" set global_id %lld -> %lld\n", ac->global_id, global_id);
227-
ac->global_id = global_id;
228-
}
229-
230239
if (ac->negotiating) {
231240
/* server does not support our protocols? */
232241
if (!protocol && result < 0) {
@@ -253,11 +262,16 @@ int ceph_handle_auth_reply(struct ceph_auth_client *ac,
253262

254263
ret = ac->ops->handle_reply(ac, result, payload, payload_end,
255264
NULL, NULL, NULL, NULL);
256-
if (ret == -EAGAIN)
265+
if (ret == -EAGAIN) {
257266
ret = build_request(ac, true, reply_buf, reply_len);
258-
else if (ret)
267+
goto out;
268+
} else if (ret) {
259269
pr_err("auth protocol '%s' mauth authentication failed: %d\n",
260270
ceph_auth_proto_name(ac->protocol), result);
271+
goto out;
272+
}
273+
274+
set_global_id(ac, global_id);
261275

262276
out:
263277
mutex_unlock(&ac->mutex);
@@ -484,15 +498,11 @@ int ceph_auth_handle_reply_done(struct ceph_auth_client *ac,
484498
int ret;
485499

486500
mutex_lock(&ac->mutex);
487-
if (global_id && ac->global_id != global_id) {
488-
dout("%s global_id %llu -> %llu\n", __func__, ac->global_id,
489-
global_id);
490-
ac->global_id = global_id;
491-
}
492-
493501
ret = ac->ops->handle_reply(ac, 0, reply, reply + reply_len,
494502
session_key, session_key_len,
495503
con_secret, con_secret_len);
504+
if (!ret)
505+
set_global_id(ac, global_id);
496506
mutex_unlock(&ac->mutex);
497507
return ret;
498508
}

0 commit comments

Comments
 (0)