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