Huawei TrustZone HuaweiNfcActiveCard Vulnerability
A buffer overflow in the SplitAidStrtok function of the HuaweiNfcActiveCard trustlet allows writing out of bounds, and an information leak in ParseAidList reveals a stack address. An attacker could exploit these to achieve arbitrary read/write and potentially code execution in the TrustZone.
blog.impalabs.com
Published on blog.impalabs.com
Alexandre Adamski](https://blog.impalabs.com/authors/alexandre-adamski.html) [{{media:2}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the lack of bounds checking in SplitAidStrtok when copying substrings into a fixed-size buffer, and a format string mistake in ParseAidList that prints an address instead of a string.
What the attacker needed
Ability to call the TA (bypass whitelist); kernel driver patching or code injection; physical access or high privileges
The fix
The vulnerability was fixed in the December 2021 update according to Huawei PSIRT.
How it was found
- Send a crafted input string to the CmdTeeHardwareSyncAidList command to trigger the information leak and obtain a stack address.
- Use the buffer overflow to overwrite the saved R5 register with the address of the saved LR, then leak the code address via SLog.
- Calculate the trustlet base address from the leaked code address.
- Use ROP gadgets to perform arbitrary read and write in the trustlet memory.
- Demonstrate the write primitive by writing to the .data section and the read primitive by dumping trustlet memory.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
This report describes two bugs in a security chip inside Huawei phones. One bug lets an attacker write too much data into a small memory area, and the other leaks a memory address. Together, they could let an attacker take control of the chip's secure code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.