]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man7/keyrings.7
pipe.2, sigaltstack.2, abort.3, signal.7: Place SH sections in standard order
[thirdparty/man-pages.git] / man7 / keyrings.7
1 .\"
2 .\" Copyright (C) 2014 Red Hat, Inc. All Rights Reserved.
3 .\" Written by David Howells (dhowells@redhat.com)
4 .\" and Copyright (C) 2016 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" %%%LICENSE_START(GPLv2+_SW_ONEPARA)
7 .\" This program is free software; you can redistribute it and/or
8 .\" modify it under the terms of the GNU General Public License
9 .\" as published by the Free Software Foundation; either version
10 .\" 2 of the License, or (at your option) any later version.
11 .\" %%%LICENSE_END
12 .\"
13 .TH KEYRINGS 7 2020-04-11 Linux "Linux Programmer's Manual"
14 .SH NAME
15 keyrings \- in-kernel key management and retention facility
16 .SH DESCRIPTION
17 The Linux key-management facility
18 is primarily a way for various kernel components
19 to retain or cache security data,
20 authentication keys, encryption keys, and other data in the kernel.
21 .PP
22 System call interfaces are provided so that user-space programs can manage
23 those objects and also use the facility for their own purposes; see
24 .BR add_key (2),
25 .BR request_key (2),
26 and
27 .BR keyctl (2).
28 .PP
29 A library and some user-space utilities are provided to allow access to the
30 facility.
31 See
32 .BR keyctl (1),
33 .BR keyctl (3),
34 and
35 .BR keyutils (7)
36 for more information.
37 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
38 .SS Keys
39 A key has the following attributes:
40 .TP
41 Serial number (ID)
42 This is a unique integer handle by which a key is referred to in system calls.
43 The serial number is sometimes synonymously referred as the key ID.
44 Programmatically, key serial numbers are represented using the type
45 .IR key_serial_t .
46 .TP
47 Type
48 A key's type defines what sort of data can be held in the key,
49 how the proposed content of the key will be parsed,
50 and how the payload will be used.
51 .IP
52 There are a number of general-purpose types available, plus some specialist
53 types defined by specific kernel components.
54 .TP
55 Description (name)
56 The key description is a printable string that is used as the search term
57 for the key (in conjunction with the key type) as well as a display name.
58 During searches, the description may be partially matched or exactly matched.
59 .TP
60 Payload (data)
61 The payload is the actual content of a key.
62 This is usually set when a key is created,
63 but it is possible for the kernel to upcall to user space to finish the
64 instantiation of a key if that key wasn't already known to the kernel
65 when it was requested.
66 For further details, see
67 .BR request_key (2).
68 .IP
69 A key's payload can be read and updated if the key type supports it and if
70 suitable permission is granted to the caller.
71 .TP
72 Access rights
73 Much as files do,
74 each key has an owning user ID, an owning group ID, and a security label.
75 Each key also has a set of permissions,
76 though there are more than for a normal UNIX file,
77 and there is an additional category\(empossessor\(embeyond the usual user,
78 group, and other (see
79 .IR Possession ,
80 below).
81 .IP
82 Note that keys are quota controlled, since they require unswappable kernel
83 memory.
84 The owning user ID specifies whose quota is to be debited.
85 .TP
86 Expiration time
87 Each key can have an expiration time set.
88 When that time is reached,
89 the key is marked as being expired and accesses to it fail with the error
90 .BR EKEYEXPIRED .
91 If not deleted, updated, or replaced, then, after a set amount of time,
92 an expired key is automatically removed (garbage collected)
93 along with all links to it,
94 and attempts to access the key fail with the error
95 .BR ENOKEY .
96 .TP
97 Reference count
98 Each key has a reference count.
99 Keys are referenced by keyrings, by currently active users,
100 and by a process's credentials.
101 When the reference count reaches zero,
102 the key is scheduled for garbage collection.
103 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
104 .SS Key types
105 The kernel provides several basic types of key:
106 .TP
107 .I """keyring"""
108 '\" Note that keyrings use different fields in struct key in order to store
109 '\" their data - index_key instead of type/description and name_link/keys
110 '\" instead of payload.
111 Keyrings are special keys which store a set of links
112 to other keys (including other keyrings),
113 analogous to a directory holding links to files.
114 The main purpose of a keyring is to prevent other keys from
115 being garbage collected because nothing refers to them.
116 .IP
117 Keyrings with descriptions (names)
118 that begin with a period (\(aq.\(aq) are reserved to the implementation.
119 .TP
120 .I """user"""
121 This is a general-purpose key type.
122 The key is kept entirely within kernel memory.
123 The payload may be read and updated by user-space applications.
124 .IP
125 The payload for keys of this type is a blob of arbitrary data
126 of up to 32,767 bytes.
127 .IP
128 The description may be any valid string, though it is preferred that it
129 start with a colon-delimited prefix representing the service
130 to which the key is of interest
131 (for instance
132 .IR """afs:mykey""" ).
133 .TP
134 .IR """logon""" " (since Linux 3.3)"
135 .\" commit 9f6ed2ca257fa8650b876377833e6f14e272848b
136 This key type is essentially the same as
137 .IR """user""" ,
138 but it does not provide reading (i.e., the
139 .BR keyctl (2)
140 .BR KEYCTL_READ
141 operation),
142 meaning that the key payload is never visible from user space.
143 This is suitable for storing username-password pairs
144 that should not be readable from user space.
145 .IP
146 The description of a
147 .IR """logon"""
148 key
149 .I must
150 start with a non-empty colon-delimited prefix whose purpose
151 is to identify the service to which the key belongs.
152 (Note that this differs from keys of the
153 .IR """user"""
154 type, where the inclusion of a prefix is recommended but is not enforced.)
155 .TP
156 .IR """big_key""" " (since Linux 3.13)"
157 .\" commit ab3c3587f8cda9083209a61dbe3a4407d3cada10
158 This key type is similar to the
159 .I """user"""
160 key type, but it may hold a payload of up to 1\ MiB in size.
161 This key type is useful for purposes such as holding Kerberos ticket caches.
162 .IP
163 The payload data may be stored in a tmpfs filesystem,
164 rather than in kernel memory,
165 if the data size exceeds the overhead of storing the data in the filesystem.
166 (Storing the data in a filesystem requires filesystem structures
167 to be allocated in the kernel.
168 The size of these structures determines the size threshold
169 above which the tmpfs storage method is used.)
170 Since Linux 4.8,
171 .\" commit 13100a72f40f5748a04017e0ab3df4cf27c809ef
172 the payload data is encrypted when stored in tmpfs,
173 thereby preventing it from being written unencrypted into swap space.
174 .PP
175 There are more specialized key types available also,
176 but they aren't discussed here
177 because they aren't intended for normal user-space use.
178 .PP
179 Key type names
180 that begin with a period (\(aq.\(aq) are reserved to the implementation.
181 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
182 .SS Keyrings
183 As previously mentioned, keyrings are a special type of key that contain
184 links to other keys (which may include other keyrings).
185 Keys may be linked to by multiple keyrings.
186 Keyrings may be considered as analogous to UNIX directories
187 where each directory contains a set of hard links to files.
188 .PP
189 Various operations (system calls) may be applied only to keyrings:
190 .IP Adding
191 A key may be added to a keyring by system calls that create keys.
192 This prevents the new key from being immediately deleted
193 when the system call releases its last reference to the key.
194 .IP Linking
195 A link may be added to a keyring pointing to a key that is already known,
196 provided this does not create a self-referential cycle.
197 .IP Unlinking
198 A link may be removed from a keyring.
199 When the last link to a key is removed,
200 that key will be scheduled for deletion by the garbage collector.
201 .IP Clearing
202 All the links may be removed from a keyring.
203 .IP Searching
204 A keyring may be considered the root of a tree or subtree in which keyrings
205 form the branches and non-keyrings the leaves.
206 This tree may be searched for a key matching
207 a particular type and description.
208 .PP
209 See
210 .BR keyctl_clear (3),
211 .BR keyctl_link (3),
212 .BR keyctl_search (3),
213 and
214 .BR keyctl_unlink (3)
215 for more information.
216 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
217 .SS Anchoring keys
218 To prevent a key from being garbage collected,
219 it must be anchored to keep its reference count elevated
220 when it is not in active use by the kernel.
221 .PP
222 Keyrings are used to anchor other keys:
223 each link is a reference on a key.
224 Note that keyrings themselves are just keys and
225 are also subject to the same anchoring requirement to prevent
226 them being garbage collected.
227 .PP
228 The kernel makes available a number of anchor keyrings.
229 Note that some of these keyrings will be created only when first accessed.
230 .TP
231 Process keyrings
232 Process credentials themselves reference keyrings with specific semantics.
233 These keyrings are pinned as long as the set of credentials exists,
234 which is usually as long as the process exists.
235 .IP
236 There are three keyrings with different inheritance/sharing rules:
237 the
238 .BR session-keyring (7)
239 (inherited and shared by all child processes),
240 the
241 .BR process-keyring (7)
242 (shared by all threads in a process) and
243 the
244 .BR thread-keyring (7)
245 (specific to a particular thread).
246 .IP
247 As an alternative to using the actual keyring IDs,
248 in calls to
249 .BR add_key (2),
250 .BR keyctl (2),
251 and
252 .BR request_key (2),
253 the special keyring values
254 .BR KEY_SPEC_SESSION_KEYRING ,
255 .BR KEY_SPEC_PROCESS_KEYRING ,
256 and
257 .BR KEY_SPEC_THREAD_KEYRING
258 can be used to refer to the caller's own instances of these keyrings.
259 .TP
260 User keyrings
261 Each UID known to the kernel has a record that contains two keyrings: the
262 .BR user-keyring (7)
263 and the
264 .BR user-session-keyring (7).
265 These exist for as long as the UID record in the kernel exists.
266 .IP
267 As an alternative to using the actual keyring IDs,
268 in calls to
269 .BR add_key (2),
270 .BR keyctl (2),
271 and
272 .BR request_key (2),
273 the special keyring values
274 .BR KEY_SPEC_USER_KEYRING
275 and
276 .BR KEY_SPEC_USER_SESSION_KEYRING
277 can be used to refer to the caller's own instances of these keyrings.
278 .IP
279 A link to the user keyring is placed in a new session keyring by
280 .BR pam_keyinit (8)
281 when a new login session is initiated.
282 .TP
283 Persistent keyrings
284 There is a
285 .BR persistent-keyring (7)
286 available to each UID known to the system.
287 It may persist beyond the life of the UID record previously mentioned,
288 but has an expiration time set such that it is automatically cleaned up
289 after a set time.
290 The persistent keyring permits, for example,
291 .BR cron (8)
292 scripts to use credentials that are left in the persistent keyring after
293 the user logs out.
294 .IP
295 Note that the expiration time of the persistent keyring
296 is reset every time the persistent key is requested.
297 .TP
298 Special keyrings
299 There are special keyrings owned by the kernel that can anchor keys
300 for special purposes.
301 An example of this is the \fIsystem keyring\fR used for holding
302 encryption keys for module signature verification.
303 .IP
304 These special keyrings are usually closed to direct alteration
305 by user space.
306 .PP
307 An originally planned "group keyring",
308 for storing keys associated with each GID known to the kernel,
309 is not so far implemented, is unlikely to be implemented.
310 Nevertheless, the constant
311 .BR KEY_SPEC_GROUP_KEYRING
312 has been defined for this keyring.
313 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
314 .SS Possession
315 The concept of possession is important to understanding the keyrings
316 security model.
317 Whether a thread possesses a key is determined by the following rules:
318 .IP (1) 4
319 Any key or keyring that does not grant
320 .I search
321 permission to the caller is ignored in all the following rules.
322 .IP (2)
323 A thread possesses its
324 .BR session-keyring (7),
325 .BR process-keyring (7),
326 and
327 .BR thread-keyring (7)
328 directly because those keyrings are referred to by its credentials.
329 .IP (3)
330 If a keyring is possessed, then any key it links to is also possessed.
331 .IP (4)
332 If any key a keyring links to is itself a keyring, then rule (3) applies
333 recursively.
334 .IP (5)
335 If a process is upcalled from the kernel to instantiate a key (see
336 .BR request_key (2)),
337 then it also possesses the requester's keyrings as in
338 rule (1) as if it were the requester.
339 .PP
340 Note that possession is not a fundamental property of a key,
341 but must rather be calculated each time the key is needed.
342 .PP
343 Possession is designed to allow set-user-ID programs run from, say
344 a user's shell to access the user's keys.
345 Granting permissions to the key possessor while denying them
346 to the key owner and group allows the prevention of access to keys
347 on the basis of UID and GID matches.
348 .PP
349 When it creates the session keyring,
350 .BR pam_keyinit (8)
351 adds a link to the
352 .BR user-keyring (7),
353 thus making the user keyring and anything it contains possessed by default.
354 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
355 .SS Access rights
356 Each key has the following security-related attributes:
357 .IP * 3
358 The owning user ID
359 .IP *
360 The ID of a group that is permitted to access the key
361 .IP *
362 A security label
363 .IP *
364 A permissions mask
365 .PP
366 The permissions mask contains four sets of rights.
367 The first three sets are mutually exclusive.
368 One and only one will be in force for a particular access check.
369 In order of descending priority, these three sets are:
370 .IP \fIuser\fR
371 The set specifies the rights granted
372 if the key's user ID matches the caller's filesystem user ID.
373 .IP \fIgroup\fR
374 The set specifies the rights granted
375 if the user ID didn't match and the key's group ID matches the caller's
376 filesystem GID or one of the caller's supplementary group IDs.
377 .IP \fIother\fR
378 The set specifies the rights granted
379 if neither the key's user ID nor group ID matched.
380 .PP
381 The fourth set of rights is:
382 .IP \fIpossessor\fR
383 The set specifies the rights granted
384 if a key is determined to be possessed by the caller.
385 .PP
386 The complete set of rights for a key is the union of whichever
387 of the first three sets is applicable plus the fourth set
388 if the key is possessed.
389 .PP
390 The set of rights that may be granted in each of the four masks
391 is as follows:
392 .TP
393 .I view
394 The attributes of the key may be read.
395 This includes the type,
396 description, and access rights (excluding the security label).
397 .TP
398 .I read
399 For a key: the payload of the key may be read.
400 For a keyring: the list of serial numbers (keys) to
401 which the keyring has links may be read.
402 .TP
403 .I write
404 The payload of the key may be updated and the key may be revoked.
405 For a keyring, links may be added to or removed from the keyring,
406 and the keyring may be cleared completely (all links are removed),
407 .TP
408 .I search
409 For a key (or a keyring): the key may be found by a search.
410 For a keyring: keys and keyrings that are linked to by the
411 keyring may be searched.
412 .TP
413 .I link
414 Links may be created from keyrings to the key.
415 The initial link to a key that is established when the key is created
416 doesn't require this permission.
417 .TP
418 .I setattr
419 The ownership details and security label of the key may be changed,
420 the key's expiration time may be set, and the key may be revoked.
421 .PP
422 In addition to access rights, any active Linux Security Module (LSM) may
423 prevent access to a key if its policy so dictates.
424 A key may be given a
425 security label or other attribute by the LSM;
426 this label is retrievable via
427 .BR keyctl_get_security (3).
428 .PP
429 See
430 .BR keyctl_chown (3),
431 .BR keyctl_describe (3),
432 .BR keyctl_get_security (3),
433 .BR keyctl_setperm (3),
434 and
435 .BR selinux (8)
436 for more information.
437 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
438 .SS Searching for keys
439 One of the key features of the Linux key-management facility
440 is the ability to find a key that a process is retaining.
441 The
442 .BR request_key (2)
443 system call is the primary point of
444 access for user-space applications to find a key.
445 (Internally, the kernel has something similar available
446 for use by internal components that make use of keys.)
447 .PP
448 The search algorithm works as follows:
449 .IP (1) 4
450 The process keyrings are searched in the following order: the thread
451 .BR thread-keyring (7)
452 if it exists, the
453 .BR process-keyring (7)
454 if it exists, and then either the
455 .BR session-keyring (7)
456 if it exists or the
457 .BR user-session-keyring (7)
458 if that exists.
459 .IP (2)
460 If the caller was a process that was invoked by the
461 .BR request_key (2)
462 upcall mechanism, then the keyrings of the original caller of
463 .BR request_key (2)
464 will be searched as well.
465 .IP (3)
466 The search of a keyring tree is in breadth-first order:
467 each keyring is searched first for a match,
468 then the keyrings referred to by that keyring are searched.
469 .IP (4)
470 If a matching key is found that is valid,
471 then the search terminates and that key is returned.
472 .IP (5)
473 If a matching key is found that has an error state attached,
474 that error state is noted and the search continues.
475 .IP (6)
476 If no valid matching key is found,
477 then the first noted error state is returned; otherwise, an
478 .B ENOKEY
479 error is returned.
480 .PP
481 It is also possible to search a specific keyring, in which case only steps
482 (3) to (6) apply.
483 .PP
484 See
485 .BR request_key (2)
486 and
487 .BR keyctl_search (3)
488 for more information.
489 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
490 .SS On-demand key creation
491 If a key cannot be found,
492 .BR request_key (2)
493 will, if given a
494 .I callout_info
495 argument, create a new key and then upcall to user space to
496 instantiate the key.
497 This allows keys to be created on an as-needed basis.
498 .PP
499 Typically,
500 this will involve the kernel creating a new process that executes the
501 .BR request-key (8)
502 program, which will then execute the appropriate handler based on its
503 configuration.
504 .PP
505 The handler is passed a special authorization key that allows it
506 and only it to instantiate the new key.
507 This is also used to permit searches performed by the
508 handler program to also search the requester's keyrings.
509 .PP
510 See
511 .BR request_key (2),
512 .BR keyctl_assume_authority (3),
513 .BR keyctl_instantiate (3),
514 .BR keyctl_negate (3),
515 .BR keyctl_reject (3),
516 .BR request-key (8),
517 and
518 .BR request-key.conf (5)
519 for more information.
520 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
521 .SS /proc files
522 The kernel provides various
523 .I /proc
524 files that expose information about keys or define limits on key usage.
525 .TP
526 .IR /proc/keys " (since Linux 2.6.10)"
527 This file exposes a list of the keys for which the reading thread has
528 .I view
529 permission, providing various information about each key.
530 The thread need not possess the key for it to be visible in this file.
531 .\" David Howells, Dec 2016 linux-man@:
532 .\" This [The thread need not possess the key for it to be visible in
533 .\" this file.] is correct. See proc_keys_show() in security/keys/proc.c:
534 .\"
535 .\" rc = key_task_permission(key_ref, ctx.cred, KEY_NEED_VIEW);
536 .\" if (rc < 0)
537 .\" return 0;
538 .\"
539 .\"Possibly it shouldn't be, but for now it is.
540 .\"
541 .IP
542 The only keys included in the list are those that grant
543 .I view
544 permission to the reading process
545 (regardless of whether or not it possesses them).
546 LSM security checks are still performed,
547 and may filter out further keys that the process is not authorized to view.
548 .IP
549 An example of the data that one might see in this file
550 (with the columns numbered for easy reference below)
551 is the following:
552 .IP
553 .in 0n
554 .EX
555 (1) (2) (3)(4) (5) (6) (7) (8) (9)
556 009a2028 I--Q--- 1 perm 3f010000 1000 1000 user krb_ccache:primary: 12
557 1806c4ba I--Q--- 1 perm 3f010000 1000 1000 keyring _pid: 2
558 25d3a08f I--Q--- 1 perm 1f3f0000 1000 65534 keyring _uid_ses.1000: 1
559 28576bd8 I--Q--- 3 perm 3f010000 1000 1000 keyring _krb: 1
560 2c546d21 I--Q--- 190 perm 3f030000 1000 1000 keyring _ses: 2
561 30a4e0be I------ 4 2d 1f030000 1000 65534 keyring _persistent.1000: 1
562 32100fab I--Q--- 4 perm 1f3f0000 1000 65534 keyring _uid.1000: 2
563 32a387ea I--Q--- 1 perm 3f010000 1000 1000 keyring _pid: 2
564 3ce56aea I--Q--- 5 perm 3f030000 1000 1000 keyring _ses: 1
565 .EE
566 .in
567 .IP
568 The fields shown in each line of this file are as follows:
569 .RS
570 .TP
571 ID (1)
572 The ID (serial number) of the key, expressed in hexadecimal.
573 .TP
574 Flags (2)
575 A set of flags describing the state of the key:
576 .RS
577 .IP I 4
578 .\" KEY_FLAG_INSTANTIATED
579 The key has been instantiated.
580 .IP R
581 .\" KEY_FLAG_REVOKED
582 The key has been revoked.
583 .IP D
584 .\" KEY_FLAG_DEAD
585 The key is dead (i.e., the key type has been unregistered).
586 .\" unregister_key_type() in the kernel source
587 (A key may be briefly in this state during garbage collection.)
588 .IP Q
589 .\" KEY_FLAG_IN_QUOTA
590 The key contributes to the user's quota.
591 .IP U
592 .\" KEY_FLAG_USER_CONSTRUCT
593 The key is under construction via a callback to user space;
594 see
595 .BR request-key (2).
596 .IP N
597 .\" KEY_FLAG_NEGATIVE
598 The key is negatively instantiated.
599 .IP i
600 .\" KEY_FLAG_INVALIDATED
601 The key has been invalidated.
602 .RE
603 .TP
604 Usage (3)
605 This is a count of the number of kernel credential
606 structures that are pinning the key
607 (approximately: the number of threads and open file references
608 that refer to this key).
609 .TP
610 Timeout (4)
611 The amount of time until the key will expire,
612 expressed in human-readable form (weeks, days, hours, minutes, and seconds).
613 The string
614 .I perm
615 here means that the key is permanent (no timeout).
616 The string
617 .I expd
618 means that the key has already expired,
619 but has not yet been garbage collected.
620 .TP
621 Permissions (5)
622 The key permissions, expressed as four hexadecimal bytes containing,
623 from left to right, the possessor, user, group, and other permissions.
624 Within each byte, the permission bits are as follows:
625 .IP
626 .PD 0
627 .RS 12
628 .TP
629 0x01
630 .I view
631 .TP
632 Ox02
633 .I read
634 .TP
635 0x04
636 .I write
637 .TP
638 0x08
639 .I search
640 .TP
641 0x10
642 .I link
643 .TP
644 0x20
645 .I setattr
646 .RE
647 .PD
648 .TP
649 UID (6)
650 The user ID of the key owner.
651 .TP
652 GID (7)
653 The group ID of the key.
654 The value \-1 here means that the key has no group ID;
655 this can occur in certain circumstances for keys created by the kernel.
656 .TP
657 Type (8)
658 The key type (user, keyring, etc.)
659 .TP
660 Description (9)
661 The key description (name).
662 This field contains descriptive information about the key.
663 For most key types, it has the form
664 .IP
665 name[: extra\-info]
666 .IP
667 The
668 .I name
669 subfield is the key's description (name).
670 The optional
671 .I extra\-info
672 field provides some further information about the key.
673 The information that appears here depends on the key type, as follows:
674 .RS
675 .TP
676 .IR """user""" " and " """logon"""
677 The size in bytes of the key payload (expressed in decimal).
678 .TP
679 .IR """keyring"""
680 The number of keys linked to the keyring,
681 or the string
682 .IR empty
683 if there are no keys linked to the keyring.
684 .TP
685 .IR """big_key"""
686 The payload size in bytes, followed either by the string
687 .IR [file] ,
688 if the key payload exceeds the threshold that means that the
689 payload is stored in a (swappable)
690 .BR tmpfs (5)
691 filesystem,
692 or otherwise the string
693 .IR [buff] ,
694 indicating that the key is small enough to reside in kernel memory.
695 .RE
696 .IP
697 For the
698 .IR """.request_key_auth"""
699 key type
700 (authorization key; see
701 .BR request_key (2)),
702 the description field has the form shown in the following example:
703 .IP
704 key:c9a9b19 pid:28880 ci:10
705 .IP
706 The three subfields are as follows:
707 .RS
708 .TP
709 .I key
710 The hexadecimal ID of the key being instantiated in the requesting program.
711 .TP
712 .I pid
713 The PID of the requesting program.
714 .TP
715 .I ci
716 The length of the callout data with which the requested key should
717 be instantiated
718 (i.e., the length of the payload associated with the authorization key).
719 .RE
720 .RE
721 .TP
722 .IR /proc/key-users " (since Linux 2.6.10)"
723 This file lists various information for each user ID that
724 has at least one key on the system.
725 An example of the data that one might see in this file is the following:
726 .IP
727 .in +4n
728 .EX
729 0: 10 9/9 2/1000000 22/25000000
730 42: 9 9/9 8/200 106/20000
731 1000: 11 11/11 10/200 271/20000
732 .EE
733 .in
734 .IP
735 The fields shown in each line are as follows:
736 .RS
737 .TP
738 .I uid
739 The user ID.
740 .TP
741 .I usage
742 This is a kernel-internal usage count for the kernel structure
743 used to record key users.
744 .TP
745 .IR nkeys / nikeys
746 The total number of keys owned by the user,
747 and the number of those keys that have been instantiated.
748 .TP
749 .IR qnkeys / maxkeys
750 The number of keys owned by the user,
751 and the maximum number of keys that the user may own.
752 .TP
753 .IR qnbytes / maxbytes
754 The number of bytes consumed in payloads of the keys owned by this user,
755 and the upper limit on the number of bytes in key payloads for that user.
756 .RE
757 .TP
758 .IR /proc/sys/kernel/keys/gc_delay " (since Linux 2.6.32)"
759 .\" commit 5d135440faf7db8d566de0c6fab36b16cf9cfc3b
760 The value in this file specifies the interval, in seconds,
761 after which revoked and expired keys will be garbage collected.
762 The purpose of having such an interval is so that there is a window
763 of time where user space can see an error (respectively
764 .BR EKEYREVOKED
765 and
766 .BR EKEYEXPIRED )
767 that indicates what happened to the key.
768 .IP
769 The default value in this file is 300 (i.e., 5 minutes).
770 .TP
771 .IR /proc/sys/kernel/keys/persistent_keyring_expiry " (since Linux 3.13)"
772 .\" commit f36f8c75ae2e7d4da34f4c908cebdb4aa42c977e
773 This file defines an interval, in seconds,
774 to which the persistent keyring's expiration timer is reset
775 each time the keyring is accessed (via
776 .BR keyctl_get_persistent (3)
777 or the
778 .BR keyctl (2)
779 .B KEYCTL_GET_PERSISTENT
780 operation.)
781 .IP
782 The default value in this file is 259200 (i.e., 3 days).
783 .PP
784 The following files (which are writable by privileged processes)
785 are used to enforce quotas on the number of keys
786 and number of bytes of data that can be stored in key payloads:
787 .TP
788 .IR /proc/sys/kernel/keys/maxbytes " (since Linux 2.6.26)"
789 .\" commit 0b77f5bfb45c13e1e5142374f9d6ca75292252a4
790 .\" Previously: KEYQUOTA_MAX_BYTES 10000
791 This is the maximum number of bytes of data that a nonroot user
792 can hold in the payloads of the keys owned by the user.
793 .IP
794 The default value in this file is 20,000.
795 .TP
796 .IR /proc/sys/kernel/keys/maxkeys " (since Linux 2.6.26)"
797 .\" commit 0b77f5bfb45c13e1e5142374f9d6ca75292252a4
798 .\" Previously: KEYQUOTA_MAX_KEYS 100
799 This is the maximum number of keys that a nonroot user may own.
800 .IP
801 The default value in this file is 200.
802 .TP
803 .IR /proc/sys/kernel/keys/root_maxbytes " (since Linux 2.6.26)"
804 This is the maximum number of bytes of data that the root user
805 (UID 0 in the root user namespace)
806 can hold in the payloads of the keys owned by root.
807 .IP
808 .\"738c5d190f6540539a04baf36ce21d46b5da04bd
809 The default value in this file is 25,000,000 (20,000 before Linux 3.17).
810 .\" commit 0b77f5bfb45c13e1e5142374f9d6ca75292252a4
811 .TP
812 .IR /proc/sys/kernel/keys/root_maxkeys " (since Linux 2.6.26)"
813 .\" commit 0b77f5bfb45c13e1e5142374f9d6ca75292252a4
814 This is the maximum number of keys that the root user
815 (UID 0 in the root user namespace)
816 may own.
817 .IP
818 .\"738c5d190f6540539a04baf36ce21d46b5da04bd
819 The default value in this file is 1,000,000 (200 before Linux 3.17).
820 .PP
821 With respect to keyrings,
822 note that each link in a keyring consumes 4 bytes of the keyring payload.
823 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
824 .SS Users
825 The Linux key-management facility has a number of users and usages,
826 but is not limited to those that already exist.
827 .PP
828 In-kernel users of this facility include:
829 .TP
830 Network filesystems - DNS
831 The kernel uses the upcall mechanism provided by the keys to upcall to
832 user space to do DNS lookups and then to cache the results.
833 .TP
834 AF_RXRPC and kAFS - Authentication
835 The AF_RXRPC network protocol and the in-kernel AFS filesystem
836 use keys to store the ticket needed to do secured or encrypted traffic.
837 These are then looked up by
838 network operations on AF_RXRPC and filesystem operations on kAFS.
839 .TP
840 NFS - User ID mapping
841 The NFS filesystem uses keys to store mappings of
842 foreign user IDs to local user IDs.
843 .TP
844 CIFS - Password
845 The CIFS filesystem uses keys to store passwords for accessing remote shares.
846 .TP
847 Module verification
848 The kernel build process can be made to cryptographically sign modules.
849 That signature is then checked when a module is loaded.
850 .PP
851 User-space users of this facility include:
852 .TP
853 Kerberos key storage
854 The MIT Kerberos 5 facility (libkrb5) can use keys to store authentication
855 tokens which can be made to be automatically cleaned up a set time after
856 the user last uses them,
857 but until then permits them to hang around after the user
858 has logged out so that
859 .BR cron (8)
860 scripts can use them.
861 .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
862 .SH SEE ALSO
863 .ad l
864 .nh
865 .BR keyctl (1),
866 .BR add_key (2),
867 .BR keyctl (2),
868 .BR request_key (2),
869 .BR keyctl (3),
870 .BR keyutils (7),
871 .BR persistent\-keyring (7),
872 .BR process\-keyring (7),
873 .BR session\-keyring (7),
874 .BR thread\-keyring (7),
875 .BR user\-keyring (7),
876 .BR user\-session\-keyring (7),
877 .BR pam_keyinit (8),
878 .BR request-key (8)
879 .PP
880 The kernel source files
881 .IR Documentation/crypto/asymmetric-keys.txt
882 and under
883 .IR Documentation/security/keys
884 (or, before Linux 4.13, in the file
885 .IR Documentation/security/keys.txt ).