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