Project

General

Profile

ExynosModemIsolation » History » Version 19

Denis 'GNUtoo' Carikli, 03/02/2020 11:41 AM

1 9 Denis 'GNUtoo' Carikli
h1. Exynos 3110 modem isolation
2 1 Paul Kocialkowski
3 11 Denis 'GNUtoo' Carikli
{{toc}}
4
5 7 Denis 'GNUtoo' Carikli
This article talks about a very serious freedom, privacy and security issue we found during Replicant development.
6 1 Paul Kocialkowski
7 9 Denis 'GNUtoo' Carikli
We found that the modem wasn't isolated and was potentially able to read and write part of the RAM used by Replicant on several devices with an Exynos 3110.
8 7 Denis 'GNUtoo' Carikli
9
h2. Affected devices:
10
11 10 Denis 'GNUtoo' Carikli
At least the following devices are affected:
12
13
* Galaxy S (GT-I9000)
14 7 Denis 'GNUtoo' Carikli
* Nexus S (GT-I9020)
15
* Nexus S (GT-I9020A)
16
* Nexus S (GT-I9023)
17
18 1 Paul Kocialkowski
h2. Hardware design matrix
19
20
|_. *Chip* |_. Controlled by the CPU |_. Controlled by the modem |_. Connected to the modem |
21
| GPS | Yes | No | No? |
22
| Audio CODEC | Yes | No | Yes |
23
| NAND | Yes | No | No |
24 3 Paul Kocialkowski
| RAM | Yes | Yes (96Mib at least) | Yes |
25 1 Paul Kocialkowski
| WiFi/Bluetooth | Yes | No | No |
26
| Sensors | Yes | No | No |
27
| NFC | Yes | No | No |
28
| Camera | Yes | No | No |
29
30 5 Denis 'GNUtoo' Carikli
h2. Modem isolation
31 1 Paul Kocialkowski
32 15 Denis 'GNUtoo' Carikli
The modem (XMM 6160) is separated from the System on a chip and communicates with it over 16Mib of shared memory that comes from a 96MiB RAM chip.
33
34
The issue is that the remaining 80M of this RAM chip are also used as normal RAM by the CPU running Replicant.
35
36
Because of that, we don't have any assurance that the modem cannot read and write all the memory in that RAM chip, enabling it to either passively monitor what is going on, and/or to take control of the CPU running Replicant.
37
38
While the hardware design could ensure that only some lines of the data address are made accessible to the modem, we don't have enough documentation to verify that, and even if it was the case it couldn't be guaranteed for every single device used with Replicant.
39
40
This is bad: it means that RAM in general is potentially compromised.
41
42 5 Denis 'GNUtoo' Carikli
Regarding audio, the modem is connected to the CODEC but cannot control it (the SoC has to enable routing from/to the modem).
43
There is no evidence that the GPS is connected to the modem, but since we cannot check on the hardware, there is no proof it's not connected to it either. The SoC is able to control the GPS power though, so we can keep it off.
44 1 Paul Kocialkowski
Since the SoC has to load the modem firmware over the (fake) serial, and following the datasheets, the modem is not connected to the NAND.
45 5 Denis 'GNUtoo' Carikli
46 15 Denis 'GNUtoo' Carikli
The modem is potentially able to read and write (at least) 96 Mib of the main memory. So far, we cannot tell:
47 3 Paul Kocialkowski
* if it can only spy 80Mib or the full memory
48 1 Paul Kocialkowski
* if it can be fixed or not
49 4 Paul Kocialkowski
50
The Linux kernel is being loaded at the beginning of the shared memory bank (0x30000000), however the kernel should be off when it loads.
51 1 Paul Kocialkowski
52 12 Denis 'GNUtoo' Carikli
h3. Nexus S (GT-I902x) Kernel details
53 1 Paul Kocialkowski
54 5 Denis 'GNUtoo' Carikli
In "kernel-crespo/arch/arm/mach-s5pv210/dev-herring-phone.c":https://git.replicant.us/replicant/kernel_samsung_crespo/tree/arch/arm/mach-s5pv210/dev-herring-phone.c#n49 we have:
55 1 Paul Kocialkowski
<pre>
56
static struct resource mdmctl_res[] = {
57
[...]
58
        [2] = {
59
                .name = "onedram",
60
                .start = (S5PV210_PA_SDRAM + 0x05000000),
61
                .end = (S5PV210_PA_SDRAM + 0x05000000 + SZ_16M - 1),
62
                .flags = IORESOURCE_MEM,
63
        },
64
};
65
</pre>
66
67
* S5PV210_PA_SDRAM is 0x30000000
68
* 0x05000000 is 80Mib
69 19 Denis 'GNUtoo' Carikli
* mdmctl_res goes in a platform device struct which is passed to the modem driver:
70 15 Denis 'GNUtoo' Carikli
71 1 Paul Kocialkowski
<pre>
72
static struct platform_device modemctl = {
73
        .name = "modemctl",
74
        .id = -1,
75
        .num_resources = ARRAY_SIZE(mdmctl_res),
76
        .resource = mdmctl_res,
77
        .dev = {
78
                .platform_data = &mdmctl_data,
79
        },
80
};
81
</pre>
82
83 6 Denis 'GNUtoo' Carikli
And in the board file, in "kernel-crespo/arch/arm/mach-s5pv210/mach-herring.c":https://git.replicant.us/replicant/kernel_samsung_crespo/tree/arch/arm/mach-s5pv210/mach-herring.c#n5596 we have: 
84 1 Paul Kocialkowski
<pre>
85
static void __init herring_fixup(struct machine_desc *desc,
86
                struct tag *tags, char **cmdline,
87
                struct meminfo *mi)
88
{
89
        mi->bank[0].start = 0x30000000;
90
        mi->bank[0].size = 80 * SZ_1M;
91
        mi->bank[0].node = 0;
92
        [...]
93
}
94
</pre>
95
96 19 Denis 'GNUtoo' Carikli
So for this RAM chip we have:
97
98
|_. CPU physical address range |_. Usage |
99
| 0x30000000 -> 0x30000000 + 80MiB -1 | System RAM |
100
| 0x30000000 + 80MiB -> 0x30000000 + 80MiB + 16MiB - 1 | Modem shared memory |
101
102 18 Denis 'GNUtoo' Carikli
So we can suppose that there is at least one ram chip that is shared between the modem and the main CPU. Avoiding the use of this memory bank would result in loosing at least 80Mib of memory.
103 13 Denis 'GNUtoo' Carikli
104
h3. Galaxy S (GT-I9000) Kernel details
105
106
In "arch/arm/mach-s5pv210/dev-s1-phone.c":https://git.replicant.us/replicant/kernel_samsung_aries/tree/arch/arm/mach-s5pv210/dev-s1-phone.c#n43 we have:
107
<pre>
108
static struct resource onedram_res[] = {
109
[...]
110
	[0] = {
111 1 Paul Kocialkowski
		.start = (S5PV210_PA_SDRAM + 0x05000000),
112 13 Denis 'GNUtoo' Carikli
		.end = (S5PV210_PA_SDRAM + 0x05000000 + SZ_16M - 1),
113
		.flags = IORESOURCE_MEM,
114 15 Denis 'GNUtoo' Carikli
		},
115
};
116 17 Denis 'GNUtoo' Carikli
</pre>
117
118
* S5PV210_PA_SDRAM is 0x30000000
119 15 Denis 'GNUtoo' Carikli
* 0x05000000 is 80Mib
120 19 Denis 'GNUtoo' Carikli
* mdmctl_res goes in a platform device struct which is passed to the modem driver:
121 13 Denis 'GNUtoo' Carikli
122
<pre>
123
static struct platform_device onedram = {
124
		.name = "onedram",
125
		.id = -1,
126
		.num_resources = ARRAY_SIZE(onedram_res),
127
		.resource = onedram_res,
128 1 Paul Kocialkowski
		.dev = {
129
			.platform_data = &onedram_data,
130
			},
131
		};
132
</pre>
133
134 13 Denis 'GNUtoo' Carikli
And in the board file, in "arch/arm/mach-s5pv210/mach-aries.c":https://git.replicant.us/replicant/kernel_samsung_aries/tree/arch/arm/mach-s5pv210/mach-aries.c#n5204 we have: 
135
<pre>
136
static void __init aries_fixup(struct machine_desc *desc,
137
		struct tag *tags, char **cmdline,
138
		struct meminfo *mi)
139
{
140
	mi->bank[0].start = 0x30000000;
141
	mi->bank[0].size = 80 * SZ_1M;
142
        [...]
143
}
144
</pre>
145 19 Denis 'GNUtoo' Carikli
146
So for this RAM chip we have:
147
148
|_. CPU physical address range |_. Usage |
149
| 0x30000000 -> 0x30000000 + 80MiB -1 | System RAM |
150
| 0x30000000 + 80MiB -> 0x30000000 + 80MiB + 16MiB - 1 | Modem shared memory |
151 13 Denis 'GNUtoo' Carikli
152 18 Denis 'GNUtoo' Carikli
So we can suppose that there is at least one ram chip that is shared between the modem and the main CPU. Avoiding the use of this memory bank would result in loosing at least 80Mib of memory.
153 13 Denis 'GNUtoo' Carikli
154 8 Denis 'GNUtoo' Carikli
h3. Workaround attempt
155 1 Paul Kocialkowski
156 8 Denis 'GNUtoo' Carikli
It might be possible to limit the amount of damage by relying on the fact that the modem has to be booted by Replicant, and make sure that the RAM chip that is shared with the modem isn't used for other things than this memory sharing.
157
158
This would make us lose about 80Mib of RAM, and the shared memory would still be used for SoC/Modem communication but as the RAM chip would be used only for that, so the modem would not be able read and write problematic data on it.
159
160
We would also need to make sure that the booloader doesn't load the kernel in that region or that the kernel is relocated to some other region before intializing the modem.
161 4 Paul Kocialkowski
162
The current diff with the Nexus S kernel is here, but it doesn't boot at all with the following changes (and mkbootimg changes):
163
164
<pre>
165
diff --git a/arch/arm/configs/herring_defconfig b/arch/arm/configs/herring_defconfig
166
old mode 100755
167
new mode 100644
168
index 11abbf0..99bf3f5
169
--- a/arch/arm/configs/herring_defconfig
170
+++ b/arch/arm/configs/herring_defconfig
171
@@ -1,7 +1,7 @@
172
 #
173
 # Automatically generated make config: don't edit
174
 # Linux kernel version: 2.6.35.7
175
-# Fri Jun  3 07:07:08 2011
176
+# Sun Apr  8 14:40:16 2012
177
 #
178
 CONFIG_ARM=y
179
 CONFIG_HAVE_PWM=y
180
@@ -418,8 +418,8 @@ CONFIG_ALIGNMENT_TRAP=y
181
 #
182
 CONFIG_ZBOOT_ROM_TEXT=0
183
 CONFIG_ZBOOT_ROM_BSS=0
184
-CONFIG_CMDLINE="console=ttyFIQ0"
185
-# CONFIG_CMDLINE_FORCE is not set
186
+CONFIG_CMDLINE="console=ttyFIQ0 no_console_suspend earlyprintk=serial,ttySAC2,115200 androidboot.serialno=3733BAB66DE200EC androidboot.bootloader=I9020XXKA3 androidboot.baseband=I9020XXKB3 androidboot.info=0x4,0x0,1 androidboot.carrier=EUR gain_code=3 s3cfb.bootloaderfb=0x34a00000 mach-herring.lcd_type=0x00000000 oem_state=unlocked"
187
+CONFIG_CMDLINE_FORCE=y
188
 # CONFIG_XIP_KERNEL is not set
189
 # CONFIG_KEXEC is not set
190
 
191
@@ -823,8 +823,6 @@ CONFIG_UEVENT_HELPER_PATH=""
192
 CONFIG_STANDALONE=y
193
 CONFIG_PREVENT_FIRMWARE_BUILD=y
194
 # CONFIG_FW_LOADER is not set
195
-# CONFIG_FIRMWARE_IN_KERNEL is not set
196
-CONFIG_EXTRA_FIRMWARE=""
197
 # CONFIG_DEBUG_DRIVER is not set
198
 # CONFIG_DEBUG_DEVRES is not set
199
 # CONFIG_SYS_HYPERVISOR is not set
200
@@ -835,7 +833,7 @@ CONFIG_MTD=y
201
 CONFIG_MTD_CONCAT=y
202
 CONFIG_MTD_PARTITIONS=y
203
 # CONFIG_MTD_REDBOOT_PARTS is not set
204
-# CONFIG_MTD_CMDLINE_PARTS is not set
205
+CONFIG_MTD_CMDLINE_PARTS=y
206
 # CONFIG_MTD_AFS_PARTS is not set
207
 # CONFIG_MTD_AR7_PARTS is not set
208
 
209
@@ -1191,6 +1189,7 @@ CONFIG_DEVKMEM=y
210
 CONFIG_SERIAL_SAMSUNG=y
211
 CONFIG_SERIAL_SAMSUNG_UARTS_4=y
212
 CONFIG_SERIAL_SAMSUNG_UARTS=4
213
+# CONFIG_SERIAL_SAMSUNG_DEBUG is not set
214
 CONFIG_SERIAL_SAMSUNG_CONSOLE=y
215
 CONFIG_SERIAL_S5PV210=y
216
 # CONFIG_SERIAL_MAX3100 is not set
217
@@ -2046,7 +2045,9 @@ CONFIG_HAVE_ARCH_KGDB=y
218
 CONFIG_DEBUG_USER=y
219
 CONFIG_DEBUG_ERRORS=y
220
 # CONFIG_DEBUG_STACK_USAGE is not set
221
-# CONFIG_DEBUG_LL is not set
222
+CONFIG_DEBUG_LL=y
223
+CONFIG_EARLY_PRINTK=y
224
+# CONFIG_DEBUG_ICEDCC is not set
225
 CONFIG_OC_ETM=y
226
 CONFIG_DEBUG_S3C_UART=2
227
 
228
diff --git a/arch/arm/mach-s5pv210/dev-herring-phone.c b/arch/arm/mach-s5pv210/dev-herring-phone.c
229
index f8798b3..ecef636 100755
230
--- a/arch/arm/mach-s5pv210/dev-herring-phone.c
231
+++ b/arch/arm/mach-s5pv210/dev-herring-phone.c
232
@@ -48,8 +48,8 @@ static struct resource mdmctl_res[] = {
233
 	},
234
 	[2] = {
235
 		.name = "onedram",
236
-		.start = (S5PV210_PA_SDRAM + 0x05000000),
237
-		.end = (S5PV210_PA_SDRAM + 0x05000000 + SZ_16M - 1),
238
+		.start = (0x30000000  + 0x05000000),
239
+		.end = (0x30000000  + 0x05000000 + SZ_16M - 1),
240
 		.flags = IORESOURCE_MEM,
241
 	},
242
 };
243
diff --git a/arch/arm/mach-s5pv210/mach-herring.c b/arch/arm/mach-s5pv210/mach-herring.c
244
index c3a0182..67fa1cf 100755
245
--- a/arch/arm/mach-s5pv210/mach-herring.c
246
+++ b/arch/arm/mach-s5pv210/mach-herring.c
247
@@ -5494,21 +5494,17 @@ static void __init herring_fixup(struct machine_desc *desc,
248
 		struct tag *tags, char **cmdline,
249
 		struct meminfo *mi)
250
 {
251
-	mi->bank[0].start = 0x30000000;
252
-	mi->bank[0].size = 80 * SZ_1M;
253
+	mi->bank[0].start = 0x40000000;
254
+	mi->bank[0].size = 256 * SZ_1M;
255
 	mi->bank[0].node = 0;
256
 
257
-	mi->bank[1].start = 0x40000000;
258
-	mi->bank[1].size = 256 * SZ_1M;
259
-	mi->bank[1].node = 1;
260
-
261
-	mi->bank[2].start = 0x50000000;
262
+	mi->bank[1].start = 0x50000000;
263
 	/* 1M for ram_console buffer */
264
-	mi->bank[2].size = 127 * SZ_1M;
265
-	mi->bank[2].node = 2;
266
-	mi->nr_banks = 3;
267
+	mi->bank[1].size = 127 * SZ_1M;
268
+	mi->bank[1].node = 1;
269
+	mi->nr_banks = 2;
270
 
271
-	ram_console_start = mi->bank[2].start + mi->bank[2].size;
272
+	ram_console_start = mi->bank[1].start + mi->bank[1].size;
273
 	ram_console_size = SZ_1M - SZ_4K;
274
 
275
 	pm_debug_scratchpad = ram_console_start + ram_console_size;
276
</pre>
277
278
<pre>
279
diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk
280
index fff6d1b..c09d935 100755
281
--- a/BoardConfigCommon.mk
282
+++ b/BoardConfigCommon.mk
283
@@ -51,10 +51,10 @@ DEFAULT_FB_NUM := 2
284
 
285
 BOARD_NAND_PAGE_SIZE := 4096 -s 128
286
 
287
-BOARD_KERNEL_BASE := 0x30000000
288
+BOARD_KERNEL_BASE := 0x40000000
289
 BOARD_KERNEL_PAGESIZE := 4096
290
-BOARD_KERNEL_CMDLINE := console=ttyFIQ0 no_console_suspend
291
-
292
+BOARD_KERNEL_CMDLINE := console=ttyFIQ0 no_console_suspend earlyprintk=serial,ttySAC2,115200 bootmem_debug
293
+BOARD_FORCE_RAMDISK_ADDRESS := 0x41000000
294
 #TARGET_RECOVERY_UI_LIB := librecovery_ui_crespo
295
 TARGET_RELEASETOOLS_EXTENSIONS := device/samsung/crespo
296
</pre>