aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/security
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/security')
-rw-r--r--Documentation/security/00-INDEX18
-rw-r--r--Documentation/security/SELinux.txt27
-rw-r--r--Documentation/security/Smack.txt541
-rw-r--r--Documentation/security/apparmor.txt39
-rw-r--r--Documentation/security/credentials.txt581
-rw-r--r--Documentation/security/keys-request-key.txt202
-rw-r--r--Documentation/security/keys-trusted-encrypted.txt145
-rw-r--r--Documentation/security/keys.txt1290
-rw-r--r--Documentation/security/tomoyo.txt55
9 files changed, 2898 insertions, 0 deletions
diff --git a/Documentation/security/00-INDEX b/Documentation/security/00-INDEX
new file mode 100644
index 000000000000..19bc49439cac
--- /dev/null
+++ b/Documentation/security/00-INDEX
@@ -0,0 +1,18 @@
100-INDEX
2 - this file.
3SELinux.txt
4 - how to get started with the SELinux security enhancement.
5Smack.txt
6 - documentation on the Smack Linux Security Module.
7apparmor.txt
8 - documentation on the AppArmor security extension.
9credentials.txt
10 - documentation about credentials in Linux.
11keys-request-key.txt
12 - description of the kernel key request service.
13keys-trusted-encrypted.txt
14 - info on the Trusted and Encrypted keys in the kernel key ring service.
15keys.txt
16 - description of the kernel key retention service.
17tomoyo.txt
18 - documentation on the TOMOYO Linux Security Module.
diff --git a/Documentation/security/SELinux.txt b/Documentation/security/SELinux.txt
new file mode 100644
index 000000000000..07eae00f3314
--- /dev/null
+++ b/Documentation/security/SELinux.txt
@@ -0,0 +1,27 @@
1If you want to use SELinux, chances are you will want
2to use the distro-provided policies, or install the
3latest reference policy release from
4 http://oss.tresys.com/projects/refpolicy
5
6However, if you want to install a dummy policy for
7testing, you can do using 'mdp' provided under
8scripts/selinux. Note that this requires the selinux
9userspace to be installed - in particular you will
10need checkpolicy to compile a kernel, and setfiles and
11fixfiles to label the filesystem.
12
13 1. Compile the kernel with selinux enabled.
14 2. Type 'make' to compile mdp.
15 3. Make sure that you are not running with
16 SELinux enabled and a real policy. If
17 you are, reboot with selinux disabled
18 before continuing.
19 4. Run install_policy.sh:
20 cd scripts/selinux
21 sh install_policy.sh
22
23Step 4 will create a new dummy policy valid for your
24kernel, with a single selinux user, role, and type.
25It will compile the policy, will set your SELINUXTYPE to
26dummy in /etc/selinux/config, install the compiled policy
27as 'dummy', and relabel your filesystem.
diff --git a/Documentation/security/Smack.txt b/Documentation/security/Smack.txt
new file mode 100644
index 000000000000..e9dab41c0fe0
--- /dev/null
+++ b/Documentation/security/Smack.txt
@@ -0,0 +1,541 @@
1
2
3 "Good for you, you've decided to clean the elevator!"
4 - The Elevator, from Dark Star
5
6Smack is the the Simplified Mandatory Access Control Kernel.
7Smack is a kernel based implementation of mandatory access
8control that includes simplicity in its primary design goals.
9
10Smack is not the only Mandatory Access Control scheme
11available for Linux. Those new to Mandatory Access Control
12are encouraged to compare Smack with the other mechanisms
13available to determine which is best suited to the problem
14at hand.
15
16Smack consists of three major components:
17 - The kernel
18 - A start-up script and a few modified applications
19 - Configuration data
20
21The kernel component of Smack is implemented as a Linux
22Security Modules (LSM) module. It requires netlabel and
23works best with file systems that support extended attributes,
24although xattr support is not strictly required.
25It is safe to run a Smack kernel under a "vanilla" distribution.
26Smack kernels use the CIPSO IP option. Some network
27configurations are intolerant of IP options and can impede
28access to systems that use them as Smack does.
29
30The startup script etc-init.d-smack should be installed
31in /etc/init.d/smack and should be invoked early in the
32start-up process. On Fedora rc5.d/S02smack is recommended.
33This script ensures that certain devices have the correct
34Smack attributes and loads the Smack configuration if
35any is defined. This script invokes two programs that
36ensure configuration data is properly formatted. These
37programs are /usr/sbin/smackload and /usr/sin/smackcipso.
38The system will run just fine without these programs,
39but it will be difficult to set access rules properly.
40
41A version of "ls" that provides a "-M" option to display
42Smack labels on long listing is available.
43
44A hacked version of sshd that allows network logins by users
45with specific Smack labels is available. This version does
46not work for scp. You must set the /etc/ssh/sshd_config
47line:
48 UsePrivilegeSeparation no
49
50The format of /etc/smack/usr is:
51
52 username smack
53
54In keeping with the intent of Smack, configuration data is
55minimal and not strictly required. The most important
56configuration step is mounting the smackfs pseudo filesystem.
57
58Add this line to /etc/fstab:
59
60 smackfs /smack smackfs smackfsdef=* 0 0
61
62and create the /smack directory for mounting.
63
64Smack uses extended attributes (xattrs) to store file labels.
65The command to set a Smack label on a file is:
66
67 # attr -S -s SMACK64 -V "value" path
68
69NOTE: Smack labels are limited to 23 characters. The attr command
70 does not enforce this restriction and can be used to set
71 invalid Smack labels on files.
72
73If you don't do anything special all users will get the floor ("_")
74label when they log in. If you do want to log in via the hacked ssh
75at other labels use the attr command to set the smack value on the
76home directory and its contents.
77
78You can add access rules in /etc/smack/accesses. They take the form:
79
80 subjectlabel objectlabel access
81
82access is a combination of the letters rwxa which specify the
83kind of access permitted a subject with subjectlabel on an
84object with objectlabel. If there is no rule no access is allowed.
85
86A process can see the smack label it is running with by
87reading /proc/self/attr/current. A privileged process can
88set the process smack by writing there.
89
90Look for additional programs on http://schaufler-ca.com
91
92From the Smack Whitepaper:
93
94The Simplified Mandatory Access Control Kernel
95
96Casey Schaufler
97casey@schaufler-ca.com
98
99Mandatory Access Control
100
101Computer systems employ a variety of schemes to constrain how information is
102shared among the people and services using the machine. Some of these schemes
103allow the program or user to decide what other programs or users are allowed
104access to pieces of data. These schemes are called discretionary access
105control mechanisms because the access control is specified at the discretion
106of the user. Other schemes do not leave the decision regarding what a user or
107program can access up to users or programs. These schemes are called mandatory
108access control mechanisms because you don't have a choice regarding the users
109or programs that have access to pieces of data.
110
111Bell & LaPadula
112
113From the middle of the 1980's until the turn of the century Mandatory Access
114Control (MAC) was very closely associated with the Bell & LaPadula security
115model, a mathematical description of the United States Department of Defense
116policy for marking paper documents. MAC in this form enjoyed a following
117within the Capital Beltway and Scandinavian supercomputer centers but was
118often sited as failing to address general needs.
119
120Domain Type Enforcement
121
122Around the turn of the century Domain Type Enforcement (DTE) became popular.
123This scheme organizes users, programs, and data into domains that are
124protected from each other. This scheme has been widely deployed as a component
125of popular Linux distributions. The administrative overhead required to
126maintain this scheme and the detailed understanding of the whole system
127necessary to provide a secure domain mapping leads to the scheme being
128disabled or used in limited ways in the majority of cases.
129
130Smack
131
132Smack is a Mandatory Access Control mechanism designed to provide useful MAC
133while avoiding the pitfalls of its predecessors. The limitations of Bell &
134LaPadula are addressed by providing a scheme whereby access can be controlled
135according to the requirements of the system and its purpose rather than those
136imposed by an arcane government policy. The complexity of Domain Type
137Enforcement and avoided by defining access controls in terms of the access
138modes already in use.
139
140Smack Terminology
141
142The jargon used to talk about Smack will be familiar to those who have dealt
143with other MAC systems and shouldn't be too difficult for the uninitiated to
144pick up. There are four terms that are used in a specific way and that are
145especially important:
146
147 Subject: A subject is an active entity on the computer system.
148 On Smack a subject is a task, which is in turn the basic unit
149 of execution.
150
151 Object: An object is a passive entity on the computer system.
152 On Smack files of all types, IPC, and tasks can be objects.
153
154 Access: Any attempt by a subject to put information into or get
155 information from an object is an access.
156
157 Label: Data that identifies the Mandatory Access Control
158 characteristics of a subject or an object.
159
160These definitions are consistent with the traditional use in the security
161community. There are also some terms from Linux that are likely to crop up:
162
163 Capability: A task that possesses a capability has permission to
164 violate an aspect of the system security policy, as identified by
165 the specific capability. A task that possesses one or more
166 capabilities is a privileged task, whereas a task with no
167 capabilities is an unprivileged task.
168
169 Privilege: A task that is allowed to violate the system security
170 policy is said to have privilege. As of this writing a task can
171 have privilege either by possessing capabilities or by having an
172 effective user of root.
173
174Smack Basics
175
176Smack is an extension to a Linux system. It enforces additional restrictions
177on what subjects can access which objects, based on the labels attached to
178each of the subject and the object.
179
180Labels
181
182Smack labels are ASCII character strings, one to twenty-three characters in
183length. Single character labels using special characters, that being anything
184other than a letter or digit, are reserved for use by the Smack development
185team. Smack labels are unstructured, case sensitive, and the only operation
186ever performed on them is comparison for equality. Smack labels cannot
187contain unprintable characters, the "/" (slash), the "\" (backslash), the "'"
188(quote) and '"' (double-quote) characters.
189Smack labels cannot begin with a '-', which is reserved for special options.
190
191There are some predefined labels:
192
193 _ Pronounced "floor", a single underscore character.
194 ^ Pronounced "hat", a single circumflex character.
195 * Pronounced "star", a single asterisk character.
196 ? Pronounced "huh", a single question mark character.
197 @ Pronounced "Internet", a single at sign character.
198
199Every task on a Smack system is assigned a label. System tasks, such as
200init(8) and systems daemons, are run with the floor ("_") label. User tasks
201are assigned labels according to the specification found in the
202/etc/smack/user configuration file.
203
204Access Rules
205
206Smack uses the traditional access modes of Linux. These modes are read,
207execute, write, and occasionally append. There are a few cases where the
208access mode may not be obvious. These include:
209
210 Signals: A signal is a write operation from the subject task to
211 the object task.
212 Internet Domain IPC: Transmission of a packet is considered a
213 write operation from the source task to the destination task.
214
215Smack restricts access based on the label attached to a subject and the label
216attached to the object it is trying to access. The rules enforced are, in
217order:
218
219 1. Any access requested by a task labeled "*" is denied.
220 2. A read or execute access requested by a task labeled "^"
221 is permitted.
222 3. A read or execute access requested on an object labeled "_"
223 is permitted.
224 4. Any access requested on an object labeled "*" is permitted.
225 5. Any access requested by a task on an object with the same
226 label is permitted.
227 6. Any access requested that is explicitly defined in the loaded
228 rule set is permitted.
229 7. Any other access is denied.
230
231Smack Access Rules
232
233With the isolation provided by Smack access separation is simple. There are
234many interesting cases where limited access by subjects to objects with
235different labels is desired. One example is the familiar spy model of
236sensitivity, where a scientist working on a highly classified project would be
237able to read documents of lower classifications and anything she writes will
238be "born" highly classified. To accommodate such schemes Smack includes a
239mechanism for specifying rules allowing access between labels.
240
241Access Rule Format
242
243The format of an access rule is:
244
245 subject-label object-label access
246
247Where subject-label is the Smack label of the task, object-label is the Smack
248label of the thing being accessed, and access is a string specifying the sort
249of access allowed. The Smack labels are limited to 23 characters. The access
250specification is searched for letters that describe access modes:
251
252 a: indicates that append access should be granted.
253 r: indicates that read access should be granted.
254 w: indicates that write access should be granted.
255 x: indicates that execute access should be granted.
256
257Uppercase values for the specification letters are allowed as well.
258Access mode specifications can be in any order. Examples of acceptable rules
259are:
260
261 TopSecret Secret rx
262 Secret Unclass R
263 Manager Game x
264 User HR w
265 New Old rRrRr
266 Closed Off -
267
268Examples of unacceptable rules are:
269
270 Top Secret Secret rx
271 Ace Ace r
272 Odd spells waxbeans
273
274Spaces are not allowed in labels. Since a subject always has access to files
275with the same label specifying a rule for that case is pointless. Only
276valid letters (rwxaRWXA) and the dash ('-') character are allowed in
277access specifications. The dash is a placeholder, so "a-r" is the same
278as "ar". A lone dash is used to specify that no access should be allowed.
279
280Applying Access Rules
281
282The developers of Linux rarely define new sorts of things, usually importing
283schemes and concepts from other systems. Most often, the other systems are
284variants of Unix. Unix has many endearing properties, but consistency of
285access control models is not one of them. Smack strives to treat accesses as
286uniformly as is sensible while keeping with the spirit of the underlying
287mechanism.
288
289File system objects including files, directories, named pipes, symbolic links,
290and devices require access permissions that closely match those used by mode
291bit access. To open a file for reading read access is required on the file. To
292search a directory requires execute access. Creating a file with write access
293requires both read and write access on the containing directory. Deleting a
294file requires read and write access to the file and to the containing
295directory. It is possible that a user may be able to see that a file exists
296but not any of its attributes by the circumstance of having read access to the
297containing directory but not to the differently labeled file. This is an
298artifact of the file name being data in the directory, not a part of the file.
299
300IPC objects, message queues, semaphore sets, and memory segments exist in flat
301namespaces and access requests are only required to match the object in
302question.
303
304Process objects reflect tasks on the system and the Smack label used to access
305them is the same Smack label that the task would use for its own access
306attempts. Sending a signal via the kill() system call is a write operation
307from the signaler to the recipient. Debugging a process requires both reading
308and writing. Creating a new task is an internal operation that results in two
309tasks with identical Smack labels and requires no access checks.
310
311Sockets are data structures attached to processes and sending a packet from
312one process to another requires that the sender have write access to the
313receiver. The receiver is not required to have read access to the sender.
314
315Setting Access Rules
316
317The configuration file /etc/smack/accesses contains the rules to be set at
318system startup. The contents are written to the special file /smack/load.
319Rules can be written to /smack/load at any time and take effect immediately.
320For any pair of subject and object labels there can be only one rule, with the
321most recently specified overriding any earlier specification.
322
323The program smackload is provided to ensure data is formatted
324properly when written to /smack/load. This program reads lines
325of the form
326
327 subjectlabel objectlabel mode.
328
329Task Attribute
330
331The Smack label of a process can be read from /proc/<pid>/attr/current. A
332process can read its own Smack label from /proc/self/attr/current. A
333privileged process can change its own Smack label by writing to
334/proc/self/attr/current but not the label of another process.
335
336File Attribute
337
338The Smack label of a filesystem object is stored as an extended attribute
339named SMACK64 on the file. This attribute is in the security namespace. It can
340only be changed by a process with privilege.
341
342Privilege
343
344A process with CAP_MAC_OVERRIDE is privileged.
345
346Smack Networking
347
348As mentioned before, Smack enforces access control on network protocol
349transmissions. Every packet sent by a Smack process is tagged with its Smack
350label. This is done by adding a CIPSO tag to the header of the IP packet. Each
351packet received is expected to have a CIPSO tag that identifies the label and
352if it lacks such a tag the network ambient label is assumed. Before the packet
353is delivered a check is made to determine that a subject with the label on the
354packet has write access to the receiving process and if that is not the case
355the packet is dropped.
356
357CIPSO Configuration
358
359It is normally unnecessary to specify the CIPSO configuration. The default
360values used by the system handle all internal cases. Smack will compose CIPSO
361label values to match the Smack labels being used without administrative
362intervention. Unlabeled packets that come into the system will be given the
363ambient label.
364
365Smack requires configuration in the case where packets from a system that is
366not smack that speaks CIPSO may be encountered. Usually this will be a Trusted
367Solaris system, but there are other, less widely deployed systems out there.
368CIPSO provides 3 important values, a Domain Of Interpretation (DOI), a level,
369and a category set with each packet. The DOI is intended to identify a group
370of systems that use compatible labeling schemes, and the DOI specified on the
371smack system must match that of the remote system or packets will be
372discarded. The DOI is 3 by default. The value can be read from /smack/doi and
373can be changed by writing to /smack/doi.
374
375The label and category set are mapped to a Smack label as defined in
376/etc/smack/cipso.
377
378A Smack/CIPSO mapping has the form:
379
380 smack level [category [category]*]
381
382Smack does not expect the level or category sets to be related in any
383particular way and does not assume or assign accesses based on them. Some
384examples of mappings:
385
386 TopSecret 7
387 TS:A,B 7 1 2
388 SecBDE 5 2 4 6
389 RAFTERS 7 12 26
390
391The ":" and "," characters are permitted in a Smack label but have no special
392meaning.
393
394The mapping of Smack labels to CIPSO values is defined by writing to
395/smack/cipso. Again, the format of data written to this special file
396is highly restrictive, so the program smackcipso is provided to
397ensure the writes are done properly. This program takes mappings
398on the standard input and sends them to /smack/cipso properly.
399
400In addition to explicit mappings Smack supports direct CIPSO mappings. One
401CIPSO level is used to indicate that the category set passed in the packet is
402in fact an encoding of the Smack label. The level used is 250 by default. The
403value can be read from /smack/direct and changed by writing to /smack/direct.
404
405Socket Attributes
406
407There are two attributes that are associated with sockets. These attributes
408can only be set by privileged tasks, but any task can read them for their own
409sockets.
410
411 SMACK64IPIN: The Smack label of the task object. A privileged
412 program that will enforce policy may set this to the star label.
413
414 SMACK64IPOUT: The Smack label transmitted with outgoing packets.
415 A privileged program may set this to match the label of another
416 task with which it hopes to communicate.
417
418Smack Netlabel Exceptions
419
420You will often find that your labeled application has to talk to the outside,
421unlabeled world. To do this there's a special file /smack/netlabel where you can
422add some exceptions in the form of :
423@IP1 LABEL1 or
424@IP2/MASK LABEL2
425
426It means that your application will have unlabeled access to @IP1 if it has
427write access on LABEL1, and access to the subnet @IP2/MASK if it has write
428access on LABEL2.
429
430Entries in the /smack/netlabel file are matched by longest mask first, like in
431classless IPv4 routing.
432
433A special label '@' and an option '-CIPSO' can be used there :
434@ means Internet, any application with any label has access to it
435-CIPSO means standard CIPSO networking
436
437If you don't know what CIPSO is and don't plan to use it, you can just do :
438echo 127.0.0.1 -CIPSO > /smack/netlabel
439echo 0.0.0.0/0 @ > /smack/netlabel
440
441If you use CIPSO on your 192.168.0.0/16 local network and need also unlabeled
442Internet access, you can have :
443echo 127.0.0.1 -CIPSO > /smack/netlabel
444echo 192.168.0.0/16 -CIPSO > /smack/netlabel
445echo 0.0.0.0/0 @ > /smack/netlabel
446
447
448Writing Applications for Smack
449
450There are three sorts of applications that will run on a Smack system. How an
451application interacts with Smack will determine what it will have to do to
452work properly under Smack.
453
454Smack Ignorant Applications
455
456By far the majority of applications have no reason whatever to care about the
457unique properties of Smack. Since invoking a program has no impact on the
458Smack label associated with the process the only concern likely to arise is
459whether the process has execute access to the program.
460
461Smack Relevant Applications
462
463Some programs can be improved by teaching them about Smack, but do not make
464any security decisions themselves. The utility ls(1) is one example of such a
465program.
466
467Smack Enforcing Applications
468
469These are special programs that not only know about Smack, but participate in
470the enforcement of system policy. In most cases these are the programs that
471set up user sessions. There are also network services that provide information
472to processes running with various labels.
473
474File System Interfaces
475
476Smack maintains labels on file system objects using extended attributes. The
477Smack label of a file, directory, or other file system object can be obtained
478using getxattr(2).
479
480 len = getxattr("/", "security.SMACK64", value, sizeof (value));
481
482will put the Smack label of the root directory into value. A privileged
483process can set the Smack label of a file system object with setxattr(2).
484
485 len = strlen("Rubble");
486 rc = setxattr("/foo", "security.SMACK64", "Rubble", len, 0);
487
488will set the Smack label of /foo to "Rubble" if the program has appropriate
489privilege.
490
491Socket Interfaces
492
493The socket attributes can be read using fgetxattr(2).
494
495A privileged process can set the Smack label of outgoing packets with
496fsetxattr(2).
497
498 len = strlen("Rubble");
499 rc = fsetxattr(fd, "security.SMACK64IPOUT", "Rubble", len, 0);
500
501will set the Smack label "Rubble" on packets going out from the socket if the
502program has appropriate privilege.
503
504 rc = fsetxattr(fd, "security.SMACK64IPIN, "*", strlen("*"), 0);
505
506will set the Smack label "*" as the object label against which incoming
507packets will be checked if the program has appropriate privilege.
508
509Administration
510
511Smack supports some mount options:
512
513 smackfsdef=label: specifies the label to give files that lack
514 the Smack label extended attribute.
515
516 smackfsroot=label: specifies the label to assign the root of the
517 file system if it lacks the Smack extended attribute.
518
519 smackfshat=label: specifies a label that must have read access to
520 all labels set on the filesystem. Not yet enforced.
521
522 smackfsfloor=label: specifies a label to which all labels set on the
523 filesystem must have read access. Not yet enforced.
524
525These mount options apply to all file system types.
526
527Smack auditing
528
529If you want Smack auditing of security events, you need to set CONFIG_AUDIT
530in your kernel configuration.
531By default, all denied events will be audited. You can change this behavior by
532writing a single character to the /smack/logging file :
5330 : no logging
5341 : log denied (default)
5352 : log accepted
5363 : log denied & accepted
537
538Events are logged as 'key=value' pairs, for each event you at least will get
539the subjet, the object, the rights requested, the action, the kernel function
540that triggered the event, plus other pairs depending on the type of event
541audited.
diff --git a/Documentation/security/apparmor.txt b/Documentation/security/apparmor.txt
new file mode 100644
index 000000000000..93c1fd7d0635
--- /dev/null
+++ b/Documentation/security/apparmor.txt
@@ -0,0 +1,39 @@
1--- What is AppArmor? ---
2
3AppArmor is MAC style security extension for the Linux kernel. It implements
4a task centered policy, with task "profiles" being created and loaded
5from user space. Tasks on the system that do not have a profile defined for
6them run in an unconfined state which is equivalent to standard Linux DAC
7permissions.
8
9--- How to enable/disable ---
10
11set CONFIG_SECURITY_APPARMOR=y
12
13If AppArmor should be selected as the default security module then
14 set CONFIG_DEFAULT_SECURITY="apparmor"
15 and CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE=1
16
17Build the kernel
18
19If AppArmor is not the default security module it can be enabled by passing
20security=apparmor on the kernel's command line.
21
22If AppArmor is the default security module it can be disabled by passing
23apparmor=0, security=XXXX (where XXX is valid security module), on the
24kernel's command line
25
26For AppArmor to enforce any restrictions beyond standard Linux DAC permissions
27policy must be loaded into the kernel from user space (see the Documentation
28and tools links).
29
30--- Documentation ---
31
32Documentation can be found on the wiki.
33
34--- Links ---
35
36Mailing List - apparmor@lists.ubuntu.com
37Wiki - http://apparmor.wiki.kernel.org/
38User space tools - https://launchpad.net/apparmor
39Kernel module - git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
diff --git a/Documentation/security/credentials.txt b/Documentation/security/credentials.txt
new file mode 100644
index 000000000000..fc0366cbd7ce
--- /dev/null
+++ b/Documentation/security/credentials.txt
@@ -0,0 +1,581 @@
1 ====================
2 CREDENTIALS IN LINUX
3 ====================
4
5By: David Howells <dhowells@redhat.com>
6
7Contents:
8
9 (*) Overview.
10
11 (*) Types of credentials.
12
13 (*) File markings.
14
15 (*) Task credentials.
16
17 - Immutable credentials.
18 - Accessing task credentials.
19 - Accessing another task's credentials.
20 - Altering credentials.
21 - Managing credentials.
22
23 (*) Open file credentials.
24
25 (*) Overriding the VFS's use of credentials.
26
27
28========
29OVERVIEW
30========
31
32There are several parts to the security check performed by Linux when one
33object acts upon another:
34
35 (1) Objects.
36
37 Objects are things in the system that may be acted upon directly by
38 userspace programs. Linux has a variety of actionable objects, including:
39
40 - Tasks
41 - Files/inodes
42 - Sockets
43 - Message queues
44 - Shared memory segments
45 - Semaphores
46 - Keys
47
48 As a part of the description of all these objects there is a set of
49 credentials. What's in the set depends on the type of object.
50
51 (2) Object ownership.
52
53 Amongst the credentials of most objects, there will be a subset that
54 indicates the ownership of that object. This is used for resource
55 accounting and limitation (disk quotas and task rlimits for example).
56
57 In a standard UNIX filesystem, for instance, this will be defined by the
58 UID marked on the inode.
59
60 (3) The objective context.
61
62 Also amongst the credentials of those objects, there will be a subset that
63 indicates the 'objective context' of that object. This may or may not be
64 the same set as in (2) - in standard UNIX files, for instance, this is the
65 defined by the UID and the GID marked on the inode.
66
67 The objective context is used as part of the security calculation that is
68 carried out when an object is acted upon.
69
70 (4) Subjects.
71
72 A subject is an object that is acting upon another object.
73
74 Most of the objects in the system are inactive: they don't act on other
75 objects within the system. Processes/tasks are the obvious exception:
76 they do stuff; they access and manipulate things.
77
78 Objects other than tasks may under some circumstances also be subjects.
79 For instance an open file may send SIGIO to a task using the UID and EUID
80 given to it by a task that called fcntl(F_SETOWN) upon it. In this case,
81 the file struct will have a subjective context too.
82
83 (5) The subjective context.
84
85 A subject has an additional interpretation of its credentials. A subset
86 of its credentials forms the 'subjective context'. The subjective context
87 is used as part of the security calculation that is carried out when a
88 subject acts.
89
90 A Linux task, for example, has the FSUID, FSGID and the supplementary
91 group list for when it is acting upon a file - which are quite separate
92 from the real UID and GID that normally form the objective context of the
93 task.
94
95 (6) Actions.
96
97 Linux has a number of actions available that a subject may perform upon an
98 object. The set of actions available depends on the nature of the subject
99 and the object.
100
101 Actions include reading, writing, creating and deleting files; forking or
102 signalling and tracing tasks.
103
104 (7) Rules, access control lists and security calculations.
105
106 When a subject acts upon an object, a security calculation is made. This
107 involves taking the subjective context, the objective context and the
108 action, and searching one or more sets of rules to see whether the subject
109 is granted or denied permission to act in the desired manner on the
110 object, given those contexts.
111
112 There are two main sources of rules:
113
114 (a) Discretionary access control (DAC):
115
116 Sometimes the object will include sets of rules as part of its
117 description. This is an 'Access Control List' or 'ACL'. A Linux
118 file may supply more than one ACL.
119
120 A traditional UNIX file, for example, includes a permissions mask that
121 is an abbreviated ACL with three fixed classes of subject ('user',
122 'group' and 'other'), each of which may be granted certain privileges
123 ('read', 'write' and 'execute' - whatever those map to for the object
124 in question). UNIX file permissions do not allow the arbitrary
125 specification of subjects, however, and so are of limited use.
126
127 A Linux file might also sport a POSIX ACL. This is a list of rules
128 that grants various permissions to arbitrary subjects.
129
130 (b) Mandatory access control (MAC):
131
132 The system as a whole may have one or more sets of rules that get
133 applied to all subjects and objects, regardless of their source.
134 SELinux and Smack are examples of this.
135
136 In the case of SELinux and Smack, each object is given a label as part
137 of its credentials. When an action is requested, they take the
138 subject label, the object label and the action and look for a rule
139 that says that this action is either granted or denied.
140
141
142====================
143TYPES OF CREDENTIALS
144====================
145
146The Linux kernel supports the following types of credentials:
147
148 (1) Traditional UNIX credentials.
149
150 Real User ID
151 Real Group ID
152
153 The UID and GID are carried by most, if not all, Linux objects, even if in
154 some cases it has to be invented (FAT or CIFS files for example, which are
155 derived from Windows). These (mostly) define the objective context of
156 that object, with tasks being slightly different in some cases.
157
158 Effective, Saved and FS User ID
159 Effective, Saved and FS Group ID
160 Supplementary groups
161
162 These are additional credentials used by tasks only. Usually, an
163 EUID/EGID/GROUPS will be used as the subjective context, and real UID/GID
164 will be used as the objective. For tasks, it should be noted that this is
165 not always true.
166
167 (2) Capabilities.
168
169 Set of permitted capabilities
170 Set of inheritable capabilities
171 Set of effective capabilities
172 Capability bounding set
173
174 These are only carried by tasks. They indicate superior capabilities
175 granted piecemeal to a task that an ordinary task wouldn't otherwise have.
176 These are manipulated implicitly by changes to the traditional UNIX
177 credentials, but can also be manipulated directly by the capset() system
178 call.
179
180 The permitted capabilities are those caps that the process might grant
181 itself to its effective or permitted sets through capset(). This
182 inheritable set might also be so constrained.
183
184 The effective capabilities are the ones that a task is actually allowed to
185 make use of itself.
186
187 The inheritable capabilities are the ones that may get passed across
188 execve().
189
190 The bounding set limits the capabilities that may be inherited across
191 execve(), especially when a binary is executed that will execute as UID 0.
192
193 (3) Secure management flags (securebits).
194
195 These are only carried by tasks. These govern the way the above
196 credentials are manipulated and inherited over certain operations such as
197 execve(). They aren't used directly as objective or subjective
198 credentials.
199
200 (4) Keys and keyrings.
201
202 These are only carried by tasks. They carry and cache security tokens
203 that don't fit into the other standard UNIX credentials. They are for
204 making such things as network filesystem keys available to the file
205 accesses performed by processes, without the necessity of ordinary
206 programs having to know about security details involved.
207
208 Keyrings are a special type of key. They carry sets of other keys and can
209 be searched for the desired key. Each process may subscribe to a number
210 of keyrings:
211
212 Per-thread keying
213 Per-process keyring
214 Per-session keyring
215
216 When a process accesses a key, if not already present, it will normally be
217 cached on one of these keyrings for future accesses to find.
218
219 For more information on using keys, see Documentation/security/keys.txt.
220
221 (5) LSM
222
223 The Linux Security Module allows extra controls to be placed over the
224 operations that a task may do. Currently Linux supports two main
225 alternate LSM options: SELinux and Smack.
226
227 Both work by labelling the objects in a system and then applying sets of
228 rules (policies) that say what operations a task with one label may do to
229 an object with another label.
230
231 (6) AF_KEY
232
233 This is a socket-based approach to credential management for networking
234 stacks [RFC 2367]. It isn't discussed by this document as it doesn't
235 interact directly with task and file credentials; rather it keeps system
236 level credentials.
237
238
239When a file is opened, part of the opening task's subjective context is
240recorded in the file struct created. This allows operations using that file
241struct to use those credentials instead of the subjective context of the task
242that issued the operation. An example of this would be a file opened on a
243network filesystem where the credentials of the opened file should be presented
244to the server, regardless of who is actually doing a read or a write upon it.
245
246
247=============
248FILE MARKINGS
249=============
250
251Files on disk or obtained over the network may have annotations that form the
252objective security context of that file. Depending on the type of filesystem,
253this may include one or more of the following:
254
255 (*) UNIX UID, GID, mode;
256
257 (*) Windows user ID;
258
259 (*) Access control list;
260
261 (*) LSM security label;
262
263 (*) UNIX exec privilege escalation bits (SUID/SGID);
264
265 (*) File capabilities exec privilege escalation bits.
266
267These are compared to the task's subjective security context, and certain
268operations allowed or disallowed as a result. In the case of execve(), the
269privilege escalation bits come into play, and may allow the resulting process
270extra privileges, based on the annotations on the executable file.
271
272
273================
274TASK CREDENTIALS
275================
276
277In Linux, all of a task's credentials are held in (uid, gid) or through
278(groups, keys, LSM security) a refcounted structure of type 'struct cred'.
279Each task points to its credentials by a pointer called 'cred' in its
280task_struct.
281
282Once a set of credentials has been prepared and committed, it may not be
283changed, barring the following exceptions:
284
285 (1) its reference count may be changed;
286
287 (2) the reference count on the group_info struct it points to may be changed;
288
289 (3) the reference count on the security data it points to may be changed;
290
291 (4) the reference count on any keyrings it points to may be changed;
292
293 (5) any keyrings it points to may be revoked, expired or have their security
294 attributes changed; and
295
296 (6) the contents of any keyrings to which it points may be changed (the whole
297 point of keyrings being a shared set of credentials, modifiable by anyone
298 with appropriate access).
299
300To alter anything in the cred struct, the copy-and-replace principle must be
301adhered to. First take a copy, then alter the copy and then use RCU to change
302the task pointer to make it point to the new copy. There are wrappers to aid
303with this (see below).
304
305A task may only alter its _own_ credentials; it is no longer permitted for a
306task to alter another's credentials. This means the capset() system call is no
307longer permitted to take any PID other than the one of the current process.
308Also keyctl_instantiate() and keyctl_negate() functions no longer permit
309attachment to process-specific keyrings in the requesting process as the
310instantiating process may need to create them.
311
312
313IMMUTABLE CREDENTIALS
314---------------------
315
316Once a set of credentials has been made public (by calling commit_creds() for
317example), it must be considered immutable, barring two exceptions:
318
319 (1) The reference count may be altered.
320
321 (2) Whilst the keyring subscriptions of a set of credentials may not be
322 changed, the keyrings subscribed to may have their contents altered.
323
324To catch accidental credential alteration at compile time, struct task_struct
325has _const_ pointers to its credential sets, as does struct file. Furthermore,
326certain functions such as get_cred() and put_cred() operate on const pointers,
327thus rendering casts unnecessary, but require to temporarily ditch the const
328qualification to be able to alter the reference count.
329
330
331ACCESSING TASK CREDENTIALS
332--------------------------
333
334A task being able to alter only its own credentials permits the current process
335to read or replace its own credentials without the need for any form of locking
336- which simplifies things greatly. It can just call:
337
338 const struct cred *current_cred()
339
340to get a pointer to its credentials structure, and it doesn't have to release
341it afterwards.
342
343There are convenience wrappers for retrieving specific aspects of a task's
344credentials (the value is simply returned in each case):
345
346 uid_t current_uid(void) Current's real UID
347 gid_t current_gid(void) Current's real GID
348 uid_t current_euid(void) Current's effective UID
349 gid_t current_egid(void) Current's effective GID
350 uid_t current_fsuid(void) Current's file access UID
351 gid_t current_fsgid(void) Current's file access GID
352 kernel_cap_t current_cap(void) Current's effective capabilities
353 void *current_security(void) Current's LSM security pointer
354 struct user_struct *current_user(void) Current's user account
355
356There are also convenience wrappers for retrieving specific associated pairs of
357a task's credentials:
358
359 void current_uid_gid(uid_t *, gid_t *);
360 void current_euid_egid(uid_t *, gid_t *);
361 void current_fsuid_fsgid(uid_t *, gid_t *);
362
363which return these pairs of values through their arguments after retrieving
364them from the current task's credentials.
365
366
367In addition, there is a function for obtaining a reference on the current
368process's current set of credentials:
369
370 const struct cred *get_current_cred(void);
371
372and functions for getting references to one of the credentials that don't
373actually live in struct cred:
374
375 struct user_struct *get_current_user(void);
376 struct group_info *get_current_groups(void);
377
378which get references to the current process's user accounting structure and
379supplementary groups list respectively.
380
381Once a reference has been obtained, it must be released with put_cred(),
382free_uid() or put_group_info() as appropriate.
383
384
385ACCESSING ANOTHER TASK'S CREDENTIALS
386------------------------------------
387
388Whilst a task may access its own credentials without the need for locking, the
389same is not true of a task wanting to access another task's credentials. It
390must use the RCU read lock and rcu_dereference().
391
392The rcu_dereference() is wrapped by:
393
394 const struct cred *__task_cred(struct task_struct *task);
395
396This should be used inside the RCU read lock, as in the following example:
397
398 void foo(struct task_struct *t, struct foo_data *f)
399 {
400 const struct cred *tcred;
401 ...
402 rcu_read_lock();
403 tcred = __task_cred(t);
404 f->uid = tcred->uid;
405 f->gid = tcred->gid;
406 f->groups = get_group_info(tcred->groups);
407 rcu_read_unlock();
408 ...
409 }
410
411Should it be necessary to hold another task's credentials for a long period of
412time, and possibly to sleep whilst doing so, then the caller should get a
413reference on them using:
414
415 const struct cred *get_task_cred(struct task_struct *task);
416
417This does all the RCU magic inside of it. The caller must call put_cred() on
418the credentials so obtained when they're finished with.
419
420 [*] Note: The result of __task_cred() should not be passed directly to
421 get_cred() as this may race with commit_cred().
422
423There are a couple of convenience functions to access bits of another task's
424credentials, hiding the RCU magic from the caller:
425
426 uid_t task_uid(task) Task's real UID
427 uid_t task_euid(task) Task's effective UID
428
429If the caller is holding the RCU read lock at the time anyway, then:
430
431 __task_cred(task)->uid
432 __task_cred(task)->euid
433
434should be used instead. Similarly, if multiple aspects of a task's credentials
435need to be accessed, RCU read lock should be used, __task_cred() called, the
436result stored in a temporary pointer and then the credential aspects called
437from that before dropping the lock. This prevents the potentially expensive
438RCU magic from being invoked multiple times.
439
440Should some other single aspect of another task's credentials need to be
441accessed, then this can be used:
442
443 task_cred_xxx(task, member)
444
445where 'member' is a non-pointer member of the cred struct. For instance:
446
447 uid_t task_cred_xxx(task, suid);
448
449will retrieve 'struct cred::suid' from the task, doing the appropriate RCU
450magic. This may not be used for pointer members as what they point to may
451disappear the moment the RCU read lock is dropped.
452
453
454ALTERING CREDENTIALS
455--------------------
456
457As previously mentioned, a task may only alter its own credentials, and may not
458alter those of another task. This means that it doesn't need to use any
459locking to alter its own credentials.
460
461To alter the current process's credentials, a function should first prepare a
462new set of credentials by calling:
463
464 struct cred *prepare_creds(void);
465
466this locks current->cred_replace_mutex and then allocates and constructs a
467duplicate of the current process's credentials, returning with the mutex still
468held if successful. It returns NULL if not successful (out of memory).
469
470The mutex prevents ptrace() from altering the ptrace state of a process whilst
471security checks on credentials construction and changing is taking place as
472the ptrace state may alter the outcome, particularly in the case of execve().
473
474The new credentials set should be altered appropriately, and any security
475checks and hooks done. Both the current and the proposed sets of credentials
476are available for this purpose as current_cred() will return the current set
477still at this point.
478
479
480When the credential set is ready, it should be committed to the current process
481by calling:
482
483 int commit_creds(struct cred *new);
484
485This will alter various aspects of the credentials and the process, giving the
486LSM a chance to do likewise, then it will use rcu_assign_pointer() to actually
487commit the new credentials to current->cred, it will release
488current->cred_replace_mutex to allow ptrace() to take place, and it will notify
489the scheduler and others of the changes.
490
491This function is guaranteed to return 0, so that it can be tail-called at the
492end of such functions as sys_setresuid().
493
494Note that this function consumes the caller's reference to the new credentials.
495The caller should _not_ call put_cred() on the new credentials afterwards.
496
497Furthermore, once this function has been called on a new set of credentials,
498those credentials may _not_ be changed further.
499
500
501Should the security checks fail or some other error occur after prepare_creds()
502has been called, then the following function should be invoked:
503
504 void abort_creds(struct cred *new);
505
506This releases the lock on current->cred_replace_mutex that prepare_creds() got
507and then releases the new credentials.
508
509
510A typical credentials alteration function would look something like this:
511
512 int alter_suid(uid_t suid)
513 {
514 struct cred *new;
515 int ret;
516
517 new = prepare_creds();
518 if (!new)
519 return -ENOMEM;
520
521 new->suid = suid;
522 ret = security_alter_suid(new);
523 if (ret < 0) {
524 abort_creds(new);
525 return ret;
526 }
527
528 return commit_creds(new);
529 }
530
531
532MANAGING CREDENTIALS
533--------------------
534
535There are some functions to help manage credentials:
536
537 (*) void put_cred(const struct cred *cred);
538
539 This releases a reference to the given set of credentials. If the
540 reference count reaches zero, the credentials will be scheduled for
541 destruction by the RCU system.
542
543 (*) const struct cred *get_cred(const struct cred *cred);
544
545 This gets a reference on a live set of credentials, returning a pointer to
546 that set of credentials.
547
548 (*) struct cred *get_new_cred(struct cred *cred);
549
550 This gets a reference on a set of credentials that is under construction
551 and is thus still mutable, returning a pointer to that set of credentials.
552
553
554=====================
555OPEN FILE CREDENTIALS
556=====================
557
558When a new file is opened, a reference is obtained on the opening task's
559credentials and this is attached to the file struct as 'f_cred' in place of
560'f_uid' and 'f_gid'. Code that used to access file->f_uid and file->f_gid
561should now access file->f_cred->fsuid and file->f_cred->fsgid.
562
563It is safe to access f_cred without the use of RCU or locking because the
564pointer will not change over the lifetime of the file struct, and nor will the
565contents of the cred struct pointed to, barring the exceptions listed above
566(see the Task Credentials section).
567
568
569=======================================
570OVERRIDING THE VFS'S USE OF CREDENTIALS
571=======================================
572
573Under some circumstances it is desirable to override the credentials used by
574the VFS, and that can be done by calling into such as vfs_mkdir() with a
575different set of credentials. This is done in the following places:
576
577 (*) sys_faccessat().
578
579 (*) do_coredump().
580
581 (*) nfs4recover.c.
diff --git a/Documentation/security/keys-request-key.txt b/Documentation/security/keys-request-key.txt
new file mode 100644
index 000000000000..51987bfecfed
--- /dev/null
+++ b/Documentation/security/keys-request-key.txt
@@ -0,0 +1,202 @@
1 ===================
2 KEY REQUEST SERVICE
3 ===================
4
5The key request service is part of the key retention service (refer to
6Documentation/security/keys.txt). This document explains more fully how
7the requesting algorithm works.
8
9The process starts by either the kernel requesting a service by calling
10request_key*():
11
12 struct key *request_key(const struct key_type *type,
13 const char *description,
14 const char *callout_info);
15
16or:
17
18 struct key *request_key_with_auxdata(const struct key_type *type,
19 const char *description,
20 const char *callout_info,
21 size_t callout_len,
22 void *aux);
23
24or:
25
26 struct key *request_key_async(const struct key_type *type,
27 const char *description,
28 const char *callout_info,
29 size_t callout_len);
30
31or:
32
33 struct key *request_key_async_with_auxdata(const struct key_type *type,
34 const char *description,
35 const char *callout_info,
36 size_t callout_len,
37 void *aux);
38
39Or by userspace invoking the request_key system call:
40
41 key_serial_t request_key(const char *type,
42 const char *description,
43 const char *callout_info,
44 key_serial_t dest_keyring);
45
46The main difference between the access points is that the in-kernel interface
47does not need to link the key to a keyring to prevent it from being immediately
48destroyed. The kernel interface returns a pointer directly to the key, and
49it's up to the caller to destroy the key.
50
51The request_key*_with_auxdata() calls are like the in-kernel request_key*()
52calls, except that they permit auxiliary data to be passed to the upcaller (the
53default is NULL). This is only useful for those key types that define their
54own upcall mechanism rather than using /sbin/request-key.
55
56The two async in-kernel calls may return keys that are still in the process of
57being constructed. The two non-async ones will wait for construction to
58complete first.
59
60The userspace interface links the key to a keyring associated with the process
61to prevent the key from going away, and returns the serial number of the key to
62the caller.
63
64
65The following example assumes that the key types involved don't define their
66own upcall mechanisms. If they do, then those should be substituted for the
67forking and execution of /sbin/request-key.
68
69
70===========
71THE PROCESS
72===========
73
74A request proceeds in the following manner:
75
76 (1) Process A calls request_key() [the userspace syscall calls the kernel
77 interface].
78
79 (2) request_key() searches the process's subscribed keyrings to see if there's
80 a suitable key there. If there is, it returns the key. If there isn't,
81 and callout_info is not set, an error is returned. Otherwise the process
82 proceeds to the next step.
83
84 (3) request_key() sees that A doesn't have the desired key yet, so it creates
85 two things:
86
87 (a) An uninstantiated key U of requested type and description.
88
89 (b) An authorisation key V that refers to key U and notes that process A
90 is the context in which key U should be instantiated and secured, and
91 from which associated key requests may be satisfied.
92
93 (4) request_key() then forks and executes /sbin/request-key with a new session
94 keyring that contains a link to auth key V.
95
96 (5) /sbin/request-key assumes the authority associated with key U.
97
98 (6) /sbin/request-key execs an appropriate program to perform the actual
99 instantiation.
100
101 (7) The program may want to access another key from A's context (say a
102 Kerberos TGT key). It just requests the appropriate key, and the keyring
103 search notes that the session keyring has auth key V in its bottom level.
104
105 This will permit it to then search the keyrings of process A with the
106 UID, GID, groups and security info of process A as if it was process A,
107 and come up with key W.
108
109 (8) The program then does what it must to get the data with which to
110 instantiate key U, using key W as a reference (perhaps it contacts a
111 Kerberos server using the TGT) and then instantiates key U.
112
113 (9) Upon instantiating key U, auth key V is automatically revoked so that it
114 may not be used again.
115
116(10) The program then exits 0 and request_key() deletes key V and returns key
117 U to the caller.
118
119This also extends further. If key W (step 7 above) didn't exist, key W would
120be created uninstantiated, another auth key (X) would be created (as per step
1213) and another copy of /sbin/request-key spawned (as per step 4); but the
122context specified by auth key X will still be process A, as it was in auth key
123V.
124
125This is because process A's keyrings can't simply be attached to
126/sbin/request-key at the appropriate places because (a) execve will discard two
127of them, and (b) it requires the same UID/GID/Groups all the way through.
128
129
130====================================
131NEGATIVE INSTANTIATION AND REJECTION
132====================================
133
134Rather than instantiating a key, it is possible for the possessor of an
135authorisation key to negatively instantiate a key that's under construction.
136This is a short duration placeholder that causes any attempt at re-requesting
137the key whilst it exists to fail with error ENOKEY if negated or the specified
138error if rejected.
139
140This is provided to prevent excessive repeated spawning of /sbin/request-key
141processes for a key that will never be obtainable.
142
143Should the /sbin/request-key process exit anything other than 0 or die on a
144signal, the key under construction will be automatically negatively
145instantiated for a short amount of time.
146
147
148====================
149THE SEARCH ALGORITHM
150====================
151
152A search of any particular keyring proceeds in the following fashion:
153
154 (1) When the key management code searches for a key (keyring_search_aux) it
155 firstly calls key_permission(SEARCH) on the keyring it's starting with,
156 if this denies permission, it doesn't search further.
157
158 (2) It considers all the non-keyring keys within that keyring and, if any key
159 matches the criteria specified, calls key_permission(SEARCH) on it to see
160 if the key is allowed to be found. If it is, that key is returned; if
161 not, the search continues, and the error code is retained if of higher
162 priority than the one currently set.
163
164 (3) It then considers all the keyring-type keys in the keyring it's currently
165 searching. It calls key_permission(SEARCH) on each keyring, and if this
166 grants permission, it recurses, executing steps (2) and (3) on that
167 keyring.
168
169The process stops immediately a valid key is found with permission granted to
170use it. Any error from a previous match attempt is discarded and the key is
171returned.
172
173When search_process_keyrings() is invoked, it performs the following searches
174until one succeeds:
175
176 (1) If extant, the process's thread keyring is searched.
177
178 (2) If extant, the process's process keyring is searched.
179
180 (3) The process's session keyring is searched.
181
182 (4) If the process has assumed the authority associated with a request_key()
183 authorisation key then:
184
185 (a) If extant, the calling process's thread keyring is searched.
186
187 (b) If extant, the calling process's process keyring is searched.
188
189 (c) The calling process's session keyring is searched.
190
191The moment one succeeds, all pending errors are discarded and the found key is
192returned.
193
194Only if all these fail does the whole thing fail with the highest priority
195error. Note that several errors may have come from LSM.
196
197The error priority is:
198
199 EKEYREVOKED > EKEYEXPIRED > ENOKEY
200
201EACCES/EPERM are only returned on a direct search of a specific keyring where
202the basal keyring does not grant Search permission.
diff --git a/Documentation/security/keys-trusted-encrypted.txt b/Documentation/security/keys-trusted-encrypted.txt
new file mode 100644
index 000000000000..8fb79bc1ac4b
--- /dev/null
+++ b/Documentation/security/keys-trusted-encrypted.txt
@@ -0,0 +1,145 @@
1 Trusted and Encrypted Keys
2
3Trusted and Encrypted Keys are two new key types added to the existing kernel
4key ring service. Both of these new types are variable length symmetic keys,
5and in both cases all keys are created in the kernel, and user space sees,
6stores, and loads only encrypted blobs. Trusted Keys require the availability
7of a Trusted Platform Module (TPM) chip for greater security, while Encrypted
8Keys can be used on any system. All user level blobs, are displayed and loaded
9in hex ascii for convenience, and are integrity verified.
10
11Trusted Keys use a TPM both to generate and to seal the keys. Keys are sealed
12under a 2048 bit RSA key in the TPM, and optionally sealed to specified PCR
13(integrity measurement) values, and only unsealed by the TPM, if PCRs and blob
14integrity verifications match. A loaded Trusted Key can be updated with new
15(future) PCR values, so keys are easily migrated to new pcr values, such as
16when the kernel and initramfs are updated. The same key can have many saved
17blobs under different PCR values, so multiple boots are easily supported.
18
19By default, trusted keys are sealed under the SRK, which has the default
20authorization value (20 zeros). This can be set at takeownership time with the
21trouser's utility: "tpm_takeownership -u -z".
22
23Usage:
24 keyctl add trusted name "new keylen [options]" ring
25 keyctl add trusted name "load hex_blob [pcrlock=pcrnum]" ring
26 keyctl update key "update [options]"
27 keyctl print keyid
28
29 options:
30 keyhandle= ascii hex value of sealing key default 0x40000000 (SRK)
31 keyauth= ascii hex auth for sealing key default 0x00...i
32 (40 ascii zeros)
33 blobauth= ascii hex auth for sealed data default 0x00...
34 (40 ascii zeros)
35 blobauth= ascii hex auth for sealed data default 0x00...
36 (40 ascii zeros)
37 pcrinfo= ascii hex of PCR_INFO or PCR_INFO_LONG (no default)
38 pcrlock= pcr number to be extended to "lock" blob
39 migratable= 0|1 indicating permission to reseal to new PCR values,
40 default 1 (resealing allowed)
41
42"keyctl print" returns an ascii hex copy of the sealed key, which is in standard
43TPM_STORED_DATA format. The key length for new keys are always in bytes.
44Trusted Keys can be 32 - 128 bytes (256 - 1024 bits), the upper limit is to fit
45within the 2048 bit SRK (RSA) keylength, with all necessary structure/padding.
46
47Encrypted keys do not depend on a TPM, and are faster, as they use AES for
48encryption/decryption. New keys are created from kernel generated random
49numbers, and are encrypted/decrypted using a specified 'master' key. The
50'master' key can either be a trusted-key or user-key type. The main
51disadvantage of encrypted keys is that if they are not rooted in a trusted key,
52they are only as secure as the user key encrypting them. The master user key
53should therefore be loaded in as secure a way as possible, preferably early in
54boot.
55
56Usage:
57 keyctl add encrypted name "new key-type:master-key-name keylen" ring
58 keyctl add encrypted name "load hex_blob" ring
59 keyctl update keyid "update key-type:master-key-name"
60
61where 'key-type' is either 'trusted' or 'user'.
62
63Examples of trusted and encrypted key usage:
64
65Create and save a trusted key named "kmk" of length 32 bytes:
66
67 $ keyctl add trusted kmk "new 32" @u
68 440502848
69
70 $ keyctl show
71 Session Keyring
72 -3 --alswrv 500 500 keyring: _ses
73 97833714 --alswrv 500 -1 \_ keyring: _uid.500
74 440502848 --alswrv 500 500 \_ trusted: kmk
75
76 $ keyctl print 440502848
77 0101000000000000000001005d01b7e3f4a6be5709930f3b70a743cbb42e0cc95e18e915
78 3f60da455bbf1144ad12e4f92b452f966929f6105fd29ca28e4d4d5a031d068478bacb0b
79 27351119f822911b0a11ba3d3498ba6a32e50dac7f32894dd890eb9ad578e4e292c83722
80 a52e56a097e6a68b3f56f7a52ece0cdccba1eb62cad7d817f6dc58898b3ac15f36026fec
81 d568bd4a706cb60bb37be6d8f1240661199d640b66fb0fe3b079f97f450b9ef9c22c6d5d
82 dd379f0facd1cd020281dfa3c70ba21a3fa6fc2471dc6d13ecf8298b946f65345faa5ef0
83 f1f8fff03ad0acb083725535636addb08d73dedb9832da198081e5deae84bfaf0409c22b
84 e4a8aea2b607ec96931e6f4d4fe563ba
85
86 $ keyctl pipe 440502848 > kmk.blob
87
88Load a trusted key from the saved blob:
89
90 $ keyctl add trusted kmk "load `cat kmk.blob`" @u
91 268728824
92
93 $ keyctl print 268728824
94 0101000000000000000001005d01b7e3f4a6be5709930f3b70a743cbb42e0cc95e18e915
95 3f60da455bbf1144ad12e4f92b452f966929f6105fd29ca28e4d4d5a031d068478bacb0b
96 27351119f822911b0a11ba3d3498ba6a32e50dac7f32894dd890eb9ad578e4e292c83722
97 a52e56a097e6a68b3f56f7a52ece0cdccba1eb62cad7d817f6dc58898b3ac15f36026fec
98 d568bd4a706cb60bb37be6d8f1240661199d640b66fb0fe3b079f97f450b9ef9c22c6d5d
99 dd379f0facd1cd020281dfa3c70ba21a3fa6fc2471dc6d13ecf8298b946f65345faa5ef0
100 f1f8fff03ad0acb083725535636addb08d73dedb9832da198081e5deae84bfaf0409c22b
101 e4a8aea2b607ec96931e6f4d4fe563ba
102
103Reseal a trusted key under new pcr values:
104
105 $ keyctl update 268728824 "update pcrinfo=`cat pcr.blob`"
106 $ keyctl print 268728824
107 010100000000002c0002800093c35a09b70fff26e7a98ae786c641e678ec6ffb6b46d805
108 77c8a6377aed9d3219c6dfec4b23ffe3000001005d37d472ac8a44023fbb3d18583a4f73
109 d3a076c0858f6f1dcaa39ea0f119911ff03f5406df4f7f27f41da8d7194f45c9f4e00f2e
110 df449f266253aa3f52e55c53de147773e00f0f9aca86c64d94c95382265968c354c5eab4
111 9638c5ae99c89de1e0997242edfb0b501744e11ff9762dfd951cffd93227cc513384e7e6
112 e782c29435c7ec2edafaa2f4c1fe6e7a781b59549ff5296371b42133777dcc5b8b971610
113 94bc67ede19e43ddb9dc2baacad374a36feaf0314d700af0a65c164b7082401740e489c9
114 7ef6a24defe4846104209bf0c3eced7fa1a672ed5b125fc9d8cd88b476a658a4434644ef
115 df8ae9a178e9f83ba9f08d10fa47e4226b98b0702f06b3b8
116
117Create and save an encrypted key "evm" using the above trusted key "kmk":
118
119 $ keyctl add encrypted evm "new trusted:kmk 32" @u
120 159771175
121
122 $ keyctl print 159771175
123 trusted:kmk 32 2375725ad57798846a9bbd240de8906f006e66c03af53b1b382dbbc55
124 be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e024717c64
125 5972dcb82ab2dde83376d82b2e3c09ffc
126
127 $ keyctl pipe 159771175 > evm.blob
128
129Load an encrypted key "evm" from saved blob:
130
131 $ keyctl add encrypted evm "load `cat evm.blob`" @u
132 831684262
133
134 $ keyctl print 831684262
135 trusted:kmk 32 2375725ad57798846a9bbd240de8906f006e66c03af53b1b382dbbc55
136 be2a44616e4959430436dc4f2a7a9659aa60bb4652aeb2120f149ed197c564e024717c64
137 5972dcb82ab2dde83376d82b2e3c09ffc
138
139
140The initial consumer of trusted keys is EVM, which at boot time needs a high
141quality symmetric key for HMAC protection of file metadata. The use of a
142trusted key provides strong guarantees that the EVM key has not been
143compromised by a user level problem, and when sealed to specific boot PCR
144values, protects against boot and offline attacks. Other uses for trusted and
145encrypted keys, such as for disk and file encryption are anticipated.
diff --git a/Documentation/security/keys.txt b/Documentation/security/keys.txt
new file mode 100644
index 000000000000..4d75931d2d79
--- /dev/null
+++ b/Documentation/security/keys.txt
@@ -0,0 +1,1290 @@
1 ============================
2 KERNEL KEY RETENTION SERVICE
3 ============================
4
5This service allows cryptographic keys, authentication tokens, cross-domain
6user mappings, and similar to be cached in the kernel for the use of
7filesystems and other kernel services.
8
9Keyrings are permitted; these are a special type of key that can hold links to
10other keys. Processes each have three standard keyring subscriptions that a
11kernel service can search for relevant keys.
12
13The key service can be configured on by enabling:
14
15 "Security options"/"Enable access key retention support" (CONFIG_KEYS)
16
17This document has the following sections:
18
19 - Key overview
20 - Key service overview
21 - Key access permissions
22 - SELinux support
23 - New procfs files
24 - Userspace system call interface
25 - Kernel services
26 - Notes on accessing payload contents
27 - Defining a key type
28 - Request-key callback service
29 - Garbage collection
30
31
32============
33KEY OVERVIEW
34============
35
36In this context, keys represent units of cryptographic data, authentication
37tokens, keyrings, etc.. These are represented in the kernel by struct key.
38
39Each key has a number of attributes:
40
41 - A serial number.
42 - A type.
43 - A description (for matching a key in a search).
44 - Access control information.
45 - An expiry time.
46 - A payload.
47 - State.
48
49
50 (*) Each key is issued a serial number of type key_serial_t that is unique for
51 the lifetime of that key. All serial numbers are positive non-zero 32-bit
52 integers.
53
54 Userspace programs can use a key's serial numbers as a way to gain access
55 to it, subject to permission checking.
56
57 (*) Each key is of a defined "type". Types must be registered inside the
58 kernel by a kernel service (such as a filesystem) before keys of that type
59 can be added or used. Userspace programs cannot define new types directly.
60
61 Key types are represented in the kernel by struct key_type. This defines a
62 number of operations that can be performed on a key of that type.
63
64 Should a type be removed from the system, all the keys of that type will
65 be invalidated.
66
67 (*) Each key has a description. This should be a printable string. The key
68 type provides an operation to perform a match between the description on a
69 key and a criterion string.
70
71 (*) Each key has an owner user ID, a group ID and a permissions mask. These
72 are used to control what a process may do to a key from userspace, and
73 whether a kernel service will be able to find the key.
74
75 (*) Each key can be set to expire at a specific time by the key type's
76 instantiation function. Keys can also be immortal.
77
78 (*) Each key can have a payload. This is a quantity of data that represent the
79 actual "key". In the case of a keyring, this is a list of keys to which
80 the keyring links; in the case of a user-defined key, it's an arbitrary
81 blob of data.
82
83 Having a payload is not required; and the payload can, in fact, just be a
84 value stored in the struct key itself.
85
86 When a key is instantiated, the key type's instantiation function is
87 called with a blob of data, and that then creates the key's payload in
88 some way.
89
90 Similarly, when userspace wants to read back the contents of the key, if
91 permitted, another key type operation will be called to convert the key's
92 attached payload back into a blob of data.
93
94 (*) Each key can be in one of a number of basic states:
95
96 (*) Uninstantiated. The key exists, but does not have any data attached.
97 Keys being requested from userspace will be in this state.
98
99 (*) Instantiated. This is the normal state. The key is fully formed, and
100 has data attached.
101
102 (*) Negative. This is a relatively short-lived state. The key acts as a
103 note saying that a previous call out to userspace failed, and acts as
104 a throttle on key lookups. A negative key can be updated to a normal
105 state.
106
107 (*) Expired. Keys can have lifetimes set. If their lifetime is exceeded,
108 they traverse to this state. An expired key can be updated back to a
109 normal state.
110
111 (*) Revoked. A key is put in this state by userspace action. It can't be
112 found or operated upon (apart from by unlinking it).
113
114 (*) Dead. The key's type was unregistered, and so the key is now useless.
115
116Keys in the last three states are subject to garbage collection. See the
117section on "Garbage collection".
118
119
120====================
121KEY SERVICE OVERVIEW
122====================
123
124The key service provides a number of features besides keys:
125
126 (*) The key service defines two special key types:
127
128 (+) "keyring"
129
130 Keyrings are special keys that contain a list of other keys. Keyring
131 lists can be modified using various system calls. Keyrings should not
132 be given a payload when created.
133
134 (+) "user"
135
136 A key of this type has a description and a payload that are arbitrary
137 blobs of data. These can be created, updated and read by userspace,
138 and aren't intended for use by kernel services.
139
140 (*) Each process subscribes to three keyrings: a thread-specific keyring, a
141 process-specific keyring, and a session-specific keyring.
142
143 The thread-specific keyring is discarded from the child when any sort of
144 clone, fork, vfork or execve occurs. A new keyring is created only when
145 required.
146
147 The process-specific keyring is replaced with an empty one in the child on
148 clone, fork, vfork unless CLONE_THREAD is supplied, in which case it is
149 shared. execve also discards the process's process keyring and creates a
150 new one.
151
152 The session-specific keyring is persistent across clone, fork, vfork and
153 execve, even when the latter executes a set-UID or set-GID binary. A
154 process can, however, replace its current session keyring with a new one
155 by using PR_JOIN_SESSION_KEYRING. It is permitted to request an anonymous
156 new one, or to attempt to create or join one of a specific name.
157
158 The ownership of the thread keyring changes when the real UID and GID of
159 the thread changes.
160
161 (*) Each user ID resident in the system holds two special keyrings: a user
162 specific keyring and a default user session keyring. The default session
163 keyring is initialised with a link to the user-specific keyring.
164
165 When a process changes its real UID, if it used to have no session key, it
166 will be subscribed to the default session key for the new UID.
167
168 If a process attempts to access its session key when it doesn't have one,
169 it will be subscribed to the default for its current UID.
170
171 (*) Each user has two quotas against which the keys they own are tracked. One
172 limits the total number of keys and keyrings, the other limits the total
173 amount of description and payload space that can be consumed.
174
175 The user can view information on this and other statistics through procfs
176 files. The root user may also alter the quota limits through sysctl files
177 (see the section "New procfs files").
178
179 Process-specific and thread-specific keyrings are not counted towards a
180 user's quota.
181
182 If a system call that modifies a key or keyring in some way would put the
183 user over quota, the operation is refused and error EDQUOT is returned.
184
185 (*) There's a system call interface by which userspace programs can create and
186 manipulate keys and keyrings.
187
188 (*) There's a kernel interface by which services can register types and search
189 for keys.
190
191 (*) There's a way for the a search done from the kernel to call back to
192 userspace to request a key that can't be found in a process's keyrings.
193
194 (*) An optional filesystem is available through which the key database can be
195 viewed and manipulated.
196
197
198======================
199KEY ACCESS PERMISSIONS
200======================
201
202Keys have an owner user ID, a group access ID, and a permissions mask. The mask
203has up to eight bits each for possessor, user, group and other access. Only
204six of each set of eight bits are defined. These permissions granted are:
205
206 (*) View
207
208 This permits a key or keyring's attributes to be viewed - including key
209 type and description.
210
211 (*) Read
212
213 This permits a key's payload to be viewed or a keyring's list of linked
214 keys.
215
216 (*) Write
217
218 This permits a key's payload to be instantiated or updated, or it allows a
219 link to be added to or removed from a keyring.
220
221 (*) Search
222
223 This permits keyrings to be searched and keys to be found. Searches can
224 only recurse into nested keyrings that have search permission set.
225
226 (*) Link
227
228 This permits a key or keyring to be linked to. To create a link from a
229 keyring to a key, a process must have Write permission on the keyring and
230 Link permission on the key.
231
232 (*) Set Attribute
233
234 This permits a key's UID, GID and permissions mask to be changed.
235
236For changing the ownership, group ID or permissions mask, being the owner of
237the key or having the sysadmin capability is sufficient.
238
239
240===============
241SELINUX SUPPORT
242===============
243
244The security class "key" has been added to SELinux so that mandatory access
245controls can be applied to keys created within various contexts. This support
246is preliminary, and is likely to change quite significantly in the near future.
247Currently, all of the basic permissions explained above are provided in SELinux
248as well; SELinux is simply invoked after all basic permission checks have been
249performed.
250
251The value of the file /proc/self/attr/keycreate influences the labeling of
252newly-created keys. If the contents of that file correspond to an SELinux
253security context, then the key will be assigned that context. Otherwise, the
254key will be assigned the current context of the task that invoked the key
255creation request. Tasks must be granted explicit permission to assign a
256particular context to newly-created keys, using the "create" permission in the
257key security class.
258
259The default keyrings associated with users will be labeled with the default
260context of the user if and only if the login programs have been instrumented to
261properly initialize keycreate during the login process. Otherwise, they will
262be labeled with the context of the login program itself.
263
264Note, however, that the default keyrings associated with the root user are
265labeled with the default kernel context, since they are created early in the
266boot process, before root has a chance to log in.
267
268The keyrings associated with new threads are each labeled with the context of
269their associated thread, and both session and process keyrings are handled
270similarly.
271
272
273================
274NEW PROCFS FILES
275================
276
277Two files have been added to procfs by which an administrator can find out
278about the status of the key service:
279
280 (*) /proc/keys
281
282 This lists the keys that are currently viewable by the task reading the
283 file, giving information about their type, description and permissions.
284 It is not possible to view the payload of the key this way, though some
285 information about it may be given.
286
287 The only keys included in the list are those that grant View permission to
288 the reading process whether or not it possesses them. Note that LSM
289 security checks are still performed, and may further filter out keys that
290 the current process is not authorised to view.
291
292 The contents of the file look like this:
293
294 SERIAL FLAGS USAGE EXPY PERM UID GID TYPE DESCRIPTION: SUMMARY
295 00000001 I----- 39 perm 1f3f0000 0 0 keyring _uid_ses.0: 1/4
296 00000002 I----- 2 perm 1f3f0000 0 0 keyring _uid.0: empty
297 00000007 I----- 1 perm 1f3f0000 0 0 keyring _pid.1: empty
298 0000018d I----- 1 perm 1f3f0000 0 0 keyring _pid.412: empty
299 000004d2 I--Q-- 1 perm 1f3f0000 32 -1 keyring _uid.32: 1/4
300 000004d3 I--Q-- 3 perm 1f3f0000 32 -1 keyring _uid_ses.32: empty
301 00000892 I--QU- 1 perm 1f000000 0 0 user metal:copper: 0
302 00000893 I--Q-N 1 35s 1f3f0000 0 0 user metal:silver: 0
303 00000894 I--Q-- 1 10h 003f0000 0 0 user metal:gold: 0
304
305 The flags are:
306
307 I Instantiated
308 R Revoked
309 D Dead
310 Q Contributes to user's quota
311 U Under construction by callback to userspace
312 N Negative key
313
314 This file must be enabled at kernel configuration time as it allows anyone
315 to list the keys database.
316
317 (*) /proc/key-users
318
319 This file lists the tracking data for each user that has at least one key
320 on the system. Such data includes quota information and statistics:
321
322 [root@andromeda root]# cat /proc/key-users
323 0: 46 45/45 1/100 13/10000
324 29: 2 2/2 2/100 40/10000
325 32: 2 2/2 2/100 40/10000
326 38: 2 2/2 2/100 40/10000
327
328 The format of each line is
329 <UID>: User ID to which this applies
330 <usage> Structure refcount
331 <inst>/<keys> Total number of keys and number instantiated
332 <keys>/<max> Key count quota
333 <bytes>/<max> Key size quota
334
335
336Four new sysctl files have been added also for the purpose of controlling the
337quota limits on keys:
338
339 (*) /proc/sys/kernel/keys/root_maxkeys
340 /proc/sys/kernel/keys/root_maxbytes
341
342 These files hold the maximum number of keys that root may have and the
343 maximum total number of bytes of data that root may have stored in those
344 keys.
345
346 (*) /proc/sys/kernel/keys/maxkeys
347 /proc/sys/kernel/keys/maxbytes
348
349 These files hold the maximum number of keys that each non-root user may
350 have and the maximum total number of bytes of data that each of those
351 users may have stored in their keys.
352
353Root may alter these by writing each new limit as a decimal number string to
354the appropriate file.
355
356
357===============================
358USERSPACE SYSTEM CALL INTERFACE
359===============================
360
361Userspace can manipulate keys directly through three new syscalls: add_key,
362request_key and keyctl. The latter provides a number of functions for
363manipulating keys.
364
365When referring to a key directly, userspace programs should use the key's
366serial number (a positive 32-bit integer). However, there are some special
367values available for referring to special keys and keyrings that relate to the
368process making the call:
369
370 CONSTANT VALUE KEY REFERENCED
371 ============================== ====== ===========================
372 KEY_SPEC_THREAD_KEYRING -1 thread-specific keyring
373 KEY_SPEC_PROCESS_KEYRING -2 process-specific keyring
374 KEY_SPEC_SESSION_KEYRING -3 session-specific keyring
375 KEY_SPEC_USER_KEYRING -4 UID-specific keyring
376 KEY_SPEC_USER_SESSION_KEYRING -5 UID-session keyring
377 KEY_SPEC_GROUP_KEYRING -6 GID-specific keyring
378 KEY_SPEC_REQKEY_AUTH_KEY -7 assumed request_key()
379 authorisation key
380
381
382The main syscalls are:
383
384 (*) Create a new key of given type, description and payload and add it to the
385 nominated keyring:
386
387 key_serial_t add_key(const char *type, const char *desc,
388 const void *payload, size_t plen,
389 key_serial_t keyring);
390
391 If a key of the same type and description as that proposed already exists
392 in the keyring, this will try to update it with the given payload, or it
393 will return error EEXIST if that function is not supported by the key
394 type. The process must also have permission to write to the key to be able
395 to update it. The new key will have all user permissions granted and no
396 group or third party permissions.
397
398 Otherwise, this will attempt to create a new key of the specified type and
399 description, and to instantiate it with the supplied payload and attach it
400 to the keyring. In this case, an error will be generated if the process
401 does not have permission to write to the keyring.
402
403 The payload is optional, and the pointer can be NULL if not required by
404 the type. The payload is plen in size, and plen can be zero for an empty
405 payload.
406
407 A new keyring can be generated by setting type "keyring", the keyring name
408 as the description (or NULL) and setting the payload to NULL.
409
410 User defined keys can be created by specifying type "user". It is
411 recommended that a user defined key's description by prefixed with a type
412 ID and a colon, such as "krb5tgt:" for a Kerberos 5 ticket granting
413 ticket.
414
415 Any other type must have been registered with the kernel in advance by a
416 kernel service such as a filesystem.
417
418 The ID of the new or updated key is returned if successful.
419
420
421 (*) Search the process's keyrings for a key, potentially calling out to
422 userspace to create it.
423
424 key_serial_t request_key(const char *type, const char *description,
425 const char *callout_info,
426 key_serial_t dest_keyring);
427
428 This function searches all the process's keyrings in the order thread,
429 process, session for a matching key. This works very much like
430 KEYCTL_SEARCH, including the optional attachment of the discovered key to
431 a keyring.
432
433 If a key cannot be found, and if callout_info is not NULL, then
434 /sbin/request-key will be invoked in an attempt to obtain a key. The
435 callout_info string will be passed as an argument to the program.
436
437 See also Documentation/security/keys-request-key.txt.
438
439
440The keyctl syscall functions are:
441
442 (*) Map a special key ID to a real key ID for this process:
443
444 key_serial_t keyctl(KEYCTL_GET_KEYRING_ID, key_serial_t id,
445 int create);
446
447 The special key specified by "id" is looked up (with the key being created
448 if necessary) and the ID of the key or keyring thus found is returned if
449 it exists.
450
451 If the key does not yet exist, the key will be created if "create" is
452 non-zero; and the error ENOKEY will be returned if "create" is zero.
453
454
455 (*) Replace the session keyring this process subscribes to with a new one:
456
457 key_serial_t keyctl(KEYCTL_JOIN_SESSION_KEYRING, const char *name);
458
459 If name is NULL, an anonymous keyring is created attached to the process
460 as its session keyring, displacing the old session keyring.
461
462 If name is not NULL, if a keyring of that name exists, the process
463 attempts to attach it as the session keyring, returning an error if that
464 is not permitted; otherwise a new keyring of that name is created and
465 attached as the session keyring.
466
467 To attach to a named keyring, the keyring must have search permission for
468 the process's ownership.
469
470 The ID of the new session keyring is returned if successful.
471
472
473 (*) Update the specified key:
474
475 long keyctl(KEYCTL_UPDATE, key_serial_t key, const void *payload,
476 size_t plen);
477
478 This will try to update the specified key with the given payload, or it
479 will return error EOPNOTSUPP if that function is not supported by the key
480 type. The process must also have permission to write to the key to be able
481 to update it.
482
483 The payload is of length plen, and may be absent or empty as for
484 add_key().
485
486
487 (*) Revoke a key:
488
489 long keyctl(KEYCTL_REVOKE, key_serial_t key);
490
491 This makes a key unavailable for further operations. Further attempts to
492 use the key will be met with error EKEYREVOKED, and the key will no longer
493 be findable.
494
495
496 (*) Change the ownership of a key:
497
498 long keyctl(KEYCTL_CHOWN, key_serial_t key, uid_t uid, gid_t gid);
499
500 This function permits a key's owner and group ID to be changed. Either one
501 of uid or gid can be set to -1 to suppress that change.
502
503 Only the superuser can change a key's owner to something other than the
504 key's current owner. Similarly, only the superuser can change a key's
505 group ID to something other than the calling process's group ID or one of
506 its group list members.
507
508
509 (*) Change the permissions mask on a key:
510
511 long keyctl(KEYCTL_SETPERM, key_serial_t key, key_perm_t perm);
512
513 This function permits the owner of a key or the superuser to change the
514 permissions mask on a key.
515
516 Only bits the available bits are permitted; if any other bits are set,
517 error EINVAL will be returned.
518
519
520 (*) Describe a key:
521
522 long keyctl(KEYCTL_DESCRIBE, key_serial_t key, char *buffer,
523 size_t buflen);
524
525 This function returns a summary of the key's attributes (but not its
526 payload data) as a string in the buffer provided.
527
528 Unless there's an error, it always returns the amount of data it could
529 produce, even if that's too big for the buffer, but it won't copy more
530 than requested to userspace. If the buffer pointer is NULL then no copy
531 will take place.
532
533 A process must have view permission on the key for this function to be
534 successful.
535
536 If successful, a string is placed in the buffer in the following format:
537
538 <type>;<uid>;<gid>;<perm>;<description>
539
540 Where type and description are strings, uid and gid are decimal, and perm
541 is hexadecimal. A NUL character is included at the end of the string if
542 the buffer is sufficiently big.
543
544 This can be parsed with
545
546 sscanf(buffer, "%[^;];%d;%d;%o;%s", type, &uid, &gid, &mode, desc);
547
548
549 (*) Clear out a keyring:
550
551 long keyctl(KEYCTL_CLEAR, key_serial_t keyring);
552
553 This function clears the list of keys attached to a keyring. The calling
554 process must have write permission on the keyring, and it must be a
555 keyring (or else error ENOTDIR will result).
556
557
558 (*) Link a key into a keyring:
559
560 long keyctl(KEYCTL_LINK, key_serial_t keyring, key_serial_t key);
561
562 This function creates a link from the keyring to the key. The process must
563 have write permission on the keyring and must have link permission on the
564 key.
565
566 Should the keyring not be a keyring, error ENOTDIR will result; and if the
567 keyring is full, error ENFILE will result.
568
569 The link procedure checks the nesting of the keyrings, returning ELOOP if
570 it appears too deep or EDEADLK if the link would introduce a cycle.
571
572 Any links within the keyring to keys that match the new key in terms of
573 type and description will be discarded from the keyring as the new one is
574 added.
575
576
577 (*) Unlink a key or keyring from another keyring:
578
579 long keyctl(KEYCTL_UNLINK, key_serial_t keyring, key_serial_t key);
580
581 This function looks through the keyring for the first link to the
582 specified key, and removes it if found. Subsequent links to that key are
583 ignored. The process must have write permission on the keyring.
584
585 If the keyring is not a keyring, error ENOTDIR will result; and if the key
586 is not present, error ENOENT will be the result.
587
588
589 (*) Search a keyring tree for a key:
590
591 key_serial_t keyctl(KEYCTL_SEARCH, key_serial_t keyring,
592 const char *type, const char *description,
593 key_serial_t dest_keyring);
594
595 This searches the keyring tree headed by the specified keyring until a key
596 is found that matches the type and description criteria. Each keyring is
597 checked for keys before recursion into its children occurs.
598
599 The process must have search permission on the top level keyring, or else
600 error EACCES will result. Only keyrings that the process has search
601 permission on will be recursed into, and only keys and keyrings for which
602 a process has search permission can be matched. If the specified keyring
603 is not a keyring, ENOTDIR will result.
604
605 If the search succeeds, the function will attempt to link the found key
606 into the destination keyring if one is supplied (non-zero ID). All the
607 constraints applicable to KEYCTL_LINK apply in this case too.
608
609 Error ENOKEY, EKEYREVOKED or EKEYEXPIRED will be returned if the search
610 fails. On success, the resulting key ID will be returned.
611
612
613 (*) Read the payload data from a key:
614
615 long keyctl(KEYCTL_READ, key_serial_t keyring, char *buffer,
616 size_t buflen);
617
618 This function attempts to read the payload data from the specified key
619 into the buffer. The process must have read permission on the key to
620 succeed.
621
622 The returned data will be processed for presentation by the key type. For
623 instance, a keyring will return an array of key_serial_t entries
624 representing the IDs of all the keys to which it is subscribed. The user
625 defined key type will return its data as is. If a key type does not
626 implement this function, error EOPNOTSUPP will result.
627
628 As much of the data as can be fitted into the buffer will be copied to
629 userspace if the buffer pointer is not NULL.
630
631 On a successful return, the function will always return the amount of data
632 available rather than the amount copied.
633
634
635 (*) Instantiate a partially constructed key.
636
637 long keyctl(KEYCTL_INSTANTIATE, key_serial_t key,
638 const void *payload, size_t plen,
639 key_serial_t keyring);
640 long keyctl(KEYCTL_INSTANTIATE_IOV, key_serial_t key,
641 const struct iovec *payload_iov, unsigned ioc,
642 key_serial_t keyring);
643
644 If the kernel calls back to userspace to complete the instantiation of a
645 key, userspace should use this call to supply data for the key before the
646 invoked process returns, or else the key will be marked negative
647 automatically.
648
649 The process must have write access on the key to be able to instantiate
650 it, and the key must be uninstantiated.
651
652 If a keyring is specified (non-zero), the key will also be linked into
653 that keyring, however all the constraints applying in KEYCTL_LINK apply in
654 this case too.
655
656 The payload and plen arguments describe the payload data as for add_key().
657
658 The payload_iov and ioc arguments describe the payload data in an iovec
659 array instead of a single buffer.
660
661
662 (*) Negatively instantiate a partially constructed key.
663
664 long keyctl(KEYCTL_NEGATE, key_serial_t key,
665 unsigned timeout, key_serial_t keyring);
666 long keyctl(KEYCTL_REJECT, key_serial_t key,
667 unsigned timeout, unsigned error, key_serial_t keyring);
668
669 If the kernel calls back to userspace to complete the instantiation of a
670 key, userspace should use this call mark the key as negative before the
671 invoked process returns if it is unable to fulfil the request.
672
673 The process must have write access on the key to be able to instantiate
674 it, and the key must be uninstantiated.
675
676 If a keyring is specified (non-zero), the key will also be linked into
677 that keyring, however all the constraints applying in KEYCTL_LINK apply in
678 this case too.
679
680 If the key is rejected, future searches for it will return the specified
681 error code until the rejected key expires. Negating the key is the same
682 as rejecting the key with ENOKEY as the error code.
683
684
685 (*) Set the default request-key destination keyring.
686
687 long keyctl(KEYCTL_SET_REQKEY_KEYRING, int reqkey_defl);
688
689 This sets the default keyring to which implicitly requested keys will be
690 attached for this thread. reqkey_defl should be one of these constants:
691
692 CONSTANT VALUE NEW DEFAULT KEYRING
693 ====================================== ====== =======================
694 KEY_REQKEY_DEFL_NO_CHANGE -1 No change
695 KEY_REQKEY_DEFL_DEFAULT 0 Default[1]
696 KEY_REQKEY_DEFL_THREAD_KEYRING 1 Thread keyring
697 KEY_REQKEY_DEFL_PROCESS_KEYRING 2 Process keyring
698 KEY_REQKEY_DEFL_SESSION_KEYRING 3 Session keyring
699 KEY_REQKEY_DEFL_USER_KEYRING 4 User keyring
700 KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5 User session keyring
701 KEY_REQKEY_DEFL_GROUP_KEYRING 6 Group keyring
702
703 The old default will be returned if successful and error EINVAL will be
704 returned if reqkey_defl is not one of the above values.
705
706 The default keyring can be overridden by the keyring indicated to the
707 request_key() system call.
708
709 Note that this setting is inherited across fork/exec.
710
711 [1] The default is: the thread keyring if there is one, otherwise
712 the process keyring if there is one, otherwise the session keyring if
713 there is one, otherwise the user default session keyring.
714
715
716 (*) Set the timeout on a key.
717
718 long keyctl(KEYCTL_SET_TIMEOUT, key_serial_t key, unsigned timeout);
719
720 This sets or clears the timeout on a key. The timeout can be 0 to clear
721 the timeout or a number of seconds to set the expiry time that far into
722 the future.
723
724 The process must have attribute modification access on a key to set its
725 timeout. Timeouts may not be set with this function on negative, revoked
726 or expired keys.
727
728
729 (*) Assume the authority granted to instantiate a key
730
731 long keyctl(KEYCTL_ASSUME_AUTHORITY, key_serial_t key);
732
733 This assumes or divests the authority required to instantiate the
734 specified key. Authority can only be assumed if the thread has the
735 authorisation key associated with the specified key in its keyrings
736 somewhere.
737
738 Once authority is assumed, searches for keys will also search the
739 requester's keyrings using the requester's security label, UID, GID and
740 groups.
741
742 If the requested authority is unavailable, error EPERM will be returned,
743 likewise if the authority has been revoked because the target key is
744 already instantiated.
745
746 If the specified key is 0, then any assumed authority will be divested.
747
748 The assumed authoritative key is inherited across fork and exec.
749
750
751 (*) Get the LSM security context attached to a key.
752
753 long keyctl(KEYCTL_GET_SECURITY, key_serial_t key, char *buffer,
754 size_t buflen)
755
756 This function returns a string that represents the LSM security context
757 attached to a key in the buffer provided.
758
759 Unless there's an error, it always returns the amount of data it could
760 produce, even if that's too big for the buffer, but it won't copy more
761 than requested to userspace. If the buffer pointer is NULL then no copy
762 will take place.
763
764 A NUL character is included at the end of the string if the buffer is
765 sufficiently big. This is included in the returned count. If no LSM is
766 in force then an empty string will be returned.
767
768 A process must have view permission on the key for this function to be
769 successful.
770
771
772 (*) Install the calling process's session keyring on its parent.
773
774 long keyctl(KEYCTL_SESSION_TO_PARENT);
775
776 This functions attempts to install the calling process's session keyring
777 on to the calling process's parent, replacing the parent's current session
778 keyring.
779
780 The calling process must have the same ownership as its parent, the
781 keyring must have the same ownership as the calling process, the calling
782 process must have LINK permission on the keyring and the active LSM module
783 mustn't deny permission, otherwise error EPERM will be returned.
784
785 Error ENOMEM will be returned if there was insufficient memory to complete
786 the operation, otherwise 0 will be returned to indicate success.
787
788 The keyring will be replaced next time the parent process leaves the
789 kernel and resumes executing userspace.
790
791
792===============
793KERNEL SERVICES
794===============
795
796The kernel services for key management are fairly simple to deal with. They can
797be broken down into two areas: keys and key types.
798
799Dealing with keys is fairly straightforward. Firstly, the kernel service
800registers its type, then it searches for a key of that type. It should retain
801the key as long as it has need of it, and then it should release it. For a
802filesystem or device file, a search would probably be performed during the open
803call, and the key released upon close. How to deal with conflicting keys due to
804two different users opening the same file is left to the filesystem author to
805solve.
806
807To access the key manager, the following header must be #included:
808
809 <linux/key.h>
810
811Specific key types should have a header file under include/keys/ that should be
812used to access that type. For keys of type "user", for example, that would be:
813
814 <keys/user-type.h>
815
816Note that there are two different types of pointers to keys that may be
817encountered:
818
819 (*) struct key *
820
821 This simply points to the key structure itself. Key structures will be at
822 least four-byte aligned.
823
824 (*) key_ref_t
825
826 This is equivalent to a struct key *, but the least significant bit is set
827 if the caller "possesses" the key. By "possession" it is meant that the
828 calling processes has a searchable link to the key from one of its
829 keyrings. There are three functions for dealing with these:
830
831 key_ref_t make_key_ref(const struct key *key,
832 unsigned long possession);
833
834 struct key *key_ref_to_ptr(const key_ref_t key_ref);
835
836 unsigned long is_key_possessed(const key_ref_t key_ref);
837
838 The first function constructs a key reference from a key pointer and
839 possession information (which must be 0 or 1 and not any other value).
840
841 The second function retrieves the key pointer from a reference and the
842 third retrieves the possession flag.
843
844When accessing a key's payload contents, certain precautions must be taken to
845prevent access vs modification races. See the section "Notes on accessing
846payload contents" for more information.
847
848(*) To search for a key, call:
849
850 struct key *request_key(const struct key_type *type,
851 const char *description,
852 const char *callout_info);
853
854 This is used to request a key or keyring with a description that matches
855 the description specified according to the key type's match function. This
856 permits approximate matching to occur. If callout_string is not NULL, then
857 /sbin/request-key will be invoked in an attempt to obtain the key from
858 userspace. In that case, callout_string will be passed as an argument to
859 the program.
860
861 Should the function fail error ENOKEY, EKEYEXPIRED or EKEYREVOKED will be
862 returned.
863
864 If successful, the key will have been attached to the default keyring for
865 implicitly obtained request-key keys, as set by KEYCTL_SET_REQKEY_KEYRING.
866
867 See also Documentation/security/keys-request-key.txt.
868
869
870(*) To search for a key, passing auxiliary data to the upcaller, call:
871
872 struct key *request_key_with_auxdata(const struct key_type *type,
873 const char *description,
874 const void *callout_info,
875 size_t callout_len,
876 void *aux);
877
878 This is identical to request_key(), except that the auxiliary data is
879 passed to the key_type->request_key() op if it exists, and the callout_info
880 is a blob of length callout_len, if given (the length may be 0).
881
882
883(*) A key can be requested asynchronously by calling one of:
884
885 struct key *request_key_async(const struct key_type *type,
886 const char *description,
887 const void *callout_info,
888 size_t callout_len);
889
890 or:
891
892 struct key *request_key_async_with_auxdata(const struct key_type *type,
893 const char *description,
894 const char *callout_info,
895 size_t callout_len,
896 void *aux);
897
898 which are asynchronous equivalents of request_key() and
899 request_key_with_auxdata() respectively.
900
901 These two functions return with the key potentially still under
902 construction. To wait for construction completion, the following should be
903 called:
904
905 int wait_for_key_construction(struct key *key, bool intr);
906
907 The function will wait for the key to finish being constructed and then
908 invokes key_validate() to return an appropriate value to indicate the state
909 of the key (0 indicates the key is usable).
910
911 If intr is true, then the wait can be interrupted by a signal, in which
912 case error ERESTARTSYS will be returned.
913
914
915(*) When it is no longer required, the key should be released using:
916
917 void key_put(struct key *key);
918
919 Or:
920
921 void key_ref_put(key_ref_t key_ref);
922
923 These can be called from interrupt context. If CONFIG_KEYS is not set then
924 the argument will not be parsed.
925
926
927(*) Extra references can be made to a key by calling the following function:
928
929 struct key *key_get(struct key *key);
930
931 These need to be disposed of by calling key_put() when they've been
932 finished with. The key pointer passed in will be returned. If the pointer
933 is NULL or CONFIG_KEYS is not set then the key will not be dereferenced and
934 no increment will take place.
935
936
937(*) A key's serial number can be obtained by calling:
938
939 key_serial_t key_serial(struct key *key);
940
941 If key is NULL or if CONFIG_KEYS is not set then 0 will be returned (in the
942 latter case without parsing the argument).
943
944
945(*) If a keyring was found in the search, this can be further searched by:
946
947 key_ref_t keyring_search(key_ref_t keyring_ref,
948 const struct key_type *type,
949 const char *description)
950
951 This searches the keyring tree specified for a matching key. Error ENOKEY
952 is returned upon failure (use IS_ERR/PTR_ERR to determine). If successful,
953 the returned key will need to be released.
954
955 The possession attribute from the keyring reference is used to control
956 access through the permissions mask and is propagated to the returned key
957 reference pointer if successful.
958
959
960(*) To check the validity of a key, this function can be called:
961
962 int validate_key(struct key *key);
963
964 This checks that the key in question hasn't expired or and hasn't been
965 revoked. Should the key be invalid, error EKEYEXPIRED or EKEYREVOKED will
966 be returned. If the key is NULL or if CONFIG_KEYS is not set then 0 will be
967 returned (in the latter case without parsing the argument).
968
969
970(*) To register a key type, the following function should be called:
971
972 int register_key_type(struct key_type *type);
973
974 This will return error EEXIST if a type of the same name is already
975 present.
976
977
978(*) To unregister a key type, call:
979
980 void unregister_key_type(struct key_type *type);
981
982
983Under some circumstances, it may be desirable to deal with a bundle of keys.
984The facility provides access to the keyring type for managing such a bundle:
985
986 struct key_type key_type_keyring;
987
988This can be used with a function such as request_key() to find a specific
989keyring in a process's keyrings. A keyring thus found can then be searched
990with keyring_search(). Note that it is not possible to use request_key() to
991search a specific keyring, so using keyrings in this way is of limited utility.
992
993
994===================================
995NOTES ON ACCESSING PAYLOAD CONTENTS
996===================================
997
998The simplest payload is just a number in key->payload.value. In this case,
999there's no need to indulge in RCU or locking when accessing the payload.
1000
1001More complex payload contents must be allocated and a pointer to them set in
1002key->payload.data. One of the following ways must be selected to access the
1003data:
1004
1005 (1) Unmodifiable key type.
1006
1007 If the key type does not have a modify method, then the key's payload can
1008 be accessed without any form of locking, provided that it's known to be
1009 instantiated (uninstantiated keys cannot be "found").
1010
1011 (2) The key's semaphore.
1012
1013 The semaphore could be used to govern access to the payload and to control
1014 the payload pointer. It must be write-locked for modifications and would
1015 have to be read-locked for general access. The disadvantage of doing this
1016 is that the accessor may be required to sleep.
1017
1018 (3) RCU.
1019
1020 RCU must be used when the semaphore isn't already held; if the semaphore
1021 is held then the contents can't change under you unexpectedly as the
1022 semaphore must still be used to serialise modifications to the key. The
1023 key management code takes care of this for the key type.
1024
1025 However, this means using:
1026
1027 rcu_read_lock() ... rcu_dereference() ... rcu_read_unlock()
1028
1029 to read the pointer, and:
1030
1031 rcu_dereference() ... rcu_assign_pointer() ... call_rcu()
1032
1033 to set the pointer and dispose of the old contents after a grace period.
1034 Note that only the key type should ever modify a key's payload.
1035
1036 Furthermore, an RCU controlled payload must hold a struct rcu_head for the
1037 use of call_rcu() and, if the payload is of variable size, the length of
1038 the payload. key->datalen cannot be relied upon to be consistent with the
1039 payload just dereferenced if the key's semaphore is not held.
1040
1041
1042===================
1043DEFINING A KEY TYPE
1044===================
1045
1046A kernel service may want to define its own key type. For instance, an AFS
1047filesystem might want to define a Kerberos 5 ticket key type. To do this, it
1048author fills in a key_type struct and registers it with the system.
1049
1050Source files that implement key types should include the following header file:
1051
1052 <linux/key-type.h>
1053
1054The structure has a number of fields, some of which are mandatory:
1055
1056 (*) const char *name
1057
1058 The name of the key type. This is used to translate a key type name
1059 supplied by userspace into a pointer to the structure.
1060
1061
1062 (*) size_t def_datalen
1063
1064 This is optional - it supplies the default payload data length as
1065 contributed to the quota. If the key type's payload is always or almost
1066 always the same size, then this is a more efficient way to do things.
1067
1068 The data length (and quota) on a particular key can always be changed
1069 during instantiation or update by calling:
1070
1071 int key_payload_reserve(struct key *key, size_t datalen);
1072
1073 With the revised data length. Error EDQUOT will be returned if this is not
1074 viable.
1075
1076
1077 (*) int (*vet_description)(const char *description);
1078
1079 This optional method is called to vet a key description. If the key type
1080 doesn't approve of the key description, it may return an error, otherwise
1081 it should return 0.
1082
1083
1084 (*) int (*instantiate)(struct key *key, const void *data, size_t datalen);
1085
1086 This method is called to attach a payload to a key during construction.
1087 The payload attached need not bear any relation to the data passed to this
1088 function.
1089
1090 If the amount of data attached to the key differs from the size in
1091 keytype->def_datalen, then key_payload_reserve() should be called.
1092
1093 This method does not have to lock the key in order to attach a payload.
1094 The fact that KEY_FLAG_INSTANTIATED is not set in key->flags prevents
1095 anything else from gaining access to the key.
1096
1097 It is safe to sleep in this method.
1098
1099
1100 (*) int (*update)(struct key *key, const void *data, size_t datalen);
1101
1102 If this type of key can be updated, then this method should be provided.
1103 It is called to update a key's payload from the blob of data provided.
1104
1105 key_payload_reserve() should be called if the data length might change
1106 before any changes are actually made. Note that if this succeeds, the type
1107 is committed to changing the key because it's already been altered, so all
1108 memory allocation must be done first.
1109
1110 The key will have its semaphore write-locked before this method is called,
1111 but this only deters other writers; any changes to the key's payload must
1112 be made under RCU conditions, and call_rcu() must be used to dispose of
1113 the old payload.
1114
1115 key_payload_reserve() should be called before the changes are made, but
1116 after all allocations and other potentially failing function calls are
1117 made.
1118
1119 It is safe to sleep in this method.
1120
1121
1122 (*) int (*match)(const struct key *key, const void *desc);
1123
1124 This method is called to match a key against a description. It should
1125 return non-zero if the two match, zero if they don't.
1126
1127 This method should not need to lock the key in any way. The type and
1128 description can be considered invariant, and the payload should not be
1129 accessed (the key may not yet be instantiated).
1130
1131 It is not safe to sleep in this method; the caller may hold spinlocks.
1132
1133
1134 (*) void (*revoke)(struct key *key);
1135
1136 This method is optional. It is called to discard part of the payload
1137 data upon a key being revoked. The caller will have the key semaphore
1138 write-locked.
1139
1140 It is safe to sleep in this method, though care should be taken to avoid
1141 a deadlock against the key semaphore.
1142
1143
1144 (*) void (*destroy)(struct key *key);
1145
1146 This method is optional. It is called to discard the payload data on a key
1147 when it is being destroyed.
1148
1149 This method does not need to lock the key to access the payload; it can
1150 consider the key as being inaccessible at this time. Note that the key's
1151 type may have been changed before this function is called.
1152
1153 It is not safe to sleep in this method; the caller may hold spinlocks.
1154
1155
1156 (*) void (*describe)(const struct key *key, struct seq_file *p);
1157
1158 This method is optional. It is called during /proc/keys reading to
1159 summarise a key's description and payload in text form.
1160
1161 This method will be called with the RCU read lock held. rcu_dereference()
1162 should be used to read the payload pointer if the payload is to be
1163 accessed. key->datalen cannot be trusted to stay consistent with the
1164 contents of the payload.
1165
1166 The description will not change, though the key's state may.
1167
1168 It is not safe to sleep in this method; the RCU read lock is held by the
1169 caller.
1170
1171
1172 (*) long (*read)(const struct key *key, char __user *buffer, size_t buflen);
1173
1174 This method is optional. It is called by KEYCTL_READ to translate the
1175 key's payload into something a blob of data for userspace to deal with.
1176 Ideally, the blob should be in the same format as that passed in to the
1177 instantiate and update methods.
1178
1179 If successful, the blob size that could be produced should be returned
1180 rather than the size copied.
1181
1182 This method will be called with the key's semaphore read-locked. This will
1183 prevent the key's payload changing. It is not necessary to use RCU locking
1184 when accessing the key's payload. It is safe to sleep in this method, such
1185 as might happen when the userspace buffer is accessed.
1186
1187
1188 (*) int (*request_key)(struct key_construction *cons, const char *op,
1189 void *aux);
1190
1191 This method is optional. If provided, request_key() and friends will
1192 invoke this function rather than upcalling to /sbin/request-key to operate
1193 upon a key of this type.
1194
1195 The aux parameter is as passed to request_key_async_with_auxdata() and
1196 similar or is NULL otherwise. Also passed are the construction record for
1197 the key to be operated upon and the operation type (currently only
1198 "create").
1199
1200 This method is permitted to return before the upcall is complete, but the
1201 following function must be called under all circumstances to complete the
1202 instantiation process, whether or not it succeeds, whether or not there's
1203 an error:
1204
1205 void complete_request_key(struct key_construction *cons, int error);
1206
1207 The error parameter should be 0 on success, -ve on error. The
1208 construction record is destroyed by this action and the authorisation key
1209 will be revoked. If an error is indicated, the key under construction
1210 will be negatively instantiated if it wasn't already instantiated.
1211
1212 If this method returns an error, that error will be returned to the
1213 caller of request_key*(). complete_request_key() must be called prior to
1214 returning.
1215
1216 The key under construction and the authorisation key can be found in the
1217 key_construction struct pointed to by cons:
1218
1219 (*) struct key *key;
1220
1221 The key under construction.
1222
1223 (*) struct key *authkey;
1224
1225 The authorisation key.
1226
1227
1228============================
1229REQUEST-KEY CALLBACK SERVICE
1230============================
1231
1232To create a new key, the kernel will attempt to execute the following command
1233line:
1234
1235 /sbin/request-key create <key> <uid> <gid> \
1236 <threadring> <processring> <sessionring> <callout_info>
1237
1238<key> is the key being constructed, and the three keyrings are the process
1239keyrings from the process that caused the search to be issued. These are
1240included for two reasons:
1241
1242 (1) There may be an authentication token in one of the keyrings that is
1243 required to obtain the key, eg: a Kerberos Ticket-Granting Ticket.
1244
1245 (2) The new key should probably be cached in one of these rings.
1246
1247This program should set it UID and GID to those specified before attempting to
1248access any more keys. It may then look around for a user specific process to
1249hand the request off to (perhaps a path held in placed in another key by, for
1250example, the KDE desktop manager).
1251
1252The program (or whatever it calls) should finish construction of the key by
1253calling KEYCTL_INSTANTIATE or KEYCTL_INSTANTIATE_IOV, which also permits it to
1254cache the key in one of the keyrings (probably the session ring) before
1255returning. Alternatively, the key can be marked as negative with KEYCTL_NEGATE
1256or KEYCTL_REJECT; this also permits the key to be cached in one of the
1257keyrings.
1258
1259If it returns with the key remaining in the unconstructed state, the key will
1260be marked as being negative, it will be added to the session keyring, and an
1261error will be returned to the key requestor.
1262
1263Supplementary information may be provided from whoever or whatever invoked this
1264service. This will be passed as the <callout_info> parameter. If no such
1265information was made available, then "-" will be passed as this parameter
1266instead.
1267
1268
1269Similarly, the kernel may attempt to update an expired or a soon to expire key
1270by executing:
1271
1272 /sbin/request-key update <key> <uid> <gid> \
1273 <threadring> <processring> <sessionring>
1274
1275In this case, the program isn't required to actually attach the key to a ring;
1276the rings are provided for reference.
1277
1278
1279==================
1280GARBAGE COLLECTION
1281==================
1282
1283Dead keys (for which the type has been removed) will be automatically unlinked
1284from those keyrings that point to them and deleted as soon as possible by a
1285background garbage collector.
1286
1287Similarly, revoked and expired keys will be garbage collected, but only after a
1288certain amount of time has passed. This time is set as a number of seconds in:
1289
1290 /proc/sys/kernel/keys/gc_delay
diff --git a/Documentation/security/tomoyo.txt b/Documentation/security/tomoyo.txt
new file mode 100644
index 000000000000..200a2d37cbc8
--- /dev/null
+++ b/Documentation/security/tomoyo.txt
@@ -0,0 +1,55 @@
1--- What is TOMOYO? ---
2
3TOMOYO is a name-based MAC extension (LSM module) for the Linux kernel.
4
5LiveCD-based tutorials are available at
6http://tomoyo.sourceforge.jp/1.7/1st-step/ubuntu10.04-live/
7http://tomoyo.sourceforge.jp/1.7/1st-step/centos5-live/ .
8Though these tutorials use non-LSM version of TOMOYO, they are useful for you
9to know what TOMOYO is.
10
11--- How to enable TOMOYO? ---
12
13Build the kernel with CONFIG_SECURITY_TOMOYO=y and pass "security=tomoyo" on
14kernel's command line.
15
16Please see http://tomoyo.sourceforge.jp/2.3/ for details.
17
18--- Where is documentation? ---
19
20User <-> Kernel interface documentation is available at
21http://tomoyo.sourceforge.jp/2.3/policy-reference.html .
22
23Materials we prepared for seminars and symposiums are available at
24http://sourceforge.jp/projects/tomoyo/docs/?category_id=532&language_id=1 .
25Below lists are chosen from three aspects.
26
27What is TOMOYO?
28 TOMOYO Linux Overview
29 http://sourceforge.jp/projects/tomoyo/docs/lca2009-takeda.pdf
30 TOMOYO Linux: pragmatic and manageable security for Linux
31 http://sourceforge.jp/projects/tomoyo/docs/freedomhectaipei-tomoyo.pdf
32 TOMOYO Linux: A Practical Method to Understand and Protect Your Own Linux Box
33 http://sourceforge.jp/projects/tomoyo/docs/PacSec2007-en-no-demo.pdf
34
35What can TOMOYO do?
36 Deep inside TOMOYO Linux
37 http://sourceforge.jp/projects/tomoyo/docs/lca2009-kumaneko.pdf
38 The role of "pathname based access control" in security.
39 http://sourceforge.jp/projects/tomoyo/docs/lfj2008-bof.pdf
40
41History of TOMOYO?
42 Realities of Mainlining
43 http://sourceforge.jp/projects/tomoyo/docs/lfj2008.pdf
44
45--- What is future plan? ---
46
47We believe that inode based security and name based security are complementary
48and both should be used together. But unfortunately, so far, we cannot enable
49multiple LSM modules at the same time. We feel sorry that you have to give up
50SELinux/SMACK/AppArmor etc. when you want to use TOMOYO.
51
52We hope that LSM becomes stackable in future. Meanwhile, you can use non-LSM
53version of TOMOYO, available at http://tomoyo.sourceforge.jp/1.7/ .
54LSM version of TOMOYO is a subset of non-LSM version of TOMOYO. We are planning
55to port non-LSM version's functionalities to LSM versions.