Added [in-progress] Developer Guides
[AGL/documentation.git] / docs / 2_Architecture_Guides / 2.2_Security_Blueprint / 4_Kernel / 1.2.4.4_Debug.md
1 ---
2 title: Debug
3 ---
4
5 # Debug
6
7 No debuggers shall be present on the file system. This includes, but is not
8 limited to, the GNU Debugger client/server (commonly known in their short form
9 names such as the `gdb` and `gdbserver` executable binaries respectively), the
10 `LLDB` next generation debugger or the `TCF` (Target Communications Framework)
11 agnostic framework. Including these binaries as part of the file system will
12 facilitate an attacker's ability to reverse engineer and debug (either locally
13 or remotely) any process that is currently executing on the device.
14
15 ## Kernel debug symbols
16
17 Debug symbols should always be removed from production kernels as they provide a
18 lot of information to attackers.
19
20 <!-- section-config -->
21
22 Domain                 | `Config` name       | `Value`
23 ---------------------- | ------------------- | -------
24 Kernel-Debug-Symbols-1 | `CONFIG_DEBUG_INFO` | `n`
25
26 <!-- end-section-config -->
27
28 These kernel debug symbols are enabled by other config items in the kernel. Care
29 should be taken to disable those also. If `CONFIG_DEBUG_INFO` cannot be
30 disabled, then enabling `CONFIG_DEBUG_INFO_REDUCED` is second best.
31
32 <!-- section-note -->
33
34 At least `CONFIG_DEBUG_INFO_REDUCED` should be always enabled for developers to
35 convert addresses in oops messages to line numbers.
36
37 <!-- end-section-note -->
38
39 --------------------------------------------------------------------------------
40
41 ## Disable Kprobes
42
43 Kprobes enables you to dynamically break into any kernel routine and collect
44 debugging and performance information non-disruptively. You can trap at almost
45 any kernel code address, specifying a handler routine to be invoked when the
46 breakpoint is hit.
47
48 <!-- section-config -->
49
50 Domain                 | `Config` name    | `Value`
51 ---------------------- | ---------------- | -------
52 Kernel-Debug-Kprobes-1 | `CONFIG_KPROBES` | `n`
53
54 <!-- end-section-config -->
55
56 --------------------------------------------------------------------------------
57
58 ## Disable Tracing
59
60 FTrace enables the kernel to trace every kernel function. Providing kernel trace
61 functionality would assist an attacker in discovering attack vectors.
62
63 <!-- section-config -->
64
65 Domain                 | `Config` name   | `Value`
66 ---------------------- | --------------- | -------
67 Kernel-Debug-Tracing-1 | `CONFIG_FTRACE` | `n`
68
69 <!-- end-section-config -->
70
71 --------------------------------------------------------------------------------
72
73 ## Disable Profiling
74
75 Profiling and OProfile enables profiling the whole system, include the kernel,
76 kernel modules, libraries, and applications. Providing profiling functionality
77 would assist an attacker in discovering attack vectors.
78
79 <!-- section-config -->
80
81 Domain                   | `Config` name      | `Value`
82 ------------------------ | ------------------ | -------
83 Kernel-Debug-Profiling-1 | `CONFIG_OPROFILE`  | `n`
84 Kernel-Debug-Profiling-2 | `CONFIG_PROFILING` | `n`
85
86 <!-- end-section-config -->
87
88 --------------------------------------------------------------------------------
89
90 ## Disable OOPS print on BUG()
91
92 The output from OOPS print can be helpful in Return Oriented Programming (ROP)
93 when trying to determine the effectiveness of an exploit.
94
95 <!-- section-config -->
96
97 Domain                   | `Config` name             | `Value`
98 ------------------------ | ------------------------- | -------
99 Kernel-Debug-OOPSOnBUG-1 | `CONFIG_DEBUG_BUGVERBOSE` | `n`
100
101 <!-- end-section-config -->
102
103 --------------------------------------------------------------------------------
104
105 ## Disable Kernel Debugging
106
107 There are development-only branches of code in the kernel enabled by the
108 `DEBUG_KERNEL` conf. This should be disabled to compile-out these branches.
109
110 <!-- section-config -->
111
112 Domain             | `Config` name         | `Value`
113 ------------------ | --------------------- | -------
114 Kernel-Debug-Dev-1 | `CONFIG_DEBUG_KERNEL` | `n`
115 Kernel-Debug-Dev-2 | `CONFIG_EMBEDDED`     | `n`
116
117 <!-- end-section-config -->
118
119 In some kernel versions, disabling this requires also disabling
120 `CONFIG_EMBEDDED`, and `CONFIG_EXPERT`. Disabling `CONFIG_EXPERT` makes it
121 impossible to disable `COREDUMP`, `DEBUG_BUGVERBOSE`, `NAMESPACES`, `KALLSYMS`
122 and `BUG`. In which case it is better to leave this enabled than enable the
123 others.
124
125 --------------------------------------------------------------------------------
126
127 <!-- pagebreak -->
128
129 ## Disable the kernel debug filesystem
130
131 The kernel debug filesystem presents a lot of useful information and means of
132 manipulation of the kernel to an attacker.
133
134 <!-- section-config -->
135
136 Domain                    | `Config` name     | `Value`
137 ------------------------- | ----------------- | -------
138 Kernel-Debug-FileSystem-1 | `CONFIG_DEBUG_FS` | `n`
139
140 <!-- end-section-config -->
141
142 --------------------------------------------------------------------------------
143
144 ## Disable BUG() support
145
146 The kernel will display backtrace and register information for BUGs and WARNs in
147 kernel space, making it easier for attackers to develop exploits.
148
149 <!-- section-config -->
150
151 Domain             | `Config` name | `Value`
152 ------------------ | ------------- | -------
153 Kernel-Debug-BUG-1 | `CONFIG_BUG`  | `n`
154
155 <!-- end-section-config -->
156
157 --------------------------------------------------------------------------------
158
159 ## Disable core dumps
160
161 Core dumps provide a lot of debug information for hackers. So disabling core
162 dumps are recommended in production builds.
163
164 This configuration is supported in **Linux 3.7 and greater** and thus should
165 only be disabled for such versions.
166
167 <!-- section-config -->
168
169 Domain                   | `Config` name     | `Value`
170 ------------------------ | ----------------- | -------
171 Kernel-Debug-CoreDumps-1 | `CONFIG_COREDUMP` | `n`
172
173 <!-- end-section-config -->
174
175 --------------------------------------------------------------------------------
176
177 <!-- pagebreak -->
178
179 ## Kernel Address Display Restriction
180
181 When attackers try to develop "run anywhere" exploits for kernel
182 vulnerabilities, they frequently need to know the location of internal kernel
183 structures. By treating kernel addresses as sensitive information, those
184 locations are not visible to regular local users.
185
186 **/proc/sys/kernel/kptr_restrict is set to "1"** to block the reporting of known
187 kernel address leaks.
188
189 <!-- section-config -->
190
191 Domain                       | `File` name                      | `Value`
192 ---------------------------- | -------------------------------- | -------
193 Kernel-Debug-AdressDisplay-1 | `/proc/sys/kernel/kptr_restrict` | `1`
194
195 <!-- end-section-config -->
196
197 Additionally, various files and directories should be readable only by the root
198 user: `/boot/vmlinuz*`, `/boot/System.map*`, `/sys/kernel/debug/`,
199 `/proc/slabinfo`
200
201 <!-- section-config -->
202
203 Domain                       | `File` or `Directorie` name | _State_
204 ---------------------------- | --------------------------- | -----------------------------
205 Kernel-Debug-AdressDisplay-1 | `/boot/vmlinuz*`            | _Readable Only for root user_
206 Kernel-Debug-AdressDisplay-2 | `/boot/System.map*`         | _Readable Only for root user_
207 Kernel-Debug-AdressDisplay-3 | `/sys/kernel/debug/`        | _Readable Only for root user_
208 Kernel-Debug-AdressDisplay-4 | `/proc/slabinfo`            | _Readable Only for root user_
209
210 <!-- end-section-config -->
211
212 --------------------------------------------------------------------------------
213
214 ## DMESG Restrictions
215
216 When attackers try to develop "run anywhere" exploits for vulnerabilities, they
217 frequently will use `dmesg` output. By treating `dmesg` output as sensitive
218 information, this output is not available to the attacker.
219
220 **/proc/sys/kernel/dmesg_restrict can be set to "1"** to treat dmesg output as
221 sensitive.
222
223 <!-- section-config -->
224
225 Domain               | `File` name                       | `Value`
226 -------------------- | --------------------------------- | -------
227 Kernel-Debug-DMESG-1 | `/proc/sys/kernel/dmesg_restrict` | `1`
228
229 <!-- end-section-config -->
230
231 Enable the below compiler and linker options when building user-space
232 applications to avoid stack smashing, buffer overflow attacks.
233
234 --------------------------------------------------------------------------------
235
236 <!-- pagebreak -->
237
238 ## Disable /proc/config.gz
239
240 It is extremely important to not expose the kernel configuration used on a
241 production device to a potential attacker. With access to the kernel config, it
242 could be possible for an attacker to build a custom kernel for the device that
243 may disable critical security features.
244
245 <!-- section-config -->
246
247 Domain                | `Config` name     | `Value`
248 --------------------- | ----------------- | -------
249 Kernel-Debug-Config-1 | `CONFIG_IKCONFIG` | `n`
250
251 <!-- end-section-config -->