aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/security
diff options
context:
space:
mode:
authorMauro Carvalho Chehab <mchehab+samsung@kernel.org>2019-04-19 20:39:29 -0400
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2019-07-15 10:03:01 -0400
commit4d3beaa06d3536aa8968d1828a66bd5ccb5036ac (patch)
tree3bc769db2b6214f2e7fa298e915a313225949a21 /Documentation/security
parente7751617dd0599ceadf4221cb08e04307b00aa1f (diff)
docs: security: move some books to it and update
The following files belong to security: Documentation/security/LSM.rst -> Documentation/security/lsm-development.rst Documentation/lsm.txt -> Documentation/security/lsm.rst Documentation/SAK.txt -> Documentation/security/sak.rst Documentation/siphash.txt -> Documentation/security/siphash.rst Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'Documentation/security')
-rw-r--r--Documentation/security/index.rst5
-rw-r--r--Documentation/security/lsm-development.rst (renamed from Documentation/security/LSM.rst)0
-rw-r--r--Documentation/security/lsm.rst201
-rw-r--r--Documentation/security/sak.rst91
-rw-r--r--Documentation/security/siphash.rst189
-rw-r--r--Documentation/security/tpm/index.rst1
-rw-r--r--Documentation/security/tpm/xen-tpmfront.rst2
7 files changed, 486 insertions, 3 deletions
diff --git a/Documentation/security/index.rst b/Documentation/security/index.rst
index aad6d92ffe31..fc503dd689a7 100644
--- a/Documentation/security/index.rst
+++ b/Documentation/security/index.rst
@@ -8,7 +8,10 @@ Security Documentation
8 credentials 8 credentials
9 IMA-templates 9 IMA-templates
10 keys/index 10 keys/index
11 LSM 11 lsm
12 lsm-development
13 sak
12 SCTP 14 SCTP
13 self-protection 15 self-protection
16 siphash
14 tpm/index 17 tpm/index
diff --git a/Documentation/security/LSM.rst b/Documentation/security/lsm-development.rst
index 31d92bc5fdd2..31d92bc5fdd2 100644
--- a/Documentation/security/LSM.rst
+++ b/Documentation/security/lsm-development.rst
diff --git a/Documentation/security/lsm.rst b/Documentation/security/lsm.rst
new file mode 100644
index 000000000000..ad4dfd020e0d
--- /dev/null
+++ b/Documentation/security/lsm.rst
@@ -0,0 +1,201 @@
1========================================================
2Linux Security Modules: General Security Hooks for Linux
3========================================================
4
5:Author: Stephen Smalley
6:Author: Timothy Fraser
7:Author: Chris Vance
8
9.. note::
10
11 The APIs described in this book are outdated.
12
13Introduction
14============
15
16In March 2001, the National Security Agency (NSA) gave a presentation
17about Security-Enhanced Linux (SELinux) at the 2.5 Linux Kernel Summit.
18SELinux is an implementation of flexible and fine-grained
19nondiscretionary access controls in the Linux kernel, originally
20implemented as its own particular kernel patch. Several other security
21projects (e.g. RSBAC, Medusa) have also developed flexible access
22control architectures for the Linux kernel, and various projects have
23developed particular access control models for Linux (e.g. LIDS, DTE,
24SubDomain). Each project has developed and maintained its own kernel
25patch to support its security needs.
26
27In response to the NSA presentation, Linus Torvalds made a set of
28remarks that described a security framework he would be willing to
29consider for inclusion in the mainstream Linux kernel. He described a
30general framework that would provide a set of security hooks to control
31operations on kernel objects and a set of opaque security fields in
32kernel data structures for maintaining security attributes. This
33framework could then be used by loadable kernel modules to implement any
34desired model of security. Linus also suggested the possibility of
35migrating the Linux capabilities code into such a module.
36
37The Linux Security Modules (LSM) project was started by WireX to develop
38such a framework. LSM is a joint development effort by several security
39projects, including Immunix, SELinux, SGI and Janus, and several
40individuals, including Greg Kroah-Hartman and James Morris, to develop a
41Linux kernel patch that implements this framework. The patch is
42currently tracking the 2.4 series and is targeted for integration into
43the 2.5 development series. This technical report provides an overview
44of the framework and the example capabilities security module provided
45by the LSM kernel patch.
46
47LSM Framework
48=============
49
50The LSM kernel patch provides a general kernel framework to support
51security modules. In particular, the LSM framework is primarily focused
52on supporting access control modules, although future development is
53likely to address other security needs such as auditing. By itself, the
54framework does not provide any additional security; it merely provides
55the infrastructure to support security modules. The LSM kernel patch
56also moves most of the capabilities logic into an optional security
57module, with the system defaulting to the traditional superuser logic.
58This capabilities module is discussed further in
59`LSM Capabilities Module <#cap>`__.
60
61The LSM kernel patch adds security fields to kernel data structures and
62inserts calls to hook functions at critical points in the kernel code to
63manage the security fields and to perform access control. It also adds
64functions for registering and unregistering security modules, and adds a
65general :c:func:`security()` system call to support new system calls
66for security-aware applications.
67
68The LSM security fields are simply ``void*`` pointers. For process and
69program execution security information, security fields were added to
70:c:type:`struct task_struct <task_struct>` and
71:c:type:`struct linux_binprm <linux_binprm>`. For filesystem
72security information, a security field was added to :c:type:`struct
73super_block <super_block>`. For pipe, file, and socket security
74information, security fields were added to :c:type:`struct inode
75<inode>` and :c:type:`struct file <file>`. For packet and
76network device security information, security fields were added to
77:c:type:`struct sk_buff <sk_buff>` and :c:type:`struct
78net_device <net_device>`. For System V IPC security information,
79security fields were added to :c:type:`struct kern_ipc_perm
80<kern_ipc_perm>` and :c:type:`struct msg_msg
81<msg_msg>`; additionally, the definitions for :c:type:`struct
82msg_msg <msg_msg>`, struct msg_queue, and struct shmid_kernel
83were moved to header files (``include/linux/msg.h`` and
84``include/linux/shm.h`` as appropriate) to allow the security modules to
85use these definitions.
86
87Each LSM hook is a function pointer in a global table, security_ops.
88This table is a :c:type:`struct security_operations
89<security_operations>` structure as defined by
90``include/linux/security.h``. Detailed documentation for each hook is
91included in this header file. At present, this structure consists of a
92collection of substructures that group related hooks based on the kernel
93object (e.g. task, inode, file, sk_buff, etc) as well as some top-level
94hook function pointers for system operations. This structure is likely
95to be flattened in the future for performance. The placement of the hook
96calls in the kernel code is described by the "called:" lines in the
97per-hook documentation in the header file. The hook calls can also be
98easily found in the kernel code by looking for the string
99"security_ops->".
100
101Linus mentioned per-process security hooks in his original remarks as a
102possible alternative to global security hooks. However, if LSM were to
103start from the perspective of per-process hooks, then the base framework
104would have to deal with how to handle operations that involve multiple
105processes (e.g. kill), since each process might have its own hook for
106controlling the operation. This would require a general mechanism for
107composing hooks in the base framework. Additionally, LSM would still
108need global hooks for operations that have no process context (e.g.
109network input operations). Consequently, LSM provides global security
110hooks, but a security module is free to implement per-process hooks
111(where that makes sense) by storing a security_ops table in each
112process' security field and then invoking these per-process hooks from
113the global hooks. The problem of composition is thus deferred to the
114module.
115
116The global security_ops table is initialized to a set of hook functions
117provided by a dummy security module that provides traditional superuser
118logic. A :c:func:`register_security()` function (in
119``security/security.c``) is provided to allow a security module to set
120security_ops to refer to its own hook functions, and an
121:c:func:`unregister_security()` function is provided to revert
122security_ops to the dummy module hooks. This mechanism is used to set
123the primary security module, which is responsible for making the final
124decision for each hook.
125
126LSM also provides a simple mechanism for stacking additional security
127modules with the primary security module. It defines
128:c:func:`register_security()` and
129:c:func:`unregister_security()` hooks in the :c:type:`struct
130security_operations <security_operations>` structure and
131provides :c:func:`mod_reg_security()` and
132:c:func:`mod_unreg_security()` functions that invoke these hooks
133after performing some sanity checking. A security module can call these
134functions in order to stack with other modules. However, the actual
135details of how this stacking is handled are deferred to the module,
136which can implement these hooks in any way it wishes (including always
137returning an error if it does not wish to support stacking). In this
138manner, LSM again defers the problem of composition to the module.
139
140Although the LSM hooks are organized into substructures based on kernel
141object, all of the hooks can be viewed as falling into two major
142categories: hooks that are used to manage the security fields and hooks
143that are used to perform access control. Examples of the first category
144of hooks include the :c:func:`alloc_security()` and
145:c:func:`free_security()` hooks defined for each kernel data
146structure that has a security field. These hooks are used to allocate
147and free security structures for kernel objects. The first category of
148hooks also includes hooks that set information in the security field
149after allocation, such as the :c:func:`post_lookup()` hook in
150:c:type:`struct inode_security_ops <inode_security_ops>`.
151This hook is used to set security information for inodes after
152successful lookup operations. An example of the second category of hooks
153is the :c:func:`permission()` hook in :c:type:`struct
154inode_security_ops <inode_security_ops>`. This hook checks
155permission when accessing an inode.
156
157LSM Capabilities Module
158=======================
159
160The LSM kernel patch moves most of the existing POSIX.1e capabilities
161logic into an optional security module stored in the file
162``security/capability.c``. This change allows users who do not want to
163use capabilities to omit this code entirely from their kernel, instead
164using the dummy module for traditional superuser logic or any other
165module that they desire. This change also allows the developers of the
166capabilities logic to maintain and enhance their code more freely,
167without needing to integrate patches back into the base kernel.
168
169In addition to moving the capabilities logic, the LSM kernel patch could
170move the capability-related fields from the kernel data structures into
171the new security fields managed by the security modules. However, at
172present, the LSM kernel patch leaves the capability fields in the kernel
173data structures. In his original remarks, Linus suggested that this
174might be preferable so that other security modules can be easily stacked
175with the capabilities module without needing to chain multiple security
176structures on the security field. It also avoids imposing extra overhead
177on the capabilities module to manage the security fields. However, the
178LSM framework could certainly support such a move if it is determined to
179be desirable, with only a few additional changes described below.
180
181At present, the capabilities logic for computing process capabilities on
182:c:func:`execve()` and :c:func:`set\*uid()`, checking
183capabilities for a particular process, saving and checking capabilities
184for netlink messages, and handling the :c:func:`capget()` and
185:c:func:`capset()` system calls have been moved into the
186capabilities module. There are still a few locations in the base kernel
187where capability-related fields are directly examined or modified, but
188the current version of the LSM patch does allow a security module to
189completely replace the assignment and testing of capabilities. These few
190locations would need to be changed if the capability-related fields were
191moved into the security field. The following is a list of known
192locations that still perform such direct examination or modification of
193capability-related fields:
194
195- ``fs/open.c``::c:func:`sys_access()`
196
197- ``fs/lockd/host.c``::c:func:`nlm_bind_host()`
198
199- ``fs/nfsd/auth.c``::c:func:`nfsd_setuser()`
200
201- ``fs/proc/array.c``::c:func:`task_cap()`
diff --git a/Documentation/security/sak.rst b/Documentation/security/sak.rst
new file mode 100644
index 000000000000..260e1d3687bd
--- /dev/null
+++ b/Documentation/security/sak.rst
@@ -0,0 +1,91 @@
1=========================================
2Linux Secure Attention Key (SAK) handling
3=========================================
4
5:Date: 18 March 2001
6:Author: Andrew Morton
7
8An operating system's Secure Attention Key is a security tool which is
9provided as protection against trojan password capturing programs. It
10is an undefeatable way of killing all programs which could be
11masquerading as login applications. Users need to be taught to enter
12this key sequence before they log in to the system.
13
14From the PC keyboard, Linux has two similar but different ways of
15providing SAK. One is the ALT-SYSRQ-K sequence. You shouldn't use
16this sequence. It is only available if the kernel was compiled with
17sysrq support.
18
19The proper way of generating a SAK is to define the key sequence using
20``loadkeys``. This will work whether or not sysrq support is compiled
21into the kernel.
22
23SAK works correctly when the keyboard is in raw mode. This means that
24once defined, SAK will kill a running X server. If the system is in
25run level 5, the X server will restart. This is what you want to
26happen.
27
28What key sequence should you use? Well, CTRL-ALT-DEL is used to reboot
29the machine. CTRL-ALT-BACKSPACE is magical to the X server. We'll
30choose CTRL-ALT-PAUSE.
31
32In your rc.sysinit (or rc.local) file, add the command::
33
34 echo "control alt keycode 101 = SAK" | /bin/loadkeys
35
36And that's it! Only the superuser may reprogram the SAK key.
37
38
39.. note::
40
41 1. Linux SAK is said to be not a "true SAK" as is required by
42 systems which implement C2 level security. This author does not
43 know why.
44
45
46 2. On the PC keyboard, SAK kills all applications which have
47 /dev/console opened.
48
49 Unfortunately this includes a number of things which you don't
50 actually want killed. This is because these applications are
51 incorrectly holding /dev/console open. Be sure to complain to your
52 Linux distributor about this!
53
54 You can identify processes which will be killed by SAK with the
55 command::
56
57 # ls -l /proc/[0-9]*/fd/* | grep console
58 l-wx------ 1 root root 64 Mar 18 00:46 /proc/579/fd/0 -> /dev/console
59
60 Then::
61
62 # ps aux|grep 579
63 root 579 0.0 0.1 1088 436 ? S 00:43 0:00 gpm -t ps/2
64
65 So ``gpm`` will be killed by SAK. This is a bug in gpm. It should
66 be closing standard input. You can work around this by finding the
67 initscript which launches gpm and changing it thusly:
68
69 Old::
70
71 daemon gpm
72
73 New::
74
75 daemon gpm < /dev/null
76
77 Vixie cron also seems to have this problem, and needs the same treatment.
78
79 Also, one prominent Linux distribution has the following three
80 lines in its rc.sysinit and rc scripts::
81
82 exec 3<&0
83 exec 4>&1
84 exec 5>&2
85
86 These commands cause **all** daemons which are launched by the
87 initscripts to have file descriptors 3, 4 and 5 attached to
88 /dev/console. So SAK kills them all. A workaround is to simply
89 delete these lines, but this may cause system management
90 applications to malfunction - test everything well.
91
diff --git a/Documentation/security/siphash.rst b/Documentation/security/siphash.rst
new file mode 100644
index 000000000000..9965821ab333
--- /dev/null
+++ b/Documentation/security/siphash.rst
@@ -0,0 +1,189 @@
1===========================
2SipHash - a short input PRF
3===========================
4
5:Author: Written by Jason A. Donenfeld <jason@zx2c4.com>
6
7SipHash is a cryptographically secure PRF -- a keyed hash function -- that
8performs very well for short inputs, hence the name. It was designed by
9cryptographers Daniel J. Bernstein and Jean-Philippe Aumasson. It is intended
10as a replacement for some uses of: `jhash`, `md5_transform`, `sha_transform`,
11and so forth.
12
13SipHash takes a secret key filled with randomly generated numbers and either
14an input buffer or several input integers. It spits out an integer that is
15indistinguishable from random. You may then use that integer as part of secure
16sequence numbers, secure cookies, or mask it off for use in a hash table.
17
18Generating a key
19================
20
21Keys should always be generated from a cryptographically secure source of
22random numbers, either using get_random_bytes or get_random_once::
23
24 siphash_key_t key;
25 get_random_bytes(&key, sizeof(key));
26
27If you're not deriving your key from here, you're doing it wrong.
28
29Using the functions
30===================
31
32There are two variants of the function, one that takes a list of integers, and
33one that takes a buffer::
34
35 u64 siphash(const void *data, size_t len, const siphash_key_t *key);
36
37And::
38
39 u64 siphash_1u64(u64, const siphash_key_t *key);
40 u64 siphash_2u64(u64, u64, const siphash_key_t *key);
41 u64 siphash_3u64(u64, u64, u64, const siphash_key_t *key);
42 u64 siphash_4u64(u64, u64, u64, u64, const siphash_key_t *key);
43 u64 siphash_1u32(u32, const siphash_key_t *key);
44 u64 siphash_2u32(u32, u32, const siphash_key_t *key);
45 u64 siphash_3u32(u32, u32, u32, const siphash_key_t *key);
46 u64 siphash_4u32(u32, u32, u32, u32, const siphash_key_t *key);
47
48If you pass the generic siphash function something of a constant length, it
49will constant fold at compile-time and automatically choose one of the
50optimized functions.
51
52Hashtable key function usage::
53
54 struct some_hashtable {
55 DECLARE_HASHTABLE(hashtable, 8);
56 siphash_key_t key;
57 };
58
59 void init_hashtable(struct some_hashtable *table)
60 {
61 get_random_bytes(&table->key, sizeof(table->key));
62 }
63
64 static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input)
65 {
66 return &table->hashtable[siphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)];
67 }
68
69You may then iterate like usual over the returned hash bucket.
70
71Security
72========
73
74SipHash has a very high security margin, with its 128-bit key. So long as the
75key is kept secret, it is impossible for an attacker to guess the outputs of
76the function, even if being able to observe many outputs, since 2^128 outputs
77is significant.
78
79Linux implements the "2-4" variant of SipHash.
80
81Struct-passing Pitfalls
82=======================
83
84Often times the XuY functions will not be large enough, and instead you'll
85want to pass a pre-filled struct to siphash. When doing this, it's important
86to always ensure the struct has no padding holes. The easiest way to do this
87is to simply arrange the members of the struct in descending order of size,
88and to use offsetendof() instead of sizeof() for getting the size. For
89performance reasons, if possible, it's probably a good thing to align the
90struct to the right boundary. Here's an example::
91
92 const struct {
93 struct in6_addr saddr;
94 u32 counter;
95 u16 dport;
96 } __aligned(SIPHASH_ALIGNMENT) combined = {
97 .saddr = *(struct in6_addr *)saddr,
98 .counter = counter,
99 .dport = dport
100 };
101 u64 h = siphash(&combined, offsetofend(typeof(combined), dport), &secret);
102
103Resources
104=========
105
106Read the SipHash paper if you're interested in learning more:
107https://131002.net/siphash/siphash.pdf
108
109-------------------------------------------------------------------------------
110
111===============================================
112HalfSipHash - SipHash's insecure younger cousin
113===============================================
114
115:Author: Written by Jason A. Donenfeld <jason@zx2c4.com>
116
117On the off-chance that SipHash is not fast enough for your needs, you might be
118able to justify using HalfSipHash, a terrifying but potentially useful
119possibility. HalfSipHash cuts SipHash's rounds down from "2-4" to "1-3" and,
120even scarier, uses an easily brute-forcable 64-bit key (with a 32-bit output)
121instead of SipHash's 128-bit key. However, this may appeal to some
122high-performance `jhash` users.
123
124Danger!
125
126Do not ever use HalfSipHash except for as a hashtable key function, and only
127then when you can be absolutely certain that the outputs will never be
128transmitted out of the kernel. This is only remotely useful over `jhash` as a
129means of mitigating hashtable flooding denial of service attacks.
130
131Generating a key
132================
133
134Keys should always be generated from a cryptographically secure source of
135random numbers, either using get_random_bytes or get_random_once:
136
137hsiphash_key_t key;
138get_random_bytes(&key, sizeof(key));
139
140If you're not deriving your key from here, you're doing it wrong.
141
142Using the functions
143===================
144
145There are two variants of the function, one that takes a list of integers, and
146one that takes a buffer::
147
148 u32 hsiphash(const void *data, size_t len, const hsiphash_key_t *key);
149
150And::
151
152 u32 hsiphash_1u32(u32, const hsiphash_key_t *key);
153 u32 hsiphash_2u32(u32, u32, const hsiphash_key_t *key);
154 u32 hsiphash_3u32(u32, u32, u32, const hsiphash_key_t *key);
155 u32 hsiphash_4u32(u32, u32, u32, u32, const hsiphash_key_t *key);
156
157If you pass the generic hsiphash function something of a constant length, it
158will constant fold at compile-time and automatically choose one of the
159optimized functions.
160
161Hashtable key function usage
162============================
163
164::
165
166 struct some_hashtable {
167 DECLARE_HASHTABLE(hashtable, 8);
168 hsiphash_key_t key;
169 };
170
171 void init_hashtable(struct some_hashtable *table)
172 {
173 get_random_bytes(&table->key, sizeof(table->key));
174 }
175
176 static inline hlist_head *some_hashtable_bucket(struct some_hashtable *table, struct interesting_input *input)
177 {
178 return &table->hashtable[hsiphash(input, sizeof(*input), &table->key) & (HASH_SIZE(table->hashtable) - 1)];
179 }
180
181You may then iterate like usual over the returned hash bucket.
182
183Performance
184===========
185
186HalfSipHash is roughly 3 times slower than JenkinsHash. For many replacements,
187this will not be a problem, as the hashtable lookup isn't the bottleneck. And
188in general, this is probably a good sacrifice to make for the security and DoS
189resistance of HalfSipHash.
diff --git a/Documentation/security/tpm/index.rst b/Documentation/security/tpm/index.rst
index af77a7bbb070..3296533e54cf 100644
--- a/Documentation/security/tpm/index.rst
+++ b/Documentation/security/tpm/index.rst
@@ -5,3 +5,4 @@ Trusted Platform Module documentation
5.. toctree:: 5.. toctree::
6 6
7 tpm_vtpm_proxy 7 tpm_vtpm_proxy
8 xen-tpmfront
diff --git a/Documentation/security/tpm/xen-tpmfront.rst b/Documentation/security/tpm/xen-tpmfront.rst
index 98a16ab87360..00d5b1db227d 100644
--- a/Documentation/security/tpm/xen-tpmfront.rst
+++ b/Documentation/security/tpm/xen-tpmfront.rst
@@ -1,5 +1,3 @@
1:orphan:
2
3============================= 1=============================
4Virtual TPM interface for Xen 2Virtual TPM interface for Xen
5============================= 3=============================