request_key.c 20 KB

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