request_key.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /* Request a key from userspace
  2. *
  3. * Copyright (C) 2004-2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. *
  11. * See Documentation/security/keys-request-key.txt
  12. */
  13. #include <linux/module.h>
  14. #include <linux/sched.h>
  15. #include <linux/kmod.h>
  16. #include <linux/err.h>
  17. #include <linux/keyctl.h>
  18. #include <linux/slab.h>
  19. #include "internal.h"
  20. #define key_negative_timeout 60 /* default timeout on a negative key's existence */
  21. /*
  22. * wait_on_bit() sleep function for uninterruptible waiting
  23. */
  24. static int key_wait_bit(void *flags)
  25. {
  26. schedule();
  27. return 0;
  28. }
  29. /*
  30. * wait_on_bit() sleep function for interruptible waiting
  31. */
  32. static int key_wait_bit_intr(void *flags)
  33. {
  34. schedule();
  35. return signal_pending(current) ? -ERESTARTSYS : 0;
  36. }
  37. /**
  38. * complete_request_key - Complete the construction of a key.
  39. * @cons: The key construction record.
  40. * @error: The success or failute of the construction.
  41. *
  42. * Complete the attempt to construct a key. The key will be negated
  43. * if an error is indicated. The authorisation key will be revoked
  44. * unconditionally.
  45. */
  46. void complete_request_key(struct key_construction *cons, int error)
  47. {
  48. kenter("{%d,%d},%d", cons->key->serial, cons->authkey->serial, error);
  49. if (error < 0)
  50. key_negate_and_link(cons->key, key_negative_timeout, NULL,
  51. cons->authkey);
  52. else
  53. key_revoke(cons->authkey);
  54. key_put(cons->key);
  55. key_put(cons->authkey);
  56. kfree(cons);
  57. }
  58. EXPORT_SYMBOL(complete_request_key);
  59. /*
  60. * Initialise a usermode helper that is going to have a specific session
  61. * keyring.
  62. *
  63. * This is called in context of freshly forked kthread before kernel_execve(),
  64. * so we can simply install the desired session_keyring at this point.
  65. */
  66. static int umh_keys_init(struct subprocess_info *info, struct cred *cred)
  67. {
  68. struct key *keyring = info->data;
  69. return install_session_keyring_to_cred(cred, keyring);
  70. }
  71. /*
  72. * Clean up a usermode helper with session keyring.
  73. */
  74. static void umh_keys_cleanup(struct subprocess_info *info)
  75. {
  76. struct key *keyring = info->data;
  77. key_put(keyring);
  78. }
  79. /*
  80. * Call a usermode helper with a specific session keyring.
  81. */
  82. static int call_usermodehelper_keys(char *path, char **argv, char **envp,
  83. struct key *session_keyring, int wait)
  84. {
  85. return call_usermodehelper_fns(path, argv, envp, wait,
  86. umh_keys_init, umh_keys_cleanup,
  87. key_get(session_keyring));
  88. }
  89. /*
  90. * Request userspace finish the construction of a key
  91. * - execute "/sbin/request-key <op> <key> <uid> <gid> <keyring> <keyring> <keyring>"
  92. */
  93. static int call_sbin_request_key(struct key_construction *cons,
  94. const char *op,
  95. void *aux)
  96. {
  97. const struct cred *cred = current_cred();
  98. key_serial_t prkey, sskey;
  99. struct key *key = cons->key, *authkey = cons->authkey, *keyring,
  100. *session;
  101. char *argv[9], *envp[3], uid_str[12], gid_str[12];
  102. char key_str[12], keyring_str[3][12];
  103. char desc[20];
  104. int ret, i;
  105. kenter("{%d},{%d},%s", key->serial, authkey->serial, op);
  106. ret = install_user_keyrings();
  107. if (ret < 0)
  108. goto error_alloc;
  109. /* allocate a new session keyring */
  110. sprintf(desc, "_req.%u", key->serial);
  111. cred = get_current_cred();
  112. keyring = keyring_alloc(desc, cred->fsuid, cred->fsgid, cred,
  113. KEY_ALLOC_QUOTA_OVERRUN, NULL);
  114. put_cred(cred);
  115. if (IS_ERR(keyring)) {
  116. ret = PTR_ERR(keyring);
  117. goto error_alloc;
  118. }
  119. /* attach the auth key to the session keyring */
  120. ret = key_link(keyring, authkey);
  121. if (ret < 0)
  122. goto error_link;
  123. /* record the UID and GID */
  124. sprintf(uid_str, "%d", cred->fsuid);
  125. sprintf(gid_str, "%d", cred->fsgid);
  126. /* we say which key is under construction */
  127. sprintf(key_str, "%d", key->serial);
  128. /* we specify the process's default keyrings */
  129. sprintf(keyring_str[0], "%d",
  130. cred->thread_keyring ? cred->thread_keyring->serial : 0);
  131. prkey = 0;
  132. if (cred->tgcred->process_keyring)
  133. prkey = cred->tgcred->process_keyring->serial;
  134. sprintf(keyring_str[1], "%d", prkey);
  135. rcu_read_lock();
  136. session = rcu_dereference(cred->tgcred->session_keyring);
  137. if (!session)
  138. session = cred->user->session_keyring;
  139. sskey = session->serial;
  140. rcu_read_unlock();
  141. sprintf(keyring_str[2], "%d", sskey);
  142. /* set up a minimal environment */
  143. i = 0;
  144. envp[i++] = "HOME=/";
  145. envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
  146. envp[i] = NULL;
  147. /* set up the argument list */
  148. i = 0;
  149. argv[i++] = "/sbin/request-key";
  150. argv[i++] = (char *) op;
  151. argv[i++] = key_str;
  152. argv[i++] = uid_str;
  153. argv[i++] = gid_str;
  154. argv[i++] = keyring_str[0];
  155. argv[i++] = keyring_str[1];
  156. argv[i++] = keyring_str[2];
  157. argv[i] = NULL;
  158. /* do it */
  159. ret = call_usermodehelper_keys(argv[0], argv, envp, keyring,
  160. UMH_WAIT_PROC);
  161. kdebug("usermode -> 0x%x", ret);
  162. if (ret >= 0) {
  163. /* ret is the exit/wait code */
  164. if (test_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags) ||
  165. key_validate(key) < 0)
  166. ret = -ENOKEY;
  167. else
  168. /* ignore any errors from userspace if the key was
  169. * instantiated */
  170. ret = 0;
  171. }
  172. error_link:
  173. key_put(keyring);
  174. error_alloc:
  175. complete_request_key(cons, ret);
  176. kleave(" = %d", ret);
  177. return ret;
  178. }
  179. /*
  180. * Call out to userspace for key construction.
  181. *
  182. * Program failure is ignored in favour of key status.
  183. */
  184. static int construct_key(struct key *key, const void *callout_info,
  185. size_t callout_len, void *aux,
  186. struct key *dest_keyring)
  187. {
  188. struct key_construction *cons;
  189. request_key_actor_t actor;
  190. struct key *authkey;
  191. int ret;
  192. kenter("%d,%p,%zu,%p", key->serial, callout_info, callout_len, aux);
  193. cons = kmalloc(sizeof(*cons), GFP_KERNEL);
  194. if (!cons)
  195. return -ENOMEM;
  196. /* allocate an authorisation key */
  197. authkey = request_key_auth_new(key, callout_info, callout_len,
  198. dest_keyring);
  199. if (IS_ERR(authkey)) {
  200. kfree(cons);
  201. ret = PTR_ERR(authkey);
  202. authkey = NULL;
  203. } else {
  204. cons->authkey = key_get(authkey);
  205. cons->key = key_get(key);
  206. /* make the call */
  207. actor = call_sbin_request_key;
  208. if (key->type->request_key)
  209. actor = key->type->request_key;
  210. ret = actor(cons, "create", aux);
  211. /* check that the actor called complete_request_key() prior to
  212. * returning an error */
  213. WARN_ON(ret < 0 &&
  214. !test_bit(KEY_FLAG_REVOKED, &authkey->flags));
  215. key_put(authkey);
  216. }
  217. kleave(" = %d", ret);
  218. return ret;
  219. }
  220. /*
  221. * Get the appropriate destination keyring for the request.
  222. *
  223. * The keyring selected is returned with an extra reference upon it which the
  224. * caller must release.
  225. */
  226. static int construct_get_dest_keyring(struct key **_dest_keyring)
  227. {
  228. struct request_key_auth *rka;
  229. const struct cred *cred = current_cred();
  230. struct key *dest_keyring = *_dest_keyring, *authkey;
  231. int ret;
  232. kenter("%p", dest_keyring);
  233. /* find the appropriate keyring */
  234. if (dest_keyring) {
  235. /* the caller supplied one */
  236. key_get(dest_keyring);
  237. } else {
  238. bool do_perm_check = true;
  239. /* use a default keyring; falling through the cases until we
  240. * find one that we actually have */
  241. switch (cred->jit_keyring) {
  242. case KEY_REQKEY_DEFL_DEFAULT:
  243. case KEY_REQKEY_DEFL_REQUESTOR_KEYRING:
  244. if (cred->request_key_auth) {
  245. authkey = cred->request_key_auth;
  246. down_read(&authkey->sem);
  247. rka = authkey->payload.data;
  248. if (!test_bit(KEY_FLAG_REVOKED,
  249. &authkey->flags))
  250. dest_keyring =
  251. key_get(rka->dest_keyring);
  252. up_read(&authkey->sem);
  253. if (dest_keyring) {
  254. do_perm_check = false;
  255. break;
  256. }
  257. }
  258. case KEY_REQKEY_DEFL_THREAD_KEYRING:
  259. dest_keyring = key_get(cred->thread_keyring);
  260. if (dest_keyring)
  261. break;
  262. case KEY_REQKEY_DEFL_PROCESS_KEYRING:
  263. dest_keyring = key_get(cred->tgcred->process_keyring);
  264. if (dest_keyring)
  265. break;
  266. case KEY_REQKEY_DEFL_SESSION_KEYRING:
  267. rcu_read_lock();
  268. dest_keyring = key_get(
  269. rcu_dereference(cred->tgcred->session_keyring));
  270. rcu_read_unlock();
  271. if (dest_keyring)
  272. break;
  273. case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
  274. dest_keyring =
  275. key_get(cred->user->session_keyring);
  276. break;
  277. case KEY_REQKEY_DEFL_USER_KEYRING:
  278. dest_keyring = key_get(cred->user->uid_keyring);
  279. break;
  280. case KEY_REQKEY_DEFL_GROUP_KEYRING:
  281. default:
  282. BUG();
  283. }
  284. /*
  285. * Require Write permission on the keyring. This is essential
  286. * because the default keyring may be the session keyring, and
  287. * joining a keyring only requires Search permission.
  288. *
  289. * However, this check is skipped for the "requestor keyring" so
  290. * that /sbin/request-key can itself use request_key() to add
  291. * keys to the original requestor's destination keyring.
  292. */
  293. if (dest_keyring && do_perm_check) {
  294. ret = key_permission(make_key_ref(dest_keyring, 1),
  295. KEY_WRITE);
  296. if (ret) {
  297. key_put(dest_keyring);
  298. return ret;
  299. }
  300. }
  301. }
  302. *_dest_keyring = dest_keyring;
  303. kleave(" [dk %d]", key_serial(dest_keyring));
  304. return 0;
  305. }
  306. /*
  307. * Allocate a new key in under-construction state and attempt to link it in to
  308. * the requested keyring.
  309. *
  310. * May return a key that's already under construction instead if there was a
  311. * race between two thread calling request_key().
  312. */
  313. static int construct_alloc_key(struct key_type *type,
  314. const char *description,
  315. struct key *dest_keyring,
  316. unsigned long flags,
  317. struct key_user *user,
  318. struct key **_key)
  319. {
  320. const struct cred *cred = current_cred();
  321. unsigned long prealloc;
  322. struct key *key;
  323. key_ref_t key_ref;
  324. int ret;
  325. kenter("%s,%s,,,", type->name, description);
  326. *_key = NULL;
  327. mutex_lock(&user->cons_lock);
  328. key = key_alloc(type, description, cred->fsuid, cred->fsgid, cred,
  329. KEY_POS_ALL, flags);
  330. if (IS_ERR(key))
  331. goto alloc_failed;
  332. set_bit(KEY_FLAG_USER_CONSTRUCT, &key->flags);
  333. if (dest_keyring) {
  334. ret = __key_link_begin(dest_keyring, type, description,
  335. &prealloc);
  336. if (ret < 0)
  337. goto link_prealloc_failed;
  338. }
  339. /* attach the key to the destination keyring under lock, but we do need
  340. * to do another check just in case someone beat us to it whilst we
  341. * waited for locks */
  342. mutex_lock(&key_construction_mutex);
  343. key_ref = search_process_keyrings(type, description, type->match, cred);
  344. if (!IS_ERR(key_ref))
  345. goto key_already_present;
  346. if (dest_keyring)
  347. __key_link(dest_keyring, key, &prealloc);
  348. mutex_unlock(&key_construction_mutex);
  349. if (dest_keyring)
  350. __key_link_end(dest_keyring, type, prealloc);
  351. mutex_unlock(&user->cons_lock);
  352. *_key = key;
  353. kleave(" = 0 [%d]", key_serial(key));
  354. return 0;
  355. /* the key is now present - we tell the caller that we found it by
  356. * returning -EINPROGRESS */
  357. key_already_present:
  358. key_put(key);
  359. mutex_unlock(&key_construction_mutex);
  360. key = key_ref_to_ptr(key_ref);
  361. if (dest_keyring) {
  362. ret = __key_link_check_live_key(dest_keyring, key);
  363. if (ret == 0)
  364. __key_link(dest_keyring, key, &prealloc);
  365. __key_link_end(dest_keyring, type, prealloc);
  366. if (ret < 0)
  367. goto link_check_failed;
  368. }
  369. mutex_unlock(&user->cons_lock);
  370. *_key = key;
  371. kleave(" = -EINPROGRESS [%d]", key_serial(key));
  372. return -EINPROGRESS;
  373. link_check_failed:
  374. mutex_unlock(&user->cons_lock);
  375. key_put(key);
  376. kleave(" = %d [linkcheck]", ret);
  377. return ret;
  378. link_prealloc_failed:
  379. mutex_unlock(&user->cons_lock);
  380. kleave(" = %d [prelink]", ret);
  381. return ret;
  382. alloc_failed:
  383. mutex_unlock(&user->cons_lock);
  384. kleave(" = %ld", PTR_ERR(key));
  385. return PTR_ERR(key);
  386. }
  387. /*
  388. * Commence key construction.
  389. */
  390. static struct key *construct_key_and_link(struct key_type *type,
  391. const char *description,
  392. const char *callout_info,
  393. size_t callout_len,
  394. void *aux,
  395. struct key *dest_keyring,
  396. unsigned long flags)
  397. {
  398. struct key_user *user;
  399. struct key *key;
  400. int ret;
  401. kenter("");
  402. if (type == &key_type_keyring)
  403. return ERR_PTR(-EPERM);
  404. ret = construct_get_dest_keyring(&dest_keyring);
  405. if (ret)
  406. goto error;
  407. user = key_user_lookup(current_fsuid(), current_user_ns());
  408. if (!user) {
  409. ret = -ENOMEM;
  410. goto error_put_dest_keyring;
  411. }
  412. ret = construct_alloc_key(type, description, dest_keyring, flags, user,
  413. &key);
  414. key_user_put(user);
  415. if (ret == 0) {
  416. ret = construct_key(key, callout_info, callout_len, aux,
  417. dest_keyring);
  418. if (ret < 0) {
  419. kdebug("cons failed");
  420. goto construction_failed;
  421. }
  422. } else if (ret == -EINPROGRESS) {
  423. ret = 0;
  424. } else {
  425. goto error_put_dest_keyring;
  426. }
  427. key_put(dest_keyring);
  428. kleave(" = key %d", key_serial(key));
  429. return key;
  430. construction_failed:
  431. key_negate_and_link(key, key_negative_timeout, NULL, NULL);
  432. key_put(key);
  433. error_put_dest_keyring:
  434. key_put(dest_keyring);
  435. error:
  436. kleave(" = %d", ret);
  437. return ERR_PTR(ret);
  438. }
  439. /**
  440. * request_key_and_link - Request a key and cache it in a keyring.
  441. * @type: The type of key we want.
  442. * @description: The searchable description of the key.
  443. * @callout_info: The data to pass to the instantiation upcall (or NULL).
  444. * @callout_len: The length of callout_info.
  445. * @aux: Auxiliary data for the upcall.
  446. * @dest_keyring: Where to cache the key.
  447. * @flags: Flags to key_alloc().
  448. *
  449. * A key matching the specified criteria is searched for in the process's
  450. * keyrings and returned with its usage count incremented if found. Otherwise,
  451. * if callout_info is not NULL, a key will be allocated and some service
  452. * (probably in userspace) will be asked to instantiate it.
  453. *
  454. * If successfully found or created, the key will be linked to the destination
  455. * keyring if one is provided.
  456. *
  457. * Returns a pointer to the key if successful; -EACCES, -ENOKEY, -EKEYREVOKED
  458. * or -EKEYEXPIRED if an inaccessible, negative, revoked or expired key was
  459. * found; -ENOKEY if no key was found and no @callout_info was given; -EDQUOT
  460. * if insufficient key quota was available to create a new key; or -ENOMEM if
  461. * insufficient memory was available.
  462. *
  463. * If the returned key was created, then it may still be under construction,
  464. * and wait_for_key_construction() should be used to wait for that to complete.
  465. */
  466. struct key *request_key_and_link(struct key_type *type,
  467. const char *description,
  468. const void *callout_info,
  469. size_t callout_len,
  470. void *aux,
  471. struct key *dest_keyring,
  472. unsigned long flags)
  473. {
  474. const struct cred *cred = current_cred();
  475. struct key *key;
  476. key_ref_t key_ref;
  477. int ret;
  478. kenter("%s,%s,%p,%zu,%p,%p,%lx",
  479. type->name, description, callout_info, callout_len, aux,
  480. dest_keyring, flags);
  481. /* search all the process keyrings for a key */
  482. key_ref = search_process_keyrings(type, description, type->match, cred);
  483. if (!IS_ERR(key_ref)) {
  484. key = key_ref_to_ptr(key_ref);
  485. if (dest_keyring) {
  486. construct_get_dest_keyring(&dest_keyring);
  487. ret = key_link(dest_keyring, key);
  488. key_put(dest_keyring);
  489. if (ret < 0) {
  490. key_put(key);
  491. key = ERR_PTR(ret);
  492. goto error;
  493. }
  494. }
  495. } else if (PTR_ERR(key_ref) != -EAGAIN) {
  496. key = ERR_CAST(key_ref);
  497. } else {
  498. /* the search failed, but the keyrings were searchable, so we
  499. * should consult userspace if we can */
  500. key = ERR_PTR(-ENOKEY);
  501. if (!callout_info)
  502. goto error;
  503. key = construct_key_and_link(type, description, callout_info,
  504. callout_len, aux, dest_keyring,
  505. flags);
  506. }
  507. error:
  508. kleave(" = %p", key);
  509. return key;
  510. }
  511. /**
  512. * wait_for_key_construction - Wait for construction of a key to complete
  513. * @key: The key being waited for.
  514. * @intr: Whether to wait interruptibly.
  515. *
  516. * Wait for a key to finish being constructed.
  517. *
  518. * Returns 0 if successful; -ERESTARTSYS if the wait was interrupted; -ENOKEY
  519. * if the key was negated; or -EKEYREVOKED or -EKEYEXPIRED if the key was
  520. * revoked or expired.
  521. */
  522. int wait_for_key_construction(struct key *key, bool intr)
  523. {
  524. int ret;
  525. ret = wait_on_bit(&key->flags, KEY_FLAG_USER_CONSTRUCT,
  526. intr ? key_wait_bit_intr : key_wait_bit,
  527. intr ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE);
  528. if (ret < 0)
  529. return ret;
  530. if (test_bit(KEY_FLAG_NEGATIVE, &key->flags))
  531. return key->type_data.reject_error;
  532. return key_validate(key);
  533. }
  534. EXPORT_SYMBOL(wait_for_key_construction);
  535. /**
  536. * request_key - Request a key and wait for construction
  537. * @type: Type of key.
  538. * @description: The searchable description of the key.
  539. * @callout_info: The data to pass to the instantiation upcall (or NULL).
  540. *
  541. * As for request_key_and_link() except that it does not add the returned key
  542. * to a keyring if found, new keys are always allocated in the user's quota,
  543. * the callout_info must be a NUL-terminated string and no auxiliary data can
  544. * be passed.
  545. *
  546. * Furthermore, it then works as wait_for_key_construction() to wait for the
  547. * completion of keys undergoing construction with a non-interruptible wait.
  548. */
  549. struct key *request_key(struct key_type *type,
  550. const char *description,
  551. const char *callout_info)
  552. {
  553. struct key *key;
  554. size_t callout_len = 0;
  555. int ret;
  556. if (callout_info)
  557. callout_len = strlen(callout_info);
  558. key = request_key_and_link(type, description, callout_info, callout_len,
  559. NULL, NULL, KEY_ALLOC_IN_QUOTA);
  560. if (!IS_ERR(key)) {
  561. ret = wait_for_key_construction(key, false);
  562. if (ret < 0) {
  563. key_put(key);
  564. return ERR_PTR(ret);
  565. }
  566. }
  567. return key;
  568. }
  569. EXPORT_SYMBOL(request_key);
  570. /**
  571. * request_key_with_auxdata - Request a key with auxiliary data for the upcaller
  572. * @type: The type of key we want.
  573. * @description: The searchable description of the key.
  574. * @callout_info: The data to pass to the instantiation upcall (or NULL).
  575. * @callout_len: The length of callout_info.
  576. * @aux: Auxiliary data for the upcall.
  577. *
  578. * As for request_key_and_link() except that it does not add the returned key
  579. * to a keyring if found and new keys are always allocated in the user's quota.
  580. *
  581. * Furthermore, it then works as wait_for_key_construction() to wait for the
  582. * completion of keys undergoing construction with a non-interruptible wait.
  583. */
  584. struct key *request_key_with_auxdata(struct key_type *type,
  585. const char *description,
  586. const void *callout_info,
  587. size_t callout_len,
  588. void *aux)
  589. {
  590. struct key *key;
  591. int ret;
  592. key = request_key_and_link(type, description, callout_info, callout_len,
  593. aux, NULL, KEY_ALLOC_IN_QUOTA);
  594. if (!IS_ERR(key)) {
  595. ret = wait_for_key_construction(key, false);
  596. if (ret < 0) {
  597. key_put(key);
  598. return ERR_PTR(ret);
  599. }
  600. }
  601. return key;
  602. }
  603. EXPORT_SYMBOL(request_key_with_auxdata);
  604. /*
  605. * request_key_async - Request a key (allow async construction)
  606. * @type: Type of key.
  607. * @description: The searchable description of the key.
  608. * @callout_info: The data to pass to the instantiation upcall (or NULL).
  609. * @callout_len: The length of callout_info.
  610. *
  611. * As for request_key_and_link() except that it does not add the returned key
  612. * to a keyring if found, new keys are always allocated in the user's quota and
  613. * no auxiliary data can be passed.
  614. *
  615. * The caller should call wait_for_key_construction() to wait for the
  616. * completion of the returned key if it is still undergoing construction.
  617. */
  618. struct key *request_key_async(struct key_type *type,
  619. const char *description,
  620. const void *callout_info,
  621. size_t callout_len)
  622. {
  623. return request_key_and_link(type, description, callout_info,
  624. callout_len, NULL, NULL,
  625. KEY_ALLOC_IN_QUOTA);
  626. }
  627. EXPORT_SYMBOL(request_key_async);
  628. /*
  629. * request a key with auxiliary data for the upcaller (allow async construction)
  630. * @type: Type of key.
  631. * @description: The searchable description of the key.
  632. * @callout_info: The data to pass to the instantiation upcall (or NULL).
  633. * @callout_len: The length of callout_info.
  634. * @aux: Auxiliary data for the upcall.
  635. *
  636. * As for request_key_and_link() except that it does not add the returned key
  637. * to a keyring if found and new keys are always allocated in the user's quota.
  638. *
  639. * The caller should call wait_for_key_construction() to wait for the
  640. * completion of the returned key if it is still undergoing construction.
  641. */
  642. struct key *request_key_async_with_auxdata(struct key_type *type,
  643. const char *description,
  644. const void *callout_info,
  645. size_t callout_len,
  646. void *aux)
  647. {
  648. return request_key_and_link(type, description, callout_info,
  649. callout_len, aux, NULL, KEY_ALLOC_IN_QUOTA);
  650. }
  651. EXPORT_SYMBOL(request_key_async_with_auxdata);