Project

General

Profile

ExynosModemIsolation » History » Version 13

Denis 'GNUtoo' Carikli, 03/02/2020 11:14 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 5 Denis 'GNUtoo' Carikli
The modem (XMM 6160) is separated from the SoC and communicates with it via serial over 16Mib of shared memory: this is bad since it means that RAM is compromised (at least 80Mib + 16Mib = 96Mib) and can be used to spy.
33
Regarding audio, the modem is connected to the CODEC but cannot control it (the SoC has to enable routing from/to the modem).
34
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.
35
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.
36
37 3 Paul Kocialkowski
The modem is able to spy on (at least) 96 Mib of the main memory. So far, we cannot tell:
38
* if it can only spy 80Mib or the full memory
39 1 Paul Kocialkowski
* if it can be fixed or not
40 4 Paul Kocialkowski
41
The Linux kernel is being loaded at the beginning of the shared memory bank (0x30000000), however the kernel should be off when it loads.
42 1 Paul Kocialkowski
43 12 Denis 'GNUtoo' Carikli
h3. Nexus S (GT-I902x) Kernel details
44 1 Paul Kocialkowski
45 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:
46 1 Paul Kocialkowski
<pre>
47
static struct resource mdmctl_res[] = {
48
[...]
49
        [2] = {
50
                .name = "onedram",
51
                .start = (S5PV210_PA_SDRAM + 0x05000000),
52
                .end = (S5PV210_PA_SDRAM + 0x05000000 + SZ_16M - 1),
53
                .flags = IORESOURCE_MEM,
54
        },
55
};
56
</pre>
57
58
* S5PV210_PA_SDRAM is 0x30000000
59 3 Paul Kocialkowski
* 0x05000000 is 80Mib
60 1 Paul Kocialkowski
* mdmctl_res goes in a platform device struct which is passed to the modem driver:
61
62
<pre>
63
static struct platform_device modemctl = {
64
        .name = "modemctl",
65
        .id = -1,
66
        .num_resources = ARRAY_SIZE(mdmctl_res),
67
        .resource = mdmctl_res,
68
        .dev = {
69
                .platform_data = &mdmctl_data,
70
        },
71
};
72
</pre>
73
74 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: 
75 1 Paul Kocialkowski
<pre>
76
static void __init herring_fixup(struct machine_desc *desc,
77
                struct tag *tags, char **cmdline,
78
                struct meminfo *mi)
79
{
80
        mi->bank[0].start = 0x30000000;
81
        mi->bank[0].size = 80 * SZ_1M;
82
        mi->bank[0].node = 0;
83
</pre>
84
85 3 Paul Kocialkowski
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 80Mib of memory.
86 4 Paul Kocialkowski
87 13 Denis 'GNUtoo' Carikli
h3. Galaxy S (GT-I9000) Kernel details
88
89
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:
90
<pre>
91
static struct resource onedram_res[] = {
92
[...]
93
	[0] = {
94
		.start = (S5PV210_PA_SDRAM + 0x05000000),
95
		.end = (S5PV210_PA_SDRAM + 0x05000000 + SZ_16M - 1),
96
		.flags = IORESOURCE_MEM,
97
		},
98
};
99
</pre>
100
101
* S5PV210_PA_SDRAM is 0x30000000
102
* 0x05000000 is 80Mib
103
* mdmctl_res goes in a platform device struct which is passed to the modem driver:
104
105
<pre>
106
static struct platform_device onedram = {
107
		.name = "onedram",
108
		.id = -1,
109
		.num_resources = ARRAY_SIZE(onedram_res),
110
		.resource = onedram_res,
111
		.dev = {
112
			.platform_data = &onedram_data,
113
			},
114
		};
115
</pre>
116
117
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: 
118
<pre>
119
static void __init aries_fixup(struct machine_desc *desc,
120
		struct tag *tags, char **cmdline,
121
		struct meminfo *mi)
122
{
123
	mi->bank[0].start = 0x30000000;
124
	mi->bank[0].size = 80 * SZ_1M;
125
        [...]
126
}
127
</pre>
128
129
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 80Mib of memory.
130
131 8 Denis 'GNUtoo' Carikli
h3. Workaround attempt
132 1 Paul Kocialkowski
133 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.
134
135
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.
136
137
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.
138 4 Paul Kocialkowski
139
The current diff with the Nexus S kernel is here, but it doesn't boot at all with the following changes (and mkbootimg changes):
140
141
<pre>
142
diff --git a/arch/arm/configs/herring_defconfig b/arch/arm/configs/herring_defconfig
143
old mode 100755
144
new mode 100644
145
index 11abbf0..99bf3f5
146
--- a/arch/arm/configs/herring_defconfig
147
+++ b/arch/arm/configs/herring_defconfig
148
@@ -1,7 +1,7 @@
149
 #
150
 # Automatically generated make config: don't edit
151
 # Linux kernel version: 2.6.35.7
152
-# Fri Jun  3 07:07:08 2011
153
+# Sun Apr  8 14:40:16 2012
154
 #
155
 CONFIG_ARM=y
156
 CONFIG_HAVE_PWM=y
157
@@ -418,8 +418,8 @@ CONFIG_ALIGNMENT_TRAP=y
158
 #
159
 CONFIG_ZBOOT_ROM_TEXT=0
160
 CONFIG_ZBOOT_ROM_BSS=0
161
-CONFIG_CMDLINE="console=ttyFIQ0"
162
-# CONFIG_CMDLINE_FORCE is not set
163
+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"
164
+CONFIG_CMDLINE_FORCE=y
165
 # CONFIG_XIP_KERNEL is not set
166
 # CONFIG_KEXEC is not set
167
 
168
@@ -823,8 +823,6 @@ CONFIG_UEVENT_HELPER_PATH=""
169
 CONFIG_STANDALONE=y
170
 CONFIG_PREVENT_FIRMWARE_BUILD=y
171
 # CONFIG_FW_LOADER is not set
172
-# CONFIG_FIRMWARE_IN_KERNEL is not set
173
-CONFIG_EXTRA_FIRMWARE=""
174
 # CONFIG_DEBUG_DRIVER is not set
175
 # CONFIG_DEBUG_DEVRES is not set
176
 # CONFIG_SYS_HYPERVISOR is not set
177
@@ -835,7 +833,7 @@ CONFIG_MTD=y
178
 CONFIG_MTD_CONCAT=y
179
 CONFIG_MTD_PARTITIONS=y
180
 # CONFIG_MTD_REDBOOT_PARTS is not set
181
-# CONFIG_MTD_CMDLINE_PARTS is not set
182
+CONFIG_MTD_CMDLINE_PARTS=y
183
 # CONFIG_MTD_AFS_PARTS is not set
184
 # CONFIG_MTD_AR7_PARTS is not set
185
 
186
@@ -1191,6 +1189,7 @@ CONFIG_DEVKMEM=y
187
 CONFIG_SERIAL_SAMSUNG=y
188
 CONFIG_SERIAL_SAMSUNG_UARTS_4=y
189
 CONFIG_SERIAL_SAMSUNG_UARTS=4
190
+# CONFIG_SERIAL_SAMSUNG_DEBUG is not set
191
 CONFIG_SERIAL_SAMSUNG_CONSOLE=y
192
 CONFIG_SERIAL_S5PV210=y
193
 # CONFIG_SERIAL_MAX3100 is not set
194
@@ -2046,7 +2045,9 @@ CONFIG_HAVE_ARCH_KGDB=y
195
 CONFIG_DEBUG_USER=y
196
 CONFIG_DEBUG_ERRORS=y
197
 # CONFIG_DEBUG_STACK_USAGE is not set
198
-# CONFIG_DEBUG_LL is not set
199
+CONFIG_DEBUG_LL=y
200
+CONFIG_EARLY_PRINTK=y
201
+# CONFIG_DEBUG_ICEDCC is not set
202
 CONFIG_OC_ETM=y
203
 CONFIG_DEBUG_S3C_UART=2
204
 
205
diff --git a/arch/arm/mach-s5pv210/dev-herring-phone.c b/arch/arm/mach-s5pv210/dev-herring-phone.c
206
index f8798b3..ecef636 100755
207
--- a/arch/arm/mach-s5pv210/dev-herring-phone.c
208
+++ b/arch/arm/mach-s5pv210/dev-herring-phone.c
209
@@ -48,8 +48,8 @@ static struct resource mdmctl_res[] = {
210
 	},
211
 	[2] = {
212
 		.name = "onedram",
213
-		.start = (S5PV210_PA_SDRAM + 0x05000000),
214
-		.end = (S5PV210_PA_SDRAM + 0x05000000 + SZ_16M - 1),
215
+		.start = (0x30000000  + 0x05000000),
216
+		.end = (0x30000000  + 0x05000000 + SZ_16M - 1),
217
 		.flags = IORESOURCE_MEM,
218
 	},
219
 };
220
diff --git a/arch/arm/mach-s5pv210/mach-herring.c b/arch/arm/mach-s5pv210/mach-herring.c
221
index c3a0182..67fa1cf 100755
222
--- a/arch/arm/mach-s5pv210/mach-herring.c
223
+++ b/arch/arm/mach-s5pv210/mach-herring.c
224
@@ -5494,21 +5494,17 @@ static void __init herring_fixup(struct machine_desc *desc,
225
 		struct tag *tags, char **cmdline,
226
 		struct meminfo *mi)
227
 {
228
-	mi->bank[0].start = 0x30000000;
229
-	mi->bank[0].size = 80 * SZ_1M;
230
+	mi->bank[0].start = 0x40000000;
231
+	mi->bank[0].size = 256 * SZ_1M;
232
 	mi->bank[0].node = 0;
233
 
234
-	mi->bank[1].start = 0x40000000;
235
-	mi->bank[1].size = 256 * SZ_1M;
236
-	mi->bank[1].node = 1;
237
-
238
-	mi->bank[2].start = 0x50000000;
239
+	mi->bank[1].start = 0x50000000;
240
 	/* 1M for ram_console buffer */
241
-	mi->bank[2].size = 127 * SZ_1M;
242
-	mi->bank[2].node = 2;
243
-	mi->nr_banks = 3;
244
+	mi->bank[1].size = 127 * SZ_1M;
245
+	mi->bank[1].node = 1;
246
+	mi->nr_banks = 2;
247
 
248
-	ram_console_start = mi->bank[2].start + mi->bank[2].size;
249
+	ram_console_start = mi->bank[1].start + mi->bank[1].size;
250
 	ram_console_size = SZ_1M - SZ_4K;
251
 
252
 	pm_debug_scratchpad = ram_console_start + ram_console_size;
253
</pre>
254
255
<pre>
256
diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk
257
index fff6d1b..c09d935 100755
258
--- a/BoardConfigCommon.mk
259
+++ b/BoardConfigCommon.mk
260
@@ -51,10 +51,10 @@ DEFAULT_FB_NUM := 2
261
 
262
 BOARD_NAND_PAGE_SIZE := 4096 -s 128
263
 
264
-BOARD_KERNEL_BASE := 0x30000000
265
+BOARD_KERNEL_BASE := 0x40000000
266
 BOARD_KERNEL_PAGESIZE := 4096
267
-BOARD_KERNEL_CMDLINE := console=ttyFIQ0 no_console_suspend
268
-
269
+BOARD_KERNEL_CMDLINE := console=ttyFIQ0 no_console_suspend earlyprintk=serial,ttySAC2,115200 bootmem_debug
270
+BOARD_FORCE_RAMDISK_ADDRESS := 0x41000000
271
 #TARGET_RECOVERY_UI_LIB := librecovery_ui_crespo
272
 TARGET_RELEASETOOLS_EXTENSIONS := device/samsung/crespo
273
</pre>