auth_x.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. #include "ceph_debug.h"
  2. #include <linux/err.h>
  3. #include <linux/module.h>
  4. #include <linux/random.h>
  5. #include "auth_x.h"
  6. #include "auth_x_protocol.h"
  7. #include "crypto.h"
  8. #include "auth.h"
  9. #include "decode.h"
  10. struct kmem_cache *ceph_x_ticketbuf_cachep;
  11. #define TEMP_TICKET_BUF_LEN 256
  12. static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed);
  13. static int ceph_x_is_authenticated(struct ceph_auth_client *ac)
  14. {
  15. struct ceph_x_info *xi = ac->private;
  16. int need;
  17. ceph_x_validate_tickets(ac, &need);
  18. dout("ceph_x_is_authenticated want=%d need=%d have=%d\n",
  19. ac->want_keys, need, xi->have_keys);
  20. return (ac->want_keys & xi->have_keys) == ac->want_keys;
  21. }
  22. static int ceph_x_encrypt_buflen(int ilen)
  23. {
  24. return sizeof(struct ceph_x_encrypt_header) + ilen + 16 +
  25. sizeof(u32);
  26. }
  27. static int ceph_x_encrypt(struct ceph_crypto_key *secret,
  28. void *ibuf, int ilen, void *obuf, size_t olen)
  29. {
  30. struct ceph_x_encrypt_header head = {
  31. .struct_v = 1,
  32. .magic = cpu_to_le64(CEPHX_ENC_MAGIC)
  33. };
  34. size_t len = olen - sizeof(u32);
  35. int ret;
  36. ret = ceph_encrypt2(secret, obuf + sizeof(u32), &len,
  37. &head, sizeof(head), ibuf, ilen);
  38. if (ret)
  39. return ret;
  40. ceph_encode_32(&obuf, len);
  41. return len + sizeof(u32);
  42. }
  43. static int ceph_x_decrypt(struct ceph_crypto_key *secret,
  44. void **p, void *end, void *obuf, size_t olen)
  45. {
  46. struct ceph_x_encrypt_header head;
  47. size_t head_len = sizeof(head);
  48. int len, ret;
  49. len = ceph_decode_32(p);
  50. if (*p + len > end)
  51. return -EINVAL;
  52. dout("ceph_x_decrypt len %d\n", len);
  53. ret = ceph_decrypt2(secret, &head, &head_len, obuf, &olen,
  54. *p, len);
  55. if (ret)
  56. return ret;
  57. if (head.struct_v != 1 || le64_to_cpu(head.magic) != CEPHX_ENC_MAGIC)
  58. return -EPERM;
  59. *p += len;
  60. return olen;
  61. }
  62. /*
  63. * get existing (or insert new) ticket handler
  64. */
  65. struct ceph_x_ticket_handler *get_ticket_handler(struct ceph_auth_client *ac,
  66. int service)
  67. {
  68. struct ceph_x_ticket_handler *th;
  69. struct ceph_x_info *xi = ac->private;
  70. struct rb_node *parent = NULL, **p = &xi->ticket_handlers.rb_node;
  71. while (*p) {
  72. parent = *p;
  73. th = rb_entry(parent, struct ceph_x_ticket_handler, node);
  74. if (service < th->service)
  75. p = &(*p)->rb_left;
  76. else if (service > th->service)
  77. p = &(*p)->rb_right;
  78. else
  79. return th;
  80. }
  81. /* add it */
  82. th = kzalloc(sizeof(*th), GFP_NOFS);
  83. if (!th)
  84. return ERR_PTR(-ENOMEM);
  85. th->service = service;
  86. rb_link_node(&th->node, parent, p);
  87. rb_insert_color(&th->node, &xi->ticket_handlers);
  88. return th;
  89. }
  90. static void remove_ticket_handler(struct ceph_auth_client *ac,
  91. struct ceph_x_ticket_handler *th)
  92. {
  93. struct ceph_x_info *xi = ac->private;
  94. dout("remove_ticket_handler %p %d\n", th, th->service);
  95. rb_erase(&th->node, &xi->ticket_handlers);
  96. ceph_crypto_key_destroy(&th->session_key);
  97. if (th->ticket_blob)
  98. ceph_buffer_put(th->ticket_blob);
  99. kfree(th);
  100. }
  101. static int ceph_x_proc_ticket_reply(struct ceph_auth_client *ac,
  102. struct ceph_crypto_key *secret,
  103. void *buf, void *end)
  104. {
  105. struct ceph_x_info *xi = ac->private;
  106. int num;
  107. void *p = buf;
  108. int ret;
  109. char *dbuf;
  110. char *ticket_buf;
  111. u8 struct_v;
  112. dbuf = kmem_cache_alloc(ceph_x_ticketbuf_cachep, GFP_NOFS | GFP_ATOMIC);
  113. if (!dbuf)
  114. return -ENOMEM;
  115. ret = -ENOMEM;
  116. ticket_buf = kmem_cache_alloc(ceph_x_ticketbuf_cachep,
  117. GFP_NOFS | GFP_ATOMIC);
  118. if (!ticket_buf)
  119. goto out_dbuf;
  120. ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
  121. struct_v = ceph_decode_8(&p);
  122. if (struct_v != 1)
  123. goto bad;
  124. num = ceph_decode_32(&p);
  125. dout("%d tickets\n", num);
  126. while (num--) {
  127. int type;
  128. u8 struct_v;
  129. struct ceph_x_ticket_handler *th;
  130. void *dp, *dend;
  131. int dlen;
  132. char is_enc;
  133. struct timespec validity;
  134. struct ceph_crypto_key old_key;
  135. void *tp, *tpend;
  136. struct ceph_buffer *new_ticket_blob;
  137. ceph_decode_need(&p, end, sizeof(u32) + 1, bad);
  138. type = ceph_decode_32(&p);
  139. dout(" ticket type %d %s\n", type, ceph_entity_type_name(type));
  140. struct_v = ceph_decode_8(&p);
  141. if (struct_v != 1)
  142. goto bad;
  143. th = get_ticket_handler(ac, type);
  144. if (IS_ERR(th)) {
  145. ret = PTR_ERR(th);
  146. goto out;
  147. }
  148. /* blob for me */
  149. dlen = ceph_x_decrypt(secret, &p, end, dbuf,
  150. TEMP_TICKET_BUF_LEN);
  151. if (dlen <= 0) {
  152. ret = dlen;
  153. goto out;
  154. }
  155. dout(" decrypted %d bytes\n", dlen);
  156. dend = dbuf + dlen;
  157. dp = dbuf;
  158. struct_v = ceph_decode_8(&dp);
  159. if (struct_v != 1)
  160. goto bad;
  161. memcpy(&old_key, &th->session_key, sizeof(old_key));
  162. ret = ceph_crypto_key_decode(&th->session_key, &dp, dend);
  163. if (ret)
  164. goto out;
  165. ceph_decode_copy(&dp, &th->validity, sizeof(th->validity));
  166. ceph_decode_timespec(&validity, &th->validity);
  167. th->expires = get_seconds() + validity.tv_sec;
  168. th->renew_after = th->expires - (validity.tv_sec / 4);
  169. dout(" expires=%lu renew_after=%lu\n", th->expires,
  170. th->renew_after);
  171. /* ticket blob for service */
  172. ceph_decode_8_safe(&p, end, is_enc, bad);
  173. tp = ticket_buf;
  174. if (is_enc) {
  175. /* encrypted */
  176. dout(" encrypted ticket\n");
  177. dlen = ceph_x_decrypt(&old_key, &p, end, ticket_buf,
  178. TEMP_TICKET_BUF_LEN);
  179. if (dlen < 0) {
  180. ret = dlen;
  181. goto out;
  182. }
  183. dlen = ceph_decode_32(&tp);
  184. } else {
  185. /* unencrypted */
  186. ceph_decode_32_safe(&p, end, dlen, bad);
  187. ceph_decode_need(&p, end, dlen, bad);
  188. ceph_decode_copy(&p, ticket_buf, dlen);
  189. }
  190. tpend = tp + dlen;
  191. dout(" ticket blob is %d bytes\n", dlen);
  192. ceph_decode_need(&tp, tpend, 1 + sizeof(u64), bad);
  193. struct_v = ceph_decode_8(&tp);
  194. th->secret_id = ceph_decode_64(&tp);
  195. ret = ceph_decode_buffer(&new_ticket_blob, &tp, tpend);
  196. if (ret)
  197. goto out;
  198. if (th->ticket_blob)
  199. ceph_buffer_put(th->ticket_blob);
  200. th->ticket_blob = new_ticket_blob;
  201. dout(" got ticket service %d (%s) secret_id %lld len %d\n",
  202. type, ceph_entity_type_name(type), th->secret_id,
  203. (int)th->ticket_blob->vec.iov_len);
  204. xi->have_keys |= th->service;
  205. }
  206. ret = 0;
  207. out:
  208. kmem_cache_free(ceph_x_ticketbuf_cachep, ticket_buf);
  209. out_dbuf:
  210. kmem_cache_free(ceph_x_ticketbuf_cachep, dbuf);
  211. return ret;
  212. bad:
  213. ret = -EINVAL;
  214. goto out;
  215. }
  216. static int ceph_x_build_authorizer(struct ceph_auth_client *ac,
  217. struct ceph_x_ticket_handler *th,
  218. struct ceph_x_authorizer *au)
  219. {
  220. int maxlen;
  221. struct ceph_x_authorize_a *msg_a;
  222. struct ceph_x_authorize_b msg_b;
  223. void *p, *end;
  224. int ret;
  225. int ticket_blob_len =
  226. (th->ticket_blob ? th->ticket_blob->vec.iov_len : 0);
  227. dout("build_authorizer for %s %p\n",
  228. ceph_entity_type_name(th->service), au);
  229. maxlen = sizeof(*msg_a) + sizeof(msg_b) +
  230. ceph_x_encrypt_buflen(ticket_blob_len);
  231. dout(" need len %d\n", maxlen);
  232. if (au->buf && au->buf->alloc_len < maxlen) {
  233. ceph_buffer_put(au->buf);
  234. au->buf = NULL;
  235. }
  236. if (!au->buf) {
  237. au->buf = ceph_buffer_new(maxlen, GFP_NOFS);
  238. if (!au->buf)
  239. return -ENOMEM;
  240. }
  241. au->service = th->service;
  242. msg_a = au->buf->vec.iov_base;
  243. msg_a->struct_v = 1;
  244. msg_a->global_id = cpu_to_le64(ac->global_id);
  245. msg_a->service_id = cpu_to_le32(th->service);
  246. msg_a->ticket_blob.struct_v = 1;
  247. msg_a->ticket_blob.secret_id = cpu_to_le64(th->secret_id);
  248. msg_a->ticket_blob.blob_len = cpu_to_le32(ticket_blob_len);
  249. if (ticket_blob_len) {
  250. memcpy(msg_a->ticket_blob.blob, th->ticket_blob->vec.iov_base,
  251. th->ticket_blob->vec.iov_len);
  252. }
  253. dout(" th %p secret_id %lld %lld\n", th, th->secret_id,
  254. le64_to_cpu(msg_a->ticket_blob.secret_id));
  255. p = msg_a + 1;
  256. p += ticket_blob_len;
  257. end = au->buf->vec.iov_base + au->buf->vec.iov_len;
  258. get_random_bytes(&au->nonce, sizeof(au->nonce));
  259. msg_b.struct_v = 1;
  260. msg_b.nonce = cpu_to_le64(au->nonce);
  261. ret = ceph_x_encrypt(&th->session_key, &msg_b, sizeof(msg_b),
  262. p, end - p);
  263. if (ret < 0)
  264. goto out_buf;
  265. p += ret;
  266. au->buf->vec.iov_len = p - au->buf->vec.iov_base;
  267. dout(" built authorizer nonce %llx len %d\n", au->nonce,
  268. (int)au->buf->vec.iov_len);
  269. BUG_ON(au->buf->vec.iov_len > maxlen);
  270. return 0;
  271. out_buf:
  272. ceph_buffer_put(au->buf);
  273. au->buf = NULL;
  274. return ret;
  275. }
  276. static int ceph_x_encode_ticket(struct ceph_x_ticket_handler *th,
  277. void **p, void *end)
  278. {
  279. ceph_decode_need(p, end, 1 + sizeof(u64), bad);
  280. ceph_encode_8(p, 1);
  281. ceph_encode_64(p, th->secret_id);
  282. if (th->ticket_blob) {
  283. const char *buf = th->ticket_blob->vec.iov_base;
  284. u32 len = th->ticket_blob->vec.iov_len;
  285. ceph_encode_32_safe(p, end, len, bad);
  286. ceph_encode_copy_safe(p, end, buf, len, bad);
  287. } else {
  288. ceph_encode_32_safe(p, end, 0, bad);
  289. }
  290. return 0;
  291. bad:
  292. return -ERANGE;
  293. }
  294. static void ceph_x_validate_tickets(struct ceph_auth_client *ac, int *pneed)
  295. {
  296. int want = ac->want_keys;
  297. struct ceph_x_info *xi = ac->private;
  298. int service;
  299. *pneed = ac->want_keys & ~(xi->have_keys);
  300. for (service = 1; service <= want; service <<= 1) {
  301. struct ceph_x_ticket_handler *th;
  302. if (!(ac->want_keys & service))
  303. continue;
  304. if (*pneed & service)
  305. continue;
  306. th = get_ticket_handler(ac, service);
  307. if (!th) {
  308. *pneed |= service;
  309. continue;
  310. }
  311. if (get_seconds() >= th->renew_after)
  312. *pneed |= service;
  313. if (get_seconds() >= th->expires)
  314. xi->have_keys &= ~service;
  315. }
  316. }
  317. static int ceph_x_build_request(struct ceph_auth_client *ac,
  318. void *buf, void *end)
  319. {
  320. struct ceph_x_info *xi = ac->private;
  321. int need;
  322. struct ceph_x_request_header *head = buf;
  323. int ret;
  324. struct ceph_x_ticket_handler *th =
  325. get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
  326. ceph_x_validate_tickets(ac, &need);
  327. dout("build_request want %x have %x need %x\n",
  328. ac->want_keys, xi->have_keys, need);
  329. if (need & CEPH_ENTITY_TYPE_AUTH) {
  330. struct ceph_x_authenticate *auth = (void *)(head + 1);
  331. void *p = auth + 1;
  332. struct ceph_x_challenge_blob tmp;
  333. char tmp_enc[40];
  334. u64 *u;
  335. if (p > end)
  336. return -ERANGE;
  337. dout(" get_auth_session_key\n");
  338. head->op = cpu_to_le16(CEPHX_GET_AUTH_SESSION_KEY);
  339. /* encrypt and hash */
  340. get_random_bytes(&auth->client_challenge, sizeof(u64));
  341. tmp.client_challenge = auth->client_challenge;
  342. tmp.server_challenge = cpu_to_le64(xi->server_challenge);
  343. ret = ceph_x_encrypt(&xi->secret, &tmp, sizeof(tmp),
  344. tmp_enc, sizeof(tmp_enc));
  345. if (ret < 0)
  346. return ret;
  347. auth->struct_v = 1;
  348. auth->key = 0;
  349. for (u = (u64 *)tmp_enc; u + 1 <= (u64 *)(tmp_enc + ret); u++)
  350. auth->key ^= *u;
  351. dout(" server_challenge %llx client_challenge %llx key %llx\n",
  352. xi->server_challenge, le64_to_cpu(auth->client_challenge),
  353. le64_to_cpu(auth->key));
  354. /* now encode the old ticket if exists */
  355. ret = ceph_x_encode_ticket(th, &p, end);
  356. if (ret < 0)
  357. return ret;
  358. return p - buf;
  359. }
  360. if (need) {
  361. void *p = head + 1;
  362. struct ceph_x_service_ticket_request *req;
  363. if (p > end)
  364. return -ERANGE;
  365. head->op = cpu_to_le16(CEPHX_GET_PRINCIPAL_SESSION_KEY);
  366. BUG_ON(!th);
  367. ret = ceph_x_build_authorizer(ac, th, &xi->auth_authorizer);
  368. if (ret)
  369. return ret;
  370. ceph_encode_copy(&p, xi->auth_authorizer.buf->vec.iov_base,
  371. xi->auth_authorizer.buf->vec.iov_len);
  372. req = p;
  373. req->keys = cpu_to_le32(need);
  374. p += sizeof(*req);
  375. return p - buf;
  376. }
  377. return 0;
  378. }
  379. static int ceph_x_handle_reply(struct ceph_auth_client *ac, int result,
  380. void *buf, void *end)
  381. {
  382. struct ceph_x_info *xi = ac->private;
  383. struct ceph_x_reply_header *head = buf;
  384. struct ceph_x_ticket_handler *th;
  385. int len = end - buf;
  386. int op;
  387. int ret;
  388. if (result)
  389. return result; /* XXX hmm? */
  390. if (xi->starting) {
  391. /* it's a hello */
  392. struct ceph_x_server_challenge *sc = buf;
  393. if (len != sizeof(*sc))
  394. return -EINVAL;
  395. xi->server_challenge = le64_to_cpu(sc->server_challenge);
  396. dout("handle_reply got server challenge %llx\n",
  397. xi->server_challenge);
  398. xi->starting = false;
  399. xi->have_keys &= ~CEPH_ENTITY_TYPE_AUTH;
  400. return -EAGAIN;
  401. }
  402. op = le32_to_cpu(head->op);
  403. result = le32_to_cpu(head->result);
  404. dout("handle_reply op %d result %d\n", op, result);
  405. switch (op) {
  406. case CEPHX_GET_AUTH_SESSION_KEY:
  407. /* verify auth key */
  408. ret = ceph_x_proc_ticket_reply(ac, &xi->secret,
  409. buf + sizeof(*head), end);
  410. break;
  411. case CEPHX_GET_PRINCIPAL_SESSION_KEY:
  412. th = get_ticket_handler(ac, CEPH_ENTITY_TYPE_AUTH);
  413. BUG_ON(!th);
  414. ret = ceph_x_proc_ticket_reply(ac, &th->session_key,
  415. buf + sizeof(*head), end);
  416. break;
  417. default:
  418. return -EINVAL;
  419. }
  420. if (ret)
  421. return ret;
  422. if (ac->want_keys == xi->have_keys)
  423. return 0;
  424. return -EAGAIN;
  425. }
  426. static int ceph_x_create_authorizer(
  427. struct ceph_auth_client *ac, int peer_type,
  428. struct ceph_authorizer **a,
  429. void **buf, size_t *len,
  430. void **reply_buf, size_t *reply_len)
  431. {
  432. struct ceph_x_authorizer *au;
  433. struct ceph_x_ticket_handler *th;
  434. int ret;
  435. th = get_ticket_handler(ac, peer_type);
  436. if (IS_ERR(th))
  437. return PTR_ERR(th);
  438. au = kzalloc(sizeof(*au), GFP_NOFS);
  439. if (!au)
  440. return -ENOMEM;
  441. ret = ceph_x_build_authorizer(ac, th, au);
  442. if (ret) {
  443. kfree(au);
  444. return ret;
  445. }
  446. *a = (struct ceph_authorizer *)au;
  447. *buf = au->buf->vec.iov_base;
  448. *len = au->buf->vec.iov_len;
  449. *reply_buf = au->reply_buf;
  450. *reply_len = sizeof(au->reply_buf);
  451. return 0;
  452. }
  453. static int ceph_x_verify_authorizer_reply(struct ceph_auth_client *ac,
  454. struct ceph_authorizer *a, size_t len)
  455. {
  456. struct ceph_x_authorizer *au = (void *)a;
  457. struct ceph_x_ticket_handler *th;
  458. int ret = 0;
  459. struct ceph_x_authorize_reply reply;
  460. void *p = au->reply_buf;
  461. void *end = p + sizeof(au->reply_buf);
  462. th = get_ticket_handler(ac, au->service);
  463. if (!th)
  464. return -EIO; /* hrm! */
  465. ret = ceph_x_decrypt(&th->session_key, &p, end, &reply, sizeof(reply));
  466. if (ret < 0)
  467. return ret;
  468. if (ret != sizeof(reply))
  469. return -EPERM;
  470. if (au->nonce + 1 != le64_to_cpu(reply.nonce_plus_one))
  471. ret = -EPERM;
  472. else
  473. ret = 0;
  474. dout("verify_authorizer_reply nonce %llx got %llx ret %d\n",
  475. au->nonce, le64_to_cpu(reply.nonce_plus_one), ret);
  476. return ret;
  477. }
  478. static void ceph_x_destroy_authorizer(struct ceph_auth_client *ac,
  479. struct ceph_authorizer *a)
  480. {
  481. struct ceph_x_authorizer *au = (void *)a;
  482. ceph_buffer_put(au->buf);
  483. kfree(au);
  484. }
  485. static void ceph_x_reset(struct ceph_auth_client *ac)
  486. {
  487. struct ceph_x_info *xi = ac->private;
  488. dout("reset\n");
  489. xi->starting = true;
  490. xi->server_challenge = 0;
  491. }
  492. static void ceph_x_destroy(struct ceph_auth_client *ac)
  493. {
  494. struct ceph_x_info *xi = ac->private;
  495. struct rb_node *p;
  496. dout("ceph_x_destroy %p\n", ac);
  497. ceph_crypto_key_destroy(&xi->secret);
  498. while ((p = rb_first(&xi->ticket_handlers)) != NULL) {
  499. struct ceph_x_ticket_handler *th =
  500. rb_entry(p, struct ceph_x_ticket_handler, node);
  501. remove_ticket_handler(ac, th);
  502. }
  503. kmem_cache_destroy(ceph_x_ticketbuf_cachep);
  504. kfree(ac->private);
  505. ac->private = NULL;
  506. }
  507. static void ceph_x_invalidate_authorizer(struct ceph_auth_client *ac,
  508. int peer_type)
  509. {
  510. struct ceph_x_ticket_handler *th;
  511. th = get_ticket_handler(ac, peer_type);
  512. if (th && !IS_ERR(th))
  513. remove_ticket_handler(ac, th);
  514. }
  515. static const struct ceph_auth_client_ops ceph_x_ops = {
  516. .is_authenticated = ceph_x_is_authenticated,
  517. .build_request = ceph_x_build_request,
  518. .handle_reply = ceph_x_handle_reply,
  519. .create_authorizer = ceph_x_create_authorizer,
  520. .verify_authorizer_reply = ceph_x_verify_authorizer_reply,
  521. .destroy_authorizer = ceph_x_destroy_authorizer,
  522. .invalidate_authorizer = ceph_x_invalidate_authorizer,
  523. .reset = ceph_x_reset,
  524. .destroy = ceph_x_destroy,
  525. };
  526. int ceph_x_init(struct ceph_auth_client *ac)
  527. {
  528. struct ceph_x_info *xi;
  529. int ret;
  530. dout("ceph_x_init %p\n", ac);
  531. xi = kzalloc(sizeof(*xi), GFP_NOFS);
  532. if (!xi)
  533. return -ENOMEM;
  534. ret = -ENOMEM;
  535. ceph_x_ticketbuf_cachep = kmem_cache_create("ceph_x_ticketbuf",
  536. TEMP_TICKET_BUF_LEN, 8,
  537. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  538. NULL);
  539. if (!ceph_x_ticketbuf_cachep)
  540. goto done_nomem;
  541. ret = -EINVAL;
  542. if (!ac->secret) {
  543. pr_err("no secret set (for auth_x protocol)\n");
  544. goto done_nomem;
  545. }
  546. ret = ceph_crypto_key_unarmor(&xi->secret, ac->secret);
  547. if (ret)
  548. goto done_nomem;
  549. xi->starting = true;
  550. xi->ticket_handlers = RB_ROOT;
  551. ac->protocol = CEPH_AUTH_CEPHX;
  552. ac->private = xi;
  553. ac->ops = &ceph_x_ops;
  554. return 0;
  555. done_nomem:
  556. kfree(xi);
  557. if (ceph_x_ticketbuf_cachep)
  558. kmem_cache_destroy(ceph_x_ticketbuf_cachep);
  559. return ret;
  560. }