-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyctl.html
2406 lines (1818 loc) · 77.5 KB
/
keyctl.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!-- Creator : groff version 1.22.4 -->
<!-- CreationDate: Wed Jan 29 11:27:23 2020 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
p { margin-top: 0; margin-bottom: 0; vertical-align: top }
pre { margin-top: 0; margin-bottom: 0; vertical-align: top }
table { margin-top: 0; margin-bottom: 0; vertical-align: top }
h1 { text-align: center }
</style>
<title>KEYCTL</title>
</head>
<body>
<h1 align="center">KEYCTL</h1>
<a href="#NAME">NAME</a><br>
<a href="#SYNOPSIS">SYNOPSIS</a><br>
<a href="#DESCRIPTION">DESCRIPTION</a><br>
<a href="#RETURN VALUE">RETURN VALUE</a><br>
<a href="#ERRORS">ERRORS</a><br>
<a href="#VERSIONS">VERSIONS</a><br>
<a href="#CONFORMING TO">CONFORMING TO</a><br>
<a href="#NOTES">NOTES</a><br>
<a href="#EXAMPLE">EXAMPLE</a><br>
<a href="#SEE ALSO">SEE ALSO</a><br>
<a href="#COLOPHON">COLOPHON</a><br>
<hr>
<h2>NAME
<a name="NAME"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em">keyctl -
manipulate the kernel’s key management facility</p>
<h2>SYNOPSIS
<a name="SYNOPSIS"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>#include
<sys/types.h> <br>
#include <keyutils.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>long
keyctl(int</b> <i>operation</i><b>, ...)</b></p>
<p style="margin-left:11%; margin-top: 1em"><b>/* For
direct call via syscall(2): */ <br>
#include <asm/unistd.h> <br>
#include <linux/keyctl.h> <br>
#include <unistd.h></b></p>
<p style="margin-left:11%; margin-top: 1em"><b>long
syscall(__NR_keyctl, int</b> <i>operation</i><b>,
__kernel_ulong_t</b> <i>arg2</i><b>, <br>
__kernel_ulong_t</b> <i>arg3</i><b>, __kernel_ulong_t</b>
<i>arg4</i><b>, <br>
__kernel_ulong_t</b> <i>arg5</i><b>);</b></p>
<p style="margin-left:11%; margin-top: 1em">No glibc
wrapper is provided for this system call; see NOTES.</p>
<h2>DESCRIPTION
<a name="DESCRIPTION"></a>
</h2>
<p style="margin-left:11%; margin-top: 1em"><b>keyctl</b>()
allows user-space programs to perform key manipulation.</p>
<p style="margin-left:11%; margin-top: 1em">The operation
performed by <b>keyctl</b>() is determined by the value of
the <i>operation</i> argument. Each of these operations is
wrapped by the <i>libkeyutils</i> library (provided by the
<i>keyutils</i> package) into individual functions (noted
below) to permit the compiler to check types.</p>
<p style="margin-left:11%; margin-top: 1em">The permitted
values for <i>operation</i> are: <b><br>
KEYCTL_GET_KEYRING_ID</b> (since Linux 2.6.10)</p>
<p style="margin-left:22%;">Map a special key ID to a real
key ID for this process.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
looks up the special key whose ID is provided in <i>arg2</i>
(cast to <i>key_serial_t</i>). If the special key is found,
the ID of the corresponding real key is returned as the
function result. The following values may be specified in
<i>arg2</i>: <b><br>
KEY_SPEC_THREAD_KEYRING</b></p>
<p style="margin-left:32%;">This specifies the calling
thread’s thread-specific keyring. See
<b>thread-keyring</b>(7).</p>
<p style="margin-left:22%;"><b>KEY_SPEC_PROCESS_KEYRING</b></p>
<p style="margin-left:32%;">This specifies the
caller’s process-specific keyring. See
<b>process-keyring</b>(7).</p>
<p style="margin-left:22%;"><b>KEY_SPEC_SESSION_KEYRING</b></p>
<p style="margin-left:32%;">This specifies the
caller’s session-specific keyring. See
<b>session-keyring</b>(7).</p>
<p style="margin-left:22%;"><b>KEY_SPEC_USER_KEYRING</b></p>
<p style="margin-left:32%;">This specifies the
caller’s UID-specific keyring. See
<b>user-keyring</b>(7).</p>
<p style="margin-left:22%;"><b>KEY_SPEC_USER_SESSION_KEYRING</b></p>
<p style="margin-left:32%;">This specifies the
caller’s UID-session keyring. See
<b>user-session-keyring</b>(7).</p>
<p style="margin-left:22%;"><b>KEY_SPEC_REQKEY_AUTH_KEY</b>
(since Linux 2.6.16)</p>
<p style="margin-left:32%;">This specifies the
authorization key created by <b>request_key</b>(2) and
passed to the process it spawns to generate a key. This key
is available only in a <b>request-key</b>(8)-style program
that was passed an authorization key by the kernel and
ceases to be available once the requested key has been
instantiated; see <b>request_key</b>(2).</p>
<p style="margin-left:22%;"><b>KEY_SPEC_REQUESTOR_KEYRING</b>
(since Linux 2.6.29)</p>
<p style="margin-left:32%;">This specifies the key ID for
the <b>request_key</b>(2) destination keyring. This keyring
is available only in a <b>request-key</b>(8)-style program
that was passed an authorization key by the kernel and
ceases to be available once the requested key has been
instantiated; see <b>request_key</b>(2).</p>
<p style="margin-left:22%; margin-top: 1em">The behavior if
the key specified in <i>arg2</i> does not exist depends on
the value of <i>arg3</i> (cast to <i>int</i>). If
<i>arg3</i> contains a nonzero value, then—if it is
appropriate to do so (e.g., when looking up the user,
user-session, or session key)—a new key is created and
its real key ID returned as the function result. Otherwise,
the operation fails with the error <b>ENOKEY</b>.</p>
<p style="margin-left:22%; margin-top: 1em">If a valid key
ID is specified in <i>arg2</i>, and the key exists, then
this operation simply returns the key ID. If the key does
not exist, the call fails with error <b>ENOKEY</b>.</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have <i>search</i> permission on a keyring in order for it
to be found.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg4</i> and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_get_keyring_ID</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_JOIN_SESSION_KEYRING</b>
(since Linux 2.6.10)</p>
<p style="margin-left:22%;">Replace the session keyring
this process subscribes to with a new session keyring.</p>
<p style="margin-left:22%; margin-top: 1em">If <i>arg2</i>
is NULL, an anonymous keyring with the description
"_ses" is created and the process is subscribed to
that keyring as its session keyring, displacing the previous
session keyring.</p>
<p style="margin-left:22%; margin-top: 1em">Otherwise,
<i>arg2</i> (cast to <i>char *</i>) is treated as the
description (name) of a keyring, and the behavior is as
follows:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="74%">
<p>If a keyring with a matching description exists, the
process will attempt to subscribe to that keyring as its
session keyring if possible; if that is not possible, an
error is returned. In order to subscribe to the keyring, the
caller must have <i>search</i> permission on the
keyring.</p> </td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="1%">
<p>*</p></td>
<td width="3%"></td>
<td width="74%">
<p>If a keyring with a matching description does not exist,
then a new keyring with the specified description is
created, and the process is subscribed to that keyring as
its session keyring.</p></td></tr>
</table>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg3</i>, <i>arg4</i>, and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_join_session_keyring</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_UPDATE</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Update a key’s data
payload.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg2</i>
argument (cast to <i>key_serial_t</i>) specifies the ID of
the key to be updated. The <i>arg3</i> argument (cast to
<i>void *</i>) points to the new payload and
<i>arg4</i> (cast to <i>size_t</i>) contains the new payload
size in bytes.</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have <i>write</i> permission on the key specified and the
key type must support updating.</p>
<p style="margin-left:22%; margin-top: 1em">A negatively
instantiated key (see the description of
<b>KEYCTL_REJECT</b>) can be positively instantiated with
this operation.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg5</i>
argument is ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_update</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_REVOKE</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Revoke the key with the ID
provided in <i>arg2</i> (cast to <i>key_serial_t</i>). The
key is scheduled for garbage collection; it will no longer
be findable, and will be unavailable for further operations.
Further attempts to use the key will fail with the error
<b>EKEYREVOKED</b>.</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have <i>write</i> or <i>setattr</i> permission on the
key.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg3</i>, <i>arg4</i>, and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_revoke</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_CHOWN</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Change the ownership (user and
group ID) of a key.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg2</i>
argument (cast to <i>key_serial_t</i>) contains the key ID.
The <i>arg3</i> argument (cast to <i>uid_t</i>) contains the
new user ID (or -1 in case the user ID shouldn’t be
changed). The <i>arg4</i> argument (cast to <i>gid_t</i>)
contains the new group ID (or -1 in case the group ID
shouldn’t be changed).</p>
<p style="margin-left:22%; margin-top: 1em">The key must
grant the caller <i>setattr</i> permission.</p>
<p style="margin-left:22%; margin-top: 1em">For the UID to
be changed, or for the GID to be changed to a group the
caller is not a member of, the caller must have the
<b>CAP_SYS_ADMIN</b> capability (see
<b>capabilities</b>(7)).</p>
<p style="margin-left:22%; margin-top: 1em">If the UID is
to be changed, the new user must have sufficient quota to
accept the key. The quota deduction will be removed from the
old user to the new user should the UID be changed.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg5</i>
argument is ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_chown</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_SETPERM</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Change the permissions of the
key with the ID provided in the <i>arg2</i> argument (cast
to <i>key_serial_t</i>) to the permissions provided in the
<i>arg3</i> argument (cast to <i>key_perm_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">If the caller
doesn’t have the <b>CAP_SYS_ADMIN</b> capability, it
can change permissions only for the keys it owns. (More
precisely: the caller’s filesystem UID must match the
UID of the key.)</p>
<p style="margin-left:22%; margin-top: 1em">The key must
grant <i>setattr</i> permission to the caller
<i>regardless</i> of the caller’s capabilities.</p>
<p style="margin-left:22%; margin-top: 1em">The permissions
in <i>arg3</i> specify masks of available operations for
each of the following user categories: <i><br>
possessor</i> (since Linux 2.6.14)</p>
<p style="margin-left:32%;">This is the permission granted
to a process that possesses the key (has it attached
searchably to one of the process’s keyrings); see
<b>keyrings</b>(7).</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="7%">
<p><i>user</i></p></td>
<td width="3%"></td>
<td width="68%">
<p>This is the permission granted to a process whose
filesystem UID matches the UID of the key.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="7%">
<p><i>group</i></p></td>
<td width="3%"></td>
<td width="68%">
<p>This is the permission granted to a process whose
filesystem GID or any of its supplementary GIDs matches the
GID of the key.</p></td></tr>
<tr valign="top" align="left">
<td width="22%"></td>
<td width="7%">
<p><i>other</i></p></td>
<td width="3%"></td>
<td width="68%">
<p>This is the permission granted to other processes that
do not match the <i>user</i> and <i>group</i>
categories.</p> </td></tr>
</table>
<p style="margin-left:22%; margin-top: 1em">The
<i>user</i>, <i>group</i>, and <i>other</i> categories are
exclusive: if a process matches the <i>user</i> category, it
will not receive permissions granted in the <i>group</i>
category; if a process matches the <i>user</i> or
<i>group</i> category, then it will not receive permissions
granted in the <i>other</i> category.</p>
<p style="margin-left:22%; margin-top: 1em">The
<i>possessor</i> category grants permissions that are
cumulative with the grants from the <i>user</i>,
<i>group</i>, or <i>other</i> category.</p>
<p style="margin-left:22%; margin-top: 1em">Each permission
mask is eight bits in size, with only six bits currently
used. The available permissions are:</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="6%">
<p style="margin-top: 1em"><i>view</i></p></td>
<td width="4%"></td>
<td width="68%">
<p style="margin-top: 1em">This permission allows reading
attributes of a key.</p></td></tr>
</table>
<p style="margin-left:32%; margin-top: 1em">This permission
is required for the <b>KEYCTL_DESCRIBE</b> operation.</p>
<p style="margin-left:32%; margin-top: 1em">The permission
bits for each category are <b>KEY_POS_VIEW</b>,
<b>KEY_USR_VIEW</b>, <b>KEY_GRP_VIEW</b>, and
<b>KEY_OTH_VIEW</b>.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="6%">
<p style="margin-top: 1em"><i>read</i></p></td>
<td width="4%"></td>
<td width="68%">
<p style="margin-top: 1em">This permission allows reading a
key’s payload.</p></td></tr>
</table>
<p style="margin-left:32%; margin-top: 1em">This permission
is required for the <b>KEYCTL_READ</b> operation.</p>
<p style="margin-left:32%; margin-top: 1em">The permission
bits for each category are <b>KEY_POS_READ</b>,
<b>KEY_USR_READ</b>, <b>KEY_GRP_READ</b>, and
<b>KEY_OTH_READ</b>.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="7%">
<p style="margin-top: 1em"><i>write</i></p></td>
<td width="3%"></td>
<td width="68%">
<p style="margin-top: 1em">This permission allows update or
instantiation of a key’s payload. For a keyring, it
allows keys to be linked and unlinked from the keyring,</p></td></tr>
</table>
<p style="margin-left:32%; margin-top: 1em">This permission
is required for the <b>KEYCTL_UPDATE</b>,
<b>KEYCTL_REVOKE</b>, <b>KEYCTL_CLEAR</b>,
<b>KEYCTL_LINK</b>, and <b>KEYCTL_UNLINK</b> operations.</p>
<p style="margin-left:32%; margin-top: 1em">The permission
bits for each category are <b>KEY_POS_WRITE</b>,
<b>KEY_USR_WRITE</b>, <b>KEY_GRP_WRITE</b>, and
<b>KEY_OTH_WRITE</b>.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="9%">
<p style="margin-top: 1em"><i>search</i></p></td>
<td width="1%"></td>
<td width="68%">
<p style="margin-top: 1em">This permission allows keyrings
to be searched and keys to be found. Searches can recurse
only into nested keyrings that have <i>search</i> permission
set.</p> </td></tr>
</table>
<p style="margin-left:32%; margin-top: 1em">This permission
is required for the <b>KEYCTL_GET_KEYRING_ID</b>,
<b>KEYCTL_JOIN_SESSION_KEYRING</b>, <b>KEYCTL_SEARCH</b>,
and <b>KEYCTL_INVALIDATE</b> operations.</p>
<p style="margin-left:32%; margin-top: 1em">The permission
bits for each category are <b>KEY_POS_SEARCH</b>,
<b>KEY_USR_SEARCH</b>, <b>KEY_GRP_SEARCH</b>, and
<b>KEY_OTH_SEARCH</b>.</p>
<table width="100%" border="0" rules="none" frame="void"
cellspacing="0" cellpadding="0">
<tr valign="top" align="left">
<td width="22%"></td>
<td width="6%">
<p style="margin-top: 1em"><i>link</i></p></td>
<td width="4%"></td>
<td width="68%">
<p style="margin-top: 1em">This permission allows a key or
keyring to be linked to.</p></td></tr>
</table>
<p style="margin-left:32%; margin-top: 1em">This permission
is required for the <b>KEYCTL_LINK</b> and
<b>KEYCTL_SESSION_TO_PARENT</b> operations.</p>
<p style="margin-left:32%; margin-top: 1em">The permission
bits for each category are <b>KEY_POS_LINK</b>,
<b>KEY_USR_LINK</b>, <b>KEY_GRP_LINK</b>, and
<b>KEY_OTH_LINK</b>.</p>
<p style="margin-left:22%;"><i>setattr</i> (since Linux
2.6.15).</p>
<p style="margin-left:32%;">This permission allows a
key’s UID, GID, and permissions mask to be
changed.</p>
<p style="margin-left:32%; margin-top: 1em">This permission
is required for the <b>KEYCTL_REVOKE</b>,
<b>KEYCTL_CHOWN</b>, and <b>KEYCTL_SETPERM</b>
operations.</p>
<p style="margin-left:32%; margin-top: 1em">The permission
bits for each category are <b>KEY_POS_SETATTR</b>,
<b>KEY_USR_SETATTR</b>, <b>KEY_GRP_SETATTR</b>, and
<b>KEY_OTH_SETATTR</b>.</p>
<p style="margin-left:22%; margin-top: 1em">As a
convenience, the following macros are defined as masks for
all of the permission bits in each of the user categories:
<b>KEY_POS_ALL</b>, <b>KEY_USR_ALL</b>, <b>KEY_GRP_ALL</b>,
and <b>KEY_OTH_ALL</b>.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg4</i>
and <i>arg5</i> arguments are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_setperm</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_DESCRIBE</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Obtain a string describing the
attributes of a specified key.</p>
<p style="margin-left:22%; margin-top: 1em">The ID of the
key to be described is specified in <i>arg2</i> (cast to
<i>key_serial_t</i>). The descriptive string is returned in
the buffer pointed to by <i>arg3</i> (cast to
<i>char *</i>); <i>arg4</i> (cast to <i>size_t</i>)
specifies the size of that buffer in bytes.</p>
<p style="margin-left:22%; margin-top: 1em">The key must
grant the caller <i>view</i> permission.</p>
<p style="margin-left:22%; margin-top: 1em">The returned
string is null-terminated and contains the following
information about the key:</p>
<p style="margin-left:28%; margin-top: 1em"><i>type</i>;<i>uid</i>;<i>gid</i>;<i>perm</i>;<i>description</i></p>
<p style="margin-left:22%; margin-top: 1em">In the above,
<i>type</i> and <i>description</i> are strings, <i>uid</i>
and <i>gid</i> are decimal strings, and <i>perm</i> is a
hexadecimal permissions mask. The descriptive string is
written with the following format:</p>
<p style="margin-left:22%; margin-top: 1em">%s;%d;%d;%08x;%s</p>
<p style="margin-left:22%; margin-top: 1em"><b>Note: the
intention is that the descriptive string should be
extensible in future kernel versions</b>. In particular, the
<i>description</i> field will not contain semicolons; it
should be parsed by working backwards from the end of the
string to find the last semicolon. This allows future
semicolon-delimited fields to be inserted in the descriptive
string in the future.</p>
<p style="margin-left:22%; margin-top: 1em">Writing to the
buffer is attempted only when <i>arg3</i> is non-NULL and
the specified buffer size is large enough to accept the
descriptive string (including the terminating null byte). In
order to determine whether the buffer size was too small,
check to see if the return value of the operation is greater
than <i>arg4</i>.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg5</i>
argument is ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_describe</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_CLEAR</b></p>
<p style="margin-left:22%;">Clear the contents of (i.e.,
unlink all keys from) a keyring.</p>
<p style="margin-left:22%; margin-top: 1em">The ID of the
key (which must be of keyring type) is provided in
<i>arg2</i> (cast to <i>key_serial_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have <i>write</i> permission on the keyring.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg3</i>, <i>arg4</i>, and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_clear</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_LINK</b> (since Linux
2.6.10)</p>
<p style="margin-left:22%;">Create a link from a keyring to
a key.</p>
<p style="margin-left:22%; margin-top: 1em">The key to be
linked is specified in <i>arg2</i> (cast to
<i>key_serial_t</i>); the keyring is specified in
<i>arg3</i> (cast to <i>key_serial_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">If a key with
the same type and description is already linked in the
keyring, then that key is displaced from the keyring.</p>
<p style="margin-left:22%; margin-top: 1em">Before creating
the link, the kernel checks the nesting of the keyrings and
returns appropriate errors if the link would produce a cycle
or if the nesting of keyrings would be too deep (The limit
on the nesting of keyrings is determined by the kernel
constant <b>KEYRING_SEARCH_MAX_DEPTH</b>, defined with the
value 6, and is necessary to prevent overflows on the kernel
stack when recursively searching keyrings).</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have <i>link</i> permission on the key being added and
<i>write</i> permission on the keyring.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg4</i> and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_link</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_UNLINK</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Unlink a key from a
keyring.</p>
<p style="margin-left:22%; margin-top: 1em">The ID of the
key to be unlinked is specified in <i>arg2</i> (cast to
<i>key_serial_t</i>); the ID of the keyring from which it is
to be unlinked is specified in <i>arg3</i> (cast to
<i>key_serial_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">If the key is
not currently linked into the keyring, an error results.</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have <i>write</i> permission on the keyring from which the
key is being removed.</p>
<p style="margin-left:22%; margin-top: 1em">If the last
link to a key is removed, then that key will be scheduled
for destruction.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg4</i> and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_unlink</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_SEARCH</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Search for a key in a keyring
tree, returning its ID and optionally linking it to a
specified keyring.</p>
<p style="margin-left:22%; margin-top: 1em">The tree to be
searched is specified by passing the ID of the head keyring
in <i>arg2</i> (cast to <i>key_serial_t</i>). The search is
performed breadth-first and recursively.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg3</i>
and <i>arg4</i> arguments specify the key to be searched
for: <i>arg3</i> (cast as <i>char *</i>) contains the
key type (a null-terminated character string up to 32 bytes
in size, including the terminating null byte), and
<i>arg4</i> (cast as <i>char *</i>) contains the
description of the key (a null-terminated character string
up to 4096 bytes in size, including the terminating null
byte).</p>
<p style="margin-left:22%; margin-top: 1em">The source
keyring must grant <i>search</i> permission to the caller.
When performing the recursive search, only keyrings that
grant the caller <i>search</i> permission will be searched.
Only keys with for which the caller has <i>search</i>
permission can be found.</p>
<p style="margin-left:22%; margin-top: 1em">If the key is
found, its ID is returned as the function result.</p>
<p style="margin-left:22%; margin-top: 1em">If the key is
found and <i>arg5</i> (cast to <i>key_serial_t</i>) is
nonzero, then, subject to the same constraints and rules as
<b>KEYCTL_LINK</b>, the key is linked into the keyring whose
ID is specified in <i>arg5</i>. If the destination keyring
specified in <i>arg5</i> already contains a link to a key
that has the same type and description, then that link will
be displaced by a link to the key found by this
operation.</p>
<p style="margin-left:22%; margin-top: 1em">Instead of
valid existing keyring IDs, the source (<i>arg2</i>) and
destination (<i>arg5</i>) keyrings can be one of the special
keyring IDs listed under <b>KEYCTL_GET_KEYRING_ID</b>.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_search</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_READ</b> (since Linux
2.6.10)</p>
<p style="margin-left:22%;">Read the payload data of a
key.</p>
<p style="margin-left:22%; margin-top: 1em">The ID of the
key whose payload is to be read is specified in <i>arg2</i>
(cast to <i>key_serial_t</i>). This can be the ID of an
existing key, or any of the special key IDs listed for
<b>KEYCTL_GET_KEYRING_ID</b>.</p>
<p style="margin-left:22%; margin-top: 1em">The payload is
placed in the buffer pointed by <i>arg3</i> (cast to
<i>char *</i>); the size of that buffer must be
specified in <i>arg4</i> (cast to <i>size_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">The returned
data will be processed for presentation according to the key
type. For example, a keyring will return an array of
<i>key_serial_t</i> entries representing the IDs of all the
keys that are linked to it. The <i>user</i> key type will
return its data as is. If a key type does not implement this
function, the operation fails with the error
<b>EOPNOTSUPP</b>.</p>
<p style="margin-left:22%; margin-top: 1em">If <i>arg3</i>
is not NULL, as much of the payload data as will fit is
copied into the buffer. On a successful return, the return
value is always the total size of the payload data. To
determine whether the buffer was of sufficient size, check
to see that the return value is less than or equal to the
value supplied in <i>arg4</i>.</p>
<p style="margin-left:22%; margin-top: 1em">The key must
either grant the caller <i>read</i> permission, or grant the
caller <i>search</i> permission when searched for from the
process keyrings (i.e., the key is possessed).</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg5</i>
argument is ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_read</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_INSTANTIATE</b>
(since Linux 2.6.10)</p>
<p style="margin-left:22%;">(Positively) instantiate an
uninstantiated key with a specified payload.</p>
<p style="margin-left:22%; margin-top: 1em">The ID of the
key to be instantiated is provided in <i>arg2</i> (cast to
<i>key_serial_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">The key payload
is specified in the buffer pointed to by <i>arg3</i> (cast
to <i>void *</i>); the size of that buffer is specified
in <i>arg4</i> (cast to <i>size_t</i>).</p>
<p style="margin-left:22%; margin-top: 1em">The payload may
be a NULL pointer and the buffer size may be 0 if this is
supported by the key type (e.g., it is a keyring).</p>
<p style="margin-left:22%; margin-top: 1em">The operation
may be fail if the payload data is in the wrong format or is
otherwise invalid.</p>
<p style="margin-left:22%; margin-top: 1em">If <i>arg5</i>
(cast to <i>key_serial_t</i>) is nonzero, then, subject to
the same constraints and rules as <b>KEYCTL_LINK</b>, the
instantiated key is linked into the keyring whose ID
specified in <i>arg5</i>.</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
have the appropriate authorization key, and once the
uninstantiated key has been instantiated, the authorization
key is revoked. In other words, this operation is available
only from a <b>request-key</b>(8)-style program. See
<b>request_key</b>(2) for an explanation of uninstantiated
keys and key instantiation.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_instantiate</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_NEGATE</b> (since
Linux 2.6.10)</p>
<p style="margin-left:22%;">Negatively instantiate an
uninstantiated key.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is equivalent to the call:</p>
<p style="margin-left:22%; margin-top: 1em">keyctl(KEYCTL_REJECT,
arg2, arg3, ENOKEY, arg4);</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg5</i>
argument is ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_negate</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_SET_REQKEY_KEYRING</b>
(since Linux 2.6.13)</p>
<p style="margin-left:22%;">Set the default keyring to
which implicitly requested keys will be linked for this
thread, and return the previous setting. Implicit key
requests are those made by internal kernel components, such
as can occur when, for example, opening files on an AFS or
NFS filesystem. Setting the default keyring also has an
effect when requesting a key from user space; see
<b>request_key</b>(2) for details.</p>
<p style="margin-left:22%; margin-top: 1em">The <i>arg2</i>
argument (cast to <i>int</i>) should contain one of the
following values, to specify the new default keyring:
<b><br>
KEY_REQKEY_DEFL_NO_CHANGE</b></p>
<p style="margin-left:32%;">Don’t change the default
keyring. This can be used to discover the current default
keyring (without changing it).</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_DEFAULT</b></p>
<p style="margin-left:32%;">This selects the default
behaviour, which is to use the thread-specific keyring if
there is one, otherwise the process-specific keyring if
there is one, otherwise the session keyring if there is one,
otherwise the UID-specific session keyring, otherwise the
user-specific keyring.</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_THREAD_KEYRING</b></p>
<p style="margin-left:32%;">Use the thread-specific keyring
(<b>thread-keyring</b>(7)) as the new default keyring.</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_PROCESS_KEYRING</b></p>
<p style="margin-left:32%;">Use the process-specific
keyring (<b>process-keyring</b>(7)) as the new default
keyring.</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_SESSION_KEYRING</b></p>
<p style="margin-left:32%;">Use the session-specific
keyring (<b>session-keyring</b>(7)) as the new default
keyring.</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_USER_KEYRING</b></p>
<p style="margin-left:32%;">Use the UID-specific keyring
(<b>user-keyring</b>(7)) as the new default keyring.</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_USER_SESSION_KEYRING</b></p>
<p style="margin-left:32%;">Use the UID-specific session
keyring (<b>user-session-keyring</b>(7)) as the new default
keyring.</p>
<p style="margin-left:22%;"><b>KEY_REQKEY_DEFL_REQUESTOR_KEYRING</b>
(since Linux 2.6.29)</p>
<p style="margin-left:32%;">Use the requestor keyring.</p>
<p style="margin-left:22%; margin-top: 1em">All other
values are invalid.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg3</i>, <i>arg4</i>, and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">The setting
controlled by this operation is inherited by the child of
<b>fork</b>(2) and preserved across <b>execve</b>(2).</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_set_reqkey_keyring</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_SET_TIMEOUT</b>
(since Linux 2.6.16)</p>
<p style="margin-left:22%;">Set a timeout on a key.</p>
<p style="margin-left:22%; margin-top: 1em">The ID of the
key is specified in <i>arg2</i> (cast to
<i>key_serial_t</i>). The timeout value, in seconds from the
current time, is specified in <i>arg3</i> (cast to
<i>unsigned int</i>). The timeout is measured against the
realtime clock.</p>
<p style="margin-left:22%; margin-top: 1em">Specifying the
timeout value as 0 clears any existing timeout on the
key.</p>
<p style="margin-left:22%; margin-top: 1em">The
<i>/proc/keys</i> file displays the remaining time until
each key will expire. (This is the only method of
discovering the timeout on a key.)</p>
<p style="margin-left:22%; margin-top: 1em">The caller must
either have the <i>setattr</i> permission on the key or hold
an instantiation authorization token for the key (see
<b>request_key</b>(2)).</p>
<p style="margin-left:22%; margin-top: 1em">The key and any
links to the key will be automatically garbage collected
after the timeout expires. Subsequent attempts to access the
key will then fail with the error <b>EKEYEXPIRED</b>.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
cannot be used to set timeouts on revoked, expired, or
negatively instantiated keys.</p>
<p style="margin-left:22%; margin-top: 1em">The arguments
<i>arg4</i> and <i>arg5</i> are ignored.</p>
<p style="margin-left:22%; margin-top: 1em">This operation
is exposed by <i>libkeyutils</i> via the function
<b>keyctl_set_timeout</b>(3).</p>
<p style="margin-left:11%;"><b>KEYCTL_ASSUME_AUTHORITY</b>