Skip to content
Race condition Write-up Advanced

Driving forward in Android drivers

The MediaTek JPEG decoder driver had a race condition between starting a decoding job and waiting for it, allowing concurrent access to shared buffer structures. An attacker could trigger use-after-free or double-free conditions, potentially leading to kernel memory corruption and privilege escalation.

googleprojectzero.blogspot.com

Published on googleprojectzero.blogspot.com

Android's open-source ecosystem has led to an incredible diversity of manufacturers and vendors developing software that runs on a broad variety of hardware. This hardware requires supporting drivers, meaning that many different codebases carry the potential to compromise a significant segment of Android phones.

The author, on googleprojectzero.blogspot.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

Likely the driver's mutex only protected core locking and unlocking, not the body of the start function, so start and unlock could race on the shared bufInfo array.

What the attacker needed

Access to the mtk_jpeg driver from an app; ability to run two processes concurrently

How it was found

  1. Process A calls the start ioctl, which locks a core and enters the start function.
  2. Process B calls the wait ioctl, confirms the core is locked, and begins a 3-second wait.
  3. Process A fails the start function, calls unlock on the core, and returns to userland.
  4. After about 3 seconds, Process A calls the start ioctl again, locking the core and entering the start function.
  5. Process B's wait times out and calls unlock on the core.
  6. Processes A and B now concurrently initialise and free the same data structures.

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 phone's kernel driver for JPEG decoding had a timing flaw: two processes could start and stop a decoding job at the same time, causing the driver to free memory that another process was still using. This kind of memory confusion can let an attacker take control of the phone's core software.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.