]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man2/keyctl.2
keyctl.2: Improve KEYCTL_ASSUME_AUTHORITY details
[thirdparty/man-pages.git] / man2 / keyctl.2
CommitLineData
4509c62e
MK
1.\" Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
2.\" Written by David Howells (dhowells@redhat.com)
3.\"
23dbdcbe 4.\" %%%LICENSE_START(GPLv2+_SW_ONEPARA)
4509c62e
MK
5.\" This program is free software; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License
7.\" as published by the Free Software Foundation; either version
8.\" 2 of the License, or (at your option) any later version.
722b6788 9.\" %%%LICENSE_END
4509c62e 10.\"
67d2c687 11.TH KEYCTL 2 2015-05-07 Linux "Linux Key Management Calls"
4509c62e 12.SH NAME
f68512e9 13keyctl \- manipulate the kernel's key management facility
4509c62e
MK
14.SH SYNOPSIS
15.nf
16.B #include <keyutils.h>
17.sp
fa76da80
ES
18.BI "long keyctl(int " cmd ", ...)"
19.sp
60fc9e95 20.B "/* For direct call via syscall(2): */"
fa76da80
ES
21.B #include <asm/unistd.h>
22.B #include <linux/keyctl.h>
23.B #include <unistd.h>
24.sp
9a9febc8
MK
25.BI "long syscall(__NR_keyctl, int " option ", __kernel_ulong_t " arg2 ,
26.BI " __kernel_ulong_t " arg3 ", __kernel_ulong_t " arg4 ,
27.BI " __kernel_ulong_t " arg5 );
6030f2d8 28.fi
4509c62e
MK
29.SH DESCRIPTION
30.BR keyctl ()
60fc9e95
MK
31allows user-space programs to perform key manipulation.
32
33The operation performed by
fa76da80 34.BR keyctl ()
60fc9e95
MK
35is determined by the value of the
36.I option
37argument.
38Each of these operations is wrapped by
39.B libkeyutils
40into individual functions (listed under SEE ALSO)
41to permit the compiler to check types.
42
43The permitted values for
fa76da80 44.I option
60fc9e95 45are:
4509c62e 46.TP
9d7346eb 47.BR KEYCTL_GET_KEYRING_ID " (since Linux 2.6.11)"
d6c7244f
MK
48Map a special key ID to a real key ID for this process.
49
50This operation looks up the special key whose ID is provided in
fa76da80 51.I arg2
fd2d68f9 52(cast to
d6c7244f
MK
53.IR key_serial_t )
54and (if it is found) the ID of corresponding real key is returned
55
56If the key specified in
57.I arg2
58does not exist, then a new key is created if the
fa76da80 59.I arg3
fd2d68f9 60argument (cast to
d6c7244f
MK
61.IR int )
62contains a non-zero value; otherwise the operation fails with the error
63.BR ENOKEY .
60fc9e95
MK
64
65The caller must have
fa76da80 66.I search
60fc9e95
MK
67permission on a keyring in order for it to be found.
68
69The arguments
70.IR arg4
71and
72.IR arg5
fa76da80 73are ignored.
d6c7244f
MK
74
75This operation is exposed by
76.I libkeyutils
77via the function
78.BR keyctl_get_keyring_ID (3).
4509c62e 79.TP
9d7346eb 80.BR KEYCTL_JOIN_SESSION_KEYRING " (since Linux 2.6.11)"
f9fa5a66
MK
81Replace the session keyring this process subscribes to with
82a new session keyring.
83
84If
fa76da80 85.I arg2
f9fa5a66
MK
86is NULL,
87an anonymous keyring with the description "_ses" is created
88and the process is subscribed to that keyring as its session keyring,
89displacing the previous session keyring.
60fc9e95 90
f9fa5a66
MK
91Otherwise,
92.I arg2
fd2d68f9 93(cast to
f9fa5a66
MK
94.IR "char\ *" )
95is treated as the description (name) of a keyring,
96and the behavior is as follows:
97.RS
98.IP * 3
99If a keyring with a matching description exists,
100the process will attempt to subscribe to that keyring if possible;
101if that is not possible, an error is returned.
102.\" FIXME What error is returned?
103In order to subscribe to the keyring,
104the caller must have
fa76da80 105.I search
f9fa5a66
MK
106permission on the keyring.
107.IP *
108If a keyring with a matching description does not exist,
109then a new keyring with that description is created,
110and the process is subscribed to that keyring as its session keyring,
111displacing the previous session keyring.
112.RE
113.IP
60fc9e95
MK
114The arguments
115.IR arg3 ,
116.IR arg4 ,
117and
118.IR arg5
fa76da80 119are ignored.
f9fa5a66
MK
120
121This operation is exposed by
122.I libkeyutils
123via the function
124.BR keyctl_join_session_keyring (3).
4509c62e 125.TP
9d7346eb 126.BR KEYCTL_UPDATE " (since Linux 2.6.11)"
60fc9e95 127Update a key's data payload.
581f8203 128
461a8ce5 129The
fa76da80 130.I arg2
fd2d68f9 131argument (cast to
fa76da80 132.IR key_serial_t )
581f8203 133specifies the ID of the key to be updated.
60fc9e95 134The
fa76da80 135.I arg3
fd2d68f9 136argument (cast to
581f8203
MK
137.IR "void\ *" )
138points to the new payload and
fa76da80 139.I arg4
fd2d68f9 140(cast to
fa76da80 141.IR size_t )
581f8203 142contains the new payload size in bytes.
60fc9e95
MK
143
144The caller must have
fa76da80 145.I write
60fc9e95 146permission on the key specified and the key type must support updating.
581f8203
MK
147
148.\" FIXME What does the following mean?
60fc9e95
MK
149A negative key can be positively instantiated with this call.
150
461a8ce5 151The
fa76da80
ES
152.I arg5
153argument is ignored.
581f8203
MK
154
155This operation is exposed by
156.I libkeyutils
157via the function
158.BR keyctl_update (3).
4509c62e 159.TP
9d7346eb 160.BR KEYCTL_REVOKE " (since Linux 2.6.11)"
60fc9e95 161Revoke the key with the ID provided in
fa76da80 162.I arg2
fd2d68f9 163(cast to
fa76da80 164.IR key_serial_t ).
60fc9e95
MK
165
166The caller must have
cbf0e35e
MK
167.IR write
168or
169.IR setattr
170permission on the key.
171.\" FIXME Keys with the KEY_FLAG_KEEP bit set cause an EPERM
172.\" error for KEYCTL_REVOKE. Does this need to be documented?
173.\" (It's not clear how KEY_FLAG_KEEP gets set.)
60fc9e95
MK
174
175The arguments
176.IR arg3 ,
177.IR arg4 ,
178and
179.IR arg5
fa76da80 180are ignored.
cbf0e35e
MK
181
182This operation is exposed by
183.I libkeyutils
184via the function
185.BR keyctl_revoke (3).
4509c62e 186.TP
9d7346eb 187.BR KEYCTL_CHOWN " (since Linux 2.6.11)"
14694cb5
MK
188Change the ownership (user and group ID) of a key.
189
461a8ce5 190The
fa76da80 191.I arg2
fd2d68f9 192argument (cast to
fa76da80 193.IR key_serial_t )
60fc9e95
MK
194contains the key ID.
195The
fa76da80 196.I arg3
fd2d68f9 197argument (cast to
fa76da80 198.IR uid_t )
60fc9e95
MK
199contains the new user ID (or \-1 in case the user ID shouldn't be changed).
200The
fa76da80 201.I arg4
fd2d68f9 202argument (cast to
fa76da80 203.IR gid_t )
60fc9e95 204contains the new group ID (or \-1 in case the group ID shouldn't be changed).
14694cb5 205
fa76da80
ES
206The key must grant the caller
207.I setattr
461a8ce5 208permission.
14694cb5 209
461a8ce5 210For the UID to be changed, or for the GID to be changed to a group
60fc9e95
MK
211the caller is not a member of, the caller must have the
212.B CAP_SYS_ADMIN
fa76da80 213capability (see
60fc9e95 214.BR capabilities (7)).
14694cb5 215
461a8ce5
MK
216If the UID is to be changed, the new user must have sufficient
217quota to accept the key.
218The quota deduction will be removed from the old user
14694cb5 219to the new user should the UID be changed.
60fc9e95 220
461a8ce5 221The
fa76da80
ES
222.I arg5
223argument is ignored.
efd4c0cd
MK
224
225This operation is exposed by
226.I libkeyutils
227via the function
228.BR keyctl_chown (3).
4509c62e 229.TP
9d7346eb 230.BR KEYCTL_SETPERM " (since Linux 2.6.11)"
60fc9e95 231Change the permissions of the key with the ID provided in the
fa76da80 232.I arg2
fd2d68f9 233argument (cast to
fa76da80 234.IR key_serial_t )
60fc9e95 235to the permissions provided in the
fa76da80 236.I arg3
fd2d68f9 237argument (cast to
3d20acc9
MK
238.IR key_perm_t ).
239
fa76da80
ES
240The key must grant
241.I setattr
461a8ce5 242permission to the caller.
3d20acc9
MK
243
244If the caller doesn't have the
60fc9e95
MK
245.B CAP_SYS_ADMIN
246capability, it can change permissions only for the keys it owns.
3d20acc9
MK
247(More precisely: the caller's filesystem UID must match the UID of the key.)
248
249The permissions in
250.IR arg3
251specify masks of available operations
252for each of the following user categories:
253.RS
254.TP
255.IR possessor " (since Linux 2.6.14)"
256.\" commit 664cceb0093b755739e56572b836a99104ee8a75
257This is the permission granted to a process that possesses the key
258(has it attached searchably to one of the process's keyrings);
259see
260.BR keyrings (7).
261.TP
262.IR user
263This is the permission granted to a process
264whose filesystem UID matches the UID of the key.
265.TP
266.IR group
267This is the permission granted to a process
268whose filesystem GID or any of its supplementary GIDs
269matches the GID of the key.
270.TP
271.IR other
272This is the permission granted to other processes
273that do not match the
274.IR user
275and
276.IR group
277categories.
278.RE
279.IP
280The
281.IR user ,
282.IR group ,
283and
284.IR other
285categories are exclusive: if a process matches the
286.IR user
287category, it will not receive permissions granted in the
288.IR group
289category; if a process matches the
290.I user
291or
292.IR group
293category, then it will not receive permissions granted in the
294.IR other
295category.
296
297The
298.I possessor
299category grants permissions that are cumulative with the grants from the
300.IR user ,
301.IR group ,
302or
303.IR other
304category.
305
306Each permission mask is eight bits in size,
307with only six bits currently used.
461a8ce5 308The available permissions are:
fa76da80 309.RS
3d20acc9
MK
310.TP
311.IR view
312This permission allows reading attributes of a key.
313
314This permission is required for the
315.BR KEYCTL_DESCRIBE
316operation.
317
318The permission bits for each category are
319.BR KEY_POS_VIEW ,
320.BR KEY_USR_VIEW ,
321.BR KEY_GRP_VIEW ,
322and
323.BR KEY_OTH_VIEW .
324.TP
325.IR read
326This permission allows reading a key's payload.
327
328This permission is required for the
329.BR KEYCTL_READ
330operation.
331
332The permission bits for each category are
333.BR KEY_POS_READ ,
334.BR KEY_USR_READ ,
335.BR KEY_GRP_READ ,
336and
337.BR KEY_OTH_READ .
338.TP
339.IR write
340This permission allows update or instantiation of a key's payload.
341For a keyring, it allows keys to be linked and unlinked from the keyring,
342
343This permission is required for the
60fc9e95
MK
344.BR KEYCTL_UPDATE ,
345.BR KEYCTL_REVOKE ,
346.BR KEYCTL_CLEAR ,
347.BR KEYCTL_LINK ,
348and
3d20acc9
MK
349.BR KEYCTL_UNLINK
350operations.
351
352The permission bits for each category are
353.BR KEY_POS_WRITE ,
354.BR KEY_USR_WRITE ,
355.BR KEY_GRP_WRITE ,
356and
357.BR KEY_OTH_WRITE .
358.TP
359.IR search
360This permission allows keyrings to be searched and keys to be found.
361Searches can recurse only into nested keyrings
461a8ce5 362that have search permission set.
3d20acc9
MK
363
364This permission is required for the
60fc9e95
MK
365.BR KEYCTL_GET_KEYRING_ID ,
366.BR KEYCTL_JOIN_SESSION_KEYRING ,
367.BR KEYCTL_SEARCH ,
368and
3d20acc9
MK
369.BR KEYCTL_INVALIDATE
370operations.
371
372The permission bits for each category are
373.BR KEY_POS_SEARCH ,
374.BR KEY_USR_SEARCH ,
375.BR KEY_GRP_SEARCH ,
376and
377.BR KEY_OTH_SEARCH .
378.TP
379.IR link
380This permission allows a key or keyring to be linked to.
381
382This permission is required for the
60fc9e95
MK
383.BR KEYCTL_LINK
384and
3d20acc9
MK
385.BR KEYCTL_SESSION_TO_PARENT
386operations.
387
388The permission bits for each category are
389.BR KEY_POS_LINK ,
390.BR KEY_USR_LINK ,
391.BR KEY_GRP_LINK ,
392and
393.BR KEY_OTH_LINK .
394.TP
395.IR setattr " (since Linux 2.6.15)."
396This permission allows a key's UID, GID, and permissions mask to be changed.
397
398This permission is required for the
60fc9e95
MK
399.BR KEYCTL_REVOKE ,
400.BR KEYCTL_CHOWN ,
401and
3d20acc9
MK
402.BR KEYCTL_SETPERM
403operations.
404
405The permission bits for each category are
406.BR KEY_POS_SETATTR ,
407.BR KEY_USR_SETATTR ,
408.BR KEY_GRP_SETATTR ,
409and
410.BR KEY_OTH_SETATTR .
fa76da80
ES
411.RE
412.IP
3d20acc9
MK
413As a convenience, the following macros are defined as masks for
414all of the permission bits in each of the user categories:
415.BR KEY_POS_ALL ,
416.BR KEY_USR_ALL,
417.BR KEY_GRP_ALL ,
418and
419.BR KEY_OTH_ALL .
420
fa76da80
ES
421The
422.IR arg4 " and " arg5
423arguments are ignored.
efd4c0cd
MK
424
425This operation is exposed by
426.I libkeyutils
427via the function
428.BR keyctl_setperm (3).
4509c62e 429.TP
9d7346eb 430.BR KEYCTL_DESCRIBE " (since Linux 2.6.11)"
015c82d5
MK
431Obtain a description of a key.
432
433The ID of the key to be described is specified in
fa76da80 434.I arg2
015c82d5 435(cast to
60fc9e95 436.IR key_serial_t ).
015c82d5 437The description is returned in the buffer pointed to by
fa76da80 438.I arg3
015c82d5 439(cast to
740fecc2 440.IR "char\ *" ),
015c82d5 441and
fa76da80 442.I arg4
015c82d5
MK
443(cast to
444.IR size_t )
445specifies the size of that buffer in bytes.
446
461a8ce5 447The key must grant the caller
fa76da80 448.I view
461a8ce5 449permission.
015c82d5
MK
450
451The returned description contains the following information about the key:
452
453.in +4n
454.IR type ; uid ; gid ; perm ; description "<NUL>"
455.in
456
457In the above,
458.IR type
459and
460.IR description
461are strings,
462.IR uid
463and
464.IR gid
465are decimal strings, and
466.I perm
467is a hexadecimal permissions mask.
468The description is written with the following format string:
469
470 %s;%d;%d;%08x;%s
471
472.BR "Note: the intention is that the key description string should"
473.BR "be extensible in future kernel versions".
474In particular, the
475.IR description
476field will not contain semicolons;
477it should be parsed by working backwards from the end of the string
478to find the last semicolon.
479This allows future semicolon-delimited fields to be inserted
480in the key description in the future.
481
482Writing to the buffer is attempted only when
483.IR arg3
484is non-NULL and the specified buffer size
485is large enough to accept the description
486(including the terminating null byte).
487'\" Function commentary says it copies up to buflen bytes, but see the
fa76da80
ES
488'\" (buffer && buflen >= ret) condition in keyctl_describe_key() in
489'\" security/keyctl.c
015c82d5
MK
490In order to determine whether the buffer size was too small,
491check to see if the return value of the operation is greater than
492.IR arg4 .
493
461a8ce5 494The
fa76da80
ES
495.I arg5
496argument is ignored.
efd4c0cd
MK
497
498This operation is exposed by
499.I libkeyutils
500via the function
501.BR keyctl_describe (3).
4509c62e 502.TP
a92d3bb4 503.B KEYCTL_CLEAR
c97582e5
MK
504Clear the contents of (i.e., unlink all keys from) a keyring.
505
506The ID of the key
507(which must be of keyring type)
508.\" or the error ENOTDIR results
509is provided in
fa76da80 510.I arg2
c97582e5 511(cast to
fa76da80 512.IR key_serial_t ).
c97582e5
MK
513.\" According to Documentation/security/keys.txt:
514.\" This function can also be used to clear special kernel keyrings if they
515.\" are appropriately marked if the user has CAP_SYS_ADMIN capability. The
516.\" DNS resolver cache keyring is an example of this.
60fc9e95
MK
517
518The caller must have
fa76da80 519.I write
c97582e5 520permission on the keyring.
60fc9e95
MK
521
522The arguments
523.IR arg3 ,
524.IR arg4 ,
525and
526.IR arg5
fa76da80 527are ignored.
efd4c0cd
MK
528
529This operation is exposed by
530.I libkeyutils
531via the function
532.BR keyctl_clear (3).
4509c62e 533.TP
9d7346eb 534.BR KEYCTL_LINK " (since Linux 2.6.11)"
c336c207
MK
535Create a link from a keyring to a key.
536
537The key to be linked is specified in
538.IR arg2
539(cast to
540.IR key_serial_t );
541the keyring is specified in
542.IR arg3
543(cast to
544.IR key_serial_t ).
545
546If a key with the same type and description is already linked in the keyring,
547then that key is displaced from the keyring.
548
549Before creating the link,
550the kernel checks the nesting of the keyrings and returns appropriate errors
551if the nesting is too deep
552.\" KEYRING_SEARCH_MAX_DEPTH 6
553or if the link would produce a cycle.
60fc9e95
MK
554
555The caller must have
fa76da80
ES
556.I link
557permission on the key being added and
558.I write
c336c207 559permission on the keyring.
60fc9e95
MK
560
561The arguments
562.IR arg4
563and
564.IR arg5
fa76da80 565are ignored.
efd4c0cd
MK
566
567This operation is exposed by
568.I libkeyutils
569via the function
570.BR keyctl_link (3).
4509c62e 571.TP
9d7346eb 572.BR KEYCTL_UNLINK " (since Linux 2.6.11)"
2981a43f
MK
573Unlink a key from a keyring.
574
575The ID of the key to be unlinked is specified in
fa76da80 576.I arg2
2981a43f
MK
577(cast to
578.IR key_serial_t );
579the ID of the keyring from which it is to be unlinked is specified in
fa76da80 580.I arg3
2981a43f
MK
581(cast to
582.IR key_serial_t ).
583
584If the key is not currently linked into the keyring, an error results.
60fc9e95
MK
585
586The caller must have
fa76da80 587.I write
60fc9e95
MK
588permission on the keyring from which the key is being removed.
589
2981a43f
MK
590If the last link to a key is removed,
591then that key will be scheduled for destruction.
60fc9e95
MK
592
593The arguments
594.IR arg4
595and
596.IR arg5
fa76da80 597are ignored.
efd4c0cd
MK
598
599This operation is exposed by
600.I libkeyutils
601via the function
602.BR keyctl_unlink (3).
4509c62e 603.TP
9d7346eb 604.BR KEYCTL_SEARCH " (since Linux 2.6.11)"
4f5a5b13
MK
605Search for a key in a keyring tree,
606returning its ID and optionally linking it to a specified keyring.
607
608The tree to be searched is specified by passing
609the ID of the head keyring in
610.IR arg2
611(cast to
fd2d68f9 612.IR key_serial_t ).
4f5a5b13
MK
613The search is performed breadth-first and recursively.
614
461a8ce5 615The
fa76da80 616.I arg3
4f5a5b13 617and
fa76da80 618.I arg4
4f5a5b13
MK
619arguments specify the key to be searched for:
620.I arg3
621(cast as
622.IR "char\ *" )
623contains the key type
624(a null-terminated character string up to 32 bytes in size,
625including the terminating null byte), and
626.I arg4
627(cast as
628.IR "char\ *" )
629contains the description of the key
630(a null-terminated character string up to 4096 bytes in size,
631including the terminating null byte).
632
633The source keyring must grant
fa76da80 634.I search
4f5a5b13
MK
635permission to the caller.
636When performing the recursive search, only keyrings that grant the caller
637.I search
638permission will be searched.
639Only keys with for which the caller has
fa76da80 640.I search
461a8ce5 641permission can be found.
60fc9e95 642
4f5a5b13
MK
643If the key is found, its ID is returned as the function result.
644
645If the key is found and
fa76da80 646.I arg5
4f5a5b13 647(cast to
fd2d68f9 648.IR key_serial_t )
4f5a5b13
MK
649is nonzero, then, subject to the same constraints and rules as
650.BR KEYCTL_LINK ,
651the key is linked into the keyring whose ID is specified in
652.IR arg5 .
653If the destination keyring specified in
654.I arg5
655already contains a link to a key that has the same type and description,
656then that link will be displaced by a link to
657the key found by this operation.
658
659Instead of valid existing keyring IDs, the source
660.RI ( arg2 )
661and destination
662.RI ( arg5 )
663keyrings can be one of the following special keyring IDs:
664.RS
665.TP
666.B KEY_SPEC_THREAD_KEYRING
667This specifies the caller's thread-specific keyring.
668See
669.BR thread_keyring (7).
670.TP
671.B KEY_SPEC_PROCESS_KEYRING
672This specifies the caller's process-specific keyring.
673See
674.BR process_keyring (7).
675.TP
676.B KEY_SPEC_SESSION_KEYRING
677This specifies the caller's session-specific keyring.
678See
679.BR session_keyring (7).
680.TP
681.B KEY_SPEC_USER_KEYRING
682This specifies the caller's UID-specific keyring.
683See
684.BR user_keyring (7).
685.TP
686.B KEY_SPEC_USER_SESSION_KEYRING
687This specifies the caller's UID-session keyring.
688See
689.BR user_session_keyring (7).
690.TP
691.BR KEY_SPEC_REQKEY_AUTH_KEY " (since Linux 2.6.16)"
692.\" commit b5f545c880a2a47947ba2118b2509644ab7a2969
693This specifies the authorization key created by
694.BR request_key (2)
695and passed to the process it spawns to generate a key.
696.TP
697.BR KEY_SPEC_REQUESTOR_KEYRING " (since Linux 2.6.29)"
698.\" commit 8bbf4976b59fc9fc2861e79cab7beb3f6d647640
699This specifies the key ID for the
700.BR request_key (2)
701destination keyring.
702.\" FIXME What about:
703.\" KEY_SPEC_REQKEY_AUTH_KEY (2.6.16)
704.\" KEY_SPEC_REQUESTOR_KEYRING (2.6.29)
705.RE
706.IP
efd4c0cd
MK
707This operation is exposed by
708.I libkeyutils
709via the function
710.BR keyctl_search (3).
4509c62e 711.TP
9d7346eb 712.BR KEYCTL_READ " (since Linux 2.6.11)"
8baa4815
MK
713Read the payload data of a key.
714
715The ID of the key whose payload is to be read is specified in
fa76da80 716.I arg2
8baa4815 717(cast to
fd2d68f9 718.IR key_serial_t ).
8baa4815 719The payload is placed in the buffer pointed by
fa76da80 720.I arg3
8baa4815 721(cast to
fd2d68f9 722.IR "char\ *" );
8baa4815 723the size of that buffer must be specified in
fa76da80 724.I arg4
8baa4815 725(cast to
fd2d68f9 726.IR size_t ).
8baa4815 727
461a8ce5 728The key must either grant the caller
fa76da80 729.I read
8baa4815 730permission, or grant the caller
fa76da80 731.I search
461a8ce5 732permission when searched for from the process keyrings.
60fc9e95 733
461a8ce5 734The
fa76da80
ES
735.I arg5
736argument is ignored.
efd4c0cd
MK
737
738This operation is exposed by
739.I libkeyutils
740via the function
741.BR keyctl_read (3).
4509c62e 742.TP
9d7346eb 743.BR KEYCTL_INSTANTIATE " (since Linux 2.6.11)"
329c2892 744.\" FIXME There's a lot more detail to add here...
9f79744c
MK
745Instantiate a partially constructed key with a specified payload.
746
747The ID of the key to be instantiated is provided in
fa76da80 748.I arg2
9f79744c
MK
749(cast to
750.IR key_serial_t ).
751
752The key payload is specified in the buffer pointed to by
fa76da80 753.I arg3
9f79744c
MK
754(cast to
755.IR "void\ *");
756the size of that buffer is specified in
fa76da80 757.I arg4
9f79744c 758(cast to
fd2d68f9 759.IR size_t ).
9f79744c
MK
760
761The payload may be a NULL pointer and the buffer size may be 0
762if this is supported by the key type.
763The operation may be fail if the payload data is in the wrong format
764or is otherwise invalid.
765
766If
fa76da80 767.I arg5
9f79744c
MK
768(cast to
769.IR key_serial_t )
770is nonzero, then, subject to the same constraints and rules as
771.BR KEYCTL_LINK ,
772the instantiated key is linked into the keyring whose ID specified in
773.IR arg5 .
774
775The caller must have the appropriate authorization key;
776see
777.BR request_key (2).
60fc9e95 778
efd4c0cd
MK
779This operation is exposed by
780.I libkeyutils
781via the function
782.BR keyctl_instantiate (3).
4509c62e 783.TP
9d7346eb 784.BR KEYCTL_NEGATE " (since Linux 2.6.11)"
39b91a53 785Negatively instantiate a partially constructed key.
60fc9e95 786
39b91a53 787This operation is equivalent to the call:
60fc9e95
MK
788
789 keyctl(KEYCTL_REJECT, arg2, arg3, ENOKEY, arg4);
790
fa76da80
ES
791The
792.I arg5
793argument is ignored.
efd4c0cd
MK
794
795This operation is exposed by
796.I libkeyutils
797via the function
798.BR keyctl_negate (3).
8ec6a211 799.TP
fa76da80 800.BR KEYCTL_SET_REQKEY_KEYRING " (since Linux 2.6.13)"
0a45d567
MK
801Set the default keyring to which implicitly requested keys
802.\" The implicit requests make use of the kernel-internal request_key()
803.\" function (which is not the same as the request_key(2) system call).
804will be linked for this thread, and return the previous setting.
805Implicit key requests can occur when, for example, opening files
806on an AFS or NFS filesystem.
807
461a8ce5 808The
fa76da80 809.I arg2
fd2d68f9
MK
810argument (cast to
811.IR int )
0a45d567
MK
812should contain one of the following values,
813to specify the new default keyring:
d1d5839d 814.RS
0a45d567 815.TP
d1d5839d
MK
816.BR KEY_REQKEY_DEFL_NO_CHANGE
817No change.
818.TP
819.BR KEY_REQKEY_DEFL_DEFAULT
0a45d567
MK
820This selects the default behaviour,
821which is to use the thread-specific keyring if there is one,
822otherwise the process-specific keyring if there is one,
823otherwise the session keyring if there is one,
824otherwise the UID-specific session keyring.
d1d5839d
MK
825.TP
826.BR KEY_REQKEY_DEFL_THREAD_KEYRING
0a45d567
MK
827Use the thread-specific keyring
828.RB ( thread_keyring (7))
829as the new default keyring.
d1d5839d
MK
830.TP
831.BR KEY_REQKEY_DEFL_PROCESS_KEYRING
0a45d567
MK
832Use the process-specific keyring
833.RB ( process_keyring (7))
834as the new default keyring.
835.TP
d1d5839d
MK
836.TP
837.BR KEY_REQKEY_DEFL_SESSION_KEYRING
0a45d567
MK
838Use the session-specific keyring
839.RB ( session_keyring (7))
840as the new default keyring.
d1d5839d
MK
841.TP
842.BR KEY_REQKEY_DEFL_USER_KEYRING
0a45d567
MK
843Use the UID-specific keyring
844.RB ( user_keyring (7))
845as the new default keyring.
d1d5839d 846.TP
0a45d567
MK
847.BR KEY_REQKEY_DEFL_USER_SESSION_KEYRING
848Use the UID-specific session keyring
849.RB ( user_session_keyring (7))
850as the new default keyring.
d1d5839d
MK
851.TP
852.BR KEY_REQKEY_DEFL_REQUESTOR_KEYRING " (since Linux 2.6.29)"
fa76da80 853'\" 8bbf4976b59fc9fc2861e79cab7beb3f6d647640
0a45d567
MK
854.\" FIXME The following needs to be expanded.
855Use the requestor keyring.
d1d5839d
MK
856.RE
857.IP
0a45d567
MK
858All other values are invalid.
859.\" (including the still-unsupported KEY_REQKEY_DEFL_GROUP_KEYRING)
60fc9e95
MK
860
861The arguments
862.IR arg3 ,
863.IR arg4 ,
864and
865.IR arg5
fa76da80 866are ignored.
efd4c0cd 867
0a45d567
MK
868The setting controlled by this operation is inherited by the child of
869.BR fork (2)
870and preserved across
871.BR execve (2).
872
efd4c0cd
MK
873This operation is exposed by
874.I libkeyutils
875via the function
876.BR keyctl_set_reqkey_keyring (3).
8ec6a211 877.TP
fa76da80 878.BR KEYCTL_SET_TIMEOUT " (since Linux 2.6.16)"
adee7073
MK
879Set a timeout on a key.
880
881The ID of the key is specified in
fa76da80 882.I arg2
adee7073
MK
883(cast to
884.IR key_serial_t ).
885The timeout value, in seconds from the current time,
886is specified in
fa76da80 887.I arg3
adee7073 888(cast to
fd2d68f9 889.IR "unsigned int" ).
60fc9e95 890
adee7073
MK
891Specifying the timeout value as 0 clears any existing timeout on the key.
892
60fc9e95 893The caller must either have the
fa76da80 894.I setattr
adee7073
MK
895permission on the key
896or hold an instantiation authorization token for the key (see
897.BR request_key (2)).
60fc9e95 898
461a8ce5
MK
899The key and any links to the key will be
900automatically garbage collected after the timeout expires.
adee7073
MK
901Subsequent attempts to access the key will then fail with the error
902.BR EKEYEXPIRED .
903
904This operation cannot be used to set timeouts on negative, revoked,
905or expired keys.
60fc9e95
MK
906
907The arguments
908.IR arg4
909and
910.IR arg5
fa76da80 911are ignored.
efd4c0cd
MK
912
913This operation is exposed by
914.I libkeyutils
915via the function
916.BR keyctl_set_timeout (3).
8ec6a211 917.TP
fa76da80 918.BR KEYCTL_ASSUME_AUTHORITY " (since Linux 2.6.16)"
076432af
MK
919.\" FIXME More needs to be said for KEYCTL_ASSUME_AUTHORITY
920Assume (or divest) the authority for the calling thread
921to instantiate a specified key.
922
923The
fa76da80 924.I arg2
fd2d68f9 925argument (cast to
076432af
MK
926.IR key_serial_t )
927specifies either a nonzero key ID to assume authority,
928or the value 0 to divest authority.
929
930If
931.I arg2
932is nonzero, then it specifies the ID of an uninstantiated key for which
933authority is to be assumed.
60fc9e95 934
076432af
MK
935Authority of a key can be assumed only if the calling thread has present
936in its keyrings the authorization key that is
937associated with the specified key.
938The caller must have
fa76da80 939.I search
076432af
MK
940permission on the authorization key.
941
942If the specified key has a matching authorization key,
943then the ID of that key is returned.
944The authorization key can be read to obtain
945the callout information passed to
946.BR request_key (2).
60fc9e95 947
076432af 948If the ID given in
fa76da80 949.I arg2
076432af
MK
950is 0, then the currently assumed authority is cleared (divested),
951and the value 0 is returned.
60fc9e95
MK
952
953The arguments
954.IR arg3 ,
955.IR arg4 ,
956and
957.IR arg5
fa76da80 958are ignored.
efd4c0cd
MK
959
960This operation is exposed by
961.I libkeyutils
962via the function
963.BR keyctl_assume_authority (3).
fa76da80
ES
964.TP
965.BR KEYCTL_GET_SECURITY " (since Linux 2.6.26)"
60fc9e95 966Get the LSM security label of the specified key.
461a8ce5 967The ID of the key should be provided in the
fa76da80 968.I arg2
fd2d68f9
MK
969argument (cast to
970.IR key_serial_t ).
60fc9e95 971The buffer where the security label should be stored is provided in the
fa76da80 972.I arg3
fd2d68f9
MK
973argument (cast to
974.IR "char\ *" )
975with its size provided in the
fa76da80 976.I arg4
fd2d68f9
MK
977argument (cast to
978.IR size_t ).
60fc9e95 979
461a8ce5 980The
fa76da80
ES
981.I arg5
982argument is ignored.
efd4c0cd
MK
983
984This operation is exposed by
985.I libkeyutils
986via the function
987.BR keyctl_get_security (3)
988and
989.BR keyctl_get_security_alloc (3).
fa76da80
ES
990.TP
991.BR KEYCTL_SESSION_TO_PARENT " (since Linux 2.6.32)"
992Apply session keyring to parent process.
993.IP
461a8ce5
MK
994Attempt to install the calling process's session keyring
995on the process's parent process.
996The keyring must exist and must grant the caller
fa76da80 997.I link
60fc9e95
MK
998permission, and the parent process must be single-threaded and have
999the same effective ownership as this process
1000and must not be be set-user-ID or set-group-ID.
fa76da80
ES
1001.IP
1002The keyring will be emplaced on the parent when it next resumes userspace.
60fc9e95
MK
1003
1004The arguments
1005.IR arg2 ,
1006.IR arg3 ,
1007.IR arg4 ,
1008and
1009.IR arg5
fa76da80 1010are ignored.
efd4c0cd
MK
1011
1012This operation is exposed by
1013.I libkeyutils
1014via the function
1015.BR keyctl_session_to_parent (3).
fa76da80
ES
1016.TP
1017.BR KEYCTL_REJECT " (since Linux 2.6.39)"
8ab24543
MK
1018.\" commit fdd1b94581782a2ddf9124414e5b7a5f48ce2f9c
1019.\" We need some text here on why it is useful to negatively instantiate a key
1020Mark a key as negatively instantiated and set an expiration timer
1021on the key.
1022This operation provides a superset of the functionality of the earlier
1023.BR KEYCTL_NEGATE
1024operation.
1025
1026The ID of the key that is to be negatively instantiated is specified in
fa76da80 1027.I arg2
8ab24543
MK
1028(cast to
1029.IR key_serial_t ).
1030The
fa76da80 1031.I arg3
8ab24543 1032(cast to
fd2d68f9 1033.IR "unsigned int" )
8ab24543
MK
1034argument specifies the lifetime of the key, in seconds.
1035The
fa76da80 1036.I arg4
fd2d68f9 1037argument (cast to
8ab24543
MK
1038.IR "unsigned int" )
1039specifies the error to be returned when a search hits this key;
1040typically, this is one of
1041.BR EKEYREJECTED ,
1042.BR EKEYREVOKED ,
1043or
1044.BR EKEYEXPIRED .
1045
1046If
fa76da80 1047.I arg5
8ab24543
MK
1048(cast to
1049.IR key_serial_t )
1050is nonzero, then, subject to the same constraints and rules as
1051.BR KEYCTL_LINK ,
1052the negatively instantiated key is linked into the keyring
1053whose ID specified in
1054.IR arg5 .
60fc9e95 1055
461a8ce5 1056The caller must have the appropriate instantiation permit set
60fc9e95
MK
1057(authorization key, see
1058.B KEYCTL_ASSUME_AUTHORITY
8ab24543
MK
1059command and
1060.BR request_key (2)).
d374e850 1061
461a8ce5 1062Negative keys are used to rate limit repeated
60fc9e95 1063.BR request_key (2)
fa76da80
ES
1064calls by causing them to return the error specified until the negative key
1065expires.
efd4c0cd
MK
1066
1067This operation is exposed by
1068.I libkeyutils
1069via the function
1070.BR keyctl_reject (3).
fa76da80
ES
1071.TP
1072.BR KEYCTL_INSTANTIATE_IOV " (since Linux 2.6.39)"
1f234c53 1073.\" commit ee009e4a0d4555ed522a631bae9896399674f063
329c2892
MK
1074Instantiate a partially constructed key with a payload specified
1075via a vector of buffers.
60fc9e95 1076
329c2892
MK
1077This operation is the same as
1078.BR KEYCTL_INSTANTIATE ,
1079but the payload data is specified as an array of
1080.IR iovec
1081structures:
1082
1083.in +4n
1084.nf
1085struct iovec {
1086 void *iov_base; /* Starting address of buffer */
1087 size_t iov_len; /* Size of buffer (in bytes) */
1088};
1089.fi
1090.in
1091
1092The pointer to the payload vector is specified in
1093.IR arg3
1094(cast as
1095.IR "const struct iovec\ *" ).
1096The number of items in the vector is specified in
1097.IR arg4
1098(cast as
1099.IR "unsigned int" ).
60fc9e95 1100
461a8ce5 1101The
329c2892
MK
1102.I arg2
1103(key ID)
1104and
fa76da80 1105.I arg5
329c2892
MK
1106(keyring ID)
1107are interpreted as for
1108.BR KEYCTL_INSTANTIATE .
efd4c0cd
MK
1109
1110This operation is exposed by
1111.I libkeyutils
1112via the function
1113.BR keyctl_instantiate_iov (3).
fa76da80
ES
1114.TP
1115.BR KEYCTL_INVALIDATE " (since Linux 3.5)"
1f234c53
MK
1116.\" commit fd75815f727f157a05f4c96b5294a4617c0557da
1117Mark a key as invalid.
1118
1119The ID of the key to be invalidated is specified in
fa76da80 1120.I arg2
1f234c53 1121(cast to
fd2d68f9 1122.IR key_serial_t ).
60fc9e95 1123
1f234c53
MK
1124To invalidate a key,
1125the caller must have
fa76da80 1126.I search
1f234c53
MK
1127permission on the key.
1128.\" CAP_SYS_ADMIN is permitted to invalidate certain special keys
1129
1130This operation immediately marks the key as invalid
1131and schedules garbage collection.
1132The garbage collector removes the invalidated key from all keyrings and
1133deletes the key when its reference count reaches zero.
1134After this operation,
1135the key will be ignored by all searches,
1136even if it is not yet deleted.
1137
1138Keys that are marked invalid become invisible to normal key operations
1139immediately, though they are still visible in
1140.I /proc/keys
1141(marked with an 'i' flag)
1142until they are actually removed.
60fc9e95
MK
1143
1144The arguments
1145.IR arg3 ,
1146.IR arg4 ,
1147and
1148.IR arg5
fa76da80 1149are ignored.
efd4c0cd
MK
1150
1151This operation is exposed by
1152.I libkeyutils
1153via the function
1154.BR keyctl_invalidate (3).
fa76da80
ES
1155.TP
1156.BR KEYCTL_GET_PERSISTENT " (since Linux 3.13)"
1157Get the persistent keyring of the user specified in the
1158.I arg2
fd2d68f9
MK
1159(cast to
1160.IR uid_t )
1161and link it to the keyring with the ID provided in the
fa76da80 1162.I arg3
fd2d68f9
MK
1163argument (cast to
1164.IR key_serial_t ).
60fc9e95
MK
1165If \-1 is provided as UID, current user's ID is used.
1166
1167The arguments
1168.IR arg4
1169and
1170.IR arg5
fa76da80 1171are ignored.
efd4c0cd
MK
1172
1173This operation is exposed by
1174.I libkeyutils
1175via the function
1176.BR keyctl_get_persistent (3).
fa76da80
ES
1177.TP
1178.BR KEYCTL_DH_COMPUTE " (since Linux 4.7)"
461a8ce5
MK
1179Compute Diffie-Hellman values.
1180The
fa76da80
ES
1181.I arg2
1182argument is a pointer to
60fc9e95 1183.I struct keyctl_dh_params
fa76da80
ES
1184which is defined in
1185.I <linux/keyctl.h>
1186as follows:
1187
1188.nf
1189.in +4n
1190struct keyctl_dh_params {
1191 int32_t private;
1192 int32_t prime;
1193 int32_t base;
1194};
1195.in
1196.fi
1197
60fc9e95 1198The
fa76da80 1199.IR private ", " prime " and " base
60fc9e95 1200fields are IDs of the keys, payload of which would be used for DH values
461a8ce5 1201calculation.
60fc9e95 1202The result is calculated as
fa76da80 1203.IR "base^private mod prime" .
60fc9e95 1204
fa76da80
ES
1205The
1206.I arg3
fd2d68f9
MK
1207argument (cast to
1208.IR "char\ *" )
1209should point to an output buffer whose size is passed in the
fa76da80 1210.I arg4
fd2d68f9
MK
1211argument (cast to
1212.IR size_t ).
60fc9e95
MK
1213The buffer should be big enough in order to accommodate the output data,
1214otherwise an error is returned.
1215A NULL pointer can be provided as buffer in order
1216to obtain the required buffer size.
1217
461a8ce5 1218The
fa76da80 1219.I arg5
60fc9e95 1220argument is reserved and must be 0.
4509c62e 1221.SH RETURN VALUE
fa76da80
ES
1222For a successful call, the return value depends on the operation:
1223.TP
1224.B KEYCTL_GET_KEYRING_ID
1225The ID of the requested keyring.
1226.TP
1227.B KEYCTL_JOIN_SESSION_KEYRING
1228The ID of the joined session keyring.
1229.TP
1230.B KEYCTL_DESCRIBE
015c82d5
MK
1231The size of the description (including the terminating null byte),
1232irrespective of the provided buffer size.
fa76da80
ES
1233.TP
1234.B KEYCTL_SEARCH
d374e850 1235The ID of the key that was found.
fa76da80
ES
1236.TP
1237.B KEYCTL_READ
8baa4815
MK
1238The amount of data that is available in the key,
1239irrespective of the provided buffer size.
fa76da80
ES
1240.TP
1241.B KEYCTL_SET_REQKEY_KEYRING
0a45d567
MK
1242The ID of the previous default keyring
1243to which implicitly requested keys were linked
1244(one of
1245.BR KEY_REQKEY_DEFL_USER_* ).
fa76da80
ES
1246.TP
1247.B KEYCTL_ASSUME_AUTHORITY
076432af
MK
1248Either 0, if the ID given was 0,
1249or the ID of the authorization key matching the specified key,
1250if a non-zero key ID was provided.
fa76da80
ES
1251.TP
1252.B KEYCTL_GET_SECURITY
60fc9e95 1253The amount of information available (including the terminating null byte),
fa76da80
ES
1254irrespective of the provided buffer size.
1255.TP
1256.B KEYCTL_GET_PERSISTENT
d374e850 1257The ID of the persistent keyring.
fa76da80
ES
1258.TP
1259.B KEYCTL_DH_COMPUTE
1260Amount of bytes being copied.
1261.TP
1262All other commands
1263Zero.
1264.PP
1265On error, \-1 is returned, and
1266.I errno
1267is set appropriately to indicate the error.
4509c62e
MK
1268.SH ERRORS
1269.TP
27807c32 1270.B EACCES
60fc9e95 1271The requested operation wasn't permitted.
27807c32 1272.TP
c336c207
MK
1273.B EDEADLK
1274.I option
1275is
1276.BR KEYCTL_LINK
1277and the requested link would result in a cycle.
1278.TP
27807c32
MK
1279.B EDQUOT
1280The key quota for the caller's user would be exceeded by creating a key or
1281linking it to the keyring.
4509c62e 1282.TP
3d20acc9
MK
1283.B EINVAL
1284.I option
1285was
1286.B KEYCTL_SETPERM
1287and an invalid permission bit was specified in
1288.IR arg3 .
1289.TP
4509c62e
MK
1290.B EKEYEXPIRED
1291An expired key was found or specified.
1292.TP
4509c62e
MK
1293.B EKEYREJECTED
1294A rejected key was found or specified.
1295.TP
27807c32
MK
1296.B EKEYREVOKED
1297A revoked key was found or specified.
4509c62e 1298.TP
c336c207
MK
1299.B ELOOP
1300.I option
1301is
1302.BR KEYCTL_LINK
1303and the requested link would cause the maximum nesting depth
1304for keyrings to be exceeded.
1305.TP
27807c32
MK
1306.B ENOKEY
1307No matching key was found or an invalid key was specified.
fa76da80 1308.TP
d6c7244f
MK
1309.B ENOKEY
1310The value
1311.B KEYCTL_GET_KEYRING_ID
1312was specified in
1313.IR option ,
1314the key specified in
1315.I arg2
1316did not exist, and
1317.I arg3
1318was zero (meaning don't create the key if it didn't exist).
1319.TP
581f8203 1320.B EOPNOTSUPP
fa76da80
ES
1321.I option
1322is
1323.B KEYCTL_UPDATE
60fc9e95 1324and the key type does not support updating.
fa76da80
ES
1325.TP
1326.B ENOTDIR
f8aead6a
MK
1327A key of keyring type was expected but the ID of a key with
1328a different type was provided.
fa76da80
ES
1329.TP
1330.B ENFILE
c336c207
MK
1331.\" FIXME Does this error really occur? I could not find where
1332.\" in the kernel source it is generated, but have not tested
1333.\" this case from a user-space program
1334.IR option
1335is
1336.BR KEYCTL_LINK
1337and the keyring is full.
fa76da80
ES
1338.TP
1339.B ENOENT
1340.I option
1341is
1342.B KEYCTL_UNLINK
2981a43f 1343and the key to be unlinked isn't linked to the keyring.
fa76da80
ES
1344.TP
1345.B EINVAL
1346.I option
1347is
1348.B KEYCTL_DH_COMPUTE
60fc9e95 1349and the buffer size provided is not enough for the result to fit in.
461a8ce5 1350Provide 0 as
fa76da80 1351a buffer size in order to obtain minimum buffer size first.
a5987bfd
MK
1352.SH VERSIONS
1353This system call first appeared in Linux 2.6.11.
1354.SH CONFORMING TO
1355This system call is a nonstandard Linux extension.
60fc9e95 1356.SH NOTES
4509c62e
MK
1357Although this is a Linux system call, it is not present in
1358.I libc
1359but can be found rather in
1360.IR libkeyutils .
1361When linking,
60fc9e95 1362.B \-lkeyutils
4509c62e 1363should be specified to the linker.
4509c62e 1364.SH SEE ALSO
e264f024
MK
1365.ad l
1366.nh
4509c62e 1367.BR keyctl (1),
4509c62e 1368.BR add_key (2),
4509c62e 1369.BR request_key (2),
4509c62e 1370.BR keyctl_chown (3),
4509c62e 1371.BR keyctl_clear (3),
cf4d4361
DP
1372.BR keyctl_describe (3),
1373.BR keyctl_describe_alloc (3),
1374.BR keyctl_get_keyring_ID (3),
4509c62e 1375.BR keyctl_instantiate (3),
cf4d4361
DP
1376.BR keyctl_join_session_keyring (3),
1377.BR keyctl_link (3),
4509c62e 1378.BR keyctl_negate (3),
d8f1a35c
MK
1379.BR keyctl_read (3),
1380.BR keyctl_read_alloc (3),
cf4d4361
DP
1381.BR keyctl_revoke (3),
1382.BR keyctl_search (3),
4509c62e 1383.BR keyctl_set_reqkey_keyring (3),
4509c62e 1384.BR keyctl_set_timeout (3),
d8f1a35c 1385.BR keyctl_setperm (3),
cf4d4361
DP
1386.BR keyctl_unlink (3),
1387.BR keyctl_update (3),
32fc2407 1388.BR keyrings (7),
4509c62e 1389.BR request-key (8)
7e7454ef 1390
bfc23228
MK
1391The kernel source files
1392.IR Documentation/security/keys.txt
1393and
1394.IR Documentation/security/keys-request-key.txt .