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