Skip to content
Memory corruption Advisory Advanced CVE-2022-22057

GHSL-2022-037: Use After Free (UAF) in Qualcomm kgsl driver - CVE-2022-22057

A use-after-free vulnerability exists in the Qualcomm kgsl driver because the timeline's fence list does not hold a reference to its fences, allowing a race condition where a fence is freed while another thread still uses it. An attacker could exploit this to gain arbitrary kernel read and write, enabling root privileges on Android devices.

m-y-mo Follow

Originally disclosed on GitHub Security Lab

The source code references are to the msm-5.4.r5 branch.

m-y-mo, on GitHub Security Lab

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 report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The kgsl_timeline::fences list does not increment the reference count of the kgsl_timeline_fence objects it holds, so a fence can be freed while still on the list, leading to a use-after-free when another thread accesses it.

What the attacker needed

Untrusted app on Android device; ability to call kgsl ioctls

How it was found

  1. Create a timeline fence using the kgsl_ioctl_timeline_fence_get ioctl, which adds the fence to the timeline's fence list and returns a file descriptor.
  2. Close the file descriptor, which drops the fence's reference count to zero and triggers timeline_fence_release.
  3. In another thread, call kgsl_ioctl_timeline_destroy to race with the release and obtain a reference to the fence before it is removed from the list.
  4. The release function frees the fence, but the destroy ioctl still uses it, causing a use-after-free.

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 report has not been written yet. The Original tab links to the source.

A use-after-free happens when a program frees memory but then keeps using it, like deleting a file and then trying to open it. Here, the graphics driver's list of fences doesn't properly track when they are in use, so one part of the driver can free a fence while another part still tries to use it. This can let an attacker take control of the device's core system (kernel) and get the highest level of access (root).

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.

More by m-y-mo

View all

64 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

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.