Reviving an already patched vulnerability for half a year? The second spring of CVE-2024-0044
The original patch for CVE-2024-0044 failed to validate the installerPackageName argument in createSessionInternal, allowing an attacker with adb access to bypass the fix and run code as any app's UID. The author found this by code review and reported it, leading to a new patch in October 2024.
This is a bypass of the initial patch of CVE-2024-0044, a High severity vulnerability in the Android framework that allows attackers with adb access to execute arbitrary code under the UID of arbitrary app. The following is copied from my repo https://github.com/canyie/CVE-2024-0044 for backup purposes.
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
CVE-2024-0044 (also tracked as A-307532206) is a High severity vulnerability in the Android framework. It lets an attacker who already has adb access run arbitrary code under the UID of any app on the device. The bug was originally found by Tom Hebb of Meta Red Team X, and the original patch shipped in the March 2024 Android Security Bulletin.
This write-up is about a bypass of that first patch. The bypass was reported on 16 May 2024, two months after the original fix, and the corrected patch is included in the October 2024 Android Security Bulletin under the same CVE ID, CVE-2024-0044. Android 12 and 13 devices whose security patch level is before 2024-10-01 are vulnerable to the bypass.
The feature involved is the PackageInstaller session mechanism in the Android framework. When a session is created, the caller can supply an installer package name, and the system records a requestedInstallerPackageName for the session. The system records a requestedInstallerPackageName for the session, and the original exploit abused how that value was set.
Setup
The precondition is adb access to the device, the same precondition as the original CVE. The researcher's repository at https://github.com/canyie/CVE-2024-0044 contains a minimum reproducible PoC and the write-up; the PoC code itself lives in that repository rather than in this text. The original exploit code from Tom Hebb's blog can also be used to reproduce the issue.
To test the researcher's PoC, build it, push the generated apk to /data/local/tmp/poc.apk, and then run the following with adb shell, replacing <victim uid> with the UID of the victim app:
replace `<victim uid>` with the UID of the victim app.
To run the exploit again after a successful attempt, uninstall the package and re-run the same code:
adb uninstall top.canyie.cve_2024_0044
Finding it
The researcher found the bypass by a code review. The starting point was the original patch itself, which added a validation for the installer package name passed to the PackageManagerService.
In that patch, params.installerPackageName is reset to null if it is not a legal Android package name. But on the next line, requestedInstallerPackageName can be set to installerPackageName when params.installerPackageName is null or invalid. That is the gap: the value that ends up in requestedInstallerPackageName is not necessarily the value that was validated.
The patch was applied to the createSessionInternal method. In that method, installerPackageName is a separate argument that does not come from param. The original patch validated params.installerPackageName but forgot to validate the installerPackageName argument. So a caller that controls the separate argument, rather than the field inside params, can still get an arbitrary installer package name into the session.
Exploitation
Step 1: Build and push the PoC
Build the PoC from the repository and push the resulting apk to the device:
/data/local/tmp/poc.apk
This places the payload where adb shell can reach it. The original exploit code from Tom Hebb's blog works for reproduction as well, so the bypass is not specific to this particular PoC.
Step 2: Run the exploit with adb shell
The PoC is executed through adb shell, with <victim uid> replaced by the UID of the target app. The report gives the invocation as the placeholder line quoted above; the concrete command is in the repository. Because the vulnerable path is the session creation call that accepts a caller-supplied installerPackageName, the PoC drives that path directly instead of going through the public PackageInstaller API.
Step 3: Re-run if needed
If the package is already installed from a previous attempt, remove it first and run the exploit again:
adb uninstall top.canyie.cve_2024_0044
Root cause
The mistake is a validation applied to the wrong input. The first patch checked params.installerPackageName inside createSessionInternal and nulled it out when it was not a legal package name. But createSessionInternal also takes a separate installerPackageName argument, and that argument is what can flow into requestedInstallerPackageName. The patch never validated that argument, so an attacker who can set it still controls the installer identity recorded for the session.
Why did the existing defences not catch it? The regression test Google added for the issue uses the public standard PackageInstaller API. That API does not allow customising installerPackageName: in the public API the value is always set to the real package name of the provided Context. When the caller is a third-party app, installerPackageName is guaranteed to belong to the caller; when the caller is adb, it is always reset to null. So the test exercises only paths where the argument is safe. The reset happens after requestedInstallerPackageName has already been set to installerPackageName, so the original value is kept.
Had the test been the original PoC from Tom Hebb rather than a newly written one, the problem would have surfaced, because the pm command calls the underlying createSession method with a customised installerPackageName.
The wider reason the gap survived is social rather than technical. The vulnerability had been analysed, reproduced and exploited widely; Qidan He (flanker) of JD Dawn Security Lab wrote that CVE-2024-0044 had been widely analysed and publicly exploited in the technical community because it is simple and direct. Someone had even successfully reproduced the exploit on patched builds, but the author did not appear to realise what that meant. The researcher's point is that a few extra seconds spent reading the patch, or simply running the public PoC against a patched build to check whether the issue was actually fixed, would have found it.
Impact
An attacker with adb access can execute arbitrary code under the UID of an arbitrary app on an affected device. The condition is the same as for the original CVE: adb access is required. The affected range is Android 12 and 13 devices with a security patch level before 2024-10-01. The report rates the vulnerability High severity.
Fix
The corrected fix is included in the October 2024 Android Security Bulletin under CVE-2024-0044. The report does not describe the contents of the new patch beyond stating that it closes the bypass; the new bulletin is where the correction lives.
Variants to test
- Look for other patches that validate one copy of a value while a second, caller-controlled copy reaches the same sink. A positive result is a code path where the validated field and the used field can diverge.
- Check regression tests added alongside security patches for whether they exercise the same entry point as the public exploit. A test that only uses a high-level API which normalises the dangerous argument will pass on a vulnerable build.
- Run the original public PoC against a patched build rather than trusting the patch. A positive result is the exploit succeeding on a build that is supposed to contain the fix.
- Trace the order of operations around any reset or sanitisation: if the value is copied into its final destination before the reset, the reset does not protect the sink. A positive result is a stored value that survives the check.
- Review internal entry points such as the
pmcommand path, which call lower-level methods with caller-supplied arguments that the public API would never allow. A positive result is an internal caller that can set an argument the public API fixes for you.
What happened, in plain words
Android phones have a system component, the Android framework, that manages apps: installing them, running them, and keeping their data separate. Each installed app gets a numeric identity called a UID, and Android uses that UID to decide which files and data an app is allowed to touch. If one app could run code under another app's UID, it would act with that app's identity.
CVE-2024-0044 is a bug in that framework. It lets someone who already has adb access to a phone run code as any app they like. adb is the Android Debug Bridge, a developer tool that lets a computer talk to a phone over a cable or network; having adb access already means the person can run commands on the device. The bug was found by Tom Hebb of Meta Red Team X, and Google shipped a fix for it in the March 2024 Android Security Bulletin, the monthly list of security fixes for Android.
This article is about a second problem: the first fix did not fully close the hole. The researcher, canyie, found a way around the patch by reading the patch code, reported it on 16 May 2024, two months after the original fix, and Google shipped a corrected fix in the October 2024 Android Security Bulletin, still under the same CVE ID, CVE-2024-0044. Phones running Android 12 or 13 with a security patch level before 2024-10-01 are vulnerable to this bypass. The report rates the issue High severity.
A CVE ID is a public label for a specific security flaw, like a case number. A-307532206 is Google's internal tracking number for the same issue.
The feature involved
The bug lives in the PackageInstaller session mechanism. Think of installing an app as a parcel delivery: the system opens a session (an order), the caller says who is sending the parcel (the installer package name), and the system records that name for the session. Android stores this as requestedInstallerPackageName. The system records that name for the session.
An API is a defined way for one piece of software to ask another to do something, like a service counter with fixed forms. The public PackageInstaller API is the official, documented way for apps to install packages. There is also an internal path that the pm command uses; pm is the package manager command you can run from adb shell.
What was wrong with the original patch
The first patch added a check on the installer package name passed to the PackageManagerService, the system service that handles package operations. The check resets params.installerPackageName to null if it is not a legal Android package name. A package name is the app's identifier, such as com.example.app.
But on the next line, requestedInstallerPackageName can be set to installerPackageName when params.installerPackageName is null or invalid. In plain words: the code checks one copy of the name, then stores a different copy. The value that ends up in requestedInstallerPackageName is not necessarily the value that was checked.
The patch was applied to a method called createSessionInternal. In that method, installerPackageName is a separate argument, a value handed to the method by whoever calls it, and it does not come from param. The original patch validated params.installerPackageName but forgot to validate the installerPackageName argument. So a caller that controls the separate argument, rather than the field inside params, can still get an arbitrary installer package name into the session.
A method is a named block of code that does a job; an argument is a value you pass into it, like filling in a field on a form. The mistake is a validation applied to the wrong input: the form was checked, but the value actually used came in through a side door.
Reproduction
The precondition is adb access to the device, the same precondition as the original CVE. The researcher's repository at https://github.com/canyie/CVE-2024-0044 contains a minimum reproducible PoC and the write-up. A PoC, proof of concept, is a small program that demonstrates a bug without doing real harm. The PoC code itself lives in that repository rather than in this text. The original exploit code from Tom Hebb's blog can also be used to reproduce the issue, so the bypass is not specific to this particular PoC.
To test the researcher's PoC, build it, push the generated apk to /data/local/tmp/poc.apk, and then run the following with adb shell, replacing <victim uid> with the UID of the victim app:
replace `<victim uid>` with the UID of the victim app.
Line by line: the first part is an instruction to build the PoC, which turns the source code into an installable Android package file, an apk. The second part copies that apk to /data/local/tmp/poc.apk, a scratch directory on the phone that adb shell can reach. The third part runs the PoC through adb shell, the command line on the phone, and you substitute the target app's UID for the placeholder. The report gives the invocation as this placeholder line; the concrete command is in the repository.
To run the exploit again after a successful attempt, uninstall the package and re-run the same code:
adb uninstall top.canyie.cve_2024_0044
Line by line: adb is the bridge tool on your computer, uninstall tells the phone to remove a package, and top.canyie.cve_2024_0044 is the package name of the PoC. Removing it first means the next run starts clean, as if the previous attempt never happened.
How it happened twice
The issue looks obvious, so how did it escape everyone's sight?
Google did add a test for this issue to ensure it is fixed. A regression test is an automated check that a fixed bug stays fixed. The test uses the public standard PackageInstaller API, which does not allow customising installerPackageName. In the public API, installerPackageName is always set to the real package name of the provided Context. A Context is the handle an app uses to talk to the system about itself.
When the caller is a third-party app, installerPackageName is guaranteed to belong to the caller; when the caller is adb, it will always be reset to null, so this seems fine. However, the operation occurs after requestedInstallerPackageName is set to installerPackageName, so the original value is kept. In everyday terms: the guard arrives after the parcel has already been logged under the sender's name, so the log keeps the wrong name.
Had the test been the original PoC from Tom Hebb rather than a newly written one, the problem would have surfaced, because the pm command calls the underlying createSession method with a customised installerPackageName. The pm command calls the underlying createSession method with a customised installerPackageName.
The wider reason the gap survived is social rather than technical. The vulnerability had been analysed, reproduced and exploited widely. Qidan He (flanker) of JD Dawn Security Lab wrote that CVE-2024-0044 had been widely analysed and publicly exploited in the technical community because it is simple and direct. Someone had even successfully reproduced the exploit on patched builds, but the author did not appear to realise what that meant. The researcher's point is that a few extra seconds spent reading the patch, or simply running the public PoC against a patched build to check whether the issue was actually fixed, would have found it. The bug bounty would have been theirs.
Impact
An attacker with adb access can execute arbitrary code under the UID of an arbitrary app on an affected device. The condition is the same as for the original CVE: adb access is required. The affected range is Android 12 and 13 devices with a security patch level before 2024-10-01. The report rates the vulnerability High severity.
Fix
The corrected fix is included in the October 2024 Android Security Bulletin under CVE-2024-0044. The report does not describe the contents of the new patch beyond stating that it closes the bypass. The new bulletin is where the correction lives.
Variants to test
- Look for other patches that validate one copy of a value while a second, caller-controlled copy reaches the same sink. A sink is the place where a value is finally used, such as a database write or a system call. A positive result is a code path where the validated field and the used field can diverge.
- Check regression tests added alongside security patches for whether they exercise the same entry point as the public exploit. A test that only uses a high-level API which normalises the dangerous argument will pass on a vulnerable build.
- Run the original public PoC against a patched build rather than trusting the patch. A positive result is the exploit succeeding on a build that is supposed to contain the fix.
- Trace the order of operations around any reset or sanitisation: if the value is copied into its final destination before the reset, the reset does not protect the sink. A positive result is a stored value that survives the check.
- Review internal entry points such as the
pmcommand path, which call lower-level methods with caller-supplied arguments that the public API would never allow. A positive result is an internal caller that can set an argument the public API fixes for you.
Glossary
- adb: Android Debug Bridge, a developer tool that lets a computer send commands to an Android device.
- Android framework: the core system software of Android that manages apps, permissions and data.
- API: a defined way for one piece of software to ask another to do something, like a service counter with fixed forms.
- apk: the installable package file format for Android apps.
- argument: a value passed into a method when it is called, like filling in a field on a form.
- CVE ID: a public label for a specific security flaw, like a case number.
- Context: the handle an app uses to talk to the system about itself.
- installer package name: the name of the app that a package claims installed it.
- method: a named block of code that performs a job.
- package name: the unique identifier of an Android app, such as
com.example.app. - PackageInstaller: the Android component and API for installing packages.
- PackageManagerService: the system service that handles package operations.
- patch: a code change that fixes a bug.
- PoC: proof of concept, a small program that demonstrates a bug without doing real harm.
- regression test: an automated check that a fixed bug stays fixed.
- requestedInstallerPackageName: the installer name recorded for an install session, later used to decide which app's UID the package is tied to.
- security patch level: the date of the latest security fixes installed on a device.
- session: an in-progress install order in PackageInstaller.
- sink: the place where a value is finally used, such as a database write or a system call.
- UID: the numeric identity Android gives each app and uses to decide what data it may access.