keyctl.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  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 -EFAULT;
  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_ref_to_ptr(key_ref)->type->name,
  435. key_ref_to_ptr(key_ref)->uid,
  436. key_ref_to_ptr(key_ref)->gid,
  437. key_ref_to_ptr(key_ref)->perm,
  438. key_ref_to_ptr(key_ref)->description ?
  439. key_ref_to_ptr(key_ref)->description : ""
  440. );
  441. /* include a NUL char at the end of the data */
  442. if (ret > PAGE_SIZE - 1)
  443. ret = PAGE_SIZE - 1;
  444. tmpbuf[ret] = 0;
  445. ret++;
  446. /* consider returning the data */
  447. if (buffer && buflen > 0) {
  448. if (buflen > ret)
  449. buflen = ret;
  450. if (copy_to_user(buffer, tmpbuf, buflen) != 0)
  451. ret = -EFAULT;
  452. }
  453. kfree(tmpbuf);
  454. error2:
  455. key_ref_put(key_ref);
  456. error:
  457. return ret;
  458. } /* end keyctl_describe_key() */
  459. /*****************************************************************************/
  460. /*
  461. * search the specified keyring for a matching key
  462. * - the start keyring must be searchable
  463. * - nested keyrings may also be searched if they are searchable
  464. * - only keys with search permission may be found
  465. * - if a key is found, it will be attached to the destination keyring if
  466. * there's one specified
  467. * - implements keyctl(KEYCTL_SEARCH)
  468. */
  469. long keyctl_keyring_search(key_serial_t ringid,
  470. const char __user *_type,
  471. const char __user *_description,
  472. key_serial_t destringid)
  473. {
  474. struct key_type *ktype;
  475. key_ref_t keyring_ref, key_ref, dest_ref;
  476. char type[32], *description;
  477. long ret;
  478. /* pull the type and description into kernel space */
  479. ret = key_get_type_from_user(type, _type, sizeof(type));
  480. if (ret < 0)
  481. goto error;
  482. description = strndup_user(_description, PAGE_SIZE);
  483. if (IS_ERR(description)) {
  484. ret = PTR_ERR(description);
  485. goto error;
  486. }
  487. /* get the keyring at which to begin the search */
  488. keyring_ref = lookup_user_key(ringid, 0, KEY_SEARCH);
  489. if (IS_ERR(keyring_ref)) {
  490. ret = PTR_ERR(keyring_ref);
  491. goto error2;
  492. }
  493. /* get the destination keyring if specified */
  494. dest_ref = NULL;
  495. if (destringid) {
  496. dest_ref = lookup_user_key(destringid, KEY_LOOKUP_CREATE,
  497. KEY_WRITE);
  498. if (IS_ERR(dest_ref)) {
  499. ret = PTR_ERR(dest_ref);
  500. goto error3;
  501. }
  502. }
  503. /* find the key type */
  504. ktype = key_type_lookup(type);
  505. if (IS_ERR(ktype)) {
  506. ret = PTR_ERR(ktype);
  507. goto error4;
  508. }
  509. /* do the search */
  510. key_ref = keyring_search(keyring_ref, ktype, description);
  511. if (IS_ERR(key_ref)) {
  512. ret = PTR_ERR(key_ref);
  513. /* treat lack or presence of a negative key the same */
  514. if (ret == -EAGAIN)
  515. ret = -ENOKEY;
  516. goto error5;
  517. }
  518. /* link the resulting key to the destination keyring if we can */
  519. if (dest_ref) {
  520. ret = key_permission(key_ref, KEY_LINK);
  521. if (ret < 0)
  522. goto error6;
  523. ret = key_link(key_ref_to_ptr(dest_ref), key_ref_to_ptr(key_ref));
  524. if (ret < 0)
  525. goto error6;
  526. }
  527. ret = key_ref_to_ptr(key_ref)->serial;
  528. error6:
  529. key_ref_put(key_ref);
  530. error5:
  531. key_type_put(ktype);
  532. error4:
  533. key_ref_put(dest_ref);
  534. error3:
  535. key_ref_put(keyring_ref);
  536. error2:
  537. kfree(description);
  538. error:
  539. return ret;
  540. } /* end keyctl_keyring_search() */
  541. /*****************************************************************************/
  542. /*
  543. * read a user key's payload
  544. * - the keyring must be readable or the key must be searchable from the
  545. * process's keyrings
  546. * - if there's a buffer, we place up to buflen bytes of data into it
  547. * - unless there's an error, we return the amount of data in the key,
  548. * irrespective of how much we may have copied
  549. * - implements keyctl(KEYCTL_READ)
  550. */
  551. long keyctl_read_key(key_serial_t keyid, char __user *buffer, size_t buflen)
  552. {
  553. struct key *key;
  554. key_ref_t key_ref;
  555. long ret;
  556. /* find the key first */
  557. key_ref = lookup_user_key(keyid, 0, 0);
  558. if (IS_ERR(key_ref)) {
  559. ret = -ENOKEY;
  560. goto error;
  561. }
  562. key = key_ref_to_ptr(key_ref);
  563. /* see if we can read it directly */
  564. ret = key_permission(key_ref, KEY_READ);
  565. if (ret == 0)
  566. goto can_read_key;
  567. if (ret != -EACCES)
  568. goto error;
  569. /* we can't; see if it's searchable from this process's keyrings
  570. * - we automatically take account of the fact that it may be
  571. * dangling off an instantiation key
  572. */
  573. if (!is_key_possessed(key_ref)) {
  574. ret = -EACCES;
  575. goto error2;
  576. }
  577. /* the key is probably readable - now try to read it */
  578. can_read_key:
  579. ret = key_validate(key);
  580. if (ret == 0) {
  581. ret = -EOPNOTSUPP;
  582. if (key->type->read) {
  583. /* read the data with the semaphore held (since we
  584. * might sleep) */
  585. down_read(&key->sem);
  586. ret = key->type->read(key, buffer, buflen);
  587. up_read(&key->sem);
  588. }
  589. }
  590. error2:
  591. key_put(key);
  592. error:
  593. return ret;
  594. } /* end keyctl_read_key() */
  595. /*****************************************************************************/
  596. /*
  597. * change the ownership of a key
  598. * - the keyring owned by the changer
  599. * - if the uid or gid is -1, then that parameter is not changed
  600. * - implements keyctl(KEYCTL_CHOWN)
  601. */
  602. long keyctl_chown_key(key_serial_t id, uid_t uid, gid_t gid)
  603. {
  604. struct key_user *newowner, *zapowner = NULL;
  605. struct key *key;
  606. key_ref_t key_ref;
  607. long ret;
  608. ret = 0;
  609. if (uid == (uid_t) -1 && gid == (gid_t) -1)
  610. goto error;
  611. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
  612. KEY_SETATTR);
  613. if (IS_ERR(key_ref)) {
  614. ret = PTR_ERR(key_ref);
  615. goto error;
  616. }
  617. key = key_ref_to_ptr(key_ref);
  618. /* make the changes with the locks held to prevent chown/chown races */
  619. ret = -EACCES;
  620. down_write(&key->sem);
  621. if (!capable(CAP_SYS_ADMIN)) {
  622. /* only the sysadmin can chown a key to some other UID */
  623. if (uid != (uid_t) -1 && key->uid != uid)
  624. goto error_put;
  625. /* only the sysadmin can set the key's GID to a group other
  626. * than one of those that the current process subscribes to */
  627. if (gid != (gid_t) -1 && gid != key->gid && !in_group_p(gid))
  628. goto error_put;
  629. }
  630. /* change the UID */
  631. if (uid != (uid_t) -1 && uid != key->uid) {
  632. ret = -ENOMEM;
  633. newowner = key_user_lookup(uid, current_user_ns());
  634. if (!newowner)
  635. goto error_put;
  636. /* transfer the quota burden to the new user */
  637. if (test_bit(KEY_FLAG_IN_QUOTA, &key->flags)) {
  638. unsigned maxkeys = (uid == 0) ?
  639. key_quota_root_maxkeys : key_quota_maxkeys;
  640. unsigned maxbytes = (uid == 0) ?
  641. key_quota_root_maxbytes : key_quota_maxbytes;
  642. spin_lock(&newowner->lock);
  643. if (newowner->qnkeys + 1 >= maxkeys ||
  644. newowner->qnbytes + key->quotalen >= maxbytes ||
  645. newowner->qnbytes + key->quotalen <
  646. newowner->qnbytes)
  647. goto quota_overrun;
  648. newowner->qnkeys++;
  649. newowner->qnbytes += key->quotalen;
  650. spin_unlock(&newowner->lock);
  651. spin_lock(&key->user->lock);
  652. key->user->qnkeys--;
  653. key->user->qnbytes -= key->quotalen;
  654. spin_unlock(&key->user->lock);
  655. }
  656. atomic_dec(&key->user->nkeys);
  657. atomic_inc(&newowner->nkeys);
  658. if (test_bit(KEY_FLAG_INSTANTIATED, &key->flags)) {
  659. atomic_dec(&key->user->nikeys);
  660. atomic_inc(&newowner->nikeys);
  661. }
  662. zapowner = key->user;
  663. key->user = newowner;
  664. key->uid = uid;
  665. }
  666. /* change the GID */
  667. if (gid != (gid_t) -1)
  668. key->gid = gid;
  669. ret = 0;
  670. error_put:
  671. up_write(&key->sem);
  672. key_put(key);
  673. if (zapowner)
  674. key_user_put(zapowner);
  675. error:
  676. return ret;
  677. quota_overrun:
  678. spin_unlock(&newowner->lock);
  679. zapowner = newowner;
  680. ret = -EDQUOT;
  681. goto error_put;
  682. } /* end keyctl_chown_key() */
  683. /*****************************************************************************/
  684. /*
  685. * change the permission mask on a key
  686. * - the keyring owned by the changer
  687. * - implements keyctl(KEYCTL_SETPERM)
  688. */
  689. long keyctl_setperm_key(key_serial_t id, key_perm_t perm)
  690. {
  691. struct key *key;
  692. key_ref_t key_ref;
  693. long ret;
  694. ret = -EINVAL;
  695. if (perm & ~(KEY_POS_ALL | KEY_USR_ALL | KEY_GRP_ALL | KEY_OTH_ALL))
  696. goto error;
  697. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
  698. KEY_SETATTR);
  699. if (IS_ERR(key_ref)) {
  700. ret = PTR_ERR(key_ref);
  701. goto error;
  702. }
  703. key = key_ref_to_ptr(key_ref);
  704. /* make the changes with the locks held to prevent chown/chmod races */
  705. ret = -EACCES;
  706. down_write(&key->sem);
  707. /* if we're not the sysadmin, we can only change a key that we own */
  708. if (capable(CAP_SYS_ADMIN) || key->uid == current_fsuid()) {
  709. key->perm = perm;
  710. ret = 0;
  711. }
  712. up_write(&key->sem);
  713. key_put(key);
  714. error:
  715. return ret;
  716. } /* end keyctl_setperm_key() */
  717. /*
  718. * get the destination keyring for instantiation
  719. */
  720. static long get_instantiation_keyring(key_serial_t ringid,
  721. struct request_key_auth *rka,
  722. struct key **_dest_keyring)
  723. {
  724. key_ref_t dkref;
  725. *_dest_keyring = NULL;
  726. /* just return a NULL pointer if we weren't asked to make a link */
  727. if (ringid == 0)
  728. return 0;
  729. /* if a specific keyring is nominated by ID, then use that */
  730. if (ringid > 0) {
  731. dkref = lookup_user_key(ringid, KEY_LOOKUP_CREATE, KEY_WRITE);
  732. if (IS_ERR(dkref))
  733. return PTR_ERR(dkref);
  734. *_dest_keyring = key_ref_to_ptr(dkref);
  735. return 0;
  736. }
  737. if (ringid == KEY_SPEC_REQKEY_AUTH_KEY)
  738. return -EINVAL;
  739. /* otherwise specify the destination keyring recorded in the
  740. * authorisation key (any KEY_SPEC_*_KEYRING) */
  741. if (ringid >= KEY_SPEC_REQUESTOR_KEYRING) {
  742. *_dest_keyring = key_get(rka->dest_keyring);
  743. return 0;
  744. }
  745. return -ENOKEY;
  746. }
  747. /*
  748. * change the request_key authorisation key on the current process
  749. */
  750. static int keyctl_change_reqkey_auth(struct key *key)
  751. {
  752. struct cred *new;
  753. new = prepare_creds();
  754. if (!new)
  755. return -ENOMEM;
  756. key_put(new->request_key_auth);
  757. new->request_key_auth = key_get(key);
  758. return commit_creds(new);
  759. }
  760. /*****************************************************************************/
  761. /*
  762. * instantiate the key with the specified payload, and, if one is given, link
  763. * the key into the keyring
  764. */
  765. long keyctl_instantiate_key(key_serial_t id,
  766. const void __user *_payload,
  767. size_t plen,
  768. key_serial_t ringid)
  769. {
  770. const struct cred *cred = current_cred();
  771. struct request_key_auth *rka;
  772. struct key *instkey, *dest_keyring;
  773. void *payload;
  774. long ret;
  775. bool vm = false;
  776. kenter("%d,,%zu,%d", id, plen, ringid);
  777. ret = -EINVAL;
  778. if (plen > 1024 * 1024 - 1)
  779. goto error;
  780. /* the appropriate instantiation authorisation key must have been
  781. * assumed before calling this */
  782. ret = -EPERM;
  783. instkey = cred->request_key_auth;
  784. if (!instkey)
  785. goto error;
  786. rka = instkey->payload.data;
  787. if (rka->target_key->serial != id)
  788. goto error;
  789. /* pull the payload in if one was supplied */
  790. payload = NULL;
  791. if (_payload) {
  792. ret = -ENOMEM;
  793. payload = kmalloc(plen, GFP_KERNEL);
  794. if (!payload) {
  795. if (plen <= PAGE_SIZE)
  796. goto error;
  797. vm = true;
  798. payload = vmalloc(plen);
  799. if (!payload)
  800. goto error;
  801. }
  802. ret = -EFAULT;
  803. if (copy_from_user(payload, _payload, plen) != 0)
  804. goto error2;
  805. }
  806. /* find the destination keyring amongst those belonging to the
  807. * requesting task */
  808. ret = get_instantiation_keyring(ringid, rka, &dest_keyring);
  809. if (ret < 0)
  810. goto error2;
  811. /* instantiate the key and link it into a keyring */
  812. ret = key_instantiate_and_link(rka->target_key, payload, plen,
  813. dest_keyring, instkey);
  814. key_put(dest_keyring);
  815. /* discard the assumed authority if it's just been disabled by
  816. * instantiation of the key */
  817. if (ret == 0)
  818. keyctl_change_reqkey_auth(NULL);
  819. error2:
  820. if (!vm)
  821. kfree(payload);
  822. else
  823. vfree(payload);
  824. error:
  825. return ret;
  826. } /* end keyctl_instantiate_key() */
  827. /*****************************************************************************/
  828. /*
  829. * negatively instantiate the key with the given timeout (in seconds), and, if
  830. * one is given, link the key into the keyring
  831. */
  832. long keyctl_negate_key(key_serial_t id, unsigned timeout, key_serial_t ringid)
  833. {
  834. const struct cred *cred = current_cred();
  835. struct request_key_auth *rka;
  836. struct key *instkey, *dest_keyring;
  837. long ret;
  838. kenter("%d,%u,%d", id, timeout, ringid);
  839. /* the appropriate instantiation authorisation key must have been
  840. * assumed before calling this */
  841. ret = -EPERM;
  842. instkey = cred->request_key_auth;
  843. if (!instkey)
  844. goto error;
  845. rka = instkey->payload.data;
  846. if (rka->target_key->serial != id)
  847. goto error;
  848. /* find the destination keyring if present (which must also be
  849. * writable) */
  850. ret = get_instantiation_keyring(ringid, rka, &dest_keyring);
  851. if (ret < 0)
  852. goto error;
  853. /* instantiate the key and link it into a keyring */
  854. ret = key_negate_and_link(rka->target_key, timeout,
  855. dest_keyring, instkey);
  856. key_put(dest_keyring);
  857. /* discard the assumed authority if it's just been disabled by
  858. * instantiation of the key */
  859. if (ret == 0)
  860. keyctl_change_reqkey_auth(NULL);
  861. error:
  862. return ret;
  863. } /* end keyctl_negate_key() */
  864. /*****************************************************************************/
  865. /*
  866. * set the default keyring in which request_key() will cache keys
  867. * - return the old setting
  868. */
  869. long keyctl_set_reqkey_keyring(int reqkey_defl)
  870. {
  871. struct cred *new;
  872. int ret, old_setting;
  873. old_setting = current_cred_xxx(jit_keyring);
  874. if (reqkey_defl == KEY_REQKEY_DEFL_NO_CHANGE)
  875. return old_setting;
  876. new = prepare_creds();
  877. if (!new)
  878. return -ENOMEM;
  879. switch (reqkey_defl) {
  880. case KEY_REQKEY_DEFL_THREAD_KEYRING:
  881. ret = install_thread_keyring_to_cred(new);
  882. if (ret < 0)
  883. goto error;
  884. goto set;
  885. case KEY_REQKEY_DEFL_PROCESS_KEYRING:
  886. ret = install_process_keyring_to_cred(new);
  887. if (ret < 0) {
  888. if (ret != -EEXIST)
  889. goto error;
  890. ret = 0;
  891. }
  892. goto set;
  893. case KEY_REQKEY_DEFL_DEFAULT:
  894. case KEY_REQKEY_DEFL_SESSION_KEYRING:
  895. case KEY_REQKEY_DEFL_USER_KEYRING:
  896. case KEY_REQKEY_DEFL_USER_SESSION_KEYRING:
  897. case KEY_REQKEY_DEFL_REQUESTOR_KEYRING:
  898. goto set;
  899. case KEY_REQKEY_DEFL_NO_CHANGE:
  900. case KEY_REQKEY_DEFL_GROUP_KEYRING:
  901. default:
  902. ret = -EINVAL;
  903. goto error;
  904. }
  905. set:
  906. new->jit_keyring = reqkey_defl;
  907. commit_creds(new);
  908. return old_setting;
  909. error:
  910. abort_creds(new);
  911. return -EINVAL;
  912. } /* end keyctl_set_reqkey_keyring() */
  913. /*****************************************************************************/
  914. /*
  915. * set or clear the timeout for a key
  916. */
  917. long keyctl_set_timeout(key_serial_t id, unsigned timeout)
  918. {
  919. struct timespec now;
  920. struct key *key;
  921. key_ref_t key_ref;
  922. time_t expiry;
  923. long ret;
  924. key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
  925. KEY_SETATTR);
  926. if (IS_ERR(key_ref)) {
  927. ret = PTR_ERR(key_ref);
  928. goto error;
  929. }
  930. key = key_ref_to_ptr(key_ref);
  931. /* make the changes with the locks held to prevent races */
  932. down_write(&key->sem);
  933. expiry = 0;
  934. if (timeout > 0) {
  935. now = current_kernel_time();
  936. expiry = now.tv_sec + timeout;
  937. }
  938. key->expiry = expiry;
  939. key_schedule_gc(key->expiry + key_gc_delay);
  940. up_write(&key->sem);
  941. key_put(key);
  942. ret = 0;
  943. error:
  944. return ret;
  945. } /* end keyctl_set_timeout() */
  946. /*****************************************************************************/
  947. /*
  948. * assume the authority to instantiate the specified key
  949. */
  950. long keyctl_assume_authority(key_serial_t id)
  951. {
  952. struct key *authkey;
  953. long ret;
  954. /* special key IDs aren't permitted */
  955. ret = -EINVAL;
  956. if (id < 0)
  957. goto error;
  958. /* we divest ourselves of authority if given an ID of 0 */
  959. if (id == 0) {
  960. ret = keyctl_change_reqkey_auth(NULL);
  961. goto error;
  962. }
  963. /* attempt to assume the authority temporarily granted to us whilst we
  964. * instantiate the specified key
  965. * - the authorisation key must be in the current task's keyrings
  966. * somewhere
  967. */
  968. authkey = key_get_instantiation_authkey(id);
  969. if (IS_ERR(authkey)) {
  970. ret = PTR_ERR(authkey);
  971. goto error;
  972. }
  973. ret = keyctl_change_reqkey_auth(authkey);
  974. if (ret < 0)
  975. goto error;
  976. key_put(authkey);
  977. ret = authkey->serial;
  978. error:
  979. return ret;
  980. } /* end keyctl_assume_authority() */
  981. /*
  982. * get the security label of a key
  983. * - the key must grant us view permission
  984. * - if there's a buffer, we place up to buflen bytes of data into it
  985. * - unless there's an error, we return the amount of information available,
  986. * irrespective of how much we may have copied (including the terminal NUL)
  987. * - implements keyctl(KEYCTL_GET_SECURITY)
  988. */
  989. long keyctl_get_security(key_serial_t keyid,
  990. char __user *buffer,
  991. size_t buflen)
  992. {
  993. struct key *key, *instkey;
  994. key_ref_t key_ref;
  995. char *context;
  996. long ret;
  997. key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, KEY_VIEW);
  998. if (IS_ERR(key_ref)) {
  999. if (PTR_ERR(key_ref) != -EACCES)
  1000. return PTR_ERR(key_ref);
  1001. /* viewing a key under construction is also permitted if we
  1002. * have the authorisation token handy */
  1003. instkey = key_get_instantiation_authkey(keyid);
  1004. if (IS_ERR(instkey))
  1005. return PTR_ERR(instkey);
  1006. key_put(instkey);
  1007. key_ref = lookup_user_key(keyid, KEY_LOOKUP_PARTIAL, 0);
  1008. if (IS_ERR(key_ref))
  1009. return PTR_ERR(key_ref);
  1010. }
  1011. key = key_ref_to_ptr(key_ref);
  1012. ret = security_key_getsecurity(key, &context);
  1013. if (ret == 0) {
  1014. /* if no information was returned, give userspace an empty
  1015. * string */
  1016. ret = 1;
  1017. if (buffer && buflen > 0 &&
  1018. copy_to_user(buffer, "", 1) != 0)
  1019. ret = -EFAULT;
  1020. } else if (ret > 0) {
  1021. /* return as much data as there's room for */
  1022. if (buffer && buflen > 0) {
  1023. if (buflen > ret)
  1024. buflen = ret;
  1025. if (copy_to_user(buffer, context, buflen) != 0)
  1026. ret = -EFAULT;
  1027. }
  1028. kfree(context);
  1029. }
  1030. key_ref_put(key_ref);
  1031. return ret;
  1032. }
  1033. /*
  1034. * attempt to install the calling process's session keyring on the process's
  1035. * parent process
  1036. * - the keyring must exist and must grant us LINK permission
  1037. * - implements keyctl(KEYCTL_SESSION_TO_PARENT)
  1038. */
  1039. long keyctl_session_to_parent(void)
  1040. {
  1041. #ifdef TIF_NOTIFY_RESUME
  1042. struct task_struct *me, *parent;
  1043. const struct cred *mycred, *pcred;
  1044. struct cred *cred, *oldcred;
  1045. key_ref_t keyring_r;
  1046. int ret;
  1047. keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK);
  1048. if (IS_ERR(keyring_r))
  1049. return PTR_ERR(keyring_r);
  1050. /* our parent is going to need a new cred struct, a new tgcred struct
  1051. * and new security data, so we allocate them here to prevent ENOMEM in
  1052. * our parent */
  1053. ret = -ENOMEM;
  1054. cred = cred_alloc_blank();
  1055. if (!cred)
  1056. goto error_keyring;
  1057. cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
  1058. keyring_r = NULL;
  1059. me = current;
  1060. write_lock_irq(&tasklist_lock);
  1061. parent = me->real_parent;
  1062. ret = -EPERM;
  1063. /* the parent mustn't be init and mustn't be a kernel thread */
  1064. if (parent->pid <= 1 || !parent->mm)
  1065. goto not_permitted;
  1066. /* the parent must be single threaded */
  1067. if (atomic_read(&parent->signal->count) != 1)
  1068. goto not_permitted;
  1069. /* the parent and the child must have different session keyrings or
  1070. * there's no point */
  1071. mycred = current_cred();
  1072. pcred = __task_cred(parent);
  1073. if (mycred == pcred ||
  1074. mycred->tgcred->session_keyring == pcred->tgcred->session_keyring)
  1075. goto already_same;
  1076. /* the parent must have the same effective ownership and mustn't be
  1077. * SUID/SGID */
  1078. if (pcred-> uid != mycred->euid ||
  1079. pcred->euid != mycred->euid ||
  1080. pcred->suid != mycred->euid ||
  1081. pcred-> gid != mycred->egid ||
  1082. pcred->egid != mycred->egid ||
  1083. pcred->sgid != mycred->egid)
  1084. goto not_permitted;
  1085. /* the keyrings must have the same UID */
  1086. if (pcred ->tgcred->session_keyring->uid != mycred->euid ||
  1087. mycred->tgcred->session_keyring->uid != mycred->euid)
  1088. goto not_permitted;
  1089. /* the LSM must permit the replacement of the parent's keyring with the
  1090. * keyring from this process */
  1091. ret = security_key_session_to_parent(mycred, pcred,
  1092. key_ref_to_ptr(keyring_r));
  1093. if (ret < 0)
  1094. goto not_permitted;
  1095. /* if there's an already pending keyring replacement, then we replace
  1096. * that */
  1097. oldcred = parent->replacement_session_keyring;
  1098. /* the replacement session keyring is applied just prior to userspace
  1099. * restarting */
  1100. parent->replacement_session_keyring = cred;
  1101. cred = NULL;
  1102. set_ti_thread_flag(task_thread_info(parent), TIF_NOTIFY_RESUME);
  1103. write_unlock_irq(&tasklist_lock);
  1104. if (oldcred)
  1105. put_cred(oldcred);
  1106. return 0;
  1107. already_same:
  1108. ret = 0;
  1109. not_permitted:
  1110. write_unlock_irq(&tasklist_lock);
  1111. put_cred(cred);
  1112. return ret;
  1113. error_keyring:
  1114. key_ref_put(keyring_r);
  1115. return ret;
  1116. #else /* !TIF_NOTIFY_RESUME */
  1117. /*
  1118. * To be removed when TIF_NOTIFY_RESUME has been implemented on
  1119. * m68k/xtensa
  1120. */
  1121. #warning TIF_NOTIFY_RESUME not implemented
  1122. return -EOPNOTSUPP;
  1123. #endif /* !TIF_NOTIFY_RESUME */
  1124. }
  1125. /*****************************************************************************/
  1126. /*
  1127. * the key control system call
  1128. */
  1129. SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
  1130. unsigned long, arg4, unsigned long, arg5)
  1131. {
  1132. switch (option) {
  1133. case KEYCTL_GET_KEYRING_ID:
  1134. return keyctl_get_keyring_ID((key_serial_t) arg2,
  1135. (int) arg3);
  1136. case KEYCTL_JOIN_SESSION_KEYRING:
  1137. return keyctl_join_session_keyring((const char __user *) arg2);
  1138. case KEYCTL_UPDATE:
  1139. return keyctl_update_key((key_serial_t) arg2,
  1140. (const void __user *) arg3,
  1141. (size_t) arg4);
  1142. case KEYCTL_REVOKE:
  1143. return keyctl_revoke_key((key_serial_t) arg2);
  1144. case KEYCTL_DESCRIBE:
  1145. return keyctl_describe_key((key_serial_t) arg2,
  1146. (char __user *) arg3,
  1147. (unsigned) arg4);
  1148. case KEYCTL_CLEAR:
  1149. return keyctl_keyring_clear((key_serial_t) arg2);
  1150. case KEYCTL_LINK:
  1151. return keyctl_keyring_link((key_serial_t) arg2,
  1152. (key_serial_t) arg3);
  1153. case KEYCTL_UNLINK:
  1154. return keyctl_keyring_unlink((key_serial_t) arg2,
  1155. (key_serial_t) arg3);
  1156. case KEYCTL_SEARCH:
  1157. return keyctl_keyring_search((key_serial_t) arg2,
  1158. (const char __user *) arg3,
  1159. (const char __user *) arg4,
  1160. (key_serial_t) arg5);
  1161. case KEYCTL_READ:
  1162. return keyctl_read_key((key_serial_t) arg2,
  1163. (char __user *) arg3,
  1164. (size_t) arg4);
  1165. case KEYCTL_CHOWN:
  1166. return keyctl_chown_key((key_serial_t) arg2,
  1167. (uid_t) arg3,
  1168. (gid_t) arg4);
  1169. case KEYCTL_SETPERM:
  1170. return keyctl_setperm_key((key_serial_t) arg2,
  1171. (key_perm_t) arg3);
  1172. case KEYCTL_INSTANTIATE:
  1173. return keyctl_instantiate_key((key_serial_t) arg2,
  1174. (const void __user *) arg3,
  1175. (size_t) arg4,
  1176. (key_serial_t) arg5);
  1177. case KEYCTL_NEGATE:
  1178. return keyctl_negate_key((key_serial_t) arg2,
  1179. (unsigned) arg3,
  1180. (key_serial_t) arg4);
  1181. case KEYCTL_SET_REQKEY_KEYRING:
  1182. return keyctl_set_reqkey_keyring(arg2);
  1183. case KEYCTL_SET_TIMEOUT:
  1184. return keyctl_set_timeout((key_serial_t) arg2,
  1185. (unsigned) arg3);
  1186. case KEYCTL_ASSUME_AUTHORITY:
  1187. return keyctl_assume_authority((key_serial_t) arg2);
  1188. case KEYCTL_GET_SECURITY:
  1189. return keyctl_get_security((key_serial_t) arg2,
  1190. (char __user *) arg3,
  1191. (size_t) arg4);
  1192. case KEYCTL_SESSION_TO_PARENT:
  1193. return keyctl_session_to_parent();
  1194. default:
  1195. return -EOPNOTSUPP;
  1196. }
  1197. } /* end sys_keyctl() */