Skip to content
Race condition Write-up Advanced

Why Android GPU drivers

A use-after-free race in the Qualcomm kgsl GPU driver's timeline destroy path let a fence object be freed while still referenced, giving the researcher arbitrary kernel read and write. From there they disabled SELinux and ran commands as root on a Samsung Galaxy Z Flip3.

Man Yue Mo Follow

Published on github.blog

Man Yue Mo·@m-y-mo

Man Yue Mo, on github.blog

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 timeline's fence list did not hold its own reference to each fence, so a fence could be freed by its release callback while the destroy ioctl was still copying it to a temporary list.

Impact

The researcher could gain arbitrary kernel memory read and write and then disable SELinux and run commands as root, though kCFI, variable initialisation and Samsung RKP limited which primitives were usable.

What the attacker needed

Local app on the device; Snapdragon 888 or newer chipset; kernel branch 5.4 or above

The fix

The bug was fixed and the fix was applied to devices in the May 2022 Android security patch.

How it was found

  1. Create a kgsl timeline object through the timeline create ioctl.
  2. Add a large number of fences to the timeline's fence list to widen the race window.
  3. In one thread, call the timeline destroy ioctl so it copies the fences to a temporary list.
  4. In a second thread, drop the last reference of the final fence so its release callback runs.
  5. The release callback frees the fence after the destroy path has already taken it, and the destroy path then uses the freed fence.

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 fence is a small kernel object used to track when GPU work finishes. The driver kept a list of these objects without holding a proper reference, so a race between destroying the list and releasing a fence could free the object while another thread still used it. That is a use-after-free: using memory after it has been handed back, which lets an attacker shape what sits there.

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.

More by Man Yue Mo

View all

3 more disclosed reports, best first.

More from Qualcomm

View all

The newest disclosed reports for this program.

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.