Skip to content
Memory corruption Write-up Advanced

Huawei TrustZone TEE_Weaver Vulnerability

The TEE_Weaver trusted application did not properly validate the type of the third parameter in the InterfaceRead command, allowing a type confusion that writes 0x10 bytes of attacker-controlled data to an arbitrary address. An attacker with the ability to call the TA could exploit this to leak memory addresses, achieve arbitrary read/write, and potentially execute code in the trusted execution environment.

blog.impalabs.com

Published on blog.impalabs.com

Alexandre Adamski](https://blog.impalabs.com/authors/alexandre-adamski.html) [{{media:2}}

The author, on blog.impalabs.com

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

The validation function for the InterfaceRead command did not check the type of the third parameter, allowing a value parameter to be passed instead of a memory reference, which caused a type confusion leading to an arbitrary write.

Impact

An attacker who can bypass the whitelist could leak memory addresses, achieve arbitrary read/write, and potentially execute code in the trusted execution environment, leading to further privilege escalation.

What the attacker needed

Ability to call the TA (bypass whitelist); access to logcat; knowledge of TA internals

The fix

The vulnerability was fixed in the January 2022 update.

How it was found

  1. Patch the kernel driver to bypass the whitelist authentication and impersonate an allowed client binary.
  2. Send a write command to set the weaver token in an unused slot (slot 63).
  3. Send a read command on the same slot to trigger the log that leaks the stack address.
  4. Parse logcat output to extract the leaked address and calculate the ASLR slide.
  5. Send a read command with a crafted parameter to write the weaver token to an arbitrary address.
  6. Overwrite the function pointer for the write command's check function to enable arbitrary read, then dump 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.

A trusted application (TA) is a small program that runs in a secure part of the phone's processor, separate from the normal operating system. The TA expected a certain type of input for one of its commands but didn't check it properly, so an attacker could trick it into writing data to any memory location. This could let an attacker take control of the secure program.

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.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.