keyctl.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  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(key_ref);
  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. struct task_struct *me, *parent;
  1042. const struct cred *mycred, *pcred;
  1043. struct cred *cred, *oldcred;
  1044. key_ref_t keyring_r;
  1045. int ret;
  1046. keyring_r = lookup_user_key(KEY_SPEC_SESSION_KEYRING, 0, KEY_LINK);
  1047. if (IS_ERR(keyring_r))
  1048. return PTR_ERR(keyring_r);
  1049. /* our parent is going to need a new cred struct, a new tgcred struct
  1050. * and new security data, so we allocate them here to prevent ENOMEM in
  1051. * our parent */
  1052. ret = -ENOMEM;
  1053. cred = cred_alloc_blank();
  1054. if (!cred)
  1055. goto error_keyring;
  1056. cred->tgcred->session_keyring = key_ref_to_ptr(keyring_r);
  1057. keyring_r = NULL;
  1058. me = current;
  1059. write_lock_irq(&tasklist_lock);
  1060. parent = me->real_parent;
  1061. ret = -EPERM;
  1062. /* the parent mustn't be init and mustn't be a kernel thread */
  1063. if (parent->pid <= 1 || !parent->mm)
  1064. goto not_permitted;
  1065. /* the parent must be single threaded */
  1066. if (atomic_read(&parent->signal->count) != 1)
  1067. goto not_permitted;
  1068. /* the parent and the child must have different session keyrings or
  1069. * there's no point */
  1070. mycred = current_cred();
  1071. pcred = __task_cred(parent);
  1072. if (mycred == pcred ||
  1073. mycred->tgcred->session_keyring == pcred->tgcred->session_keyring)
  1074. goto already_same;
  1075. /* the parent must have the same effective ownership and mustn't be
  1076. * SUID/SGID */
  1077. if (pcred-> uid != mycred->euid ||
  1078. pcred->euid != mycred->euid ||
  1079. pcred->suid != mycred->euid ||
  1080. pcred-> gid != mycred->egid ||
  1081. pcred->egid != mycred->egid ||
  1082. pcred->sgid != mycred->egid)
  1083. goto not_permitted;
  1084. /* the keyrings must have the same UID */
  1085. if (pcred ->tgcred->session_keyring->uid != mycred->euid ||
  1086. mycred->tgcred->session_keyring->uid != mycred->euid)
  1087. goto not_permitted;
  1088. /* the LSM must permit the replacement of the parent's keyring with the
  1089. * keyring from this process */
  1090. ret = security_key_session_to_parent(mycred, pcred,
  1091. key_ref_to_ptr(keyring_r));
  1092. if (ret < 0)
  1093. goto not_permitted;
  1094. /* if there's an already pending keyring replacement, then we replace
  1095. * that */
  1096. oldcred = parent->replacement_session_keyring;
  1097. /* the replacement session keyring is applied just prior to userspace
  1098. * restarting */
  1099. parent->replacement_session_keyring = cred;
  1100. cred = NULL;
  1101. set_ti_thread_flag(task_thread_info(parent), TIF_NOTIFY_RESUME);
  1102. write_unlock_irq(&tasklist_lock);
  1103. if (oldcred)
  1104. put_cred(oldcred);
  1105. return 0;
  1106. already_same:
  1107. ret = 0;
  1108. not_permitted:
  1109. write_unlock_irq(&tasklist_lock);
  1110. put_cred(cred);
  1111. return ret;
  1112. error_keyring:
  1113. key_ref_put(keyring_r);
  1114. return ret;
  1115. }
  1116. /*****************************************************************************/
  1117. /*
  1118. * the key control system call
  1119. */
  1120. SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
  1121. unsigned long, arg4, unsigned long, arg5)
  1122. {
  1123. switch (option) {
  1124. case KEYCTL_GET_KEYRING_ID:
  1125. return keyctl_get_keyring_ID((key_serial_t) arg2,
  1126. (int) arg3);
  1127. case KEYCTL_JOIN_SESSION_KEYRING:
  1128. return keyctl_join_session_keyring((const char __user *) arg2);
  1129. case KEYCTL_UPDATE:
  1130. return keyctl_update_key((key_serial_t) arg2,
  1131. (const void __user *) arg3,
  1132. (size_t) arg4);
  1133. case KEYCTL_REVOKE:
  1134. return keyctl_revoke_key((key_serial_t) arg2);
  1135. case KEYCTL_DESCRIBE:
  1136. return keyctl_describe_key((key_serial_t) arg2,
  1137. (char __user *) arg3,
  1138. (unsigned) arg4);
  1139. case KEYCTL_CLEAR:
  1140. return keyctl_keyring_clear((key_serial_t) arg2);
  1141. case KEYCTL_LINK:
  1142. return keyctl_keyring_link((key_serial_t) arg2,
  1143. (key_serial_t) arg3);
  1144. case KEYCTL_UNLINK:
  1145. return keyctl_keyring_unlink((key_serial_t) arg2,
  1146. (key_serial_t) arg3);
  1147. case KEYCTL_SEARCH:
  1148. return keyctl_keyring_search((key_serial_t) arg2,
  1149. (const char __user *) arg3,
  1150. (const char __user *) arg4,
  1151. (key_serial_t) arg5);
  1152. case KEYCTL_READ:
  1153. return keyctl_read_key((key_serial_t) arg2,
  1154. (char __user *) arg3,
  1155. (size_t) arg4);
  1156. case KEYCTL_CHOWN:
  1157. return keyctl_chown_key((key_serial_t) arg2,
  1158. (uid_t) arg3,
  1159. (gid_t) arg4);
  1160. case KEYCTL_SETPERM:
  1161. return keyctl_setperm_key((key_serial_t) arg2,
  1162. (key_perm_t) arg3);
  1163. case KEYCTL_INSTANTIATE:
  1164. return keyctl_instantiate_key((key_serial_t) arg2,
  1165. (const void __user *) arg3,
  1166. (size_t) arg4,
  1167. (key_serial_t) arg5);
  1168. case KEYCTL_NEGATE:
  1169. return keyctl_negate_key((key_serial_t) arg2,
  1170. (unsigned) arg3,
  1171. (key_serial_t) arg4);
  1172. case KEYCTL_SET_REQKEY_KEYRING:
  1173. return keyctl_set_reqkey_keyring(arg2);
  1174. case KEYCTL_SET_TIMEOUT:
  1175. return keyctl_set_timeout((key_serial_t) arg2,
  1176. (unsigned) arg3);
  1177. case KEYCTL_ASSUME_AUTHORITY:
  1178. return keyctl_assume_authority((key_serial_t) arg2);
  1179. case KEYCTL_GET_SECURITY:
  1180. return keyctl_get_security((key_serial_t) arg2,
  1181. (char __user *) arg3,
  1182. (size_t) arg4);
  1183. case KEYCTL_SESSION_TO_PARENT:
  1184. return keyctl_session_to_parent();
  1185. default:
  1186. return -EOPNOTSUPP;
  1187. }
  1188. } /* end sys_keyctl() */