Attacking Pixel's Titan M with Only One Byte (CVE202220233) and getting 75,000 USD bounty
A one-byte out-of-bounds write in the Titan M firmware's Keymaster task allowed an attacker to corrupt a pointer to the incoming request buffer, redirecting subsequent requests to overwrite a return address and hijack execution. The attacker could then build a ROP chain to read arbitrary memory, including StrongBox-protected keys and the Root of Trust.
Published on blog.quarkslab.com
Posted Thu 11 August 2022 Authors Damiano Melotti, Maxime Rossi Bellom Category Android Tags reverse-engineering, fuzzing, vulnerability, exploitation, Android, 2022
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.
Context
Titan M is a security chip that Google introduced in its Pixel smartphones starting with the Pixel 3 in 2018. It sits on a separate system-on-a-chip (SoC) inside the device, runs its own firmware, and communicates with the Application Processor (AP) over the SPI bus. Its purpose is to reduce the attack surface available to attackers and to mitigate hardware tampering and side-channel attacks. It implements APIs that protect the most security-sensitive features of the phone, such as secure boot and a hardware-backed Keystore with StrongBox.
The firmware is based on Embedded Controller (EC), a lightweight open source OS for micro-controllers. That OS is built around the concept of tasks, each with a fixed stack size and no heap, so there is no complex dynamic allocation. The chip therefore has an essentially static memory layout, which lets the researchers assume that some objects are always located at the same address. The OS also eliminates some temporal memory safety bugs associated with dynamic allocation. The chip has a Memory Protection Unit (MPU) configured so that no region has Write and eXecute permissions at the same time, and secure boot is implemented with signature checks performed before loading the firmware. Apart from a hardcoded stack canary placed at the end of the tasks' stacks to detect errors, no common exploit mitigation techniques are present on the chip.
The vulnerability described here is CVE-2022-20233, found in the Keymaster task while processing an ImportKey request. The vulnerable firmware was introduced by Google's Pixel security update of May 2022.
Setup
The researchers (Damiano Melotti, Maxime Rossi Bellom and Philippe Teuwen) had spent about a year and a half reverse engineering the Titan M, and had previously presented results at Black Hat EU 2021 together with a whitepaper containing the background knowledge from the first part of the research.
The main tool is nosclient, a custom client that runs natively on Android and communicates directly with the kernel driver responsible for communication with the chip. It allows forging arbitrary messages and sending them directly to the driver. After sending a request, Titan M replies with a return code and a response, which is empty in case of errors. Using nosclient requires a rooted device, or physical access to the SPI bus.
For fuzzing, the researchers used two approaches. Black-box fuzzing relied on nosclient as the channel to communicate with the chip and on the return code from the library functions as the signal to infer what happened. Most tasks communicating with Android use Protobuf to serialise messages, and the open source definitions in AOSP allowed mutating these messages with libprotobuf-mutator. For Nugget, one of the tasks that does not use Protobuf, they used Radamsa to generate test cases.
Emulation-based fuzzing used the Unicorn emulator engine with AFL++ as the fuzzing framework. Unicorn is a QEMU-based project that only supports CPU emulation, without full-system emulation, which made it easy to set up scripts and implement ad-hoc tweaks. Unicorn integrates with AFL++ through its unicorn mode, which allows fuzzing anything that can be emulated with Unicorn; the only required step is defining the place_input_callback, a function that writes inputs into the target's memory at every interaction. AFL++ custom mutators let them plug libprotobuf-mutator again and emulate three tasks separately: Keymaster, Identity and Weaver. AVB was ignored because of its limited attack surface, with most interactions happening while the device is in bootloader mode.
For observing the chip, the UART console is essential. There are two ways to access it. The first uses a special debugging cable called SuzyQable, officially mentioned as the cable to debug Chrome OS microcontrollers; since Titan M is based on the same operating system, it also works with it. To activate it, boot the Pixel in fastboot mode and run:
fastboot oem citadel suzyq on
Then, connecting the device with the SuzyQable gives access to the UART console as a tty interface on the laptop, while the cable also allows communicating with the device through adb. The drawback is that as soon as the chip crashes, or even after a reboot command is sent over the console, the channel is closed and the interface must be activated again by going back to fastboot mode.
The second solution is the MacGyver one: the Titan M exposes the UART pins on the motherboard, so the researchers soldered two wires and obtained the same shell as with the cable. In this case the console never closes and stays active no matter what happens to the device or the chip.

The Titan M console is extremely basic and allows simple interactions with the chip to investigate statistics, versions and similar things. Most importantly, it is where debugging logs are printed.
Finding it
While fuzzing the Keymaster task, the researchers found a crash caused by a UC_ERR_WRITE_UNMAPPED while processing an ImportKey request. The crash occurred in a strb instruction, meaning the firmware was trying to write 1 byte into an unmapped memory area.
A simple message that triggers the vulnerability is the following:
ImportKeyRequest
params {
params {
tag: ALGORITHM
integer: 4
}
params {
tag: DIGEST
integer: 40706
}
}
symmetric_key {
material: "<1h5\003H\232@\233"
}
ImportKey messages contain a KeyParameters field, which is made of one or more KeyParameter objects. The bug occurs while processing the tags in a key parameter: the vulnerable function loops through the list of parameters and, for each one, checks whether the tag is 0x20005, corresponding to DIGEST. When such a parameter is found, the function takes the associated integer field and, after some checks, uses it as an offset into a stack buffer to set a byte to 1. Passing a large enough integer writes that one byte value of 0x01 out of bounds.
The assembly and decompiled views below show the checks as well as the strb instruction causing the out of bounds write and the subsequent crash. At that point, r1 is 0x1, r7 is the buffer address and r3 is the integer field of the current KeyParameter.
ldr.w r1,[r2,#-0x4]
ldr r3,[PTR_DAT_0005d808] ; 0x20005
cmp r1,r3
bne increment_loop_vars
ldr r3,[r2,#0x0]
uxtb r0,r3
cmp r0,#0x4
bhi error_exit
movs r1,#0x1
lsl.w r0,r1,r0
tst r0,#0x15
beq error_exit
strb r1,[r7,r3]
if (((nugget_app_keymaster_KeyParameter *)(offset + -1))->tag == 0x20005) {
masked = *offset & 0xff;
if ((4 < masked) || ((1 << masked & 0x15U) == 0)) {
return 0x26;
}
*(undefined *)(buffer + *offset) = 1;
*param_3 = *param_3 + 1;
*param_4 = offset;
}
The vulnerability can be triggered as many times as there are parameters with a DIGEST tag, limited only by the maximum size of the KeyParameters list. This results in multiple 1-byte out-of-bounds writes. The writes are far from arbitrary because of the checks on the offset: without entering into the details of the bit-wise operations, the least significant byte can only be 0x0, 0x2 or 0x4.
At first sight this looks like a very minor and hardly exploitable issue. But Titan M's memory is completely static, and the bug can be reached by different code paths, considering the various messages that contain a KeyParameters field. Provided the write lands at the right place, setting a single byte to 1 can do many things, from a simple DoS to altering a size variable somewhere in memory and causing a corruption elsewhere.
Exploitation
The researchers wrote a small script to generate and highlight all the possible writable addresses in Ghidra, then searched for interesting targets. As it turned out, triggering the vulnerability just once was enough to compromise the chip.
Step 1: choose what to overwrite
During their tests, the researchers found they could reach the vulnerable code with r1 containing 0x14019. Applying a 0xa204 offset to this (the least significant byte allows passing the checks) reaches 0x1e21d. This address is part of a structure they called KEYMASTER_SPI_DATA, which contains information about the exchange of Keymaster messages with Android. In particular, one byte of the memory location pointing to where incoming requests for the Keymaster task are stored can be overwritten: by default this is 0x192c8, but writing 0x1 to 0x1e21d makes the value 0x101c8. As a result, the following Keymaster requests are stored quite far from where they are supposed to be, with catastrophic consequences for the Titan M.
Step 2: redirect execution flow
Because the new location is still in the memory space of the chip, an incoming message ends up overwriting other data in Titan M's memory. The researchers tried sending larger and larger commands while monitoring the UART logs. After some testing, they found that placing a valid code address after 556 bytes of payload allowed jumping to that address, practically redirecting execution to a function of their choice. They detected this thanks to logs printed in the UART console.

They suppose that this portion of memory was being used by some task (probably idle), which may have pushed a return address to its stack that was now overwritten. At this point they knew they could jump to an arbitrary function.
Step 3: pivot the stack
Because writable memory is not executable, shellcode cannot be written and jumped to. Instead the researchers relied on a code-reuse attack based on Return Oriented Programming, with the objective of building a read-anywhere primitive so that secrets protected by Titan M could be leaked with a crafted command from nosclient.
The ROP chain could not be written exactly where the first gadget was written, because that would corrupt memory and make the chip crash before the exploit completed. The first challenge was therefore to pivot the stack. Ideally they wanted to decrease the stack pointer: assuming the stack moves towards larger addresses, they wanted to rely on the payload placed in those 556 bytes, which they knew could be set as desired without nasty side-effects. They found only one gadget to do so, which also does a few more things:
sub sp, #0x20; mov r4, r0; ldr r3, [r0]; add.w r5, r4, #0x70; ldr r3, [r3, #8]; blx r3;
They wrote a ROP chain that calls this gadget several times, making sure r0 pointed to a memory area they also controlled, where they wrote gadgets to make the ldr and blx instructions work as intended. The picture below shows this approach graphically for the first iterations (it is actually done several more times). The red arrows follow the execution flow and the blue ones the stack pointer; the scale is not respected.

Step 4: reach the command handler context
After having climbed up the stack a few times, the actual attack could proceed. The only way to return leaked bytes to Android was to copy them into the response of an SPI command. For this to happen, execution needed to be in the context of the command handler, which is called taking its address from memory after parsing the command code. That address could therefore be overwritten, but replacing the actual code was impossible: all they could do was make it jump into a memory area they also controlled and write more gadgets there for the ROP chain. This is done in the space created in the first step, making sure to ignore the slots used in the previous ROP chain (assigning them to registers that are not used).
This step was probably the most challenging, as it required finding the right gadget to make the stack pivot to a memory area that remains under control when the handler is triggered. No such gadget existed, so the researchers had to be creative. By emulating the execution of the Keymaster DestroyAttestationIds command handler, they understood that there was one single 32-bit slot in its stack that was not overwritten by previous functions in the call chain. They wrote one single gadget there, acting as a trampoline to move the stack far enough from the Keymaster stack and reach an area where the payload would be preserved.

Wrapping up, the exploit goes as follows:
- move up on the stack from where code execution is obtained;
- once there is enough space, execute a ROP chain that:
- replaces the Keymaster DestroyAttestationIds command handler with one gadget, popping some registers from the stack;
- writes one gadget on the Keymaster stack, which ends up being executed when the handler is triggered and moves the stack pointer enough to reach an area where what is written will not be tampered with by the normal execution of the firmware;
- copies the final ROP chain to such an area.
Step 5: leak memory
Once this was achieved, finishing the exploit was relatively straightforward, as execution was controlled from the handler context. The researchers called memcpy with user-provided arguments to copy what they wanted to read into the Keymaster SPI response buffer, then jumped back to the Keymaster stack, like the normal command handler would have done.
Root cause
The vulnerable function processes the tags of a KeyParameter and, when the tag is 0x20005 (DIGEST), takes the associated integer field and uses it as an offset into a stack buffer to write the byte 0x01. The checks only constrain the least significant byte of the offset to 0x0, 0x2 or 0x4, so a large enough integer writes out of bounds. The write is limited to one byte with a constrained value, but the static memory layout of the chip and the multiple code paths that reach the vulnerable code make a single such write enough to corrupt a pointer in KEYMASTER_SPI_DATA.
The chip's defences did not stop the attack. The MPU prevents a region from being writable and executable at the same time, which is why the researchers used ROP rather than shellcode, but it does not prevent the out of bounds write itself. The hardcoded stack canary detects errors at the end of task stacks; the report does not say whether it played any role here.
Impact
The leak functionality built with this exploit allows reading arbitrary memory on the chip, so any readable address can be accessed. As a consequence, the secrets stored in the chip can be dumped, such as the Root of Trust sent by the Pixel bootloader when the Titan M is updated. The Boot ROM, previously unavailable, can also be accessed. This is possible despite the slightly customised version of memcpy in the chip, which checks whether the src or dst buffers equal 0x0: instead of jumping directly to the entry point of the function, the exploit skips those checks and jumps directly to the basic block where the copying happens.
One of the most interesting consequences is the ability to retrieve any StrongBox protected key, defeating the highest level of protection of the Android Keystore. As in TrustZone, these keys can only be used inside Titan M, while they are stored in an encrypted key blob on the device. The procedure is:
- read a key blob from the Android OS (from any application);
- send a valid, well-formed BeginOperation request containing such a key blob: the handler for this command decrypts the key and stores it at a specific memory address, preparing the chip to perform the requested operation;
- run the exploit and leak the memory where the plaintext key is now stored.
To demonstrate the attack, the researchers developed a dummy application that creates a StrongBox-protected AES key and encrypts a string with it. With the exploit and the approach above, the corresponding key can be leaked from the Titan M, and by re-using the same initialization vector the string can be decrypted offline (or rather "off phone").
There are two conditions to perform this attack. First, it must be possible to send commands to the chip, either from a rooted device (required to use nosclient) or by physically accessing the SPI bus. Second, there must be a way to access the key blobs on the Android file system, which can again be done by being root, or with some exploit to bypass File Based Encryption or the uid access control.
Fix
The vulnerability was reported to Google and the best mitigation is the patch provided in the June security bulletin. Google published the June 2022 Pixel update with fixes for CVE-2022-20233 (Severity: Critical) and 4 other vulnerabilities (3 ranked High severity, 1 Moderate) in the Titan M component. The report does not describe the code change itself.
The researchers also point out a feature that would have made the StrongBox key blob leak impossible: an application can create a key that is authentication-bound, specifying setUserAuthenticationRequired(true) when building it with KeyGenParameterSpec. This way, users need to authenticate before using the key, and the key blob is encrypted a second time using a special key derived from the user password that the attacker does not have.
Variants to test
- Fuzz other Titan M tasks with emulation-based fuzzing. The researchers emulated Keymaster, Identity and Weaver separately with libprotobuf-mutator and AFL++ in Unicorn mode. A positive result is a UC_ERR_WRITE_UNMAPPED or similar Unicorn error in a memory-writing instruction such as strb, with a reproducible input.
- Look for other single-byte writes into static structures that hold pointers or sizes. The KEYMASTER_SPI_DATA pointer to the incoming request buffer was the target here. A positive result is a controlled change of a pointer or size value that redirects later processing to memory you can influence.
- Test other messages that contain a KeyParameters field, since the bug can be reached by different code paths. A positive result is the same out of bounds write through a different request type.
- Try the same approach on other chips running Embedded Controller with fixed-size task stacks and no heap. A positive result is a static address that can be overwritten with a constrained byte value and that influences control flow or data placement.
- Check whether authentication-bound keys are used in a target application. A positive result, from the attacker's perspective, is a StrongBox key blob that can be decrypted after leaking the key without the user password; if the key is authentication-bound, the second encryption layer should prevent this.
What happened, in plain words
Google's Pixel phones contain a small extra chip called Titan M. It is a separate computer inside the phone, with its own tiny operating system, whose job is to keep the most sensitive secrets safe: the keys that unlock the phone, the keys that encrypt your data, and the checks that make sure the phone has not been tampered with. Because it is separate, an attacker who takes over the main phone software still has to get past this chip.
Two researchers, Damiano Melotti and Maxime Rossi Bellom, together with Philippe Teuwen, spent about a year and a half studying this chip. They found a bug in its software (the firmware) that lets someone who can send it commands write a single byte of data to a place in the chip's memory where that byte should not go. That sounds tiny, and it is: one byte, and the value of that byte is heavily restricted. But because the chip's memory is laid out in exactly the same way every time it starts, the researchers could work out precisely which byte to change. Changing that one byte made the chip store incoming commands in the wrong place, which then let them take control of what the chip executes. From there they could read any memory on the chip, including the secret keys it is supposed to protect.
They reported the bug to Google in March 2022. Google fixed it in the June 2022 Pixel security update and assigned it the identifier CVE-2022-20233. The initial reward was 10,000 USD; it was later increased to 75,000 USD. The researchers presented the work at the TROOPERS conference in June 2022 and at Black Hat USA in August 2022.
This article walks through the whole story in the same order as the original technical write-up, explaining each idea from scratch.
Background: what the Titan M is and why it matters
A modern phone is really several computers. The main one, the Application Processor (AP), runs Android and all your apps. The Titan M is a second, much smaller computer on its own chip. Google introduced it in Pixel phones in 2018, starting with the Pixel 3.
The point of a separate chip is to shrink what an attacker can reach. If malware takes over Android, it still cannot directly touch the Titan M's internals. The chip also makes certain physical attacks harder, such as measuring tiny variations in power use or timing to guess secrets (these are called side-channel attacks), or physically tampering with the hardware.
The Titan M talks to the main processor over a bus called SPI (Serial Peripheral Interface), a simple way for chips to exchange data. It offers APIs, which are agreed ways for one piece of software to ask another to do something. Think of an API as a service counter: you hand over a request in an agreed format, and you get back a result. The Titan M's APIs cover the most sensitive jobs on the phone, including secure boot (checking that the software the phone is about to run is genuine and unmodified) and a hardware-backed Keystore with a feature called StrongBox.
The Keystore is Android's system for storing cryptographic keys. StrongBox is its strongest level: the keys live inside a dedicated security chip (here, the Titan M) and are only ever used there. They are stored on the phone in encrypted form, in what is called a key blob. Even if someone copies the blob, they cannot use the key without the chip.
The Titan M's firmware is built on Embedded Controller (EC), a lightweight open source operating system for micro-controllers (small, low-power computers). EC is organised around tasks: independent pieces of code, each with a fixed amount of working memory called a stack. A stack is where a running function keeps its local variables and the address it should return to when it finishes. EC has no heap, meaning no pool of memory that programs can grab and release as they go. Everything is laid out in advance.
That last point matters a lot. Because there is no dynamic allocation, the chip's memory layout is essentially static: the same objects sit at the same addresses every time. For an attacker, that is a gift, because a single known address can be targeted reliably.
The lack of a heap also removes a whole class of bugs called temporal memory safety issues, which happen when memory is freed and then used again by mistake. The chip also has a Memory Protection Unit (MPU), hardware that enforces rules about which memory can be read, written or executed. The MPU is configured so that no region is both writable and executable at the same time. That stops an attacker from writing their own code into memory and then running it. Secure boot is enforced by signature checks performed before the firmware is loaded: the chip only runs firmware whose cryptographic signature matches.
Apart from a stack canary, there are no common exploit mitigations on the chip. A stack canary is a known value placed at the end of a stack; if a bug overwrites past the end of a buffer, the canary changes, and the program can notice and stop. That is the only guard rail described.
All of this leaves the Titan M fairly exposed to memory corruption bugs, which are bugs where a program writes data outside the area it was supposed to. The researchers therefore set out to hunt for them.
Fuzzing Titan M
Fuzzing is a way of finding bugs automatically: you feed a program huge numbers of slightly varied inputs and watch for crashes or odd behaviour. It is one of the most effective ways to find memory corruption in code written in languages like C, which do not check memory accesses for you. Fuzzing a security chip is hard, though, because you do not have the source code and much of the code depends on specific hardware. The researchers tried two approaches.
Black-box fuzzing
Black-box means you cannot see inside. You only have a way to send input and a way to notice when something goes wrong. For the Titan M, the input channel was nosclient, a custom client the researchers had built that runs natively on Android and talks directly to the kernel driver that handles communication with the chip. A kernel driver is the part of the operating system that knows how to talk to a piece of hardware. The signal was the return code from the library functions: a number the function hands back to say whether it succeeded or failed.
Most of the tasks that talk to Android use Protobuf, a format for serialising structured messages (turning data structures into bytes and back). Because the message definitions are open source in AOSP (the Android Open Source Project), the researchers could take valid messages and mutate them with libprotobuf-mutator, a tool that changes Protobuf messages in structured ways rather than randomly. For one task called Nugget, which does not use Protobuf, they used Radamsa, a general-purpose tool that generates mangled test inputs.
This approach did produce results. It rediscovered several bugs the researchers already knew about, including a buffer overflow they had exploited in earlier research, while fuzzing an older firmware version. It also found two new crashes in the latest firmware at the time, but both came from the same null pointer dereference (trying to read or write through an address that is zero), which Google did not consider serious enough to count as a vulnerability or include in an Android Security Bulletin.
Black-box fuzzing has clear limits. Detection is hard, because you only notice bugs that cause a crash or a bad return code. More importantly, it tends to only reach the shallow states of a program: the parts that are easy to get to, because you cannot see what is happening inside. That may explain why all the crashes appeared after only a few minutes of fuzzing.
Emulation-based fuzzing
Emulation means running software for one machine on a different machine, instruction by instruction, in a simulated environment. Since the firmware is publicly available, the researchers could emulate it on a laptop. Their hours of reverse engineering gave them the knowledge to set this up.
They used Unicorn, an emulator engine based on QEMU (a well-known open source emulator). Unicorn only emulates the CPU, not a whole system, which made it easy to script and to add custom tweaks. They paired it with AFL++, a coverage-guided fuzzer: a fuzzer that watches which parts of the code each input reaches and prefers inputs that reach new code, adjusting its mutations accordingly. Unicorn plugs into AFL++ through unicorn mode, which lets you fuzz anything Unicorn can emulate. The only thing you must define is the place_input_callback, a function that writes each test input into the target's memory before execution.
With AFL++'s support for custom mutators (functions that decide how to change inputs), they plugged libprotobuf-mutator back in and emulated three tasks separately: Keymaster, Identity and Weaver. They skipped AVB (Android Verified Boot) because it exposes little attack surface, with most of its interactions happening while the device is in bootloader mode (a special startup mode used for flashing and recovery).
They first checked whether this new setup could rediscover the bugs they already knew about. It could, with one exception, which illustrates the limits of emulation:
- Hardware-dependent functions: parts of the code that rely on real hardware cannot easily be emulated, so they had to be hooked (replaced with stand-ins), which reduces coverage.
- Limited detection: only bugs that cause Unicorn errors are caught, so in-page overflows, off-by-ones and similar issues are missed. An off-by-one is a bug where a loop or calculation is wrong by exactly one, often writing one byte too many.
- No full-system emulation: ignoring some functions means missing some bugs, which is why one known vulnerability could not be rediscovered.
To improve detection, Unicorn lets you set hooks, custom code that runs when certain memory accesses or code fragments happen. The researchers added heuristics (rules of thumb) to catch patterns such as broken calls to memcpy that ended up reading from the Boot ROM, the chip's first, immutable startup code, mapped at address 0x0. Hooks cost performance, though, and there is always a trade-off between time spent reverse engineering to spot patterns and time letting the fuzzer run freely.
The vulnerability
While fuzzing the Keymaster task, the researchers hit a crash reported as UC_ERR_WRITE_UNMAPPED: the emulator noticed the firmware trying to write to a memory address that is not mapped, meaning it does not exist or is not allowed. The crash happened in a strb instruction, which stores a single byte. In other words, the firmware was trying to write 1 byte into an unmapped area. The vulnerable firmware had been introduced by Google's Pixel security update of May 2022.
A simple message that triggers the vulnerability is the following:
ImportKeyRequest
params {
params {
tag: ALGORITHM
integer: 4
}
params {
tag: DIGEST
integer: 40706
}
}
symmetric_key {
material: "<1h5\003H\232@\233"
}
This is a Protobuf message. Line by line:
ImportKeyRequestnames the type of request: the caller wants to import a key into the chip.params { ... }is the outer list of key parameters.- Inside it,
params { tag: ALGORITHM integer: 4 }is one parameter saying which algorithm the key is for.tagis the name of the setting,integeris its value. params { tag: DIGEST integer: 40706 }is a second parameter, this time for the digest (hash function) setting, with the value 40706. This large number is the important part.symmetric_key { material: "..." }is the key material itself, given as a string of bytes.
ImportKey messages contain a field called KeyParameters, made of one or more KeyParameter objects. The bug happens while processing the tags in a key parameter. The vulnerable function loops through the list of parameters and, for each one, checks whether the tag is 0x20005, which corresponds to DIGEST. When it finds such a parameter, it takes the associated integer field and, after some checks, uses it as an offset into a stack buffer to set a byte to 1. An offset is a distance from a starting point: if the buffer starts at address X, an offset of 10 means address X+10. Passing a large enough integer writes that one byte, value 0x01, outside the buffer.
The assembly and decompiled views below show the checks and the strb instruction that causes the out of bounds write and the crash. At that point, r1 is 0x1, r7 is the buffer address, and r3 is the integer field of the current KeyParameter. Assembly is the low-level instruction language of the CPU; decompiled code is a higher-level reconstruction produced by a tool such as Ghidra, which turns machine code back into something resembling C.
ldr.w r1,[r2,#-0x4]
ldr r3,[PTR_DAT_0005d808] ; 0x20005
cmp r1,r3
bne increment_loop_vars
ldr r3,[r2,#0x0]
uxtb r0,r3
cmp r0,#0x4
bhi error_exit
movs r1,#0x1
lsl.w r0,r1,r0
tst r0,#0x15
beq error_exit
strb r1,[r7,r3]
Line by line:
ldr.w r1,[r2,#-0x4]loads a 32-bit value from memory at the address inr2minus 4 intor1. This is the tag of the current parameter.ldr r3,[PTR_DAT_0005d808] ; 0x20005loads the constant0x20005(the DIGEST tag) intor3.cmp r1,r3compares the parameter's tag with0x20005.bne increment_loop_varsbranches away if they are not equal, moving on to the next parameter.ldr r3,[r2,#0x0]loads the integer field of the parameter intor3.uxtb r0,r3takes the least significant byte ofr3(its lowest 8 bits) and zero-extends it intor0.cmp r0,#0x4compares that byte with 4.bhi error_exitbranches to an error exit if the byte is greater than 4.movs r1,#0x1puts the value 1 intor1.lsl.w r0,r1,r0shiftsr1left byr0bits and stores the result inr0. This builds a bit mask.tst r0,#0x15tests that mask against0x15(binary 10101).beq error_exitbranches to the error exit if the test result is zero, meaning the byte is not one of the allowed values.strb r1,[r7,r3]stores the single byte inr1(value 1) at the addressr7 + r3. This is the out of bounds write:r7is the buffer, andr3is the attacker-supplied integer.
if (((nugget_app_keymaster_KeyParameter *)(offset + -1))->tag == 0x20005) {
masked = *offset & 0xff;
if ((4 < masked) || ((1 << masked & 0x15U) == 0)) {
return 0x26;
}
*(undefined *)(buffer + *offset) = 1;
*param_3 = *param_3 + 1;
*param_4 = offset;
}
Line by line:
if (((nugget_app_keymaster_KeyParameter *)(offset + -1))->tag == 0x20005)checks whether the current parameter's tag is DIGEST.masked = *offset & 0xff;keeps only the lowest byte of the integer field.if ((4 < masked) || ((1 << masked & 0x15U) == 0))rejects the value if that byte is greater than 4, or if shifting 1 left by that byte and ANDing with0x15gives zero. In practice this allows only a few values.return 0x26;is the error exit.*(undefined *)(buffer + *offset) = 1;is the actual write: it sets one byte atbuffer + offsetto 1. Becauseoffsetcan be large, this lands outside the buffer.*param_3 = *param_3 + 1;increments a counter.*param_4 = offset;saves the current position.
The bug can be triggered as many times as there are parameters with a DIGEST tag, limited only by the maximum size of the KeyParameters list. That gives multiple 1-byte out of bounds writes. The writes are far from arbitrary, though, because of the checks on the offset: without going into the bit-wise details, the least significant byte can only be 0x0, 0x2 or 0x4.
At first sight this looks minor and hard to exploit. But remember that Titan M's memory is completely static, and the bug can be reached through different code paths, since several messages contain a KeyParameters field. If the write lands in the right place, setting a single byte to 1 can do a lot: from a simple DoS (denial of service, making the chip stop working) to altering a size variable somewhere in memory and causing corruption elsewhere.
Exploitation
The researchers wrote a small script to generate and highlight all the possible writable addresses in Ghidra, a reverse engineering tool that displays and analyses compiled code. Then they searched for interesting targets. As it turned out, triggering the vulnerability just once was enough to compromise the chip.
Step 1: choose what to overwrite
During their tests, the researchers found they could reach the vulnerable code with r1 containing 0x14019. Applying a 0xa204 offset to this (the least significant byte allows passing the checks) reaches 0x1e21d. That address is part of a structure they called KEYMASTER_SPI_DATA, which holds information about the exchange of Keymaster messages with Android. In particular, one byte of the memory location pointing to where incoming requests for the Keymaster task are stored can be overwritten. By default that pointer is 0x192c8; writing 0x1 to 0x1e21d changes the value to 0x101c8. As a result, the following Keymaster requests are stored quite far from where they are supposed to be, with catastrophic consequences for the Titan M.
In plain terms: the chip keeps a note saying "incoming commands go in this box". The one-byte write changes the note so that commands go to a different box, one that overlaps other important data.
Step 2: redirect execution flow
Because the new location is still inside the chip's memory, an incoming message ends up overwriting other data. The researchers sent larger and larger commands while watching the UART logs. UART is a simple serial connection; the console it exposes is where the chip prints debugging messages. After some testing, they found that placing a valid code address after 556 bytes of payload allowed jumping to that address, effectively redirecting execution to a function of their choice. They detected this thanks to logs printed in the UART console.

They suppose that this portion of memory was being used by some task (probably the idle task), which may have pushed a return address onto its stack, and that address was now overwritten. A return address is where a function goes back to when it finishes; overwriting it lets an attacker choose where execution continues. At this point they knew they could jump to an arbitrary function.
Step 3: pivot the stack
Because writable memory is not executable, they could not write their own code (shellcode) and jump to it. Shellcode is small machine code an attacker injects and runs. Instead they used a code-reuse attack based on Return Oriented Programming (ROP). ROP works by chaining together small snippets of existing code, called gadgets, each ending in a return instruction, so that the CPU executes them in sequence. The goal was to build a read-anywhere primitive: a reliable way to read any memory address, so that secrets protected by Titan M could be leaked with a crafted command from nosclient.
The ROP chain could not be written exactly where the first gadget was written, because that would corrupt memory and crash the chip before the exploit finished. The first challenge was therefore to pivot the stack, meaning to move the stack pointer to a different area. Ideally they wanted to decrease the stack pointer: assuming the stack grows towards larger addresses, they wanted to rely on the payload in those 556 bytes, which they knew they could set freely without nasty side-effects. They found only one gadget to do so, and it also does a few more things:
sub sp, #0x20; mov r4, r0; ldr r3, [r0]; add.w r5, r4, #0x70; ldr r3, [r3, #8]; blx r3;
Line by line:
sub sp, #0x20subtracts0x20from the stack pointersp, moving the stack down by 32 bytes.mov r4, r0copiesr0intor4.ldr r3, [r0]loads the value at the address inr0intor3.add.w r5, r4, #0x70setsr5tor4 + 0x70.ldr r3, [r3, #8]loads the value atr3 + 8intor3.blx r3branches to the address inr3and, because of thex, switches instruction set if needed. In effect, it calls whatever function pointer was just loaded.
They wrote a ROP chain that calls this gadget several times, making sure r0 pointed to a memory area they also controlled, where they wrote gadgets to make the ldr and blx instructions work as intended. The picture below shows this graphically for the first iterations (it is actually done several more times). The red arrows follow the execution flow and the blue ones the stack pointer; the scale is not respected.

Step 4: reach the command handler context
After climbing up the stack a few times, the actual attack could proceed. The only way to return leaked bytes to Android was to copy them into the response of an SPI command. For that, execution needed to be in the context of the command handler, the function that processes a command. The handler is called by taking its address from memory after parsing the command code. That address could therefore be overwritten, but replacing the actual code was impossible: all they could do was make it jump into a memory area they also controlled and write more gadgets there for the ROP chain. This is done in the space created in the first step, making sure to ignore the slots used in the previous ROP chain (assigning them to registers that are not used).
This step was probably the most challenging, because it required finding the right gadget to make the stack pivot to a memory area that stays under control when the handler is triggered. No such gadget existed, so the researchers had to be creative. By emulating the execution of the Keymaster DestroyAttestationIds command handler, they understood that there was one single 32-bit slot in its stack that was not overwritten by previous functions in the call chain. They wrote one single gadget there, acting as a trampoline to move the stack far enough from the Keymaster stack and reach an area where the payload would be preserved. A trampoline here means a small piece of code whose only job is to bounce execution somewhere else.

Wrapping up, the exploit goes as follows:
- move up on the stack from where code execution is obtained;
- once there is enough space, execute a ROP chain that:
- replaces the Keymaster DestroyAttestationIds command handler with one gadget, popping some registers from the stack;
- writes one gadget on the Keymaster stack, which ends up being executed when the handler is triggered and moves the stack pointer enough to reach an area where what is written will not be tampered with by the normal execution of the firmware;
- copies the final ROP chain to such an area.
Step 5: leak memory
Once this was achieved, finishing the exploit was relatively straightforward, because execution was controlled from the handler context. The researchers called memcpy with user-provided arguments to copy what they wanted to read into the Keymaster SPI response buffer, then jumped back to the Keymaster stack, like the normal command handler would have done. memcpy is a standard function that copies a block of bytes from one place to another; by choosing the source and destination, they could read memory and send it back to Android.
Root cause
The vulnerable function processes the tags of a KeyParameter and, when the tag is 0x20005 (DIGEST), takes the associated integer field and uses it as an offset into a stack buffer to write the byte 0x01. The checks only constrain the least significant byte of the offset to 0x0, 0x2 or 0x4, so a large enough integer writes out of bounds. The write is limited to one byte with a constrained value, but the static memory layout of the chip and the multiple code paths that reach the vulnerable code make a single such write enough to corrupt a pointer in KEYMASTER_SPI_DATA.
The chip's defences did not stop the attack. The MPU prevents a region from being writable and executable at the same time, which is why the researchers used ROP rather than shellcode, but it does not prevent the out of bounds write itself. The hardcoded stack canary detects errors at the end of task stacks; the report does not say whether it played any role here.
Impact
The leak functionality built with this exploit allows reading arbitrary memory on the chip, so any readable address can be accessed. As a consequence, the secrets stored in the chip can be dumped, such as the Root of Trust sent by the Pixel bootloader when the Titan M is updated. The Root of Trust is the foundational secret that everything else ultimately depends on. The Boot ROM, previously unavailable, can also be accessed. This is possible despite the slightly customised version of memcpy in the chip, which checks whether the source or destination buffers equal 0x0: instead of jumping directly to the entry point of the function, the exploit skips those checks and jumps directly to the basic block where the copying happens. A basic block is a straight-line sequence of instructions with no branches in the middle.
One of the most interesting consequences is the ability to retrieve any StrongBox protected key, defeating the highest level of protection of the Android Keystore. As in TrustZone (a similar security feature on ARM processors), these keys can only be used inside Titan M, while they are stored in an encrypted key blob on the device. The procedure is:
- read a key blob from the Android OS (from any application);
- send a valid, well-formed BeginOperation request containing such a key blob: the handler for this command decrypts the key and stores it at a specific memory address, preparing the chip to perform the requested operation;
- run the exploit and leak the memory where the plaintext key is now stored.
To demonstrate the attack, the researchers developed a dummy application that creates a StrongBox-protected AES key and encrypts a string with it. AES is a widely used encryption algorithm. With the exploit and the approach above, the corresponding key can be leaked from the Titan M, and by re-using the same initialization vector the string can be decrypted offline (or rather "off phone"). An initialization vector is a value used alongside the key so that encrypting the same data twice does not produce the same output; if you know it, you can reproduce the decryption.
There are two conditions to perform this attack. First, it must be possible to send commands to the chip, either from a rooted device (root means full administrative control of Android, which is required to use nosclient) or by physically accessing the SPI bus. Second, there must be a way to access the key blobs on the Android file system, which can again be done by being root, or with some exploit to bypass File Based Encryption or the uid access control. File Based Encryption is Android's scheme for encrypting files per user; uid access control means each app runs under its own user identifier and can only reach its own files.
Fix
The vulnerability was reported to Google, and the best mitigation is the patch provided in the June security bulletin. Google published the June 2022 Pixel update with fixes for CVE-2022-20233 (Severity: Critical) and 4 other vulnerabilities (3 ranked High severity, 1 Moderate) in the Titan M component. The report does not describe the code change itself.
The researchers also point out a feature that would have made the StrongBox key blob leak impossible: an application can create a key that is authentication-bound, specifying setUserAuthenticationRequired(true) when building it with KeyGenParameterSpec. This way, users need to authenticate before using the key, and the key blob is encrypted a second time using a special key derived from the user password that the attacker does not have.
Variants to test
- Fuzz other Titan M tasks with emulation-based fuzzing. The researchers emulated Keymaster, Identity and Weaver separately with libprotobuf-mutator and AFL++ in Unicorn mode. A positive result is a
UC_ERR_WRITE_UNMAPPEDor similar Unicorn error in a memory-writing instruction such asstrb, with a reproducible input. - Look for other single-byte writes into static structures that hold pointers or sizes. The
KEYMASTER_SPI_DATApointer to the incoming request buffer was the target here. A positive result is a controlled change of a pointer or size value that redirects later processing to memory you can influence. - Test other messages that contain a KeyParameters field, since the bug can be reached by different code paths. A positive result is the same out of bounds write through a different request type.
- Try the same approach on other chips running Embedded Controller with fixed-size task stacks and no heap. A positive result is a static address that can be overwritten with a constrained byte value and that influences control flow or data placement.
- Check whether authentication-bound keys are used in a target application. A positive result, from the attacker's perspective, is a StrongBox key blob that can be decrypted after leaking the key without the user password; if the key is authentication-bound, the second encryption layer should prevent this.
Glossary
- API: an agreed way for one piece of software to ask another to do something, like a service counter with a fixed request format.
- AES: a widely used symmetric encryption algorithm.
- AFL++: a coverage-guided fuzzer that prefers inputs reaching new code.
- AOSP: the Android Open Source Project, the public source code of Android.
- Application Processor (AP): the main computer in a phone, running Android.
- Assembly: the low-level instruction language of a CPU.
- Authentication-bound key: a key that can only be used after the user authenticates, and whose blob is encrypted a second time with a password-derived key.
- AVB: Android Verified Boot, which checks the integrity of the software the phone runs.
- Basic block: a straight-line sequence of instructions with no branches in the middle.
- BeginOperation: a Keymaster request that starts a cryptographic operation and decrypts the key into memory.
- Black-box fuzzing: fuzzing without visibility into the program's internals, relying only on inputs and observable outcomes.
- Boot ROM: the chip's first, immutable startup code.
- Buffer overflow: a bug where a program writes past the end of a buffer.
- Code-reuse attack: an attack that chains existing code fragments instead of injecting new code.
- Command handler: the function that processes a particular command.
- Coverage-guided fuzzer: a fuzzer that tracks which code each input reaches and prefers inputs that reach new code.
- CVE: a public identifier for a known vulnerability.
- DoS (denial of service): making a system stop working.
- Embedded Controller (EC): a lightweight open source OS for micro-controllers, used by Titan M.
- Emulation: running software for one machine on another, instruction by instruction.
- File Based Encryption: Android's scheme for encrypting files per user.
- Firmware: the software built into a hardware device.
- Fuzzing: automatically feeding a program many varied inputs to find crashes and bugs.
- Gadget: a short sequence of existing instructions ending in a return, used in ROP.
- Ghidra: a reverse engineering tool that displays and analyses compiled code.
- Hardware-dependent function: code that relies on specific hardware and cannot easily be emulated.
- Heap: a pool of memory programs can grab and release dynamically.
- Hook: custom code that runs when a certain event happens, used to monitor or replace behaviour.
- Initialization vector: a value used alongside an encryption key so repeated encryption does not produce identical output.
- Key blob: the encrypted form in which a key is stored on the device.
- Keymaster: the Titan M task that handles cryptographic keys.
- Keystore: Android's system for storing and using cryptographic keys.
- Kernel driver: the part of the operating system that talks to a piece of hardware.
- libprotobuf-mutator: a tool that mutates Protobuf messages in structured ways.
- Memory corruption: a bug where a program writes data outside the area it was supposed to.
- Memory Protection Unit (MPU): hardware that enforces which memory can be read, written or executed.
- memcpy: a standard function that copies a block of bytes from one place to another.
- Null pointer dereference: trying to read or write through an address that is zero.
- nosclient: the researchers' custom client that sends arbitrary messages to the Titan M.
- Nugget: a Titan M task that does not use Protobuf.
- Off-by-one: a bug where a loop or calculation is wrong by exactly one.
- Offset: a distance from a starting point, used to compute an address.
- Protobuf: a format for serialising structured messages.
- QEMU: a well-known open source emulator.
- Radamsa: a general-purpose tool that generates mangled test inputs.
- Return address: where a function goes back to when it finishes.
- Return code: a number a function hands back to say whether it succeeded or failed.
- Return Oriented Programming (ROP): chaining small existing code snippets, each ending in a return, to perform an attack.
- Reverse engineering: working out how software works from its compiled form.
- Root of Trust: the foundational secret that everything else ultimately depends on.
- Rooted: having full administrative control of Android.
- Secure boot: checking that the software about to run is genuine and unmodified.
- Shellcode: small machine code an attacker injects and runs.
- Side-channel attack: guessing secrets from physical effects such as power use or timing.
- Signature check: verifying a cryptographic signature to confirm software is genuine.
- SPI: Serial Peripheral Interface, a simple bus for chips to exchange data.
- Stack: the working memory a running function uses for local variables and return addresses.
- Stack canary: a known value at the end of a stack that changes if a buffer is overwritten, so the program can notice.
- Static memory layout: a layout where the same objects sit at the same addresses every time.
- strb: an assembly instruction that stores a single byte.
- StrongBox: the strongest level of Android Keystore, with keys held inside a dedicated security chip.
- SuzyQable: a special debugging cable for Chrome OS microcontrollers that also works with Titan M.
- System-on-a-chip (SoC): a complete computer on a single chip.
- Task: an independent piece of code in EC, with its own fixed stack.
- Temporal memory safety: bugs that arise when memory is freed and then used again by mistake.
- Titan M: Google's security chip in Pixel phones, introduced with the Pixel 3.
- Trampoline: a small piece of code whose only job is to bounce execution somewhere else.
- TrustZone: a similar security feature on ARM processors.
- UART: a simple serial connection; the Titan M console prints debugging logs there.
- UC_ERR_WRITE_UNMAPPED: a Unicorn error meaning the code tried to write to an unmapped address.
- uid access control: Android's rule that each app runs under its own user identifier and can only reach its own files.
- Unicorn: a QEMU-based emulator engine that only emulates the CPU.
- unicorn mode: AFL++'s mode for fuzzing anything Unicorn can emulate.
- Weaver: a Titan M task.
- Whitepaper: a detailed technical document describing research.