Project

General

Profile

ExynosModemIsolation » History » Version 22

Denis 'GNUtoo' Carikli, 03/28/2020 10:37 PM

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