Summary
Several ESP-TEE secure-service wrappers in ESP-IDF insufficiently validate caller-supplied pointers, allowing access to TEE-exclusive memory via hardware peripherals running in machine mode.
An attacker code running in the rich execution environment (REE) can abuse these services to read or infer sensitive data from TEE memory, including through oracle-style incremental disclosure.
Affected context
The vulnerability arises in ESP-IDF deployments that use ESP-TEE secure-service wrappers to access hardware peripherals such as ECC, SHA, or SPI from non-secure (REE) code.
It manifests when the wrapper functions accept caller-supplied pointers and only partially validate them, failing to ensure that input buffers do not reference TEE-exclusive memory regions.
The issue is most relevant where sensitive keys, credentials, or confidential application data are stored in TEE memory under the assumption that REE code cannot read them directly.
Exploit preconditions
- Attack surface: Secure-service APIs exposed by ESP-TEE wrappers in esp_secure_services.c and esp_secure_services_iram.c.
- Required access: Ability to execute or control code in the REE context that can invoke these secure-service wrappers.
- Trigger point: Calls to affected wrappers that pass attacker-controlled pointers as input buffers, pointing into TEE-protected memory.
- Why exploitation is possible: The wrapper functions only validate some pointer arguments and do not consistently enforce that all input pointers reference allowed REE memory ranges, while the underlying peripherals execute in RISC‑V M‑mode with full address-space access and can operate over TEE memory.
Why this happens
The core issue is incomplete validation of untrusted input pointers passed across a privilege boundary into trusted execution code.
Some secure-service wrappers check only subsets of arguments or rely on assumptions about pointer provenance, allowing REE-controlled pointers to reference TEE-exclusive memory.
Because the TEE hardware peripherals execute with high privilege and unrestricted address-space access, they will read from the supplied addresses without enforcing TEE/REE separation.
This maps to:
- CWE-20 (Improper Input Validation): Pointer arguments are not fully validated against expected address ranges.
- CWE-125 (Out-of-Bounds Read): Peripheral operations read from memory regions outside the intended accessible domain.
- CWE-200 (Information Exposure): Data from TEE-only regions is returned or inferable in the REE, breaking confidentiality guarantees.
Potential impact
- Exposure of cryptographic keys or intermediate values stored in TEE memory.
- Disclosure of sensitive application data or credentials resident in secure memory.
- Reconstruction of TEE-resident information via repeated oracle-style queries, even when only derived values or single bits are returned per call.
- Undermining of the isolation guarantees between TEE and REE, weakening overall platform trust assumptions.
- Potential facilitation of further attacks that rely on knowledge of TEE-internal state.
General mitigation guidance
Effective mitigation focuses on enforcing strict memory and trust boundaries at the secure-service API layer and within TEE code:
- Validate all pointer arguments in secure-service wrappers, ensuring they point only to approved REE-accessible regions before invoking high-privilege peripherals.
- Centralize pointer validation logic into reusable helpers so every TEE entry point consistently applies the same address-range and alignment checks.
- Design secure-service interfaces to minimize or eliminate the need for caller-supplied input pointers into arbitrary memory, favoring fixed or pre-validated buffers where practical.
- Restrict the amount and granularity of data returned from TEE operations, especially where derived outputs could form an oracle for incremental disclosure.
- Apply least-privilege principles to TEE-accessible peripherals and code paths, reducing the scope of memory they can legitimately access when servicing REE requests.
How teams detect issues like this
Detection typically relies on a combination of code-centric and policy-centric approaches:
- Static analysis: Define rules to flag TEE entry points that accept raw pointers from less-privileged contexts without comprehensive range checks against trusted memory regions.
- Code review: Pay particular attention to secure-service wrapper implementations, verifying that every pointer argument (input and output) is validated before dereference or peripheral invocation.
- Architecture review: Maintain explicit documentation of TEE vs. REE memory maps and require that all cross-world APIs reference standardized validation routines aligned with these maps.
- Automated testing: Add negative tests that attempt to pass pointers near or into TEE-exclusive regions and verify that calls fail safely rather than leaking data.
- Tooling integration: Use automated code review or security scanning tools to enforce patterns such as "no direct dereference or peripheral use of unvalidated REE pointers in TEE code."

