Skip to content

Commit 6daca13

Browse files
committed
libceph: add authorizer challenge
When a client authenticates with a service, an authorizer is sent with a nonce to the service (ceph_x_authorize_[ab]) and the service responds with a mutation of that nonce (ceph_x_authorize_reply). This lets the client verify the service is who it says it is but it doesn't protect against a replay: someone can trivially capture the exchange and reuse the same authorizer to authenticate themselves. Allow the service to reject an initial authorizer with a random challenge (ceph_x_authorize_challenge). The client then has to respond with an updated authorizer proving they are able to decrypt the service's challenge and that the new authorizer was produced for this specific connection instance. The accepting side requires this challenge and response unconditionally if the client side advertises they have CEPHX_V2 feature bit. This addresses CVE-2018-1128. Link: http://tracker.ceph.com/issues/24836 Signed-off-by: Ilya Dryomov <idryomov@gmail.com> Reviewed-by: Sage Weil <sage@redhat.com>
1 parent 149cac4 commit 6daca13

9 files changed

Lines changed: 140 additions & 7 deletions

File tree

‎fs/ceph/mds_client.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,6 +4154,16 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
41544154
return auth;
41554155
}
41564156

4157+
static int add_authorizer_challenge(struct ceph_connection *con,
4158+
void *challenge_buf, int challenge_buf_len)
4159+
{
4160+
struct ceph_mds_session *s = con->private;
4161+
struct ceph_mds_client *mdsc = s->s_mdsc;
4162+
struct ceph_auth_client *ac = mdsc->fsc->client->monc.auth;
4163+
4164+
return ceph_auth_add_authorizer_challenge(ac, s->s_auth.authorizer,
4165+
challenge_buf, challenge_buf_len);
4166+
}
41574167

41584168
static int verify_authorizer_reply(struct ceph_connection *con)
41594169
{
@@ -4217,6 +4227,7 @@ static const struct ceph_connection_operations mds_con_ops = {
42174227
.put = con_put,
42184228
.dispatch = dispatch,
42194229
.get_authorizer = get_authorizer,
4230+
.add_authorizer_challenge = add_authorizer_challenge,
42204231
.verify_authorizer_reply = verify_authorizer_reply,
42214232
.invalidate_authorizer = invalidate_authorizer,
42224233
.peer_reset = peer_reset,

‎include/linux/ceph/auth.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ struct ceph_auth_client_ops {
6464
/* ensure that an existing authorizer is up to date */
6565
int (*update_authorizer)(struct ceph_auth_client *ac, int peer_type,
6666
struct ceph_auth_handshake *auth);
67+
int (*add_authorizer_challenge)(struct ceph_auth_client *ac,
68+
struct ceph_authorizer *a,
69+
void *challenge_buf,
70+
int challenge_buf_len);
6771
int (*verify_authorizer_reply)(struct ceph_auth_client *ac,
6872
struct ceph_authorizer *a);
6973
void (*invalidate_authorizer)(struct ceph_auth_client *ac,
@@ -118,6 +122,10 @@ void ceph_auth_destroy_authorizer(struct ceph_authorizer *a);
118122
extern int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
119123
int peer_type,
120124
struct ceph_auth_handshake *a);
125+
int ceph_auth_add_authorizer_challenge(struct ceph_auth_client *ac,
126+
struct ceph_authorizer *a,
127+
void *challenge_buf,
128+
int challenge_buf_len);
121129
extern int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
122130
struct ceph_authorizer *a);
123131
extern void ceph_auth_invalidate_authorizer(struct ceph_auth_client *ac,

‎include/linux/ceph/messenger.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ struct ceph_connection_operations {
3131
struct ceph_auth_handshake *(*get_authorizer) (
3232
struct ceph_connection *con,
3333
int *proto, int force_new);
34+
int (*add_authorizer_challenge)(struct ceph_connection *con,
35+
void *challenge_buf,
36+
int challenge_buf_len);
3437
int (*verify_authorizer_reply) (struct ceph_connection *con);
3538
int (*invalidate_authorizer)(struct ceph_connection *con);
3639

‎include/linux/ceph/msgr.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct ceph_entity_inst {
9191
#define CEPH_MSGR_TAG_SEQ 13 /* 64-bit int follows with seen seq number */
9292
#define CEPH_MSGR_TAG_KEEPALIVE2 14 /* keepalive2 byte + ceph_timespec */
9393
#define CEPH_MSGR_TAG_KEEPALIVE2_ACK 15 /* keepalive2 reply */
94-
94+
#define CEPH_MSGR_TAG_CHALLENGE_AUTHORIZER 16 /* cephx v2 doing server challenge */
9595

9696
/*
9797
* connection negotiation

‎net/ceph/auth.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,22 @@ int ceph_auth_update_authorizer(struct ceph_auth_client *ac,
315315
}
316316
EXPORT_SYMBOL(ceph_auth_update_authorizer);
317317

318+
int ceph_auth_add_authorizer_challenge(struct ceph_auth_client *ac,
319+
struct ceph_authorizer *a,
320+
void *challenge_buf,
321+
int challenge_buf_len)
322+
{
323+
int ret = 0;
324+
325+
mutex_lock(&ac->mutex);
326+
if (ac->ops && ac->ops->add_authorizer_challenge)
327+
ret = ac->ops->add_authorizer_challenge(ac, a, challenge_buf,
328+
challenge_buf_len);
329+
mutex_unlock(&ac->mutex);
330+
return ret;
331+
}
332+
EXPORT_SYMBOL(ceph_auth_add_authorizer_challenge);
333+
318334
int ceph_auth_verify_authorizer_reply(struct ceph_auth_client *ac,
319335
struct ceph_authorizer *a)
320336
{

‎net/ceph/auth_x.c‎

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
295295
* authorizer. The first part (ceph_x_authorize_a) should already be
296296
* encoded.
297297
*/
298-
static int encrypt_authorizer(struct ceph_x_authorizer *au)
298+
static int encrypt_authorizer(struct ceph_x_authorizer *au,
299+
u64 *server_challenge)
299300
{
300301
struct ceph_x_authorize_a *msg_a;
301302
struct ceph_x_authorize_b *msg_b;
@@ -308,16 +309,28 @@ static int encrypt_authorizer(struct ceph_x_authorizer *au)
308309
end = au->buf->vec.iov_base + au->buf->vec.iov_len;
309310

310311
msg_b = p + ceph_x_encrypt_offset();
311-
msg_b->struct_v = 1;
312+
msg_b->struct_v = 2;
312313
msg_b->nonce = cpu_to_le64(au->nonce);
314+
if (server_challenge) {
315+
msg_b->have_challenge = 1;
316+
msg_b->server_challenge_plus_one =
317+
cpu_to_le64(*server_challenge + 1);
318+
} else {
319+
msg_b->have_challenge = 0;
320+
msg_b->server_challenge_plus_one = 0;
321+
}
313322

314323
ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b));
315324
if (ret < 0)
316325
return ret;
317326

318327
p += ret;
319-
WARN_ON(p > end);
320-
au->buf->vec.iov_len = p - au->buf->vec.iov_base;
328+
if (server_challenge) {
329+
WARN_ON(p != end);
330+
} else {
331+
WARN_ON(p > end);
332+
au->buf->vec.iov_len = p - au->buf->vec.iov_base;
333+
}
321334

322335
return 0;
323336
}
@@ -382,7 +395,7 @@ static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
382395
le64_to_cpu(msg_a->ticket_blob.secret_id));
383396

384397
get_random_bytes(&au->nonce, sizeof(au->nonce));
385-
ret = encrypt_authorizer(au);
398+
ret = encrypt_authorizer(au, NULL);
386399
if (ret) {
387400
pr_err("failed to encrypt authorizer: %d", ret);
388401
goto out_au;
@@ -664,6 +677,54 @@ static int ceph_x_update_authorizer(
664677
return 0;
665678
}
666679

680+
static int decrypt_authorize_challenge(struct ceph_x_authorizer *au,
681+
void *challenge_buf,
682+
int challenge_buf_len,
683+
u64 *server_challenge)
684+
{
685+
struct ceph_x_authorize_challenge *ch =
686+
challenge_buf + sizeof(struct ceph_x_encrypt_header);
687+
int ret;
688+
689+
/* no leading len */
690+
ret = __ceph_x_decrypt(&au->session_key, challenge_buf,
691+
challenge_buf_len);
692+
if (ret < 0)
693+
return ret;
694+
if (ret < sizeof(*ch)) {
695+
pr_err("bad size %d for ceph_x_authorize_challenge\n", ret);
696+
return -EINVAL;
697+
}
698+
699+
*server_challenge = le64_to_cpu(ch->server_challenge);
700+
return 0;
701+
}
702+
703+
static int ceph_x_add_authorizer_challenge(struct ceph_auth_client *ac,
704+
struct ceph_authorizer *a,
705+
void *challenge_buf,
706+
int challenge_buf_len)
707+
{
708+
struct ceph_x_authorizer *au = (void *)a;
709+
u64 server_challenge;
710+
int ret;
711+
712+
ret = decrypt_authorize_challenge(au, challenge_buf, challenge_buf_len,
713+
&server_challenge);
714+
if (ret) {
715+
pr_err("failed to decrypt authorize challenge: %d", ret);
716+
return ret;
717+
}
718+
719+
ret = encrypt_authorizer(au, &server_challenge);
720+
if (ret) {
721+
pr_err("failed to encrypt authorizer w/ challenge: %d", ret);
722+
return ret;
723+
}
724+
725+
return 0;
726+
}
727+
667728
static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
668729
struct ceph_authorizer *a)
669730
{
@@ -816,6 +877,7 @@ static const struct ceph_auth_client_ops ceph_x_ops = {
816877
.handle_reply = ceph_x_handle_reply,
817878
.create_authorizer = ceph_x_create_authorizer,
818879
.update_authorizer = ceph_x_update_authorizer,
880+
.add_authorizer_challenge = ceph_x_add_authorizer_challenge,
819881
.verify_authorizer_reply = ceph_x_verify_authorizer_reply,
820882
.invalidate_authorizer = ceph_x_invalidate_authorizer,
821883
.reset = ceph_x_reset,

‎net/ceph/auth_x_protocol.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ struct ceph_x_authorize_a {
7070
struct ceph_x_authorize_b {
7171
__u8 struct_v;
7272
__le64 nonce;
73+
__u8 have_challenge;
74+
__le64 server_challenge_plus_one;
75+
} __attribute__ ((packed));
76+
77+
struct ceph_x_authorize_challenge {
78+
__u8 struct_v;
79+
__le64 server_challenge;
7380
} __attribute__ ((packed));
7481

7582
struct ceph_x_authorize_reply {

‎net/ceph/messenger.c‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,9 +2080,24 @@ static int process_connect(struct ceph_connection *con)
20802080
if (con->auth) {
20812081
/*
20822082
* Any connection that defines ->get_authorizer()
2083-
* should also define ->verify_authorizer_reply().
2083+
* should also define ->add_authorizer_challenge() and
2084+
* ->verify_authorizer_reply().
2085+
*
20842086
* See get_connect_authorizer().
20852087
*/
2088+
if (con->in_reply.tag == CEPH_MSGR_TAG_CHALLENGE_AUTHORIZER) {
2089+
ret = con->ops->add_authorizer_challenge(
2090+
con, con->auth->authorizer_reply_buf,
2091+
le32_to_cpu(con->in_reply.authorizer_len));
2092+
if (ret < 0)
2093+
return ret;
2094+
2095+
con_out_kvec_reset(con);
2096+
__prepare_write_connect(con);
2097+
prepare_read_connect(con);
2098+
return 0;
2099+
}
2100+
20862101
ret = con->ops->verify_authorizer_reply(con);
20872102
if (ret < 0) {
20882103
con->error_msg = "bad authorize reply";

‎net/ceph/osd_client.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5393,6 +5393,16 @@ static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
53935393
return auth;
53945394
}
53955395

5396+
static int add_authorizer_challenge(struct ceph_connection *con,
5397+
void *challenge_buf, int challenge_buf_len)
5398+
{
5399+
struct ceph_osd *o = con->private;
5400+
struct ceph_osd_client *osdc = o->o_osdc;
5401+
struct ceph_auth_client *ac = osdc->client->monc.auth;
5402+
5403+
return ceph_auth_add_authorizer_challenge(ac, o->o_auth.authorizer,
5404+
challenge_buf, challenge_buf_len);
5405+
}
53965406

53975407
static int verify_authorizer_reply(struct ceph_connection *con)
53985408
{
@@ -5442,6 +5452,7 @@ static const struct ceph_connection_operations osd_con_ops = {
54425452
.put = put_osd_con,
54435453
.dispatch = dispatch,
54445454
.get_authorizer = get_authorizer,
5455+
.add_authorizer_challenge = add_authorizer_challenge,
54455456
.verify_authorizer_reply = verify_authorizer_reply,
54465457
.invalidate_authorizer = invalidate_authorizer,
54475458
.alloc_msg = alloc_msg,

0 commit comments

Comments
 (0)