Skip to content

Commit 95ce278

Browse files
authored
Merge pull request #1713 from HackTricks-wiki/research_update_src_hardware-physical-access_firmware-analysis_android-mediatek-secure-boot-bl2_ext-bypass-el3_20251226_082903
Research Update Enhanced src/hardware-physical-access/firmwa...
2 parents a807923 + 573329d commit 95ce278

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

src/hardware-physical-access/firmware-analysis/android-mediatek-secure-boot-bl2_ext-bypass-el3.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ Example log excerpt:
4343
4444
Note: Some devices reportedly skip bl2_ext verification even with a locked bootloader, which exacerbates the impact.
4545
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+
4648
## Practical exploitation workflow (Fenrir PoC)
4749
4850
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.
4951
5052
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`
5254
- Build a patched image that disables the bl2_ext verification policy
5355
- Flash the resulting payload to the device (fastboot assumed by the helper script)
5456
@@ -61,12 +63,18 @@ Commands:
6163
# Build from a custom bootloader path
6264
./build.sh pacman /path/to/your/bootloader.bin
6365
64-
# Flash the resulting lk.patched (fastboot required by helper script)
66+
# Flash the resulting lk.patched (fastboot required by the helper script)
6567
./flash.sh
6668
```
6769

6870
If fastboot is unavailable, you must use a suitable alternative flashing method for your platform.
6971

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+
7078
## Runtime payload capabilities (EL3)
7179

7280
A patched bl2_ext payload can:
@@ -77,32 +85,58 @@ A patched bl2_ext payload can:
7785

7886
Limitation: Current PoCs note that runtime memory modification may fault due to MMU constraints; payloads generally avoid live memory writes until this is resolved.
7987

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+
void cmd_r0rt1z2(const char *arg, void *data, unsigned int sz) {
96+
video_printf("r0rt1z2 was here...\n");
97+
fastboot_info("pwned by r0rt1z2");
98+
fastboot_okay("");
99+
}
100+
101+
__attribute__((section(".text.main"))) void main(void) {
102+
fastboot_register("oem r0rt1z2", cmd_r0rt1z2, true, false);
103+
notify_enter_fastboot();
104+
}
105+
```
106+
107+
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+
80116
## Porting tips
81117

82118
- Reverse engineer the device-specific bl2_ext to locate verification policy logic (e.g., sec_get_vfy_policy).
83119
- Identify the policy return site or decision branch and patch it to “no verification required” (return 0 / unconditional allow).
84120
- Keep offsets fully device- and firmware-specific; do not reuse addresses between variants.
85121
- 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.
86124

87125
## Security impact
88126

89127
- EL3 code execution after Preloader and full chain-of-trust collapse for the rest of the boot path.
90128
- Ability to boot unsigned TEE/GZ/LK/Kernel, bypassing secure/verified boot expectations and enabling persistent compromise.
91129

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).
97-
98130
## Device notes
99131

100132
- Confirmed supported: Nothing Phone (2a) (Pacman)
101133
- Known working (incomplete support): CMF Phone 1 (Tetris)
102134
- Observed: Vivo X80 Pro reportedly did not verify bl2_ext even when locked
135+
- Industry coverage highlights additional lk2-based vendors shipping the same logic flaw, so expect further overlap across 2024–2025 MTK releases.
103136

104137
## References
105138

106139
- [Fenrir – MediaTek bl2_ext secure‑boot bypass (PoC)](https://github.com/R0rt1z2/fenrir)
140+
- [Cyber Security News – PoC Exploit Released For Nothing Phone Code Execution Vulnerability](https://cybersecuritynews.com/nothing-phone-code-execution-vulnerability/)
107141

108-
{{#include ../../banners/hacktricks-training.md}}
142+
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)