3d7fae01ed297a6762a7b4f112409eadd23d8ea6
[AGL/documentation.git] / docs / 2_Architecture_Guides / 2.2_Security_Blueprint / 4_Kernel / 1.2.4.1_General.md
1 ---
2 edit_link: ''
3 title: General
4 origin_url: >-
5   https://raw.githubusercontent.com/automotive-grade-linux/docs-sources/master/docs/security-blueprint/part-4/1-General.md
6 ---
7
8 <!-- WARNING: This file is generated by fetch_docs.js using /home/boron/Documents/AGL/docs-webtemplate/site/_data/tocs/architecture/master/security_blueprint-security-blueprint-book.yml -->
9
10 # General configuration
11
12 ## Mandatory Access Control
13
14 Kernel should controls access with labels and policy.
15
16 <!-- section-config -->
17
18 Domain               | `Config` name  | `Value`
19 -------------------- | -------------- | --------------------------------------
20 Kernel-General-MAC-1 | CONFIG_IP_NF_SECURITY   | m
21 Kernel-General-MAC-2 | CONFIG_IP6_NF_SECURITY  | m
22 Kernel-General-MAC-3 | CONFIG_EXT2_FS_SECURITY | y
23 Kernel-General-MAC-4 | CONFIG_EXT3_FS_SECURITY | y
24 Kernel-General-MAC-5 | CONFIG_EXT4_FS_SECURITY | y
25 Kernel-General-MAC-6 | CONFIG_SECURITY         | y
26 Kernel-General-MAC-7 | CONFIG_SECURITY_SMACK   | y
27 Kernel-General-MAC-8 | CONFIG_TMPFS_XATTR      | y
28
29 <!-- end-section-config -->
30
31 Please also refer to the [**Mandatory Access Control** documentation in Platform](../part-5/1-MAC.html) part.
32 You can also find useful documentation and links on wikipedia about [**MAC**](https://en.wikipedia.org/wiki/Mandatory_access_control)
33 and about [**SMACK**](https://en.wikipedia.org/wiki/Simplified_Mandatory_Access_Control_Kernel).
34
35 --------------------------------------------------------------------------------
36
37 ## Disable kexec
38
39 **Kexec** is a system call that enables you to load and boot into another kernel from the currently running kernel. This feature is not required in a production environment.
40
41 <!-- section-config -->
42
43 Domain                 | `Config` name  | `Value`
44 ---------------------- | -------------- | -------
45 Kernel-General-kexec-1 | `CONFIG_KEXEC` | `n`
46
47 <!-- end-section-config -->
48
49 <!-- section-note -->
50
51 **kexec** can load arbitrary kernels but signing of new kernel can be enforced like it is can be enforced for new modules.
52
53 <!-- end-section-note -->
54
55 --------------------------------------------------------------------------------
56
57 ## Disable kernel IP auto-configuration
58
59 It is preferable to have an IP configuration performed using a user-space tool as these tend to have more validation. We do not want the network interface coming up until the system has come up properly.
60
61 <!-- section-config -->
62
63 Domain                      | `Config` name   | `Value`
64 --------------------------- | --------------- | -------
65 Kernel-General-IPAutoConf-1 | `CONFIG_IP_PNP` | `n`
66
67 <!-- end-section-config -->
68
69 --------------------------------------------------------------------------------
70
71 ## Disable Sysctl syscall support
72
73 Enabling this will result in code being included that is hard to maintain and not well tested.
74
75 <!-- section-config -->
76
77 Domain                          | `Config` name           | `Value`
78 ------------------------------- | ----------------------- | -------
79 Kernel-General-SysCtl_SysCall-1 | `CONFIG_SYSCTL_SYSCALL` | `n`
80
81 <!-- end-section-config -->
82
83 --------------------------------------------------------------------------------
84
85 ## Disable Legacy Linux Support
86
87 There are some Kernel Configs which are present only to support legacy binaries. See also "Consoles" part in order to disabling support for legacy binary formats. The `uselib` system call, in particular, has no valid use in any `libc6` or `uclibc` system in recent times. This configuration is supported in **Linux 3.15 and greater** and thus should only be disabled for such versions.
88
89 <!-- section-config -->
90
91 Domain                       | `Config` name   | `Value`
92 ---------------------------- | --------------- | -------
93 Kernel-General-LegacyLinux-1 | `CONFIG_USELIB` | `n`
94
95 <!-- end-section-config -->
96
97 --------------------------------------------------------------------------------
98
99 ## Disable firmware auto-loading user mode helper
100
101 The firmware auto loading helper, which is a utility executed by the kernel on `hotplug` events requiring firmware, can to be set `setuid`. As a result of this, the helper utility is an attractive target for attackers with control of physical ports on the device. Disabling this configuration that is supported in **Linux 3.9 and greater**.
102
103 <!-- section-config -->
104
105 Domain                      | `Config` name                  | `Value`
106 --------------------------- | ------------------------------ | -------
107 Kernel-General-FirmHelper-1 | `CONFIG_FW_LOADER_USER_HELPER` | `n`
108
109 <!-- end-section-config -->
110
111 <!-- section-note -->
112
113 It doesn't strictly need to be `setuid`, there is an option of shipping firmware builtin into kernel without initrd/filesystem.
114
115 <!-- end-section-note -->
116
117 --------------------------------------------------------------------------------
118
119 ## Enable Kernel Panic on OOPS
120
121 When fuzzing the kernel or attempting kernel exploits attackers are likely to trigger kernel OOPSes. Setting the behavior on OOPS to PANIC can impede their progress.
122
123 This configuration is supported in **Linux 3.5 and greater** and thus should only be enabled for such versions.
124
125 <!-- section-config -->
126
127 Domain                       | `Config` name          | `Value`
128 ---------------------------- | ---------------------- | -------
129 Kernel-General-PanicOnOOPS-1 | `CONFIG_PANIC_ON_OOPS` | `y`
130
131 <!-- end-section-config -->
132
133 --------------------------------------------------------------------------------
134
135 <!-- pagebreak -->
136
137 ## Disable socket monitoring interface
138
139 These monitors can be used to inspect shared file descriptors on Unix Domain sockets or traffic on 'localhost' which is otherwise assumed to be confidential.
140
141 The `CONFIG_PACKET_DIAG` configuration is supported in **Linux 3.7 and greater** and thus should only be disabled for such versions.
142
143 The `CONFIG_UNIX_DIAG` configuration is supported in **Linux 3.3 and greater** and thus should only be disabled for such versions.
144
145 <!-- section-config -->
146
147 Domain                     | `Config` name        | `Value`
148 -------------------------- | -------------------- | -------
149 Kernel-General-SocketMon-1 | `CONFIG_PACKET_DIAG` | `n`
150 Kernel-General-SocketMon-2 | `CONFIG_UNIX_DIAG`   | `n`
151
152 <!-- end-section-config -->
153
154 --------------------------------------------------------------------------------
155
156 ## Disable BPF JIT
157
158 The BPF JIT can be used to create kernel-payloads from firewall table rules.
159
160 This configuration for is supported in **Linux 3.16 and greater** and thus should only be disabled for such versions.
161
162 <!-- section-config -->
163
164 Domain                   | `Config` name    | `Value`
165 ------------------------ | ---------------- | -------
166 Kernel-General-BPF_JIT-1 | `CONFIG_BPF_JIT` | `n`
167
168 <!-- end-section-config -->
169
170 --------------------------------------------------------------------------------
171
172 ## Enable Enforced Module Signing
173
174 The kernel should never allow an unprivileged user the ability to load specific kernel modules,
175 since that would provide a facility to unexpectedly extend the available attack surface.
176
177 To protect against even privileged users, systems may need to either disable
178 module loading entirely, or provide signed modules
179 (e.g. `CONFIG_MODULE_SIG_FORCE`, or dm-crypt with LoadPin), to keep from having
180 root load arbitrary kernel code via the module loader interface.
181
182 This configuration is supported in **Linux 3.7 and greater** and thus should only be enabled for such versions.
183
184 <!-- section-config -->
185
186 Domain                         | `Config` name             | `Value`
187 ------------------------------ | ------------------------- | -------
188 Kernel-General-ModuleSigning-1 | `CONFIG_MODULE_SIG_FORCE` | `y`
189
190 <!-- end-section-config -->
191
192 It is also possible to block the loading of modules after startup with "kernel.modules_disabled".
193
194 <!-- section-config -->
195
196 Domain                         | `Variable` name           | `Value`
197 ------------------------------ | ------------------------- | -------
198 Kernel-General-ModuleSigning-2 | `kernel.modules_disabled` | `1`
199
200 <!-- end-section-config -->
201
202 --------------------------------------------------------------------------------
203
204 <!-- pagebreak -->
205
206 ## Disable all USB, PCMCIA (and other `hotplug` bus) drivers that aren't needed
207
208 To reduce the attack surface, the driver enumeration, probe, and operation happen in the kernel. The driver data is parsed by the kernel, so any logic bugs in these drivers can become kernel exploits.
209
210 <!-- section-config -->
211
212 Domain                   | Object              | _State_
213 ------------------------ | ------------------- | ----------
214 Kernel-General-Drivers-1 | `USB`               | _Disabled_
215 Kernel-General-Drivers-2 | `PCMCIA`            | _Disabled_
216 Kernel-General-Drivers-3 | Other `hotplug` bus | _Disabled_
217
218 <!-- end-section-config -->
219
220 --------------------------------------------------------------------------------
221
222 ## Position Independent Executables
223
224 <!-- section-todo -->
225
226 Domain                           | Improvement
227 -------------------------------- | -----------------------------
228 Kernel-General-IndependentExec-1 | Kernel or/and platform part ?
229
230 <!-- end-section-todo -->
231
232 <!-- section-config -->
233
234 Domain                           | `compiler` and `linker` options | _State_
235 -------------------------------- | ------------------------------- | --------
236 Kernel-General-IndependentExec-1 | `-pie -fpic`                    | _Enable_
237
238 <!-- end-section-config -->
239
240 Produce a position independent executable on targets which supports it.
241
242 --------------------------------------------------------------------------------
243
244 ## Prevent Overwrite Attacks
245
246 `-z,relro` linking option helps during program load, several ELF memory sections need to be written by the linker, but can be turned read-only before turning over control to the program. This prevents some Global Offset Table GOT overwrite attacks, or in the dtors section of the ELF binary.
247
248 <!-- section-config -->
249
250 Domain                            | `compiler` and `linker` options | _State_
251 --------------------------------- | ------------------------------- | --------
252 Kernel-General-OverwriteAttacks-1 | `-z,relro`                      | _Enable_
253 Kernel-General-OverwriteAttacks-2 | `-z,now`                        | _Enable_
254
255 <!-- end-section-config -->
256
257 During program load, all dynamic symbols are resolved, allowing for the complete GOT to be marked read-only (due to `-z relro` above). This prevents GOT overwrite attacks. For very large application, this can incur some performance loss during initial load while symbols are resolved, but this shouldn't be an issue for daemons.
258
259 --------------------------------------------------------------------------------
260
261 <!-- pagebreak -->
262
263 ## Library linking
264
265 <!-- section-todo -->
266
267 Domain                          | Improvement
268 ------------------------------- | ---------------
269 Kernel-General-LibraryLinking-1 | Keep this part?
270
271 <!-- end-section-todo -->
272
273 It is recommended that dynamic linking should generally not be allowed. This will avoid the user from replacing a library with malicious library.
274
275 <!-- section-config -->
276
277 Domain                          | Object          | Recommendations
278 ------------------------------- | --------------- | --------------------------------
279 Kernel-General-LibraryLinking-1 | Dynamic linking | Should generally not be allowed.
280
281 <!-- end-section-config -->
282
283 <!-- section-note -->
284
285 Linking everything statically doesn't change anything wrt security as binaries will live under same user:group as libraries and setuid executables ignore `LD_PRELOAD/LD_LIBRARY_PATH`. It also increases RSS footprint and creates problems with upgrading.
286
287 <!-- end-section-note -->