blob: 462786f571e7b183d77de8a78e4337933771bf09 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Sage Weilec0994e2010-02-02 16:25:35 -08002
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07003#include <linux/ceph/ceph_debug.h>
Sage Weilec0994e2010-02-02 16:25:35 -08004
5#include <linux/err.h>
6#include <linux/module.h>
7#include <linux/random.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09008#include <linux/slab.h>
Sage Weilec0994e2010-02-02 16:25:35 -08009
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070010#include <linux/ceph/decode.h>
11#include <linux/ceph/auth.h>
Ilya Dryomovcc255c72018-07-27 19:25:32 +020012#include <linux/ceph/ceph_features.h>
Ilya Dryomova51983e2015-10-28 23:52:06 +010013#include <linux/ceph/libceph.h>
Yan, Zheng33d07332014-11-04 16:33:37 +080014#include <linux/ceph/messenger.h>
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070015
16#include "crypto.h"
Sage Weilec0994e2010-02-02 16:25:35 -080017#include "auth_x.h"
18#include "auth_x_protocol.h"
Sage Weilec0994e2010-02-02 16:25:35 -080019
Sage Weilec0994e2010-02-02 16:25:35 -080020static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed);
21
22static int ceph_x_is_authenticated(struct ceph_auth_client *ac)
23{
24 struct ceph_x_info *xi = ac->private;
25 int need;
26
27 ceph_x_validate_tickets(ac, &need);
28 dout("ceph_x_is_authenticated want=%d need=%d have=%d\n",
29 ac->want_keys, need, xi->have_keys);
30 return (ac->want_keys & xi->have_keys) == ac->want_keys;
31}
32
Sage Weila41359f2010-05-25 15:39:06 -070033static int ceph_x_should_authenticate(struct ceph_auth_client *ac)
34{
35 struct ceph_x_info *xi = ac->private;
36 int need;
37
38 ceph_x_validate_tickets(ac, &need);
39 dout("ceph_x_should_authenticate want=%d need=%d have=%d\n",
40 ac->want_keys, need, xi->have_keys);
41 return need != 0;
42}
43
Ilya Dryomov55d9cc832016-12-02 16:35:07 +010044static int ceph_x_encrypt_offset(void)
45{
46 return sizeof(u32) + sizeof(struct ceph_x_encrypt_header);
47}
48
Sage Weil807c86e2010-03-15 15:52:17 -070049static int ceph_x_encrypt_buflen(int ilen)
50{
Ilya Dryomov55d9cc832016-12-02 16:35:07 +010051 return ceph_x_encrypt_offset() + ilen + 16;
Sage Weil807c86e2010-03-15 15:52:17 -070052}
53
Ilya Dryomovd03857c2016-12-02 16:35:07 +010054static int ceph_x_encrypt(struct ceph_crypto_key *secret, void *buf,
55 int buf_len, int plaintext_len)
Sage Weilec0994e2010-02-02 16:25:35 -080056{
Ilya Dryomovd03857c2016-12-02 16:35:07 +010057 struct ceph_x_encrypt_header *hdr = buf + sizeof(u32);
58 int ciphertext_len;
Sage Weilec0994e2010-02-02 16:25:35 -080059 int ret;
60
Ilya Dryomovd03857c2016-12-02 16:35:07 +010061 hdr->struct_v = 1;
62 hdr->magic = cpu_to_le64(CEPHX_ENC_MAGIC);
63
64 ret = ceph_crypt(secret, true, buf + sizeof(u32), buf_len - sizeof(u32),
65 plaintext_len + sizeof(struct ceph_x_encrypt_header),
66 &ciphertext_len);
Sage Weilec0994e2010-02-02 16:25:35 -080067 if (ret)
68 return ret;
Ilya Dryomovd03857c2016-12-02 16:35:07 +010069
70 ceph_encode_32(&buf, ciphertext_len);
71 return sizeof(u32) + ciphertext_len;
Sage Weilec0994e2010-02-02 16:25:35 -080072}
73
Ilya Dryomovc571fe22018-07-26 18:05:43 +020074static int __ceph_x_decrypt(struct ceph_crypto_key *secret, void *p,
75 int ciphertext_len)
76{
77 struct ceph_x_encrypt_header *hdr = p;
78 int plaintext_len;
79 int ret;
80
81 ret = ceph_crypt(secret, false, p, ciphertext_len, ciphertext_len,
82 &plaintext_len);
83 if (ret)
84 return ret;
85
86 if (le64_to_cpu(hdr->magic) != CEPHX_ENC_MAGIC) {
87 pr_err("%s bad magic\n", __func__);
88 return -EINVAL;
89 }
90
91 return plaintext_len - sizeof(*hdr);
92}
93
Ilya Dryomove15fd0a2016-12-02 16:35:08 +010094static int ceph_x_decrypt(struct ceph_crypto_key *secret, void **p, void *end)
Sage Weilec0994e2010-02-02 16:25:35 -080095{
Ilya Dryomovc571fe22018-07-26 18:05:43 +020096 int ciphertext_len;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +010097 int ret;
Sage Weilec0994e2010-02-02 16:25:35 -080098
Ilya Dryomove15fd0a2016-12-02 16:35:08 +010099 ceph_decode_32_safe(p, end, ciphertext_len, e_inval);
100 ceph_decode_need(p, end, ciphertext_len, e_inval);
Sage Weilec0994e2010-02-02 16:25:35 -0800101
Ilya Dryomovc571fe22018-07-26 18:05:43 +0200102 ret = __ceph_x_decrypt(secret, *p, ciphertext_len);
103 if (ret < 0)
Sage Weilec0994e2010-02-02 16:25:35 -0800104 return ret;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100105
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100106 *p += ciphertext_len;
Ilya Dryomovc571fe22018-07-26 18:05:43 +0200107 return ret;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100108
109e_inval:
110 return -EINVAL;
Sage Weilec0994e2010-02-02 16:25:35 -0800111}
112
113/*
114 * get existing (or insert new) ticket handler
115 */
Yehuda Sadehcd84db62010-06-11 16:58:48 -0700116static struct ceph_x_ticket_handler *
117get_ticket_handler(struct ceph_auth_client *ac, int service)
Sage Weilec0994e2010-02-02 16:25:35 -0800118{
119 struct ceph_x_ticket_handler *th;
120 struct ceph_x_info *xi = ac->private;
121 struct rb_node *parent = NULL, **p = &xi->ticket_handlers.rb_node;
122
123 while (*p) {
124 parent = *p;
125 th = rb_entry(parent, struct ceph_x_ticket_handler, node);
126 if (service < th->service)
127 p = &(*p)->rb_left;
128 else if (service > th->service)
129 p = &(*p)->rb_right;
130 else
131 return th;
132 }
133
134 /* add it */
135 th = kzalloc(sizeof(*th), GFP_NOFS);
136 if (!th)
137 return ERR_PTR(-ENOMEM);
138 th->service = service;
139 rb_link_node(&th->node, parent, p);
140 rb_insert_color(&th->node, &xi->ticket_handlers);
141 return th;
142}
143
144static void remove_ticket_handler(struct ceph_auth_client *ac,
145 struct ceph_x_ticket_handler *th)
146{
147 struct ceph_x_info *xi = ac->private;
148
149 dout("remove_ticket_handler %p %d\n", th, th->service);
150 rb_erase(&th->node, &xi->ticket_handlers);
151 ceph_crypto_key_destroy(&th->session_key);
152 if (th->ticket_blob)
153 ceph_buffer_put(th->ticket_blob);
154 kfree(th);
155}
156
Ilya Dryomov597cda32014-09-08 17:25:34 +0400157static int process_one_ticket(struct ceph_auth_client *ac,
158 struct ceph_crypto_key *secret,
Ilya Dryomovc27a3e42014-09-09 19:39:15 +0400159 void **p, void *end)
Ilya Dryomov597cda32014-09-08 17:25:34 +0400160{
161 struct ceph_x_info *xi = ac->private;
162 int type;
163 u8 tkt_struct_v, blob_struct_v;
164 struct ceph_x_ticket_handler *th;
165 void *dp, *dend;
166 int dlen;
167 char is_enc;
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200168 struct timespec64 validity;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400169 void *tp, *tpend;
Ilya Dryomove9226d72014-10-22 18:15:37 +0400170 void **ptp;
Ilya Dryomovb51456a2017-05-19 14:24:36 +0200171 struct ceph_crypto_key new_session_key = { 0 };
Ilya Dryomov597cda32014-09-08 17:25:34 +0400172 struct ceph_buffer *new_ticket_blob;
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200173 time64_t new_expires, new_renew_after;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400174 u64 new_secret_id;
175 int ret;
176
177 ceph_decode_need(p, end, sizeof(u32) + 1, bad);
178
179 type = ceph_decode_32(p);
180 dout(" ticket type %d %s\n", type, ceph_entity_type_name(type));
181
182 tkt_struct_v = ceph_decode_8(p);
183 if (tkt_struct_v != 1)
184 goto bad;
185
186 th = get_ticket_handler(ac, type);
187 if (IS_ERR(th)) {
188 ret = PTR_ERR(th);
189 goto out;
190 }
191
192 /* blob for me */
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100193 dp = *p + ceph_x_encrypt_offset();
194 ret = ceph_x_decrypt(secret, p, end);
195 if (ret < 0)
Ilya Dryomov597cda32014-09-08 17:25:34 +0400196 goto out;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100197 dout(" decrypted %d bytes\n", ret);
198 dend = dp + ret;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400199
200 tkt_struct_v = ceph_decode_8(&dp);
201 if (tkt_struct_v != 1)
202 goto bad;
203
Ilya Dryomov597cda32014-09-08 17:25:34 +0400204 ret = ceph_crypto_key_decode(&new_session_key, &dp, dend);
205 if (ret)
206 goto out;
207
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200208 ceph_decode_timespec64(&validity, dp);
Ilya Dryomovf6cdb292016-01-15 13:20:01 +0100209 dp += sizeof(struct ceph_timespec);
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200210 new_expires = ktime_get_real_seconds() + validity.tv_sec;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400211 new_renew_after = new_expires - (validity.tv_sec / 4);
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200212 dout(" expires=%llu renew_after=%llu\n", new_expires,
Ilya Dryomov597cda32014-09-08 17:25:34 +0400213 new_renew_after);
214
215 /* ticket blob for service */
216 ceph_decode_8_safe(p, end, is_enc, bad);
Ilya Dryomov597cda32014-09-08 17:25:34 +0400217 if (is_enc) {
218 /* encrypted */
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100219 tp = *p + ceph_x_encrypt_offset();
220 ret = ceph_x_decrypt(&th->session_key, p, end);
221 if (ret < 0)
Ilya Dryomov597cda32014-09-08 17:25:34 +0400222 goto out;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100223 dout(" encrypted ticket, decrypted %d bytes\n", ret);
Ilya Dryomove9226d72014-10-22 18:15:37 +0400224 ptp = &tp;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100225 tpend = tp + ret;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400226 } else {
227 /* unencrypted */
Ilya Dryomove9226d72014-10-22 18:15:37 +0400228 ptp = p;
229 tpend = end;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400230 }
Ilya Dryomove9226d72014-10-22 18:15:37 +0400231 ceph_decode_32_safe(ptp, tpend, dlen, bad);
Ilya Dryomov597cda32014-09-08 17:25:34 +0400232 dout(" ticket blob is %d bytes\n", dlen);
Ilya Dryomove9226d72014-10-22 18:15:37 +0400233 ceph_decode_need(ptp, tpend, 1 + sizeof(u64), bad);
234 blob_struct_v = ceph_decode_8(ptp);
Ilya Dryomovd18a1242017-05-19 12:21:56 +0200235 if (blob_struct_v != 1)
236 goto bad;
237
Ilya Dryomove9226d72014-10-22 18:15:37 +0400238 new_secret_id = ceph_decode_64(ptp);
239 ret = ceph_decode_buffer(&new_ticket_blob, ptp, tpend);
Ilya Dryomov597cda32014-09-08 17:25:34 +0400240 if (ret)
241 goto out;
242
243 /* all is well, update our ticket */
244 ceph_crypto_key_destroy(&th->session_key);
245 if (th->ticket_blob)
246 ceph_buffer_put(th->ticket_blob);
247 th->session_key = new_session_key;
248 th->ticket_blob = new_ticket_blob;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400249 th->secret_id = new_secret_id;
250 th->expires = new_expires;
251 th->renew_after = new_renew_after;
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100252 th->have_key = true;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400253 dout(" got ticket service %d (%s) secret_id %lld len %d\n",
254 type, ceph_entity_type_name(type), th->secret_id,
255 (int)th->ticket_blob->vec.iov_len);
256 xi->have_keys |= th->service;
Ilya Dryomovb51456a2017-05-19 14:24:36 +0200257 return 0;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400258
259bad:
260 ret = -EINVAL;
Ilya Dryomovb51456a2017-05-19 14:24:36 +0200261out:
262 ceph_crypto_key_destroy(&new_session_key);
263 return ret;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400264}
265
Sage Weilec0994e2010-02-02 16:25:35 -0800266static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
267 struct ceph_crypto_key *secret,
268 void *buf, void *end)
269{
Sage Weilec0994e2010-02-02 16:25:35 -0800270 void *p = buf;
Sage Weilb736b3d2010-04-30 12:45:02 -0700271 u8 reply_struct_v;
Ilya Dryomov597cda32014-09-08 17:25:34 +0400272 u32 num;
273 int ret;
Sage Weilec0994e2010-02-02 16:25:35 -0800274
Ilya Dryomov597cda32014-09-08 17:25:34 +0400275 ceph_decode_8_safe(&p, end, reply_struct_v, bad);
Sage Weilb736b3d2010-04-30 12:45:02 -0700276 if (reply_struct_v != 1)
Ilya Dryomov597cda32014-09-08 17:25:34 +0400277 return -EINVAL;
278
279 ceph_decode_32_safe(&p, end, num, bad);
Sage Weilec0994e2010-02-02 16:25:35 -0800280 dout("%d tickets\n", num);
Ilya Dryomov597cda32014-09-08 17:25:34 +0400281
Sage Weilec0994e2010-02-02 16:25:35 -0800282 while (num--) {
Ilya Dryomovc27a3e42014-09-09 19:39:15 +0400283 ret = process_one_ticket(ac, secret, &p, end);
Sage Weilec0994e2010-02-02 16:25:35 -0800284 if (ret)
Ilya Dryomovc27a3e42014-09-09 19:39:15 +0400285 return ret;
Sage Weilec0994e2010-02-02 16:25:35 -0800286 }
287
Ilya Dryomovc27a3e42014-09-09 19:39:15 +0400288 return 0;
Sage Weilec0994e2010-02-02 16:25:35 -0800289
290bad:
Ilya Dryomovc27a3e42014-09-09 19:39:15 +0400291 return -EINVAL;
Sage Weilec0994e2010-02-02 16:25:35 -0800292}
293
Ilya Dryomov149cac42018-07-27 16:37:54 +0200294/*
295 * Encode and encrypt the second part (ceph_x_authorize_b) of the
296 * authorizer. The first part (ceph_x_authorize_a) should already be
297 * encoded.
298 */
Ilya Dryomov6daca132018-07-27 19:18:34 +0200299static int encrypt_authorizer(struct ceph_x_authorizer *au,
300 u64 *server_challenge)
Ilya Dryomov149cac42018-07-27 16:37:54 +0200301{
302 struct ceph_x_authorize_a *msg_a;
303 struct ceph_x_authorize_b *msg_b;
304 void *p, *end;
305 int ret;
306
307 msg_a = au->buf->vec.iov_base;
308 WARN_ON(msg_a->ticket_blob.secret_id != cpu_to_le64(au->secret_id));
309 p = (void *)(msg_a + 1) + le32_to_cpu(msg_a->ticket_blob.blob_len);
310 end = au->buf->vec.iov_base + au->buf->vec.iov_len;
311
312 msg_b = p + ceph_x_encrypt_offset();
Ilya Dryomov6daca132018-07-27 19:18:34 +0200313 msg_b->struct_v = 2;
Ilya Dryomov149cac42018-07-27 16:37:54 +0200314 msg_b->nonce = cpu_to_le64(au->nonce);
Ilya Dryomov6daca132018-07-27 19:18:34 +0200315 if (server_challenge) {
316 msg_b->have_challenge = 1;
317 msg_b->server_challenge_plus_one =
318 cpu_to_le64(*server_challenge + 1);
319 } else {
320 msg_b->have_challenge = 0;
321 msg_b->server_challenge_plus_one = 0;
322 }
Ilya Dryomov149cac42018-07-27 16:37:54 +0200323
324 ret = ceph_x_encrypt(&au->session_key, p, end - p, sizeof(*msg_b));
325 if (ret < 0)
326 return ret;
327
328 p += ret;
Ilya Dryomov6daca132018-07-27 19:18:34 +0200329 if (server_challenge) {
330 WARN_ON(p != end);
331 } else {
332 WARN_ON(p > end);
333 au->buf->vec.iov_len = p - au->buf->vec.iov_base;
334 }
Ilya Dryomov149cac42018-07-27 16:37:54 +0200335
336 return 0;
337}
338
Ilya Dryomovcbf99a12015-10-26 11:03:46 +0100339static void ceph_x_authorizer_cleanup(struct ceph_x_authorizer *au)
340{
341 ceph_crypto_key_destroy(&au->session_key);
342 if (au->buf) {
343 ceph_buffer_put(au->buf);
344 au->buf = NULL;
345 }
346}
347
Sage Weilec0994e2010-02-02 16:25:35 -0800348static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
349 struct ceph_x_ticket_handler *th,
350 struct ceph_x_authorizer *au)
351{
Sage Weil807c86e2010-03-15 15:52:17 -0700352 int maxlen;
Sage Weilec0994e2010-02-02 16:25:35 -0800353 struct ceph_x_authorize_a *msg_a;
Ilya Dryomovd03857c2016-12-02 16:35:07 +0100354 struct ceph_x_authorize_b *msg_b;
Sage Weilec0994e2010-02-02 16:25:35 -0800355 int ret;
356 int ticket_blob_len =
357 (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0);
358
359 dout("build_authorizer for %s %p\n",
360 ceph_entity_type_name(th->service), au);
361
Yan, Zhengae385ea2014-11-04 16:32:35 +0800362 ceph_crypto_key_destroy(&au->session_key);
363 ret = ceph_crypto_key_clone(&au->session_key, &th->session_key);
364 if (ret)
Ilya Dryomovcbf99a12015-10-26 11:03:46 +0100365 goto out_au;
Yan, Zhengae385ea2014-11-04 16:32:35 +0800366
Ilya Dryomov36721ec2016-12-02 16:35:06 +0100367 maxlen = sizeof(*msg_a) + ticket_blob_len +
Ilya Dryomovd03857c2016-12-02 16:35:07 +0100368 ceph_x_encrypt_buflen(sizeof(*msg_b));
Sage Weil807c86e2010-03-15 15:52:17 -0700369 dout(" need len %d\n", maxlen);
370 if (au->buf && au->buf->alloc_len < maxlen) {
Sage Weilec0994e2010-02-02 16:25:35 -0800371 ceph_buffer_put(au->buf);
372 au->buf = NULL;
373 }
374 if (!au->buf) {
Sage Weil807c86e2010-03-15 15:52:17 -0700375 au->buf = ceph_buffer_new(maxlen, GFP_NOFS);
Yan, Zhengae385ea2014-11-04 16:32:35 +0800376 if (!au->buf) {
Ilya Dryomovcbf99a12015-10-26 11:03:46 +0100377 ret = -ENOMEM;
378 goto out_au;
Yan, Zhengae385ea2014-11-04 16:32:35 +0800379 }
Sage Weilec0994e2010-02-02 16:25:35 -0800380 }
381 au->service = th->service;
Sage Weil0bed9b52013-03-25 10:26:01 -0700382 au->secret_id = th->secret_id;
Sage Weilec0994e2010-02-02 16:25:35 -0800383
384 msg_a = au->buf->vec.iov_base;
385 msg_a->struct_v = 1;
386 msg_a->global_id = cpu_to_le64(ac->global_id);
387 msg_a->service_id = cpu_to_le32(th->service);
388 msg_a->ticket_blob.struct_v = 1;
389 msg_a->ticket_blob.secret_id = cpu_to_le64(th->secret_id);
390 msg_a->ticket_blob.blob_len = cpu_to_le32(ticket_blob_len);
391 if (ticket_blob_len) {
392 memcpy(msg_a->ticket_blob.blob, th->ticket_blob->vec.iov_base,
393 th->ticket_blob->vec.iov_len);
394 }
395 dout(" th %p secret_id %lld %lld\n", th, th->secret_id,
396 le64_to_cpu(msg_a->ticket_blob.secret_id));
397
Sage Weilec0994e2010-02-02 16:25:35 -0800398 get_random_bytes(&au->nonce, sizeof(au->nonce));
Ilya Dryomov6daca132018-07-27 19:18:34 +0200399 ret = encrypt_authorizer(au, NULL);
Ilya Dryomov149cac42018-07-27 16:37:54 +0200400 if (ret) {
401 pr_err("failed to encrypt authorizer: %d", ret);
Ilya Dryomovcbf99a12015-10-26 11:03:46 +0100402 goto out_au;
Ilya Dryomov149cac42018-07-27 16:37:54 +0200403 }
Ilya Dryomov36721ec2016-12-02 16:35:06 +0100404
Sage Weilec0994e2010-02-02 16:25:35 -0800405 dout(" built authorizer nonce %llx len %d\n", au->nonce,
406 (int)au->buf->vec.iov_len);
Sage Weilec0994e2010-02-02 16:25:35 -0800407 return 0;
408
Ilya Dryomovcbf99a12015-10-26 11:03:46 +0100409out_au:
410 ceph_x_authorizer_cleanup(au);
Sage Weilec0994e2010-02-02 16:25:35 -0800411 return ret;
412}
413
414static int ceph_x_encode_ticket(struct ceph_x_ticket_handler *th,
415 void **p, void *end)
416{
417 ceph_decode_need(p, end, 1 + sizeof(u64), bad);
418 ceph_encode_8(p, 1);
419 ceph_encode_64(p, th->secret_id);
420 if (th->ticket_blob) {
421 const char *buf = th->ticket_blob->vec.iov_base;
422 u32 len = th->ticket_blob->vec.iov_len;
423
424 ceph_encode_32_safe(p, end, len, bad);
425 ceph_encode_copy_safe(p, end, buf, len, bad);
426 } else {
427 ceph_encode_32_safe(p, end, 0, bad);
428 }
429
430 return 0;
431bad:
432 return -ERANGE;
433}
434
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100435static bool need_key(struct ceph_x_ticket_handler *th)
436{
437 if (!th->have_key)
438 return true;
439
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200440 return ktime_get_real_seconds() >= th->renew_after;
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100441}
442
443static bool have_key(struct ceph_x_ticket_handler *th)
444{
445 if (th->have_key) {
Arnd Bergmann473bd2d2018-07-13 22:18:34 +0200446 if (ktime_get_real_seconds() >= th->expires)
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100447 th->have_key = false;
448 }
449
450 return th->have_key;
451}
452
Sage Weilec0994e2010-02-02 16:25:35 -0800453static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed)
454{
455 int want = ac->want_keys;
456 struct ceph_x_info *xi = ac->private;
457 int service;
458
459 *pneed = ac->want_keys & ~(xi->have_keys);
460
461 for (service = 1; service <= want; service <<= 1) {
462 struct ceph_x_ticket_handler *th;
463
464 if (!(ac->want_keys & service))
465 continue;
466
467 if (*pneed & service)
468 continue;
469
470 th = get_ticket_handler(ac, service);
Dan Carpenterb5457872010-08-26 11:12:38 +0200471 if (IS_ERR(th)) {
Sage Weilec0994e2010-02-02 16:25:35 -0800472 *pneed |= service;
473 continue;
474 }
475
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100476 if (need_key(th))
Sage Weilec0994e2010-02-02 16:25:35 -0800477 *pneed |= service;
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100478 if (!have_key(th))
Sage Weilec0994e2010-02-02 16:25:35 -0800479 xi->have_keys &= ~service;
480 }
481}
482
Sage Weilec0994e2010-02-02 16:25:35 -0800483static int ceph_x_build_request(struct ceph_auth_client *ac,
484 void *buf, void *end)
485{
486 struct ceph_x_info *xi = ac->private;
487 int need;
488 struct ceph_x_request_header *head = buf;
489 int ret;
490 struct ceph_x_ticket_handler *th =
491 get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
492
Dan Carpenterb5457872010-08-26 11:12:38 +0200493 if (IS_ERR(th))
494 return PTR_ERR(th);
495
Sage Weilec0994e2010-02-02 16:25:35 -0800496 ceph_x_validate_tickets(ac, &need);
497
498 dout("build_request want %x have %x need %x\n",
499 ac->want_keys, xi->have_keys, need);
500
501 if (need & CEPH_ENTITY_TYPE_AUTH) {
502 struct ceph_x_authenticate *auth = (void *)(head + 1);
503 void *p = auth + 1;
Ilya Dryomovd03857c2016-12-02 16:35:07 +0100504 void *enc_buf = xi->auth_authorizer.enc_buf;
505 struct ceph_x_challenge_blob *blob = enc_buf +
506 ceph_x_encrypt_offset();
Sage Weilec0994e2010-02-02 16:25:35 -0800507 u64 *u;
508
509 if (p > end)
510 return -ERANGE;
511
512 dout(" get_auth_session_key\n");
513 head->op = cpu_to_le16(CEPHX_GET_AUTH_SESSION_KEY);
514
515 /* encrypt and hash */
516 get_random_bytes(&auth->client_challenge, sizeof(u64));
Ilya Dryomovd03857c2016-12-02 16:35:07 +0100517 blob->client_challenge = auth->client_challenge;
518 blob->server_challenge = cpu_to_le64(xi->server_challenge);
519 ret = ceph_x_encrypt(&xi->secret, enc_buf, CEPHX_AU_ENC_BUF_LEN,
520 sizeof(*blob));
Sage Weilec0994e2010-02-02 16:25:35 -0800521 if (ret < 0)
522 return ret;
523
524 auth->struct_v = 1;
525 auth->key = 0;
Ilya Dryomovd03857c2016-12-02 16:35:07 +0100526 for (u = (u64 *)enc_buf; u + 1 <= (u64 *)(enc_buf + ret); u++)
Yehuda Sadehcd84db62010-06-11 16:58:48 -0700527 auth->key ^= *(__le64 *)u;
Sage Weilec0994e2010-02-02 16:25:35 -0800528 dout(" server_challenge %llx client_challenge %llx key %llx\n",
529 xi->server_challenge, le64_to_cpu(auth->client_challenge),
530 le64_to_cpu(auth->key));
531
532 /* now encode the old ticket if exists */
533 ret = ceph_x_encode_ticket(th, &p, end);
534 if (ret < 0)
535 return ret;
536
537 return p - buf;
538 }
539
540 if (need) {
541 void *p = head + 1;
542 struct ceph_x_service_ticket_request *req;
543
544 if (p > end)
545 return -ERANGE;
546 head->op = cpu_to_le16(CEPHX_GET_PRINCIPAL_SESSION_KEY);
547
Sage Weilec0994e2010-02-02 16:25:35 -0800548 ret = ceph_x_build_authorizer(ac, th, &xi->auth_authorizer);
549 if (ret)
550 return ret;
551 ceph_encode_copy(&p, xi->auth_authorizer.buf->vec.iov_base,
552 xi->auth_authorizer.buf->vec.iov_len);
553
554 req = p;
555 req->keys = cpu_to_le32(need);
556 p += sizeof(*req);
557 return p - buf;
558 }
559
560 return 0;
561}
562
563static int ceph_x_handle_reply(struct ceph_auth_client *ac, int result,
564 void *buf, void *end)
565{
566 struct ceph_x_info *xi = ac->private;
567 struct ceph_x_reply_header *head = buf;
568 struct ceph_x_ticket_handler *th;
569 int len = end - buf;
570 int op;
571 int ret;
572
573 if (result)
574 return result; /* XXX hmm? */
575
576 if (xi->starting) {
577 /* it's a hello */
578 struct ceph_x_server_challenge *sc = buf;
579
580 if (len != sizeof(*sc))
581 return -EINVAL;
582 xi->server_challenge = le64_to_cpu(sc->server_challenge);
583 dout("handle_reply got server challenge %llx\n",
584 xi->server_challenge);
585 xi->starting = false;
586 xi->have_keys &= ~CEPH_ENTITY_TYPE_AUTH;
587 return -EAGAIN;
588 }
589
Yehuda Sadeh0cf55372010-06-11 15:57:06 -0700590 op = le16_to_cpu(head->op);
Sage Weilec0994e2010-02-02 16:25:35 -0800591 result = le32_to_cpu(head->result);
592 dout("handle_reply op %d result %d\n", op, result);
593 switch (op) {
594 case CEPHX_GET_AUTH_SESSION_KEY:
595 /* verify auth key */
596 ret = ceph_x_proc_ticket_reply(ac, &xi->secret,
597 buf + sizeof(*head), end);
598 break;
599
600 case CEPHX_GET_PRINCIPAL_SESSION_KEY:
601 th = get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
Dan Carpenterb5457872010-08-26 11:12:38 +0200602 if (IS_ERR(th))
603 return PTR_ERR(th);
Sage Weilec0994e2010-02-02 16:25:35 -0800604 ret = ceph_x_proc_ticket_reply(ac, &th->session_key,
605 buf + sizeof(*head), end);
606 break;
607
608 default:
609 return -EINVAL;
610 }
611 if (ret)
612 return ret;
613 if (ac->want_keys == xi->have_keys)
614 return 0;
615 return -EAGAIN;
616}
617
Ilya Dryomov6c1ea262016-04-11 19:34:49 +0200618static void ceph_x_destroy_authorizer(struct ceph_authorizer *a)
619{
620 struct ceph_x_authorizer *au = (void *)a;
621
622 ceph_x_authorizer_cleanup(au);
623 kfree(au);
624}
625
Sage Weilec0994e2010-02-02 16:25:35 -0800626static int ceph_x_create_authorizer(
627 struct ceph_auth_client *ac, int peer_type,
Alex Elder74f18692012-05-16 15:16:39 -0500628 struct ceph_auth_handshake *auth)
Sage Weilec0994e2010-02-02 16:25:35 -0800629{
630 struct ceph_x_authorizer *au;
631 struct ceph_x_ticket_handler *th;
632 int ret;
633
634 th = get_ticket_handler(ac, peer_type);
635 if (IS_ERR(th))
636 return PTR_ERR(th);
637
638 au = kzalloc(sizeof(*au), GFP_NOFS);
639 if (!au)
640 return -ENOMEM;
641
Ilya Dryomov6c1ea262016-04-11 19:34:49 +0200642 au->base.destroy = ceph_x_destroy_authorizer;
643
Sage Weilec0994e2010-02-02 16:25:35 -0800644 ret = ceph_x_build_authorizer(ac, th, au);
645 if (ret) {
646 kfree(au);
647 return ret;
648 }
649
Alex Elder74f18692012-05-16 15:16:39 -0500650 auth->authorizer = (struct ceph_authorizer *) au;
651 auth->authorizer_buf = au->buf->vec.iov_base;
652 auth->authorizer_buf_len = au->buf->vec.iov_len;
Ilya Dryomov7882a262016-12-02 16:35:07 +0100653 auth->authorizer_reply_buf = au->enc_buf;
654 auth->authorizer_reply_buf_len = CEPHX_AU_ENC_BUF_LEN;
Yan, Zheng33d07332014-11-04 16:33:37 +0800655 auth->sign_message = ac->ops->sign_message;
656 auth->check_message_signature = ac->ops->check_message_signature;
Alex Elder74f18692012-05-16 15:16:39 -0500657
Sage Weilec0994e2010-02-02 16:25:35 -0800658 return 0;
659}
660
Sage Weil0bed9b52013-03-25 10:26:01 -0700661static int ceph_x_update_authorizer(
662 struct ceph_auth_client *ac, int peer_type,
663 struct ceph_auth_handshake *auth)
664{
665 struct ceph_x_authorizer *au;
666 struct ceph_x_ticket_handler *th;
Sage Weil0bed9b52013-03-25 10:26:01 -0700667
668 th = get_ticket_handler(ac, peer_type);
669 if (IS_ERR(th))
670 return PTR_ERR(th);
671
672 au = (struct ceph_x_authorizer *)auth->authorizer;
673 if (au->secret_id < th->secret_id) {
674 dout("ceph_x_update_authorizer service %u secret %llu < %llu\n",
675 au->service, au->secret_id, th->secret_id);
676 return ceph_x_build_authorizer(ac, th, au);
677 }
678 return 0;
679}
680
Ilya Dryomov6daca132018-07-27 19:18:34 +0200681static int decrypt_authorize_challenge(struct ceph_x_authorizer *au,
682 void *challenge_buf,
683 int challenge_buf_len,
684 u64 *server_challenge)
685{
686 struct ceph_x_authorize_challenge *ch =
687 challenge_buf + sizeof(struct ceph_x_encrypt_header);
688 int ret;
689
690 /* no leading len */
691 ret = __ceph_x_decrypt(&au->session_key, challenge_buf,
692 challenge_buf_len);
693 if (ret < 0)
694 return ret;
695 if (ret < sizeof(*ch)) {
696 pr_err("bad size %d for ceph_x_authorize_challenge\n", ret);
697 return -EINVAL;
698 }
699
700 *server_challenge = le64_to_cpu(ch->server_challenge);
701 return 0;
702}
703
704static int ceph_x_add_authorizer_challenge(struct ceph_auth_client *ac,
705 struct ceph_authorizer *a,
706 void *challenge_buf,
707 int challenge_buf_len)
708{
709 struct ceph_x_authorizer *au = (void *)a;
710 u64 server_challenge;
711 int ret;
712
713 ret = decrypt_authorize_challenge(au, challenge_buf, challenge_buf_len,
714 &server_challenge);
715 if (ret) {
716 pr_err("failed to decrypt authorize challenge: %d", ret);
717 return ret;
718 }
719
720 ret = encrypt_authorizer(au, &server_challenge);
721 if (ret) {
722 pr_err("failed to encrypt authorizer w/ challenge: %d", ret);
723 return ret;
724 }
725
726 return 0;
727}
728
Sage Weilec0994e2010-02-02 16:25:35 -0800729static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
Ilya Dryomov0dde5842016-12-02 16:35:09 +0100730 struct ceph_authorizer *a)
Sage Weilec0994e2010-02-02 16:25:35 -0800731{
732 struct ceph_x_authorizer *au = (void *)a;
Ilya Dryomov7882a262016-12-02 16:35:07 +0100733 void *p = au->enc_buf;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100734 struct ceph_x_authorize_reply *reply = p + ceph_x_encrypt_offset();
735 int ret;
Sage Weilec0994e2010-02-02 16:25:35 -0800736
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100737 ret = ceph_x_decrypt(&au->session_key, &p, p + CEPHX_AU_ENC_BUF_LEN);
Sage Weilec0994e2010-02-02 16:25:35 -0800738 if (ret < 0)
739 return ret;
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100740 if (ret != sizeof(*reply))
Sage Weilec0994e2010-02-02 16:25:35 -0800741 return -EPERM;
742
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100743 if (au->nonce + 1 != le64_to_cpu(reply->nonce_plus_one))
Sage Weilec0994e2010-02-02 16:25:35 -0800744 ret = -EPERM;
745 else
746 ret = 0;
747 dout("verify_authorizer_reply nonce %llx got %llx ret %d\n",
Ilya Dryomove15fd0a2016-12-02 16:35:08 +0100748 au->nonce, le64_to_cpu(reply->nonce_plus_one), ret);
Sage Weilec0994e2010-02-02 16:25:35 -0800749 return ret;
750}
751
Sage Weilec0994e2010-02-02 16:25:35 -0800752static void ceph_x_reset(struct ceph_auth_client *ac)
753{
754 struct ceph_x_info *xi = ac->private;
755
756 dout("reset\n");
757 xi->starting = true;
758 xi->server_challenge = 0;
759}
760
761static void ceph_x_destroy(struct ceph_auth_client *ac)
762{
763 struct ceph_x_info *xi = ac->private;
764 struct rb_node *p;
765
766 dout("ceph_x_destroy %p\n", ac);
767 ceph_crypto_key_destroy(&xi->secret);
768
769 while ((p = rb_first(&xi->ticket_handlers)) != NULL) {
770 struct ceph_x_ticket_handler *th =
771 rb_entry(p, struct ceph_x_ticket_handler, node);
772 remove_ticket_handler(ac, th);
773 }
774
Ilya Dryomovcbf99a12015-10-26 11:03:46 +0100775 ceph_x_authorizer_cleanup(&xi->auth_authorizer);
Sage Weil22b1de02010-07-05 15:36:49 -0700776
Sage Weilec0994e2010-02-02 16:25:35 -0800777 kfree(ac->private);
778 ac->private = NULL;
779}
780
Ilya Dryomov187d1312016-01-14 17:31:51 +0100781static void invalidate_ticket(struct ceph_auth_client *ac, int peer_type)
Sage Weilec0994e2010-02-02 16:25:35 -0800782{
783 struct ceph_x_ticket_handler *th;
784
785 th = get_ticket_handler(ac, peer_type);
Dan Carpenterb5457872010-08-26 11:12:38 +0200786 if (!IS_ERR(th))
Ilya Dryomov6abe0972016-01-14 16:35:35 +0100787 th->have_key = false;
Sage Weilec0994e2010-02-02 16:25:35 -0800788}
789
Ilya Dryomov187d1312016-01-14 17:31:51 +0100790static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac,
791 int peer_type)
792{
793 /*
794 * We are to invalidate a service ticket in the hopes of
795 * getting a new, hopefully more valid, one. But, we won't get
796 * it unless our AUTH ticket is good, so invalidate AUTH ticket
797 * as well, just in case.
798 */
799 invalidate_ticket(ac, peer_type);
800 invalidate_ticket(ac, CEPH_ENTITY_TYPE_AUTH);
801}
802
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100803static int calc_signature(struct ceph_x_authorizer *au, struct ceph_msg *msg,
804 __le64 *psig)
Yan, Zheng33d07332014-11-04 16:33:37 +0800805{
Ilya Dryomovd03857c2016-12-02 16:35:07 +0100806 void *enc_buf = au->enc_buf;
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100807 int ret;
808
Ilya Dryomovcc255c72018-07-27 19:25:32 +0200809 if (!CEPH_HAVE_FEATURE(msg->con->peer_features, CEPHX_V2)) {
810 struct {
811 __le32 len;
812 __le32 header_crc;
813 __le32 front_crc;
814 __le32 middle_crc;
815 __le32 data_crc;
816 } __packed *sigblock = enc_buf + ceph_x_encrypt_offset();
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100817
Ilya Dryomovcc255c72018-07-27 19:25:32 +0200818 sigblock->len = cpu_to_le32(4*sizeof(u32));
819 sigblock->header_crc = msg->hdr.crc;
820 sigblock->front_crc = msg->footer.front_crc;
821 sigblock->middle_crc = msg->footer.middle_crc;
822 sigblock->data_crc = msg->footer.data_crc;
823
824 ret = ceph_x_encrypt(&au->session_key, enc_buf,
825 CEPHX_AU_ENC_BUF_LEN, sizeof(*sigblock));
826 if (ret < 0)
827 return ret;
828
829 *psig = *(__le64 *)(enc_buf + sizeof(u32));
830 } else {
831 struct {
832 __le32 header_crc;
833 __le32 front_crc;
834 __le32 front_len;
835 __le32 middle_crc;
836 __le32 middle_len;
837 __le32 data_crc;
838 __le32 data_len;
839 __le32 seq_lower_word;
840 } __packed *sigblock = enc_buf;
841 struct {
842 __le64 a, b, c, d;
843 } __packed *penc = enc_buf;
844 int ciphertext_len;
845
846 sigblock->header_crc = msg->hdr.crc;
847 sigblock->front_crc = msg->footer.front_crc;
848 sigblock->front_len = msg->hdr.front_len;
849 sigblock->middle_crc = msg->footer.middle_crc;
850 sigblock->middle_len = msg->hdr.middle_len;
851 sigblock->data_crc = msg->footer.data_crc;
852 sigblock->data_len = msg->hdr.data_len;
853 sigblock->seq_lower_word = *(__le32 *)&msg->hdr.seq;
854
855 /* no leading len, no ceph_x_encrypt_header */
856 ret = ceph_crypt(&au->session_key, true, enc_buf,
857 CEPHX_AU_ENC_BUF_LEN, sizeof(*sigblock),
858 &ciphertext_len);
859 if (ret)
860 return ret;
861
862 *psig = penc->a ^ penc->b ^ penc->c ^ penc->d;
863 }
864
Yan, Zheng33d07332014-11-04 16:33:37 +0800865 return 0;
866}
867
868static int ceph_x_sign_message(struct ceph_auth_handshake *auth,
869 struct ceph_msg *msg)
870{
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100871 __le64 sig;
Yan, Zheng33d07332014-11-04 16:33:37 +0800872 int ret;
Ilya Dryomov4199b8e2015-10-27 16:42:49 +0100873
Ilya Dryomova51983e2015-10-28 23:52:06 +0100874 if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN))
875 return 0;
876
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100877 ret = calc_signature((struct ceph_x_authorizer *)auth->authorizer,
878 msg, &sig);
879 if (ret)
Yan, Zheng33d07332014-11-04 16:33:37 +0800880 return ret;
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100881
882 msg->footer.sig = sig;
Yan, Zheng33d07332014-11-04 16:33:37 +0800883 msg->footer.flags |= CEPH_MSG_FOOTER_SIGNED;
884 return 0;
885}
886
887static int ceph_x_check_message_signature(struct ceph_auth_handshake *auth,
888 struct ceph_msg *msg)
889{
890 __le64 sig_check;
891 int ret;
892
Ilya Dryomova51983e2015-10-28 23:52:06 +0100893 if (ceph_test_opt(from_msgr(msg->con->msgr), NOMSGSIGN))
894 return 0;
895
Ilya Dryomov4eb45172016-12-02 16:35:07 +0100896 ret = calc_signature((struct ceph_x_authorizer *)auth->authorizer,
897 msg, &sig_check);
898 if (ret)
Yan, Zheng33d07332014-11-04 16:33:37 +0800899 return ret;
900 if (sig_check == msg->footer.sig)
901 return 0;
902 if (msg->footer.flags & CEPH_MSG_FOOTER_SIGNED)
903 dout("ceph_x_check_message_signature %p has signature %llx "
904 "expect %llx\n", msg, msg->footer.sig, sig_check);
905 else
906 dout("ceph_x_check_message_signature %p sender did not set "
907 "CEPH_MSG_FOOTER_SIGNED\n", msg);
908 return -EBADMSG;
909}
Sage Weilec0994e2010-02-02 16:25:35 -0800910
911static const struct ceph_auth_client_ops ceph_x_ops = {
Sage Weil559c1e02010-05-14 09:55:18 -0700912 .name = "x",
Sage Weilec0994e2010-02-02 16:25:35 -0800913 .is_authenticated = ceph_x_is_authenticated,
Sage Weila41359f2010-05-25 15:39:06 -0700914 .should_authenticate = ceph_x_should_authenticate,
Sage Weilec0994e2010-02-02 16:25:35 -0800915 .build_request = ceph_x_build_request,
916 .handle_reply = ceph_x_handle_reply,
917 .create_authorizer = ceph_x_create_authorizer,
Sage Weil0bed9b52013-03-25 10:26:01 -0700918 .update_authorizer = ceph_x_update_authorizer,
Ilya Dryomov6daca132018-07-27 19:18:34 +0200919 .add_authorizer_challenge = ceph_x_add_authorizer_challenge,
Sage Weilec0994e2010-02-02 16:25:35 -0800920 .verify_authorizer_reply = ceph_x_verify_authorizer_reply,
Sage Weilec0994e2010-02-02 16:25:35 -0800921 .invalidate_authorizer = ceph_x_invalidate_authorizer,
922 .reset = ceph_x_reset,
923 .destroy = ceph_x_destroy,
Yan, Zheng33d07332014-11-04 16:33:37 +0800924 .sign_message = ceph_x_sign_message,
925 .check_message_signature = ceph_x_check_message_signature,
Sage Weilec0994e2010-02-02 16:25:35 -0800926};
927
928
929int ceph_x_init(struct ceph_auth_client *ac)
930{
931 struct ceph_x_info *xi;
932 int ret;
933
934 dout("ceph_x_init %p\n", ac);
Sage Weilb0930f82010-04-29 13:26:53 -0700935 ret = -ENOMEM;
Sage Weilec0994e2010-02-02 16:25:35 -0800936 xi = kzalloc(sizeof(*xi), GFP_NOFS);
937 if (!xi)
Sage Weilb0930f82010-04-29 13:26:53 -0700938 goto out;
Sage Weilec0994e2010-02-02 16:25:35 -0800939
Sage Weilec0994e2010-02-02 16:25:35 -0800940 ret = -EINVAL;
Tommi Virtanen8323c3a2011-03-25 16:32:57 -0700941 if (!ac->key) {
Sage Weilec0994e2010-02-02 16:25:35 -0800942 pr_err("no secret set (for auth_x protocol)\n");
Sage Weilb0930f82010-04-29 13:26:53 -0700943 goto out_nomem;
Sage Weilec0994e2010-02-02 16:25:35 -0800944 }
945
Tommi Virtanen8323c3a2011-03-25 16:32:57 -0700946 ret = ceph_crypto_key_clone(&xi->secret, ac->key);
947 if (ret < 0) {
948 pr_err("cannot clone key: %d\n", ret);
Sage Weilb0930f82010-04-29 13:26:53 -0700949 goto out_nomem;
Tommi Virtanen8323c3a2011-03-25 16:32:57 -0700950 }
Sage Weilec0994e2010-02-02 16:25:35 -0800951
952 xi->starting = true;
953 xi->ticket_handlers = RB_ROOT;
954
955 ac->protocol = CEPH_AUTH_CEPHX;
956 ac->private = xi;
957 ac->ops = &ceph_x_ops;
958 return 0;
959
Sage Weilb0930f82010-04-29 13:26:53 -0700960out_nomem:
Sage Weilec0994e2010-02-02 16:25:35 -0800961 kfree(xi);
Sage Weilb0930f82010-04-29 13:26:53 -0700962out:
Sage Weilec0994e2010-02-02 16:25:35 -0800963 return ret;
964}