9c3fdb1e6b60ea9a7b6f146dff038ea7aaec32c5
[AGL/documentation.git] / docs / 2_Architecture_Guides / 2.2_Security_Blueprint / 4_Kernel / 1.2.4.2_Memory.md
1 ---
2 edit_link: ''
3 title: Memory
4 origin_url: >-
5   https://raw.githubusercontent.com/automotive-grade-linux/docs-sources/master/docs/security-blueprint/part-4/2-Memory.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 # Memory
11
12 ## Restrict access to kernel memory
13
14 The /dev/kmem file in Linux systems is directly mapped to kernel virtual memory. This can be disastrous if an attacker gains root access, as the attacker would have direct access to kernel virtual memory.
15
16 To disable the /dev/kmem file, which is very infrequently used by applications, the following kernel option should be set in the compile-time kernel configuration:
17
18 <!-- section-config -->
19
20 Domain                         | `Config` name    | `Value`
21 ------------------------------ | ---------------- | -------
22 Kernel-Memory-RestrictAccess-1 | `CONFIG_DEVKMEM` | `n`
23
24 <!-- end-section-config -->
25
26 In case applications in userspace need /dev/kmem support, it should be available only for authenticated applications.
27
28 --------------------------------------------------------------------------------
29
30 ## Disable access to a kernel core dump
31
32 This kernel configuration disables access to a kernel core dump from user space. If enabled, it gives attackers a useful view into kernel memory.
33
34 <!-- section-config -->
35
36 Domain                   | `Config` name       | `Value`
37 ------------------------ | ------------------- | -------
38 Kernel-Memory-CoreDump-1 | `CONFIG_PROC_KCORE` | `n`
39
40 <!-- end-section-config -->
41
42 --------------------------------------------------------------------------------
43
44 ## Disable swap
45
46 If not disabled, attackers can enable swap at runtime, add pressure to the memory subsystem and then scour the pages written to swap for useful information.
47
48 <!-- section-config -->
49
50 Domain               | `Config` name | `Value`
51 -------------------- | ------------- | -------
52 Kernel-Memory-Swap-1 | `CONFIG_SWAP` | `n`
53
54 <!-- end-section-config -->
55
56 <!-- section-note -->
57
58 - Enabling swap at runtime require `CAP_SYS_ADMIN`.
59 - Swap block device is usually under root:disk.
60 - Linux never swaps kernel pages.
61 - If swap disabling is not possible, swap encryption should be enabled.
62
63 <!-- end-section-note -->
64
65 --------------------------------------------------------------------------------
66
67 <!-- pagebreak -->
68
69 ## Disable "Load All Symbols"
70
71 There is a /proc/kallsyms file which exposes the kernel memory space address of many kernel symbols (functions, variables, etc...). This information is useful to attackers in identifying kernel versions/configurations and in preparing payloads for the exploits of kernel space.
72
73 Both `KALLSYMS_ALL` and `KALLSYMS` shall be disabled;
74
75 <!-- section-config -->
76
77 Domain                         | `Config` name         | `Value`
78 ------------------------------ | --------------------- | -------
79 Kernel-Memory-LoadAllSymbols-1 | `CONFIG_KALLSYMS`     | `n`
80 Kernel-Memory-LoadAllSymbols-2 | `CONFIG_KALLSYMS_ALL` | `n`
81
82 <!-- end-section-config -->
83
84 --------------------------------------------------------------------------------
85
86 ## Stack protection
87
88 To prevent stack-smashing, similar to the stack protector used for ELF programs in user-space, the kernel can protect its internal stacks as well.
89
90 This configuration is supported in **Linux 3.11 and greater** and thus should only be enabled for such versions.
91
92 This configuration also requires building the kernel with the **gcc compiler 4.2 or greater**.
93
94 <!-- section-config -->
95
96 Domain                | `Config` name              | `Value`
97 --------------------- | -------------------------- | -------
98 Kernel-Memory-Stack-1 | `CONFIG_CC_STACKPROTECTOR` | `y`
99
100 <!-- end-section-config -->
101
102 Other defenses include things like shadow stacks.
103
104 --------------------------------------------------------------------------------
105
106 ## Disable access to /dev/mem
107
108 The /dev/mem file in Linux systems is directly mapped to physical memory. This can be disastrous if an attacker gains root access, as the attacker would have direct access to physical memory through this convenient device file. It may not always be possible to disable such file, as some applications might need such support. In that case, then this device file should be available only for authenticated applications.
109
110 This configuration is supported in **Linux 4.0 and greater** and thus should only be disabled for such versions.
111
112 <!-- section-config -->
113
114 Domain                 | `Config` name   | `Value`
115 ---------------------- | --------------- | -------
116 Kernel-Memory-Access-1 | `CONFIG_DEVMEM` | `n`
117
118 <!-- end-section-config -->
119
120 --------------------------------------------------------------------------------
121
122 <!-- pagebreak -->
123
124 ## Disable cross-memory attach
125
126 Disable the process_vm_*v syscalls which allow one process to peek/poke the virtual memory of another.
127
128 This configuration is supported in **Linux 3.5 and greater** and thus should only be disabled for such versions.
129
130 <!-- section-config -->
131
132 Domain                         | `Config` name         | `Value`
133 ------------------------------ | --------------------- | -------
134 Kernel-Memory-CrossMemAttach-1 | `CROSS_MEMORY_ATTACH` | `n`
135
136 <!-- end-section-config -->
137
138 --------------------------------------------------------------------------------
139
140 ## Stack Smashing Attacks
141
142 <!-- section-config -->
143
144 Domain                        | `compiler` and `linker` options | _State_
145 ----------------------------- | ------------------------------- | --------
146 Kernel-Memory-StackSmashing-1 | `-fstack-protector-all`         | _Enable_
147
148 <!-- end-section-config -->
149
150 Emit extra code to check for buffer overflows, such as stack smashing attacks.
151
152 --------------------------------------------------------------------------------
153
154 ## Detect Buffer Overflows
155
156 <!-- section-config -->
157
158 Domain                          | `compiler` options and `config` name | `Value`
159 ------------------------------- | ------------------------------------ | -------
160 Kernel-Memory-BufferOverflows-1 | `-D_FORTIFY_SOURCE`                  | `2`
161 Kernel-Memory-BufferOverflows-2 | `CONFIG_FORTIFY_SOURCE`              | `y`
162
163 <!-- end-section-config -->
164
165 Helps detect some buffer overflow errors.