keyctl.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. /* keyctl.c: userspace keyctl operations
  2. *
  3. * Copyright (C) 2004-5 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. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/sched.h>
  14. #include <linux/slab.h>
  15. #include <linux/syscalls.h>
  16. #include <linux/keyctl.h>
  17. #include <linux/fs.h>
  18. #include <linux/capability.h>
  19. #include <linux/string.h>
  20. #include <linux/err.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/security.h>
  23. #include <asm/uaccess.h>
  24. #include "internal.h"
  25. static int key_get_type_from_user(char *type,
  26. const char __user *_type,
  27. unsigned len)
  28. {
  29. int ret;
  30. ret = strncpy_from_user(type, _type, len);
  31. if (ret < 0)
  32. return ret;
  33. if (ret == 0 || ret >= len)
  34. return -EINVAL;
  35. if (type[0] == '.')
  36. return -EPERM;
  37. type[len - 1] = '\0';
  38. return 0;
  39. }
  40. /*****************************************************************************/
  41. /*
  42. * extract the description of a new key from userspace and either add it as a
  43. * new key to the specified keyring or update a matching key in that keyring
  44. * - the keyring must be writable
  45. * - returns the new key's serial number
  46. * - implements add_key()
  47. */
  48. SYSCALL_DEFINE5(add_key, const char __user *, _type,
  49. const char __user *, _description,
  50. const void __user *, _payload,
  51. size_t, plen,
  52. key_serial_t, ringid)
  53. {
  54. key_ref_t keyring_ref, key_ref;
  55. char type[32], *description;
  56. void *payload;
  57. long ret;
  58. bool vm;
  59. ret = -EINVAL;
  60. if (plen > 1024 * 1024 - 1)
  61. goto error;
  62. /* draw all the data into kernel space */
  63. ret = key_get_type_from_user(type, _type, sizeof(type));
  64. if (ret < 0)
  65. goto error;
  66. description = strndup_user(_description, PAGE_SIZE);
  67. if (IS_ERR(description)) {
  68. ret = PTR_ERR(description);
  69. goto error;
  70. }
  71. /* pull the payload in if one was supplied */
  72. payload = NULL;
  73. vm = false;
  74. if (_payload) {
  75. ret = -ENOMEM;
  76. payload = kmalloc(plen, GFP_KERNEL);
  77. if (!payload) {
  78. if (plen <= PAGE_SIZE)
  79. goto error2;
  80. vm = true;
  81. payload = vmalloc(plen);
  82. if (!payload)
  83. goto error2;
  84. }
  85. ret = -EFAULT;
  86. if (copy_from_user(payload, _payload, plen) != 0)
  87. goto error3;
  88. }
  89. /* find the target keyring (which must be writable) */
  90. keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
  91. if (IS_ERR(keyring_ref)) {
  92. ret = PTR_ERR(keyring_ref);
  93. goto error3;
  94. }
  95. /* create or update the requested key and add it to the target
  96. * keyring */
  97. key_ref = key_create_or_update(keyring_ref, type, description,
  98. payload, plen, KEY_PERM_UNDEF,
  99. KEY_ALLOC_IN_QUOTA);
  100. if (!IS_ERR(key_ref)) {
  101. ret = key_ref_to_ptr(key_ref)->serial;
  102. key_ref_put(key_ref);
  103. }
  104. else {
  105. ret = PTR_ERR(key_ref);
  106. }
  107. key_ref_put(keyring_ref);
  108. error3:
  109. if (!vm)
  110. kfree(payload);
  111. else
  112. vfree(payload);
  113. error2:
  114. kfree(description);
  115. error:
  116. return ret;
  117. } /* end sys_add_key() */
  118. /*****************************************************************************/
  119. /*
  120. * search the process keyrings for a matching key
  121. * - nested keyrings may also be searched if they have Search permission
  122. * - if a key is found, it will be attached to the destination keyring if
  123. * there's one specified
  124. * - /sbin/request-key will be invoked if _callout_info is non-NULL
  125. * - the _callout_info string will be passed to /sbin/request-key
  126. * - if the _callout_info string is empty, it will be rendered as "-"
  127. * - implements request_key()
  128. */
  129. SYSCALL_DEFINE4(request_key, const char __user *, _type,
  130. const char __user *, _description,
  131. const char __user *, _callout_info,
  132. key_serial_t, destringid)
  133. {
  134. struct key_type *ktype;
  135. struct key *key;
  136. key_ref_t dest_ref;
  137. size_t callout_len;
  138. char type[32], *description, *callout_info;
  139. long ret;
  140. /* pull the type into kernel space */
  141. ret = key_get_type_from_user(type, _type, sizeof(type));
  142. if (ret < 0)
  143. goto error;
  144. /* pull the description into kernel space */
  145. description = strndup_user(_description, PAGE_SIZE);
  146. if (IS_ERR(description)) {
  147. ret = PTR_ERR(description);
  148. goto error;
  149. }
  150. /* pull the callout info into kernel space */
  151. callout_info = NULL;
  152. callout_len = 0;
  153. if (_callout_info) {
  154. callout_info = strndup_user(_callout_info, PAGE_SIZE);
  155. if (IS_ERR(callout_info)) {
  156. ret = PTR_ERR(callout_info);
  157. goto error2;
  158. }
  159. callout_len = strlen(callout_info);
  160. }
  161. /* get the destination keyring if specified */
  162. dest_ref = NULL;
  163. if (destringid) {
  164. dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,
  165. KEY_WRITE);
  166. if (IS_ERR(dest_ref)) {
  167. ret = PTR_ERR(dest_ref);
  168. goto error3;
  169. }
  170. }
  171. /* find the key type */
  172. ktype = key_type_lookup(type);
  173. if (IS_ERR(ktype)) {
  174. ret = PTR_ERR(ktype);
  175. goto error4;
  176. }
  177. /* do the search */
  178. key = request_key_and_link(ktype, description, callout_info,
  179. callout_len, NULL, key_ref_to_ptr(dest_ref),
  180. KEY_ALLOC_IN_QUOTA);
  181. if (IS_ERR(key)) {
  182. ret = PTR_ERR(key);
  183. goto error5;
  184. }
  185. ret = key->serial;
  186. key_put(key);
  187. error5:
  188. key_type_put(ktype);
  189. error4:
  190. key_ref_put(dest_ref);
  191. error3:
  192. kfree(callout_info);
  193. error2:
  194. kfree(description);
  195. error:
  196. return ret;
  197. } /* end sys_request_key() */
  198. /*****************************************************************************/
  199. /*
  200. * get the ID of the specified process keyring
  201. * - the keyring must have search permission to be found
  202. * - implements keyctl(KEYCTL_GET_KEYRING_ID)
  203. */
  204. long keyctl_get_keyring_ID(key_serial_t id, int create)
  205. {
  206. key_ref_t key_ref;
  207. unsigned long lflags;
  208. long ret;
  209. lflags = create ? KEY_LOOKUP_CREATE : 0;
  210. key_ref = lookup_user_key(id, lflags, KEY_SEARCH);
  211. if (IS_ERR(key_ref)) {
  212. ret = PTR_ERR(key_ref);
  213. goto error;
  214. }
  215. ret = key_ref_to_ptr(key_ref)->serial;
  216. key_ref_put(key_ref);
  217. error:
  218. return ret;
  219. } /* end keyctl_get_keyring_ID() */
  220. /*****************************************************************************/
  221. /*
  222. * join the session keyring
  223. * - implements keyctl(KEYCTL_JOIN_SESSION_KEYRING)
  224. */
  225. long keyctl_join_session_keyring(const char __user *_name)
  226. {
  227. char *name;
  228. long ret;
  229. /* fetch the name from userspace */
  230. name = NULL;
  231. if (_name) {
  232. name = strndup_user(_name, PAGE_SIZE);
  233. if (IS_ERR(name)) {
  234. ret = PTR_ERR(name);
  235. goto error;
  236. }
  237. }
  238. /* join the session */
  239. ret = join_session_keyring(name);
  240. kfree(name);
  241. error:
  242. return ret;
  243. } /* end keyctl_join_session_keyring() */
  244. /*****************************************************************************/
  245. /*
  246. * update a key's data payload
  247. * - the key must be writable
  248. * - implements keyctl(KEYCTL_UPDATE)
  249. */
  250. long keyctl_update_key(key_serial_t id,
  251. const void __user *_payload,
  252. size_t plen)
  253. {
  254. key_ref_t key_ref;
  255. void *payload;
  256. long ret;
  257. ret = -EINVAL;
  258. if (plen > PAGE_SIZE)
  259. goto error;
  260. /* pull the payload in if one was supplied */
  261. payload = NULL;
  262. if (_payload) {
  263. ret = -ENOMEM;
  264. payload = kmalloc(plen, GFP_KERNEL);
  265. if (!payload)
  266. goto error;
  267. ret = -EFAULT;
  268. if (copy_from_user(payload, _payload, plen) != 0)
  269. goto error2;
  270. }
  271. /* find the target key (which must be writable) */
  272. key_ref = lookup_user_key(id, 0, KEY_WRITE);
  273. if (IS_ERR(key_ref)) {
  274. ret = PTR_ERR(key_ref);
  275. goto error2;
  276. }
  277. /* update the key */
  278. ret = key_update(key_ref, payload, plen);
  279. key_ref_put(key_ref);
  280. error2:
  281. kfree(payload);
  282. error:
  283. return ret;
  284. } /* end keyctl_update_key() */
  285. /*****************************************************************************/
  286. /*
  287. * revoke a key
  288. * - the key must be writable
  289. * - implements keyctl(KEYCTL_REVOKE)
  290. */
  291. long keyctl_revoke_key(key_serial_t id)
  292. {
  293. key_ref_t key_ref;
  294. long ret;
  295. key_ref = lookup_user_key(id, 0, KEY_WRITE);
  296. if (IS_ERR(key_ref)) {
  297. ret = PTR_ERR(key_ref);
  298. if (ret != -EACCES)
  299. goto error;
  300. key_ref = lookup_user_key(id, 0, KEY_SETATTR);
  301. if (IS_ERR(key_ref)) {
  302. ret = PTR_ERR(key_ref);
  303. goto error;
  304. }
  305. }
  306. key_revoke(key_ref_to_ptr(key_ref));
  307. ret = 0;
  308. key_ref_put(key_ref);
  309. error:
  310. return ret;
  311. } /* end keyctl_revoke_key() */
  312. /*****************************************************************************/
  313. /*
  314. * clear the specified process keyring
  315. * - the keyring must be writable
  316. * - implements keyctl(KEYCTL_CLEAR)
  317. */
  318. long keyctl_keyring_clear(key_serial_t ringid)
  319. {
  320. key_ref_t keyring_ref;
  321. long ret;
  322. keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
  323. if (IS_ERR(keyring_ref)) {
  324. ret = PTR_ERR(keyring_ref);
  325. goto error;
  326. }
  327. ret = keyring_clear(key_ref_to_ptr(keyring_ref));
  328. key_ref_put(keyring_ref);
  329. error:
  330. return ret;
  331. } /* end keyctl_keyring_clear() */
  332. /*****************************************************************************/
  333. /*
  334. * link a key into a keyring
  335. * - the keyring must be writable
  336. * - the key must be linkable
  337. * - implements keyctl(KEYCTL_LINK)
  338. */
  339. long keyctl_keyring_link(key_serial_t id, key_serial_t ringid)
  340. {
  341. key_ref_t keyring_ref, key_ref;
  342. long ret;
  343. keyring_ref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
  344. if (IS_ERR(keyring_ref)) {
  345. ret = PTR_ERR(keyring_ref);
  346. goto error;
  347. }
  348. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE, KEY_LINK);
  349. if (IS_ERR(key_ref)) {
  350. ret = PTR_ERR(key_ref);
  351. goto error2;
  352. }
  353. ret = key_link(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
  354. key_ref_put(key_ref);
  355. error2:
  356. key_ref_put(keyring_ref);
  357. error:
  358. return ret;
  359. } /* end keyctl_keyring_link() */
  360. /*****************************************************************************/
  361. /*
  362. * unlink the first attachment of a key from a keyring
  363. * - the keyring must be writable
  364. * - we don't need any permissions on the key
  365. * - implements keyctl(KEYCTL_UNLINK)
  366. */
  367. long keyctl_keyring_unlink(key_serial_t id, key_serial_t ringid)
  368. {
  369. key_ref_t keyring_ref, key_ref;
  370. long ret;
  371. keyring_ref = lookup_user_key(ringid, 0, KEY_WRITE);
  372. if (IS_ERR(keyring_ref)) {
  373. ret = PTR_ERR(keyring_ref);
  374. goto error;
  375. }
  376. key_ref = lookup_user_key(id, KEY_LOOKUP_FOR_UNLINK, 0);
  377. if (IS_ERR(key_ref)) {
  378. ret = PTR_ERR(key_ref);
  379. goto error2;
  380. }
  381. ret = key_unlink(key_ref_to_ptr(keyring_ref), key_ref_to_ptr(key_ref));
  382. key_ref_put(key_ref);
  383. error2:
  384. key_ref_put(keyring_ref);
  385. error:
  386. return ret;
  387. } /* end keyctl_keyring_unlink() */
  388. /*****************************************************************************/
  389. /*
  390. * describe a user key
  391. * - the key must have view permission
  392. * - if there's a buffer, we place up to buflen bytes of data into it
  393. * - unless there's an error, we return the amount of description available,
  394. * irrespective of how much we may have copied
  395. * - the description is formatted thus:
  396. * type;uid;gid;perm;description<NUL>
  397. * - implements keyctl(KEYCTL_DESCRIBE)
  398. */
  399. long keyctl_describe_key(key_serial_t keyid,
  400. char __user *buffer,
  401. size_t buflen)
  402. {
  403. struct key *key, *instkey;
  404. key_ref_t key_ref;
  405. char *tmpbuf;
  406. long ret;
  407. key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);
  408. if (IS_ERR(key_ref)) {
  409. /* viewing a key under construction is permitted if we have the
  410. * authorisation token handy */
  411. if (PTR_ERR(key_ref) == -EACCES) {
  412. instkey = key_get_instantiation_authkey(keyid);
  413. if (!IS_ERR(instkey)) {
  414. key_put(instkey);
  415. key_ref = lookup_user_key(keyid,
  416. KEY_LOOKUP_PARTIAL,
  417. 0);
  418. if (!IS_ERR(key_ref))
  419. goto okay;
  420. }
  421. }
  422. ret = PTR_ERR(key_ref);
  423. goto error;
  424. }
  425. okay:
  426. /* calculate how much description we're going to return */
  427. ret = -ENOMEM;
  428. tmpbuf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  429. if (!tmpbuf)
  430. goto error2;
  431. key = key_ref_to_ptr(key_ref);
  432. ret = snprintf(tmpbuf, PAGE_SIZE - 1,
  433. "%s;%d;%d;%08x;%s",
  434. key->type->name,
  435. key->uid,
  436. key->gid,
  437. key->perm,
  438. key->description ?: "");
  439. /* include a NUL char at the end of the data */
  440. if (ret > PAGE_SIZE - 1)
  441. ret = PAGE_SIZE - 1;
  442. tmpbuf[ret] = 0;
  443. ret++;
  444. /* consider returning the data */
  445. if (buffer && buflen > 0) {
  446. if (buflen > ret)
  447. buflen = ret;
  448. if (copy_to_user(buffer, tmpbuf, buflen) != 0)
  449. ret = -EFAULT;
  450. }
  451. kfree(tmpbuf);
  452. error2:
  453. key_ref_put(key_ref);
  454. error:
  455. return ret;
  456. } /* end keyctl_describe_key() */
  457. /*****************************************************************************/
  458. /*
  459. * search the specified keyring for a matching key
  460. * - the start keyring must be searchable
  461. * - nested keyrings may also be searched if they are searchable
  462. * - only keys with search permission may be found
  463. * - if a key is found, it will be attached to the destination keyring if
  464. * there's one specified
  465. * - implements keyctl(KEYCTL_SEARCH)
  466. */
  467. long keyctl_keyring_search(key_serial_t ringid,
  468. const char __user *_type,
  469. const char __user *_description,
  470. key_serial_t destringid)
  471. {
  472. struct key_type *ktype;
  473. key_ref_t keyring_ref, key_ref, dest_ref;
  474. char type[32], *description;
  475. long ret;
  476. /* pull the type and description into kernel space */
  477. ret = key_get_type_from_user(type, _type, sizeof(type));
  478. if (ret < 0)
  479. goto error;
  480. description = strndup_user(_description, PAGE_SIZE);
  481. if (IS_ERR(description)) {
  482. ret = PTR_ERR(description);
  483. goto error;
  484. }
  485. /* get the keyring at which to begin the search */
  486. keyring_ref = lookup_user_key(ringid, 0, KEY_SEARCH);
  487. if (IS_ERR(keyring_ref)) {
  488. ret = PTR_ERR(keyring_ref);
  489. goto error2;
  490. }
  491. /* get the destination keyring if specified */
  492. dest_ref = NULL;
  493. if (destringid) {
  494. dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,
  495. KEY_WRITE);
  496. if (IS_ERR(dest_ref)) {
  497. ret = PTR_ERR(dest_ref);
  498. goto error3;
  499. }
  500. }
  501. /* find the key type */
  502. ktype = key_type_lookup(type);
  503. if (IS_ERR(ktype)) {
  504. ret = PTR_ERR(ktype);
  505. goto error4;
  506. }
  507. /* do the search */
  508. key_ref = keyring_search(keyring_ref, ktype, description);
  509. if (IS_ERR(key_ref)) {
  510. ret = PTR_ERR(key_ref);
  511. /* treat lack or presence of a negative key the same */
  512. if (ret == -EAGAIN)
  513. ret = -ENOKEY;
  514. goto error5;
  515. }
  516. /* link the resulting key to the destination keyring if we can */
  517. if (dest_ref) {
  518. ret = key_permission(key_ref, KEY_LINK);
  519. if (ret < 0)
  520. goto error6;
  521. ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref));
  522. if (ret < 0)
  523. goto error6;
  524. }
  525. ret = key_ref_to_ptr(key_ref)->serial;
  526. error6:
  527. key_ref_put(key_ref);
  528. error5:
  529. key_type_put(ktype);
  530. error4:
  531. key_ref_put(dest_ref);
  532. error3:
  533. key_ref_put(keyring_ref);
  534. error2:
  535. kfree(description);
  536. error:
  537. return ret;
  538. } /* end keyctl_keyring_search() */
  539. /*****************************************************************************/
  540. /*
  541. * read a user key's payload
  542. * - the keyring must be readable or the key must be searchable from the
  543. * process's keyrings
  544. * - if there's a buffer, we place up to buflen bytes of data into it
  545. * - unless there's an error, we return the amount of data in the key,
  546. * irrespective of how much we may have copied
  547. * - implements keyctl(KEYCTL_READ)
  548. */
  549. long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
  550. {
  551. struct key *key;
  552. key_ref_t key_ref;
  553. long ret;
  554. /* find the key first */
  555. key_ref = lookup_user_key(keyid, 0, 0);
  556. if (IS_ERR(key_ref)) {
  557. ret = -ENOKEY;
  558. goto error;
  559. }
  560. key = key_ref_to_ptr(key_ref);
  561. /* see if we can read it directly */
  562. ret = key_permission(key_ref, KEY_READ);
  563. if (ret == 0)
  564. goto can_read_key;
  565. if (ret != -EACCES)
  566. goto error;
  567. /* we can't; see if it's searchable from this process's keyrings
  568. * - we automatically take account of the fact that it may be
  569. * dangling off an instantiation key
  570. */
  571. if (!is_key_possessed(key_ref)) {
  572. ret = -EACCES;
  573. goto error2;
  574. }
  575. /* the key is probably readable - now try to read it */
  576. can_read_key:
  577. ret = key_validate(key);
  578. if (ret == 0) {
  579. ret = -EOPNOTSUPP;
  580. if (key->type->read) {
  581. /* read the data with the semaphore held (since we
  582. * might sleep) */
  583. down_read(&key->sem);
  584. ret = key->type->read(key, buffer, buflen);
  585. up_read(&key->sem);
  586. }
  587. }
  588. error2:
  589. key_put(key);
  590. error:
  591. return ret;
  592. } /* end keyctl_read_key() */
  593. /*****************************************************************************/
  594. /*
  595. * change the ownership of a key
  596. * - the keyring owned by the changer
  597. * - if the uid or gid is -1, then that parameter is not changed
  598. * - implements keyctl(KEYCTL_CHOWN)
  599. */
  600. long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
  601. {
  602. struct key_user *newowner, *zapowner = NULL;
  603. struct key *key;
  604. key_ref_t key_ref;
  605. long ret;
  606. ret = 0;
  607. if (uid == (uid_t) -1 && gid == (gid_t) -1)
  608. goto error;
  609. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
  610. KEY_SETATTR);
  611. if (IS_ERR(key_ref)) {
  612. ret = PTR_ERR(key_ref);
  613. goto error;
  614. }
  615. key = key_ref_to_ptr(key_ref);
  616. /* make the changes with the locks held to prevent chown/chown races */
  617. ret = -EACCES;
  618. down_write(&key->sem);
  619. if (!capable(CAP_SYS_ADMIN)) {
  620. /* only the sysadmin can chown a key to some other UID */
  621. if (uid != (uid_t) -1 && key->uid != uid)
  622. goto error_put;
  623. /* only the sysadmin can set the key's GID to a group other
  624. * than one of those that the current process subscribes to */
  625. if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid))
  626. goto error_put;
  627. }
  628. /* change the UID */
  629. if (uid != (uid_t) -1 && uid != key->uid) {
  630. ret = -ENOMEM;
  631. newowner = key_user_lookup(uid, current_user_ns());
  632. if (!newowner)
  633. goto error_put;
  634. /* transfer the quota burden to the new user */
  635. if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) {
  636. unsigned maxkeys = (uid == 0) ?
  637. key_quota_root_maxkeys : key_quota_maxkeys;
  638. unsigned maxbytes = (uid == 0) ?
  639. key_quota_root_maxbytes : key_quota_maxbytes;
  640. spin_lock(&newowner->lock);
  641. if (newowner->qnkeys + 1 >= maxkeys ||
  642. newowner->qnbytes + key->quotalen >= maxbytes ||
  643. newowner->qnbytes + key->quotalen <
  644. newowner->qnbytes)
  645. goto quota_overrun;
  646. newowner->qnkeys++;
  647. newowner->qnbytes += key->quotalen;
  648. spin_unlock(&newowner->lock);
  649. spin_lock(&key->user->lock);
  650. key->user->qnkeys--;
  651. key->user->qnbytes -= key->quotalen;
  652. spin_unlock(&key->user->lock);
  653. }
  654. atomic_dec(&key->user->nkeys);
  655. atomic_inc(&newowner->nkeys);
  656. if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
  657. atomic_dec(&key->user->nikeys);
  658. atomic_inc(&newowner->nikeys);
  659. }
  660. zapowner = key->user;
  661. key->user = newowner;
  662. key->uid = uid;
  663. }
  664. /* change the GID */
  665. if (gid != (gid_t) -1)
  666. key->gid = gid;
  667. ret = 0;
  668. error_put:
  669. up_write(&key->sem);
  670. key_put(key);
  671. if (zapowner)
  672. key_user_put(zapowner);
  673. error:
  674. return ret;
  675. quota_overrun:
  676. spin_unlock(&newowner->lock);
  677. zapowner = newowner;
  678. ret = -EDQUOT;
  679. goto error_put;
  680. } /* end keyctl_chown_key() */
  681. /*****************************************************************************/
  682. /*
  683. * change the permission mask on a key
  684. * - the keyring owned by the changer
  685. * - implements keyctl(KEYCTL_SETPERM)
  686. */
  687. long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
  688. {
  689. struct key *key;
  690. key_ref_t key_ref;
  691. long ret;
  692. ret = -EINVAL;
  693. if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL))
  694. goto error;
  695. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
  696. KEY_SETATTR);
  697. if (IS_ERR(key_ref)) {
  698. ret = PTR_ERR(key_ref);
  699. goto error;
  700. }
  701. key = key_ref_to_ptr(key_ref);
  702. /* make the changes with the locks held to prevent chown/chmod races */
  703. ret = -EACCES;
  704. down_write(&key->sem);
  705. /* if we're not the sysadmin, we can only change a key that we own */
  706. if (capable(CAP_SYS_ADMIN) || key->uid == current_fsuid()) {
  707. key->perm = perm;
  708. ret = 0;
  709. }
  710. up_write(&key->sem);
  711. key_put(key);
  712. error:
  713. return ret;
  714. } /* end keyctl_setperm_key() */
  715. /*
  716. * get the destination keyring for instantiation
  717. */
  718. static long get_instantiation_keyring(key_serial_t ringid,
  719. struct request_key_auth *rka,
  720. struct key **_dest_keyring)
  721. {
  722. key_ref_t dkref;
  723. *_dest_keyring = NULL;
  724. /* just return a NULL pointer if we weren't asked to make a link */
  725. if (ringid == 0)
  726. return 0;
  727. /* if a specific keyring is nominated by ID, then use that */
  728. if (ringid > 0) {
  729. dkref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
  730. if (IS_ERR(dkref))
  731. return PTR_ERR(dkref);
  732. *_dest_keyring = key_ref_to_ptr(dkref);
  733. return 0;
  734. }
  735. if (ringid == KEY_SPEC_REQKEY_AUTH_KEY)
  736. return -EINVAL;
  737. /* otherwise specify the destination keyring recorded in the
  738. * authorisation key (any KEY_SPEC_*_KEYRING) */
  739. if (ringid >= KEY_SPEC_REQUESTOR_KEYRING) {
  740. *_dest_keyring = key_get(rka->dest_keyring);
  741. return 0;
  742. }
  743. return -ENOKEY;
  744. }
  745. /*
  746. * change the request_key authorisation key on the current process
  747. */
  748. static int keyctl_change_reqkey_auth(struct key *key)
  749. {
  750. struct cred *new;
  751. new = prepare_creds();
  752. if (!new)
  753. return -ENOMEM;
  754. key_put(new->request_key_auth);
  755. new->request_key_auth = key_get(key);
  756. return commit_creds(new);
  757. }
  758. /*****************************************************************************/
  759. /*
  760. * instantiate the key with the specified payload, and, if one is given, link
  761. * the key into the keyring
  762. */
  763. long keyctl_instantiate_key(key_serial_t id,
  764. const void __user *_payload,
  765. size_t plen,
  766. key_serial_t ringid)
  767. {
  768. const struct cred *cred = current_cred();
  769. struct request_key_auth *rka;
  770. struct key *instkey, *dest_keyring;
  771. void *payload;
  772. long ret;
  773. bool vm = false;
  774. kenter("%d,,%zu,%d", id, plen, ringid);
  775. ret = -EINVAL;
  776. if (plen > 1024 * 1024 - 1)
  777. goto error;
  778. /* the appropriate instantiation authorisation key must have been
  779. * assumed before calling this */
  780. ret = -EPERM;
  781. instkey = cred->request_key_auth;
  782. if (!instkey)
  783. goto error;
  784. rka = instkey->payload.data;
  785. if (rka->target_key->serial != id)
  786. goto error;
  787. /* pull the payload in if one was supplied */
  788. payload = NULL;
  789. if (_payload) {
  790. ret = -ENOMEM;
  791. payload = kmalloc(plen, GFP_KERNEL);
  792. if (!payload) {
  793. if (plen <= PAGE_SIZE)
  794. goto error;
  795. vm = true;
  796. payload = vmalloc(plen);
  797. if (!payload)
  798. goto error;
  799. }
  800. ret = -EFAULT;
  801. if (copy_from_user(payload, _payload, plen) != 0)
  802. goto error2;
  803. }
  804. /* find the destination keyring amongst those belonging to the
  805. * requesting task */
  806. ret = get_instantiation_keyring(ringid, rka, &dest_keyring);
  807. if (ret < 0)
  808. goto error2;
  809. /* instantiate the key and link it into a keyring */
  810. ret = key_instantiate_and_link(rka->target_key, payload, plen,
  811. dest_keyring, instkey);
  812. key_put(dest_keyring);
  813. /* discard the assumed authority if it's just been disabled by
  814. * instantiation of the key */
  815. if (ret == 0)
  816. keyctl_change_reqkey_auth(NULL);
  817. error2:
  818. if (!vm)
  819. kfree(payload);
  820. else
  821. vfree(payload);
  822. error:
  823. return ret;
  824. } /* end keyctl_instantiate_key() */
  825. /*****************************************************************************/
  826. /*
  827. * negatively instantiate the key with the given timeout (in seconds), and, if
  828. * one is given, link the key into the keyring
  829. */
  830. long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
  831. {
  832. const struct cred *cred = current_cred();
  833. struct request_key_auth *rka;
  834. struct key *instkey, *dest_keyring;
  835. long ret;
  836. kenter("%d,%u,%d", id, timeout, ringid);
  837. /* the appropriate instantiation authorisation key must have been
  838. * assumed before calling this */
  839. ret = -EPERM;
  840. instkey = cred->request_key_auth;
  841. if (!instkey)
  842. goto error;
  843. rka = instkey->payload.data;
  844. if (rka->target_key->serial != id)
  845. goto error;
  846. /* find the destination keyring if present (which must also be
  847. * writable) */
  848. ret = get_instantiation_keyring(ringid, rka, &dest_keyring);
  849. if (ret < 0)
  850. goto error;
  851. /* instantiate the key and link it into a keyring */
  852. ret = key_negate_and_link(rka->target_key, timeout,
  853. dest_keyring, instkey);
  854. key_put(dest_keyring);
  855. /* discard the assumed authority if it's just been disabled by
  856. * instantiation of the key */
  857. if (ret == 0)
  858. keyctl_change_reqkey_auth(NULL);
  859. error:
  860. return ret;
  861. } /* end keyctl_negate_key() */
  862. /*****************************************************************************/
  863. /*
  864. * set the default keyring in which request_key() will cache keys
  865. * - return the old setting
  866. */
  867. long keyctl_set_reqkey_keyring(int reqkey_defl)
  868. {
  869. struct cred *new;
  870. int ret, old_setting;
  871. old_setting = current_cred_xxx(jit_keyring);
  872. if (reqkey_defl == KEY_REQKEY_DEFL_NO_CHANGE)
  873. return old_setting;
  874. new = prepare_creds();
  875. if (!new)
  876. return -ENOMEM;
  877. switch (reqkey_defl) {
  878. case KEY_REQKEY_DEFL_THREAD_KEYRING:
  879. ret = install_thread_keyring_to_cred(new);
  880. if (ret < 0)
  881. goto error;
  882. goto set;
  883. case KEY_REQKEY_DEFL_PROCESS_KEYRING:
  884. ret = install_process_keyring_to_cred(new);
  885. if (ret < 0) {
  886. if (ret != -EEXIST)
  887. goto error;
  888. ret = 0;
  889. }
  890. goto set;
  891. case KEY_REQKEY_DEFL_DEFAULT:
  892. case KEY_REQKEY_DEFL_SESSION_KEYRING:
  893. case KEY_REQKEY_DEFL_USER_KEYRING:
  894. case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
  895. case KEY_REQKEY_DEFL_REQUESTOR_KEYRING:
  896. goto set;
  897. case KEY_REQKEY_DEFL_NO_CHANGE:
  898. case KEY_REQKEY_DEFL_GROUP_KEYRING:
  899. default:
  900. ret = -EINVAL;
  901. goto error;
  902. }
  903. set:
  904. new->jit_keyring = reqkey_defl;
  905. commit_creds(new);
  906. return old_setting;
  907. error:
  908. abort_creds(new);
  909. return ret;
  910. } /* end keyctl_set_reqkey_keyring() */
  911. /*****************************************************************************/
  912. /*
  913. * set or clear the timeout for a key
  914. */
  915. long keyctl_set_timeout(key_serial_t id, unsigned timeout)
  916. {
  917. struct timespec now;
  918. struct key *key, *instkey;
  919. key_ref_t key_ref;
  920. time_t expiry;
  921. long ret;
  922. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
  923. KEY_SETATTR);
  924. if (IS_ERR(key_ref)) {
  925. /* setting the timeout on a key under construction is permitted
  926. * if we have the authorisation token handy */
  927. if (PTR_ERR(key_ref) == -EACCES) {
  928. instkey = key_get_instantiation_authkey(id);
  929. if (!IS_ERR(instkey)) {
  930. key_put(instkey);
  931. key_ref = lookup_user_key(id,
  932. KEY_LOOKUP_PARTIAL,
  933. 0);
  934. if (!IS_ERR(key_ref))
  935. goto okay;
  936. }
  937. }
  938. ret = PTR_ERR(key_ref);
  939. goto error;
  940. }
  941. okay:
  942. key = key_ref_to_ptr(key_ref);
  943. /* make the changes with the locks held to prevent races */
  944. down_write(&key->sem);
  945. expiry = 0;
  946. if (timeout > 0) {
  947. now = current_kernel_time();
  948. expiry = now.tv_sec + timeout;
  949. }
  950. key->expiry = expiry;
  951. key_schedule_gc(key->expiry + key_gc_delay);
  952. up_write(&key->sem);
  953. key_put(key);
  954. ret = 0;
  955. error:
  956. return ret;
  957. } /* end keyctl_set_timeout() */
  958. /*****************************************************************************/
  959. /*
  960. * assume the authority to instantiate the specified key
  961. */
  962. long keyctl_assume_authority(key_serial_t id)
  963. {
  964. struct key *authkey;
  965. long ret;
  966. /* special key IDs aren't permitted */
  967. ret = -EINVAL;
  968. if (id < 0)
  969. goto error;
  970. /* we divest ourselves of authority if given an ID of 0 */
  971. if (id == 0) {
  972. ret = keyctl_change_reqkey_auth(NULL);
  973. goto error;
  974. }
  975. /* attempt to assume the authority temporarily granted to us whilst we
  976. * instantiate the specified key
  977. * - the authorisation key must be in the current task's keyrings
  978. * somewhere
  979. */
  980. authkey = key_get_instantiation_authkey(id);
  981. if (IS_ERR(authkey)) {
  982. ret = PTR_ERR(authkey);
  983. goto error;
  984. }
  985. ret = keyctl_change_reqkey_auth(authkey);
  986. if (ret < 0)
  987. goto error;
  988. key_put(authkey);
  989. ret = authkey->serial;
  990. error:
  991. return ret;
  992. } /* end keyctl_assume_authority() */
  993. /*
  994. * get the security label of a key
  995. * - the key must grant us view permission
  996. * - if there's a buffer, we place up to buflen bytes of data into it
  997. * - unless there's an error, we return the amount of information available,
  998. * irrespective of how much we may have copied (including the terminal NUL)
  999. * - implements keyctl(KEYCTL_GET_SECURITY)
  1000. */
  1001. long keyctl_get_security(key_serial_t keyid,
  1002. char __user *buffer,
  1003. size_t buflen)
  1004. {
  1005. struct key *key, *instkey;
  1006. key_ref_t key_ref;
  1007. char *context;
  1008. long ret;
  1009. key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);
  1010. if (IS_ERR(key_ref)) {
  1011. if (PTR_ERR(key_ref) != -EACCES)
  1012. return PTR_ERR(key_ref);
  1013. /* viewing a key under construction is also permitted if we
  1014. * have the authorisation token handy */
  1015. instkey = key_get_instantiation_authkey(keyid);
  1016. if (IS_ERR(instkey))
  1017. return PTR_ERR(instkey);
  1018. key_put(instkey);
  1019. key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, 0);
  1020. if (IS_ERR(key_ref))
  1021. return PTR_ERR(key_ref);
  1022. }
  1023. key = key_ref_to_ptr(key_ref);
  1024. ret = security_key_getsecurity(key, &context);
  1025. if (ret == 0) {
  1026. /* if no information was returned, give userspace an empty
  1027. * string */
  1028. ret = 1;
  1029. if (buffer && buflen > 0 &&
  1030. copy_to_user(buffer, "", 1) != 0)
  1031. ret = -EFAULT;
  1032. } else if (ret > 0) {
  1033. /* return as much data as there's room for */
  1034. if (buffer && buflen > 0) {
  1035. if (buflen > ret)
  1036. buflen = ret;
  1037. if (copy_to_user(buffer, context, buflen) != 0)
  1038. ret = -EFAULT;
  1039. }
  1040. kfree(context);
  1041. }
  1042. key_ref_put(key_ref);
  1043. return ret;
  1044. }
  1045. /*
  1046. * attempt to install the calling process's session keyring on the process's
  1047. * parent process
  1048. * - the keyring must exist and must grant us LINK permission
  1049. * - implements keyctl(KEYCTL_SESSION_TO_PARENT)
  1050. */
  1051. long keyctl_session_to_parent(void)
  1052. {
  1053. #ifdef TIF_NOTIFY_RESUME
  1054. struct task_struct *me, *parent;
  1055. const struct cred *mycred, *pcred;
  1056. struct cred *cred, *oldcred;
  1057. key_ref_t keyring_r;
  1058. int ret;
  1059. keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK);
  1060. if (IS_ERR(keyring_r))
  1061. return PTR_ERR(keyring_r);
  1062. /* our parent is going to need a new cred struct, a new tgcred struct
  1063. * and new security data, so we allocate them here to prevent ENOMEM in
  1064. * our parent */
  1065. ret = -ENOMEM;
  1066. cred = cred_alloc_blank();
  1067. if (!cred)
  1068. goto error_keyring;
  1069. cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
  1070. keyring_r = NULL;
  1071. me = current;
  1072. rcu_read_lock();
  1073. write_lock_irq(&tasklist_lock);
  1074. parent = me->real_parent;
  1075. ret = -EPERM;
  1076. /* the parent mustn't be init and mustn't be a kernel thread */
  1077. if (parent->pid <= 1 || !parent->mm)
  1078. goto not_permitted;
  1079. /* the parent must be single threaded */
  1080. if (!thread_group_empty(parent))
  1081. goto not_permitted;
  1082. /* the parent and the child must have different session keyrings or
  1083. * there's no point */
  1084. mycred = current_cred();
  1085. pcred = __task_cred(parent);
  1086. if (mycred == pcred ||
  1087. mycred->tgcred->session_keyring == pcred->tgcred->session_keyring)
  1088. goto already_same;
  1089. /* the parent must have the same effective ownership and mustn't be
  1090. * SUID/SGID */
  1091. if (pcred->uid != mycred->euid ||
  1092. pcred->euid != mycred->euid ||
  1093. pcred->suid != mycred->euid ||
  1094. pcred->gid != mycred->egid ||
  1095. pcred->egid != mycred->egid ||
  1096. pcred->sgid != mycred->egid)
  1097. goto not_permitted;
  1098. /* the keyrings must have the same UID */
  1099. if ((pcred->tgcred->session_keyring &&
  1100. pcred->tgcred->session_keyring->uid != mycred->euid) ||
  1101. mycred->tgcred->session_keyring->uid != mycred->euid)
  1102. goto not_permitted;
  1103. /* if there's an already pending keyring replacement, then we replace
  1104. * that */
  1105. oldcred = parent->replacement_session_keyring;
  1106. /* the replacement session keyring is applied just prior to userspace
  1107. * restarting */
  1108. parent->replacement_session_keyring = cred;
  1109. cred = NULL;
  1110. set_ti_thread_flag(task_thread_info(parent), TIF_NOTIFY_RESUME);
  1111. write_unlock_irq(&tasklist_lock);
  1112. rcu_read_unlock();
  1113. if (oldcred)
  1114. put_cred(oldcred);
  1115. return 0;
  1116. already_same:
  1117. ret = 0;
  1118. not_permitted:
  1119. write_unlock_irq(&tasklist_lock);
  1120. rcu_read_unlock();
  1121. put_cred(cred);
  1122. return ret;
  1123. error_keyring:
  1124. key_ref_put(keyring_r);
  1125. return ret;
  1126. #else /* !TIF_NOTIFY_RESUME */
  1127. /*
  1128. * To be removed when TIF_NOTIFY_RESUME has been implemented on
  1129. * m68k/xtensa
  1130. */
  1131. #warning TIF_NOTIFY_RESUME not implemented
  1132. return -EOPNOTSUPP;
  1133. #endif /* !TIF_NOTIFY_RESUME */
  1134. }
  1135. /*****************************************************************************/
  1136. /*
  1137. * the key control system call
  1138. */
  1139. SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
  1140. unsigned long, arg4, unsigned long, arg5)
  1141. {
  1142. switch (option) {
  1143. case KEYCTL_GET_KEYRING_ID:
  1144. return keyctl_get_keyring_ID((key_serial_t) arg2,
  1145. (int) arg3);
  1146. case KEYCTL_JOIN_SESSION_KEYRING:
  1147. return keyctl_join_session_keyring((const char __user *) arg2);
  1148. case KEYCTL_UPDATE:
  1149. return keyctl_update_key((key_serial_t) arg2,
  1150. (const void __user *) arg3,
  1151. (size_t) arg4);
  1152. case KEYCTL_REVOKE:
  1153. return keyctl_revoke_key((key_serial_t) arg2);
  1154. case KEYCTL_DESCRIBE:
  1155. return keyctl_describe_key((key_serial_t) arg2,
  1156. (char __user *) arg3,
  1157. (unsigned) arg4);
  1158. case KEYCTL_CLEAR:
  1159. return keyctl_keyring_clear((key_serial_t) arg2);
  1160. case KEYCTL_LINK:
  1161. return keyctl_keyring_link((key_serial_t) arg2,
  1162. (key_serial_t) arg3);
  1163. case KEYCTL_UNLINK:
  1164. return keyctl_keyring_unlink((key_serial_t) arg2,
  1165. (key_serial_t) arg3);
  1166. case KEYCTL_SEARCH:
  1167. return keyctl_keyring_search((key_serial_t) arg2,
  1168. (const char __user *) arg3,
  1169. (const char __user *) arg4,
  1170. (key_serial_t) arg5);
  1171. case KEYCTL_READ:
  1172. return keyctl_read_key((key_serial_t) arg2,
  1173. (char __user *) arg3,
  1174. (size_t) arg4);
  1175. case KEYCTL_CHOWN:
  1176. return keyctl_chown_key((key_serial_t) arg2,
  1177. (uid_t) arg3,
  1178. (gid_t) arg4);
  1179. case KEYCTL_SETPERM:
  1180. return keyctl_setperm_key((key_serial_t) arg2,
  1181. (key_perm_t) arg3);
  1182. case KEYCTL_INSTANTIATE:
  1183. return keyctl_instantiate_key((key_serial_t) arg2,
  1184. (const void __user *) arg3,
  1185. (size_t) arg4,
  1186. (key_serial_t) arg5);
  1187. case KEYCTL_NEGATE:
  1188. return keyctl_negate_key((key_serial_t) arg2,
  1189. (unsigned) arg3,
  1190. (key_serial_t) arg4);
  1191. case KEYCTL_SET_REQKEY_KEYRING:
  1192. return keyctl_set_reqkey_keyring(arg2);
  1193. case KEYCTL_SET_TIMEOUT:
  1194. return keyctl_set_timeout((key_serial_t) arg2,
  1195. (unsigned) arg3);
  1196. case KEYCTL_ASSUME_AUTHORITY:
  1197. return keyctl_assume_authority((key_serial_t) arg2);
  1198. case KEYCTL_GET_SECURITY:
  1199. return keyctl_get_security((key_serial_t) arg2,
  1200. (char __user *) arg3,
  1201. (size_t) arg4);
  1202. case KEYCTL_SESSION_TO_PARENT:
  1203. return keyctl_session_to_parent();
  1204. default:
  1205. return -EOPNOTSUPP;
  1206. }
  1207. } /* end sys_keyctl() */