You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/hardware-physical-access/firmware-analysis/android-mediatek-secure-boot-bl2_ext-bypass-el3.md
+43-9Lines changed: 43 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,12 +43,14 @@ Example log excerpt:
43
43
44
44
Note: Some devices reportedly skip bl2_ext verification even with a locked bootloader, which exacerbates the impact.
45
45
46
+
Devices that ship the lk2 secondary bootloader have been observed with the same logic gap, so grab expdb logs for both bl2_ext and lk2 partitions to confirm whether either path enforces signatures before you attempt porting.
47
+
46
48
## Practical exploitation workflow (Fenrir PoC)
47
49
48
50
Fenrir is a reference exploit/patching toolkit for this class of issue. It supports Nothing Phone (2a) (Pacman) and is known working (incompletely supported) on CMF Phone 1 (Tetris). Porting to other models requires reverse engineering the device-specific bl2_ext.
49
51
50
52
High-level process:
51
-
- Obtain the device bootloader image for your target codename and place it as bin/<device>.bin
53
+
- Obtain the device bootloader image for your target codename and place it as `bin/<device>.bin`
52
54
- Build a patched image that disables the bl2_ext verification policy
53
55
- Flash the resulting payload to the device (fastboot assumed by the helper script)
54
56
@@ -61,12 +63,18 @@ Commands:
61
63
# Build from a custom bootloader path
62
64
./build.sh pacman /path/to/your/bootloader.bin
63
65
64
-
# Flash the resulting lk.patched (fastboot required by helper script)
66
+
# Flash the resulting lk.patched (fastboot required by the helper script)
65
67
./flash.sh
66
68
```
67
69
68
70
If fastboot is unavailable, you must use a suitable alternative flashing method for your platform.
69
71
72
+
### Build automation & payload debugging
73
+
74
+
-`build.sh` now auto-downloads and exports the Arm GNU Toolchain 14.2 (aarch64-none-elf) the first time you run it, so you do not have to juggle cross-compilers manually.
75
+
- Export `DEBUG=1` before invoking `build.sh` to compile payloads with verbose serial prints, which greatly helps when you are blind-patching EL3 code paths.
76
+
- Successful builds drop both `lk.patched` and `<device>-fenrir.bin`; the latter already has the payload injected and is what you should flash/boot-test.
77
+
70
78
## Runtime payload capabilities (EL3)
71
79
72
80
A patched bl2_ext payload can:
@@ -77,32 +85,58 @@ A patched bl2_ext payload can:
77
85
78
86
Limitation: Current PoCs note that runtime memory modification may fault due to MMU constraints; payloads generally avoid live memory writes until this is resolved.
79
87
88
+
## Payload staging patterns (EL3)
89
+
90
+
Fenrir splits its instrumentation into three compile-time stages: stage1 runs before `platform_init()`, stage2 runs before LK signals fastboot entry, and stage3 executes immediately before LK loads Linux. Each device header under `payload/devices/` provides the addresses for these hooks plus fastboot helper symbols, so keep those offsets synchronized with your target build.
91
+
92
+
Stage2 is a convenient location to register arbitrary `fastboot oem` verbs:
93
+
94
+
```c
95
+
voidcmd_r0rt1z2(const char *arg, void *data, unsigned int sz) {
Stage3 demonstrates how to temporarily flip page-table attributes to patch immutable strings such as Android’s “Orange State” warning without needing downstream kernel access:
108
+
109
+
```c
110
+
set_pte_rwx(0xFFFF000050f9E3AE);
111
+
strcpy((char *)0xFFFF000050f9E3AE, "Patched by stage3");
112
+
```
113
+
114
+
Because stage1 fires prior to platform bring-up, it is the right place to call into OEM power/reset primitives or to insert additional integrity logging before the verified boot chain is torn down.
115
+
80
116
## Porting tips
81
117
82
118
- Reverse engineer the device-specific bl2_ext to locate verification policy logic (e.g., sec_get_vfy_policy).
83
119
- Identify the policy return site or decision branch and patch it to “no verification required” (return 0 / unconditional allow).
84
120
- Keep offsets fully device- and firmware-specific; do not reuse addresses between variants.
85
121
- Validate on a sacrificial unit first. Prepare a recovery plan (e.g., EDL/BootROM loader/SoC-specific download mode) before you flash.
122
+
- Devices using the lk2 secondary bootloader or reporting “img_auth_required = 0” for bl2_ext even while locked should be treated as vulnerable copies of this bug class; Vivo X80 Pro has already been observed skipping verification despite a reported lock state.
123
+
- Compare expdb logs from both locked and unlocked states—if certificate timing jumps from 0 ms to a non-zero value once you relock, you likely patched the right decision point but still need to harden lock-state spoofing to hide the modification.
86
124
87
125
## Security impact
88
126
89
127
- EL3 code execution after Preloader and full chain-of-trust collapse for the rest of the boot path.
90
128
- Ability to boot unsigned TEE/GZ/LK/Kernel, bypassing secure/verified boot expectations and enabling persistent compromise.
91
129
92
-
## Detection and hardening ideas
93
-
94
-
- Ensure Preloader verifies bl2_ext regardless of seccfg state.
95
-
- Enforce authentication results and gather audit evidence (timings > 0 ms, strict errors on mismatch).
96
-
- Lock-state spoofing should be made ineffective for attestation (tie lock state to AVB/vbmeta verification decisions and fuse-backed state).
0 commit comments