Insufficient data validation in Updater (CVE-2024-3173)
A low-privileged user could create a hard link in a world-writable temporary directory to make the Keystone updater, running as root, change permissions on any file. Combined with missing code-signing checks and a race condition, this allowed arbitrary code execution as root.
- Fix shipped in 38 days
VULNERABILITY DETAILS
0x01
On macOS, Keystone components are used in Chrome (and other Google software such as "Chrome Remote Desktop") for software updates.
When the user installs Chrome Enterprise, configures Chrome updates, or installs other Google software, the Keystone component will run with root privileges (for example: Keystone in GoogleSoftwareUpdate component: "/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle").
During software installation or update, the Keystone component implements a lock operation:
id __cdecl +[KSInstallSettings userInstallLockFile:](id a1, SEL a2, id a3)
{
__CFString *v4; // rdi
v4 = CFSTR("/tmp/com.google.Keystone");
if ( objc_msgSend(a3, "length") )
v4 = (__CFString *)a3;
return objc_msgSend(v4, "stringByAppendingPathComponent:", CFSTR(".keystone_install_lock"));
}
This lock file will be opened and changed to the "-rw-rw-rw-" permission. The Keystone component detects whether it is a symbolic link (via O_NOFOLLOW) when the file is opened, but this detection can be bypassed by a hard link on macOS.
Since the "/tmp/" directory of macOS is writable by any user, a low-privileged user can create the "/tmp/com.google.Keystone" directory in advance and create a hard link ".keystone_install_lock" in it to point to any file. When the Chrome or other Google software is installed or updated, the Keystone component runs with root permissions, the attacker can change the permission of any file in system to readable and writable permissions for any user.
After the attacker gains the ability to read and write arbitrary files, it needs to be converted into executing arbitrary code with root privileges:
Since the modification permission is "-rw-rw-rw-", attackers cannot escalate privileges via "/etc/sudoers" or similar files. The system will check the permissions of these files. If the file is writable by ordinary users, the configuration will not take effect. And since there is no executable permission ("-rw-rw-rw-"), attackers can't escalate privileges via modifying the executable program running as root.
Under the old macOS version, attackers can escalate privileges via modifying "/etc/defaults/periodic.conf" (The settings are automatically triggered when macOS performs periodic tasks).
However, in higher versions, macOS has added TCC protection to the "/etc/defaults/periodic.conf" file (and some similar files). No matter what permissions the process (even root) modifies this file, "SomeApp would like to administer your computer" will be prompted by the system and requires the user's active allow.
Although in lower versions, I have been able to silently escalate privileges and obtain a shell running with root privileges, I need an exploit that can escalate privileges by default setting under the latest version of macOS to complete the weaponized exploit and improve the severity of this issue.
Apple is working on mitigations to reduce this exploit method (from "arbitrary file write" to "arbitrary code run with root") in the system itself.
I started reviewing components in Google itself to see if there are some issues that could be exploited to complete privilege escalation. Then I discovered the following 0x02 (actually 0x02 contains two issues).
0x02
I found that after the enterprise administrator deploys the installation package for Chrome Enterprise, when installing the GoogleChrome.pkg, the Keystone component will run with root privileges in the postinstall script of installation package and attempt to install GoogleSoftwareUpdate service to:
/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle
The ksinstall will be executed as root:
/path/to/ksinstall --install=/path/to/Keystone.tbz
The key issues in this process:
https://crbug.com/chromium/1
ksinstall will detect the version of GoogleSoftwareUpdate in Keystone.tbz, then unzip it to "/tmp/{random_path}/GoogleSoftwareUpdate.bundle" for checking its codesign.
However, it will only check the codesign information in Keystone.tbz when the installing version is greater than the GoogleSoftwareUpdate version that exists on the system:
2023-10-28 18:23:39.091656+0800 ksinstall[47378:757020] 2023-10-28 18:23:39.091 ksinstall[47378/0x7ff857d89640] [lvl=2] -[KeystoneInstallBackend shouldInstallWithVersion:error:] Google Software Update installer attempting to install unsigned bundle: <KSError:0x600000c23030
......
NSLocalizedDescription = "KSCodeSigningVerification failed to validate code signing for '/tmp/ksinstall.ysB18JUBzv/GoogleSoftwareUpdate.bundle'. Error code: -67030";
line = 303;
filename = "KSCodeSigningVerification.m";
function = "+[KSCodeSigningVerification verifyBundle:applicationId:error:]";
date = 2023-10-28 10:23:39 +0000;
}
So if the GoogleSoftwareUpdate component does not exist on the system before, ksinstall will install GoogleSoftwareUpdate directly (without codesign check).
In this case, the attacker can directly combine the issue in 0x01, overwrite the Keystone.tbz (with a fake GoogleSoftwareUpdateDaemon), and wait until the GoogleSoftwareUpdate component is installed in "/Library/Google/GoogleSoftwareUpdate/". After that, the attacker can make a request to "com.google.Keystone.Daemon.UpdateEngineXPC" service through NSXPC, and the system will run "/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/GoogleSoftwareUpdateDaemon" with root privileges. The attacker successfully completed the LPE attack and executed arbitrary code with root privileges.
https://crbug.com/chromium/2
In addition, for case that the GoogleSoftwareUpdate component already exists in the system:
There is a race condition issue between ksinstall check component version and check codesign information after compression.
ksinstall check the component version via:
/usr/bin/tar -Oxjf /path/to/Keystone.tbz GoogleSoftwareUpdate.bundle/Contents/Info.plist
Therefore, if an attacker has permission to write the /path/to/Keystone.tbz file, he can first fake a GoogleSoftwareUpdate component with a larger CFBundleVersion. When ksinstall determines that the version is newer than the local installed version, it will do the update process: decompress Keystone.tbz and check the codesign information in it.
Before decompression, the attacker can change the compressed GoogleSoftwareUpdate.bundle in /path/to/Keystone.tbz to a symbol link pointing to "/tmp/GoogleSoftwareUpdate.bundle" (a location controllable by the attacker). ksinstall does not prevent symbolic link when checking codesign information. Finally, ksinstall will move the symbolic link pointing to "/tmp/GoogleSoftwareUpdate.bundle" into "/Library/Google/GoogleSoftwareUpdate/":
$ ls -la /Library/Google/GoogleSoftwareUpdate/
total 0
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 .
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 ..
lrwxr-xr-x 1 root wheel 32 Oct 28 12:35 GoogleSoftwareUpdate.bundle -> /tmp/GoogleSoftwareUpdate.bundle
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 TicketStore
At this point, the "/tmp/GoogleSoftwareUpdate.bundle/Contents/MacOS/GoogleSoftwareUpdateDaemon" is fully controllable by attacker. By modifying GoogleSoftwareUpdateDaemon and triggering it via NSXPC "com.google.Keystone.Daemon.UpdateEngineXPC", the attacker can complete the LPE attack and executed arbitrary code with root privileges.
Note that before ksinstall executes the installation, it will confirm whether 3550s has passed since the last update (through a file that records the update timestamp: {NSTemporaryDirectory}/.ksinstall-0-installAttempts.plist). So, to facilitate reproduction, you can manually change the computer time delay 1 hour when you reproduce, or just delete this file directly. I have implemented it into the clean_sys.sh script I mentioned below.
VERSION
Chrome Version: 118.0.5993.117 stable (Official Build) (x86_64) Operating System: macOS Sonoma 14.1 23B73 (all versions affected)
REPRODUCTION CASE
a. This vulnerability can be automatically triggered in software updates (e.g., GoogleSoftwareUpdate.bundle component automatically update) / the enterprise administrator deploys Chrome installation package / or in any scenario where the Keystone component is used. In these enumerated scenarios, the triggering of this vulnerability does not require user interaction.
b. The exploit I wrote is for the installation of GoogleChrome.pkg, but these issues affect all processes mentioned above using Keystone.
c. There are two exploit_1 / exploit_2 in the attachment that exploit https://crbug.com/chromium/1 and https://crbug.com/chromium/2 in 0x02 respectively. The scenario of explot_1 is the first time to install Chrome Enterprise or configure Chrome update in the system (no "GoogleSoftwareUpdate.bundle" installed before). exploit_2 does not have any scenario restrictions and can be automatically triggered when Chrome is updated or when an enterprise administrator deploys GoogleChrome.pkg. So exploit_2 is more powerful. However, I recommend using exploit_1 to verify the vulnerability first, because exploit_2 exploits the race condition issue. Although it is 100% stable on my computer, I am not sure whether the usleep(300000) in "exploit_2/exploit.mm" is related to the computer configuration.
-
Download the attachment, unzip and enter the folder.
-
Clear the system through the script I provided to avoid previous reproduce from affecting this reproduce:
sudo ./clean_sys.sh
- Compile the exploit and trigger (the trigger is used for sending NSXPC request):
clang++ ./exploit.mm -o exp
clang++ ./trigger.mm -framework foundation -o trigger
- Run the exploit with a low-privileges user until prompt (keep exploit running and do next step):
$ ./exp
[*] Setting the Environment ......
[*] Waiting for the install/update process ......
-
Simulate the scenario that the enterprise administrator deploys GoogleChrome.pkg for installation or updates: Download GoogleChrome.pkg from https://chromeenterprise.google/browser/download/#mac-tab and install it as an administrator.
-
Just wait. No user interaction is required. You can see that exploit finally obtains an interactive shell with root privileges (from the low-privileges user):
$ ./exp
[*] Setting the Environment ......
[*] Waiting for the install/update process ......
[+] Overwrite the Magic File
[*] Waiting for the Attack ......
[+] Trigger the Fake GoogleSoftwareUpdateDaemon Service
[*] Elevation of Privilege ......
[+] Exploit Successfully!!!
[+] Please Enjoy Your ROOT SHELL:
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2# whoami
whoami
root
bash-3.2#
Suggestions
0x01: Check the case of HardLink.
0x02: I don't think the two issues in 0x02 can be exploited independently, but they do provide the ability to execute arbitrary code with root privileges after the attacker gains arbitrary file write. As Apple is working on mitigations to reduce this exploit method (from "arbitrary file write" to "arbitrary code run with root") in the system itself.
You can mitigate the two issues in 0x02 through strict codesign and symlink checking, or just fix the issue in 0x01
CREDIT INFORMATION
Reporter credit: NorthSea
Context
On macOS, Google's software updater is built on a component called Keystone. Chrome uses it, and so do other Google products such as Chrome Remote Desktop. When a user installs Chrome Enterprise, configures Chrome updates, or installs other Google software, the Keystone component runs with root privileges. A typical installation path for the component is:
/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle
The report covers two related weaknesses. The first is a lock file handling bug in Keystone that lets a low-privileged local user turn a hard link into an arbitrary file permission change. The second covers two flaws in ksinstall, the installer that the Chrome Enterprise package's postinstall script runs as root, which allow a fake GoogleSoftwareUpdateDaemon to end up in a root-owned location and then be launched with root privileges. The reporter notes that Apple is working on mitigations that reduce the "arbitrary file write to arbitrary code run with root" technique inside macOS itself.
Setup
The testing was done on:
| Item | Value |
|---|---|
| Chrome | 118.0.5993.117 stable (Official Build) (x86_64) |
| Operating system | macOS Sonoma 14.1 23B73 (report states all versions affected) |
| Attacker position | low-privileged local user |
| Trigger | Chrome Enterprise install or update, or any other Keystone-driven update |
The exploit was written against the installation of GoogleChrome.pkg, but the reporter stresses that the issues affect every process that uses Keystone. Two exploit variants are provided: exploit_1 targets the first issue in section 0x02 and exploit_2 targets the second. exploit_2 has no scenario restrictions and can be triggered automatically on a Chrome update or when an enterprise administrator deploys GoogleChrome.pkg, which makes it the more powerful of the two. The reporter nevertheless recommends verifying with exploit_1 first, because exploit_2 depends on a race condition and its usleep(300000) in exploit_2/exploit.mm may be sensitive to the machine's configuration, even though it was 100% stable on the reporter's computer.
Finding it
The lock file in 0x01
During installation or update, Keystone takes a lock. The reporter quotes the implementation:
id __cdecl +[KSInstallSettings userInstallLockFile:](id a1, SEL a2, id a3)
{
__CFString *v4; // rdi
v4 = CFSTR("/tmp/com.google.Keystone");
if ( objc_msgSend(a3, "length") )
v4 = (__CFString *)a3;
return objc_msgSend(v4, "stringByAppendingPathComponent:", CFSTR(".keystone_install_lock"));
}
The lock file is opened and its permissions are changed to -rw-rw-rw-. Keystone checks for a symbolic link when opening the file by using O_NOFOLLOW, but that check can be bypassed with a hard link on macOS. Because /tmp/ is writable by any user, a low-privileged user can create /tmp/com.google.Keystone in advance and place a hard link named .keystone_install_lock inside it that points at any file. When Chrome or another Google product is installed or updated, Keystone runs as root and the attacker gets that file changed to readable and writable by any user.
Turning file write into root code execution
The reporter then analyses what the -rw-rw-rw- permission actually buys. It is not enough to modify /etc/sudoers or similar files, because the system checks their permissions and ignores configuration that ordinary users can write. It is also not enough to modify a program that runs as root, because the new mode carries no executable bit.
On older macOS versions, /etc/defaults/periodic.conf could be modified to escalate, since its settings are triggered when macOS performs periodic tasks. On higher versions, macOS added TCC protection to that file and to some similar files: whatever the permissions of the modifying process, even root, the system prompts "SomeApp would like to administer your computer" and requires the user to allow it. The reporter had a silent privilege escalation and a root shell on lower versions, but needed a default-setting escalation on the latest macOS to make the exploit weaponised and raise the severity. That is what led to reviewing Google's own components, and to section 0x02.
The installer in 0x02
After an enterprise administrator deploys the Chrome Enterprise installation package, the postinstall script of GoogleChrome.pkg runs the Keystone component as root and tries to install the GoogleSoftwareUpdate service to:
/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle
ksinstall is executed as root:
/path/to/ksinstall --install=/path/to/Keystone.tbz
Two problems were found in that process.
Issue 1: codesign check skipped on first install
ksinstall reads the version of GoogleSoftwareUpdate inside Keystone.tbz, unpacks it to /tmp/{random_path}/GoogleSoftwareUpdate.bundle and checks its code signature. But it only checks the signature when the version being installed is greater than the GoogleSoftwareUpdate version already on the system. The reporter captured the log line from a failed signature validation:
2023-10-28 18:23:39.091656+0800 ksinstall[47378:757020] 2023-10-28 18:23:39.091 ksinstall[47378/0x7ff857d89640] [lvl=2] -[KeystoneInstallBackend shouldInstallWithVersion:error:] Google Software Update installer attempting to install unsigned bundle: <KSError:0x600000c23030
......
NSLocalizedDescription = "KSCodeSigningVerification failed to validate code signing for '/tmp/ksinstall.ysB18JUBzv/GoogleSoftwareUpdate.bundle'. Error code: -67030";
line = 303;
filename = "KSCodeSigningVerification.m";
function = "+[KSCodeSigningVerification verifyBundle:applicationId:error:]";
date = 2023-10-28 10:23:39 +0000;
}
If GoogleSoftwareUpdate is not present on the system beforehand, ksinstall installs it directly, without the codesign check. Combined with the arbitrary file write from 0x01, an attacker can overwrite Keystone.tbz with a fake GoogleSoftwareUpdateDaemon and wait until the component is installed into /Library/Google/GoogleSoftwareUpdate/. The attacker then sends a request to the com.google.Keystone.Daemon.UpdateEngineXPC service over NSXPC, and the system runs /Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/GoogleSoftwareUpdateDaemon as root. That completes the local privilege escalation.
Issue 2: race between version check and codesign check
When GoogleSoftwareUpdate already exists on the system, there is a race condition between the version check and the codesign check after decompression. The version is read with:
/usr/bin/tar -Oxjf /path/to/Keystone.tbz GoogleSoftwareUpdate.bundle/Contents/Info.plist
An attacker who can write /path/to/Keystone.tbz can first place a fake GoogleSoftwareUpdate component with a larger CFBundleVersion in it. Once ksinstall decides the version is newer than the installed one, it proceeds to decompress Keystone.tbz and check the code signature. Before decompression, the attacker replaces the compressed GoogleSoftwareUpdate.bundle inside /path/to/Keystone.tbz with a symbolic link pointing to /tmp/GoogleSoftwareUpdate.bundle, a location the attacker controls. ksinstall does not prevent symbolic links when checking the code signature. It then moves the symbolic link into /Library/Google/GoogleSoftwareUpdate/:
$ ls -la /Library/Google/GoogleSoftwareUpdate/
total 0
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 .
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 ..
lrwxr-xr-x 1 root wheel 32 Oct 28 12:35 GoogleSoftwareUpdate.bundle -> /tmp/GoogleSoftwareUpdate.bundle
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 TicketStore
At that point /tmp/GoogleSoftwareUpdate.bundle/Contents/MacOS/GoogleSoftwareUpdateDaemon is fully controlled by the attacker. Modifying that daemon and triggering it through the NSXPC service com.google.Keystone.Daemon.UpdateEngineXPC gives arbitrary code execution as root.
One operational detail matters for reproduction: before executing the installation, ksinstall checks whether 3550 seconds have passed since the last update, using a file that records the update timestamp, {NSTemporaryDirectory}/.ksinstall-0-installAttempts.plist. To reproduce, either move the computer clock forward by one hour or delete that file. The reporter folded this into the clean_sys.sh script.
Exploitation
Step 1: prepare the system
Download the attachment, unzip it and enter the folder. Then clear the system so that earlier reproduction attempts do not interfere:
sudo ./clean_sys.sh
Step 2: compile the exploit and the trigger
The trigger is used to send the NSXPC request:
clang++ ./exploit.mm -o exp
clang++ ./trigger.mm -framework foundation -o trigger
Step 3: run the exploit as a low-privileged user
Keep the exploit running and continue with the next step:
$ ./exp
[*] Setting the Environment ......
[*] Waiting for the install/update process ......
Step 4: simulate the enterprise deployment
Download GoogleChrome.pkg from https://chromeenterprise.google/browser/download/#mac-tab and install it as an administrator.
Step 5: wait for the root shell
No user interaction is required. The exploit eventually obtains an interactive shell with root privileges from the low-privileged user:
$ ./exp
[*] Setting the Environment ......
[*] Waiting for the install/update process ......
[+] Overwrite the Magic File
[*] Waiting for the Attack ......
[+] Trigger the Fake GoogleSoftwareUpdateDaemon Service
[*] Elevation of Privilege ......
[+] Exploit Successfully!!!
[+] Please Enjoy Your ROOT SHELL:
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2# whoami
whoami
root
bash-3.2#
The output shows the sequence: the magic file is overwritten, the fake daemon service is triggered, and the resulting shell answers root to whoami.
Root cause
Three mistakes combine.
- The lock file path is built under
/tmp/com.google.Keystone, a directory any local user can create, and the only protection against a link attack isO_NOFOLLOW. On macOS a hard link bypasses that check, so the root-run permission change (-rw-rw-rw-) can be aimed at any file. ksinstallonly verifies the code signature of the GoogleSoftwareUpdate bundle when the incoming version is newer than the installed one. On a system without GoogleSoftwareUpdate, the signature check is skipped entirely, so a bundle supplied through the arbitrary write is installed and later executed as root.- When an older component is present, the version check and the signature check operate on different states of the archive. The version is read from
Info.plistinside the tarball, and the signature check happens after decompression, without rejecting symbolic links. An attacker who can rewrite the archive between those points can have a symlink to an attacker-controlled directory moved into/Library/Google/GoogleSoftwareUpdate/.
The existing defences did not stop the chain. The O_NOFOLLOW check covers symbolic links but not hard links. The codesign check is conditional, and the symlink check is missing at the point where the bundle is moved into place. The reporter also notes that Apple's TCC protection on /etc/defaults/periodic.conf prompts the user for approval, which is why the Google components were needed to finish the chain silently on current macOS.
Impact
A low-privileged local user can obtain arbitrary code execution as root. The trigger does not require user interaction and fires in several situations: automatic software updates such as the GoogleSoftwareUpdate.bundle component updating itself, an enterprise administrator deploying the Chrome installation package, or any other scenario in which Keystone is used. The reporter's exploit targets GoogleChrome.pkg, but the issues affect all of those processes. The first issue in 0x02 requires that GoogleSoftwareUpdate is not already installed; the second has no scenario restrictions and works when Chrome is updated or when an enterprise administrator deploys GoogleChrome.pkg. The reporter also states that the two issues in 0x02 cannot be exploited independently, but they provide root code execution once the attacker has arbitrary file write.
Fix
For 0x01, the suggestion is to check for the hard link case.
For 0x02, the reporter suggests strict codesign and symlink checking, or simply fixing the issue in 0x01. The report does not describe a patch that was applied.
Variants to test
- Other lock files under world-writable directories. Look for privileged installers that build lock or state paths under
/tmpor similar directories and rely onO_NOFOLLOW. A positive result is a hard link in that directory causing a root-run process to change the mode of a file the attacker chose. - Conditional signature checks. Search installer code for signature verification that only runs when a version comparison succeeds. A positive result is a bundle installed and later executed as root without a signature check on a system where the component is absent.
- Time-of-check to time-of-use on archives. Where an installer reads a version from an archive and verifies the signature after extraction, try swapping the archive contents between the two operations. A positive result is a symlink or modified bundle moved into a root-owned location.
- Symlinks in privileged move operations. Check whether installers reject symbolic links when moving extracted bundles into
/Libraryor similar locations. A positive result is a root-owned symlink pointing to an attacker-controlled directory. - XPC services that launch installed binaries. Enumerate privileged XPC services such as
com.google.Keystone.Daemon.UpdateEngineXPCand check whether the binary they launch can be influenced by a local user. A positive result is a root shell from a low-privileged account after triggering the service.
What happened, in plain words
A security researcher found a way for an ordinary user account on a Mac to become the all-powerful root account, without the person being asked to approve anything. The trick lives in Google's software updater, a helper program called Keystone. Chrome uses Keystone to update itself, and so do other Google products such as Chrome Remote Desktop. Because an updater has to replace files in protected system folders, it runs with the highest level of permission on the machine, the same level as the root account.
The researcher found three mistakes that, chained together, let a low-privileged user plant their own program in a place the updater trusts, and then have the system launch that program as root. The report is split into two sections: 0x01 describes the first mistake (a lock file that can be redirected to any file on disk), and 0x02 describes two more mistakes in the installer that the Chrome Enterprise package runs as root.
A few words you will meet constantly below:
- Privilege means permission to do things. A normal user can change their own files.
rootcan change anything, including system files. - Privilege escalation means going from a low level of permission to a higher one. A local privilege escalation (LPE) means the attacker already has an account on the machine and only needs to climb from there.
- A bundle on macOS is a folder that looks like a single file to the user, for example an application. Inside it are the program and its resources.
- A daemon is a background program with no window, which the system starts and keeps running.
Context
On macOS, Google's software updater is built on a component called Keystone. Chrome uses it, and so do other Google products such as Chrome Remote Desktop. When a user installs Chrome Enterprise, configures Chrome updates, or installs other Google software, the Keystone component runs with root privileges. A typical installation path for the component is:
/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle
This is a folder path. /Library is a system-wide folder shared by all users, and writing there normally requires administrator or root rights. That is exactly why the updater runs as root: it has to put files there.
The report covers two related weaknesses. The first is a lock file handling bug in Keystone that lets a low-privileged local user turn a hard link into an arbitrary file permission change. The second covers two flaws in ksinstall, the installer that the Chrome Enterprise package's postinstall script runs as root, which allow a fake GoogleSoftwareUpdateDaemon to end up in a root-owned location and then be launched with root privileges. The reporter notes that Apple is working on mitigations that reduce the "arbitrary file write to arbitrary code run with root" technique inside macOS itself.
Two terms from that paragraph are worth unpacking now, because the whole report depends on them:
- Arbitrary file write means the attacker can make a privileged program write to, or change the permissions of, a file of the attacker's choosing. On its own it is not code execution, but it is a powerful building block.
- Arbitrary code execution means the attacker can make the machine run a program the attacker supplied. With
rootprivileges, that is the end of the game: the attacker controls the machine.
Setup
The testing was done on:
| Item | Value |
|---|---|
| Chrome | 118.0.5993.117 stable (Official Build) (x86_64) |
| Operating system | macOS Sonoma 14.1 23B73 (report states all versions affected) |
| Attacker position | low-privileged local user |
| Trigger | Chrome Enterprise install or update, or any other Keystone-driven update |
The "attacker position" row matters: the attacker is not a remote stranger on the internet. They are someone with a normal account on the same Mac, for example a shared office machine or a machine where a less trusted person has a login. The "trigger" row says what makes the vulnerable code run: an install or an update, which happens routinely and without the user doing anything special.
The exploit was written against the installation of GoogleChrome.pkg, but the reporter stresses that the issues affect every process that uses Keystone. A .pkg file is macOS's installer package format, the equivalent of a .msi on Windows. Two exploit variants are provided: exploit_1 targets the first issue in section 0x02 and exploit_2 targets the second. exploit_2 has no scenario restrictions and can be triggered automatically on a Chrome update or when an enterprise administrator deploys GoogleChrome.pkg, which makes it the more powerful of the two. The reporter nevertheless recommends verifying with exploit_1 first, because exploit_2 depends on a race condition and its usleep(300000) in exploit_2/exploit.mm may be sensitive to the machine's configuration, even though it was 100% stable on the reporter's computer.
A race condition is a bug that appears only when two things happen in a particular order or at a particular moment. Think of two people reaching for the same door handle at once: usually nothing goes wrong, but occasionally one gets there first and the other is surprised. Because timing is involved, such bugs can behave differently on a fast machine and a slow one, which is why the reporter warns about the usleep(300000) line. usleep is a function that makes a program pause for a number of microseconds, here 300000 of them, which is 0.3 seconds. The pause is there to try to hit the right moment.
Finding it
The lock file in 0x01
During installation or update, Keystone takes a lock. A lock file is a common technique: a program creates a small file to signal "I am busy, do not start a second copy of me". If the file exists, another copy knows to wait. The reporter quotes the implementation:
id __cdecl +[KSInstallSettings userInstallLockFile:](id a1, SEL a2, id a3)
{
__CFString *v4; // rdi
v4 = CFSTR("/tmp/com.google.Keystone");
if ( objc_msgSend(a3, "length") )
v4 = (__CFString *)a3;
return objc_msgSend(v4, "stringByAppendingPathComponent:", CFSTR(".keystone_install_lock"));
}
This is Objective-C, the language macOS software has traditionally been written in. Line by line:
id __cdecl +[KSInstallSettings userInstallLockFile:](id a1, SEL a2, id a3)declares a class method (the+means class method, not instance method) nameduserInstallLockFile:on the classKSInstallSettings. It takes an argumenta3, which is a string.idis Objective-C's "some object" type, andSELis a method selector.__CFString *v4;declares a variablev4that will hold a string.v4 = CFSTR("/tmp/com.google.Keystone");sets the default value to the fixed path/tmp/com.google.Keystone.if ( objc_msgSend(a3, "length") )sends thelengthmessage to the argument. In plain words: if the caller passed a non-empty string, use it instead.v4 = (__CFString *)a3;replaces the default with the caller's string.return objc_msgSend(v4, "stringByAppendingPathComponent:", CFSTR(".keystone_install_lock"));appends the file name.keystone_install_lockto the folder and returns the result.
So the lock file is /tmp/com.google.Keystone/.keystone_install_lock unless the caller supplies a different folder. /tmp is a folder that every user on the machine can write to; that is its purpose, temporary files shared between programs. That single fact is the seed of the bug.
The lock file is opened and its permissions are changed to -rw-rw-rw-. Permissions on Unix-like systems are written as a string of letters. The first character is the file type (- for a regular file, d for a directory, l for a symbolic link). The next three groups of three are the permissions for the owner, the group, and everyone else. r is read, w is write, x is execute. So -rw-rw-rw- means: a regular file, readable and writable by the owner, by the group, and by everybody else. No execute bit.
Keystone checks for a symbolic link when opening the file by using O_NOFOLLOW, but that check can be bypassed with a hard link on macOS. Two kinds of link need explaining:
- A symbolic link (symlink) is like a shortcut or a signpost. It is a small file whose contents are "the real file is over there". When a program opens the symlink, the operating system follows the signpost and opens the target.
- A hard link is different. It is a second name for the same file. There is no signpost; the file simply has two entries in the directory listing, and both point at the same data on disk. Deleting one name does not delete the data while the other name exists.
O_NOFOLLOW is a flag a program can pass when opening a file, meaning "if the path is a symbolic link, refuse to open it". It protects against the signpost trick. It does nothing against a hard link, because a hard link is not a signpost: it is the file itself under another name. That is the bypass.
Because /tmp/ is writable by any user, a low-privileged user can create /tmp/com.google.Keystone in advance and place a hard link named .keystone_install_lock inside it that points at any file. When Chrome or another Google product is installed or updated, Keystone runs as root and the attacker gets that file changed to readable and writable by any user.
In other words, the attacker does not need to guess a password or exploit a memory bug. They only need to prepare a folder and a name, then wait for a routine update to run as root and apply the permission change to the file the attacker chose.
Turning file write into root code execution
The reporter then analyses what the -rw-rw-rw- permission actually buys. It is not enough to modify /etc/sudoers or similar files, because the system checks their permissions and ignores configuration that ordinary users can write. /etc/sudoers is the configuration file that decides who may run commands as root; if an ordinary user could edit it, they could grant themselves root. The system defends against that by refusing to honour a sudoers file that is writable by ordinary users, so the attacker's new write permission is not enough there.
It is also not enough to modify a program that runs as root, because the new mode carries no executable bit. Remember -rw-rw-rw- has no x. On Unix-like systems a file must have the execute permission for the operating system to run it as a program. So the attacker can rewrite a root-owned program's contents, but cannot make the system execute it.
On older macOS versions, /etc/defaults/periodic.conf could be modified to escalate, since its settings are triggered when macOS performs periodic tasks. Periodic tasks are maintenance jobs the system runs on a schedule, such as cleaning up logs. If an attacker can change the configuration of those jobs, they can arrange for their own command to run, and those jobs run as root. That was the classic path from file write to code execution.
On higher versions, macOS added TCC protection to that file and to some similar files: whatever the permissions of the modifying process, even root, the system prompts "SomeApp would like to administer your computer" and requires the user to allow it. TCC stands for Transparency, Consent and Control. It is the macOS privacy system that pops up dialogs like "SomeApp would like to access your Photos". It is a second gate that sits in front of certain sensitive files and actions, independent of Unix permissions. So even a root process that writes the file triggers a dialog, and the change only takes effect if the human clicks Allow. That breaks the silent attack.
The reporter had a silent privilege escalation and a root shell on lower versions, but needed a default-setting escalation on the latest macOS to make the exploit weaponised and raise the severity. That is what led to reviewing Google's own components, and to section 0x02. In other words: Apple closed the easy door, so the researcher went looking for a different door in software that Google ships.
The installer in 0x02
After an enterprise administrator deploys the Chrome Enterprise installation package, the postinstall script of GoogleChrome.pkg runs the Keystone component as root and tries to install the GoogleSoftwareUpdate service to:
/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle
A postinstall script is a small program that runs automatically at the end of an installer, after the files have been copied. Installers use them to register services, set permissions, and so on. Because the installer itself runs with administrator rights, its postinstall script runs as root too.
ksinstall is executed as root:
/path/to/ksinstall --install=/path/to/Keystone.tbz
This is a command line. /path/to/ksinstall is the program being run. --install= is an option telling it what to install, and /path/to/Keystone.tbz is the archive it should install from. A .tbz file is a compressed archive, like a .zip: a single file that contains a folder tree. The archive holds the GoogleSoftwareUpdate bundle that will end up in /Library.
Two problems were found in that process.
Issue 1: codesign check skipped on first install
ksinstall reads the version of GoogleSoftwareUpdate inside Keystone.tbz, unpacks it to /tmp/{random_path}/GoogleSoftwareUpdate.bundle and checks its code signature. But it only checks the signature when the version being installed is greater than the GoogleSoftwareUpdate version already on the system. The reporter captured the log line from a failed signature validation:
2023-10-28 18:23:39.091656+0800 ksinstall[47378:757020] 2023-10-28 18:23:39.091 ksinstall[47378/0x7ff857d89640] [lvl=2] -[KeystoneInstallBackend shouldInstallWithVersion:error:] Google Software Update installer attempting to install unsigned bundle: <KSError:0x600000c23030
......
NSLocalizedDescription = "KSCodeSigningVerification failed to validate code signing for '/tmp/ksinstall.ysB18JUBzv/GoogleSoftwareUpdate.bundle'. Error code: -67030";
line = 303;
filename = "KSCodeSigningVerification.m";
function = "+[KSCodeSigningVerification verifyBundle:applicationId:error:]";
date = 2023-10-28 10:23:39 +0000;
}
A code signature is a cryptographic stamp that macOS checks to confirm who made a program and that nobody has altered it since. It is like a wax seal on an envelope: if the seal is intact, the contents are as the sender left them. When the signature check fails, the system should refuse to install the bundle. The log above is exactly that refusal: KSCodeSigningVerification failed to validate code signing for the unpacked bundle in /tmp/ksinstall.ysB18JUBzv/GoogleSoftwareUpdate.bundle, with error code -67030.
Reading the log line by line:
2023-10-28 18:23:39.091656+0800 ksinstall[47378:757020]is the timestamp, the program nameksinstall, and its process and thread identifiers.[lvl=2]is a log level.-[KeystoneInstallBackend shouldInstallWithVersion:error:]names the method that produced the message. The leading-means an instance method.Google Software Update installer attempting to install unsigned bundle:is the human-readable message: the installer is trying to install a bundle with no valid signature.- The indented lines are the details of the error object: a description naming the file and the error code, the source line
303, the source fileKSCodeSigningVerification.m, the function+[KSCodeSigningVerification verifyBundle:applicationId:error:], and the date.
If GoogleSoftwareUpdate is not present on the system beforehand, ksinstall installs it directly, without the codesign check. That is the flaw: the check is conditional on a version comparison, and on a fresh machine there is nothing to compare against, so the check is skipped. Combined with the arbitrary file write from 0x01, an attacker can overwrite Keystone.tbz with a fake GoogleSoftwareUpdateDaemon and wait until the component is installed into /Library/Google/GoogleSoftwareUpdate/. The attacker then sends a request to the com.google.Keystone.Daemon.UpdateEngineXPC service over NSXPC, and the system runs /Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/MacOS/GoogleSoftwareUpdateDaemon as root. That completes the local privilege escalation.
XPC is macOS's mechanism for one program to send messages to another program on the same machine. It is like an internal postal service: a client sends a message to a named service, and the system delivers it. NSXPC is the Objective-C framework that makes writing such clients and services easier. com.google.Keystone.Daemon.UpdateEngineXPC is the name of the service, and the daemon behind it runs as root. So once the attacker's fake daemon sits at the path the service launches, sending a message to the service is the same as asking the system to run the attacker's program as root.
Issue 2: race between version check and codesign check
When GoogleSoftwareUpdate already exists on the system, there is a race condition between the version check and the codesign check after decompression. The version is read with:
/usr/bin/tar -Oxjf /path/to/Keystone.tbz GoogleSoftwareUpdate.bundle/Contents/Info.plist
tar is the standard Unix archiving tool. The flags here mean: -O write the extracted file to standard output instead of to disk, -x extract, -j the archive is bzip2-compressed, -f the next argument is the archive file. So the command reads one file out of the archive, GoogleSoftwareUpdate.bundle/Contents/Info.plist, and prints it. Info.plist is the metadata file inside a macOS bundle; it contains the version number, among other things. The installer reads the version from the archive without unpacking the whole thing.
An attacker who can write /path/to/Keystone.tbz can first place a fake GoogleSoftwareUpdate component with a larger CFBundleVersion in it. CFBundleVersion is the key in Info.plist that holds the version number. A larger number makes the installer believe the archive is newer than what is installed, which is the condition for proceeding with the update.
Once ksinstall decides the version is newer than the installed one, it proceeds to decompress Keystone.tbz and check the code signature. Before decompression, the attacker replaces the compressed GoogleSoftwareUpdate.bundle inside /path/to/Keystone.tbz with a symbolic link pointing to /tmp/GoogleSoftwareUpdate.bundle, a location the attacker controls. ksinstall does not prevent symbolic links when checking the code signature. It then moves the symbolic link into /Library/Google/GoogleSoftwareUpdate/:
$ ls -la /Library/Google/GoogleSoftwareUpdate/
total 0
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 .
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 ..
lrwxr-xr-x 1 root wheel 32 Oct 28 12:35 GoogleSoftwareUpdate.bundle -> /tmp/GoogleSoftwareUpdate.bundle
drwxr-xr-x 4 root wheel 128 Oct 28 22:14 TicketStore
ls -la lists a directory with long format and includes hidden entries. Line by line:
total 0is the total size of the listed blocks.drwxr-xr-x 4 root wheel 128 Oct 28 22:14 .is the directory itself. The leadingdsays directory,rootis the owner,wheelis the group,128is the size, and the date is the modification time.drwxr-xr-x 4 root wheel 128 Oct 28 22:14 ..is the parent directory.lrwxr-xr-x 1 root wheel 32 Oct 28 12:35 GoogleSoftwareUpdate.bundle -> /tmp/GoogleSoftwareUpdate.bundleis the important line. The leadinglsays symbolic link, and the arrow shows where it points:/tmp/GoogleSoftwareUpdate.bundle. The link is owned byroot, but its target is in/tmp, which the attacker controls.drwxr-xr-x 4 root wheel 128 Oct 28 22:14 TicketStoreis another directory in the same folder.
At that point /tmp/GoogleSoftwareUpdate.bundle/Contents/MacOS/GoogleSoftwareUpdateDaemon is fully controlled by the attacker. Modifying that daemon and triggering it through the NSXPC service com.google.Keystone.Daemon.UpdateEngineXPC gives arbitrary code execution as root.
The essence of this second issue is the gap in time between two checks. The installer first looks at the version (reading Info.plist from the archive), then later looks at the signature (after unpacking). Between those two moments, the attacker swaps the contents of the archive. The version check saw a legitimate-looking, newer version; the signature check then sees a symlink, which it does not reject; and the final move puts a root-owned symlink into /Library pointing at the attacker's folder. This is the classic time-of-check to time-of-use pattern: the thing that was checked is not the thing that is used.
One operational detail matters for reproduction: before executing the installation, ksinstall checks whether 3550 seconds have passed since the last update, using a file that records the update timestamp, {NSTemporaryDirectory}/.ksinstall-0-installAttempts.plist. To reproduce, either move the computer clock forward by one hour or delete that file. The reporter folded this into the clean_sys.sh script. NSTemporaryDirectory is a macOS function that returns the current user's temporary folder path. The 3550 seconds is a little under an hour, a rate limit so the updater does not run too often.
Exploitation
Step 1: prepare the system
Download the attachment, unzip it and enter the folder. Then clear the system so that earlier reproduction attempts do not interfere:
sudo ./clean_sys.sh
sudo runs the following command with administrator rights. ./clean_sys.sh means "run the script named clean_sys.sh in the current folder". The reason for this step is to avoid previous reproduction attempts affecting this one.
Step 2: compile the exploit and the trigger
The trigger is used to send the NSXPC request:
clang++ ./exploit.mm -o exp
clang++ ./trigger.mm -framework foundation -o trigger
clang++ is the compiler, the program that turns source code into a runnable program. .mm is the file extension for Objective-C++ source. -o exp says "name the output exp". -framework foundation links the Foundation framework, which provides basic macOS classes. So the first command builds the exploit into a program called exp, and the second builds the trigger into a program called trigger.
Step 3: run the exploit as a low-privileged user
Keep the exploit running and continue with the next step:
$ ./exp
[*] Setting the Environment ......
[*] Waiting for the install/update process ......
The $ prompt means an ordinary user's shell, not root. The program prints that it is setting up the environment, then waits. It is waiting for the privileged install or update to happen, because that is the moment the vulnerable code runs as root.
Step 4: simulate the enterprise deployment
Download GoogleChrome.pkg from https://chromeenterprise.google/browser/download/#mac-tab and install it as an administrator. This is the stand-in for the routine event that triggers the bug: an administrator deploying Chrome Enterprise.
Step 5: wait for the root shell
No user interaction is required. The exploit eventually obtains an interactive shell with root privileges from the low-privileged user:
$ ./exp
[*] Setting the Environment ......
[*] Waiting for the install/update process ......
[+] Overwrite the Magic File
[*] Waiting for the Attack ......
[+] Trigger the Fake GoogleSoftwareUpdateDaemon Service
[*] Elevation of Privilege ......
[+] Exploit Successfully!!!
[+] Please Enjoy Your ROOT SHELL:
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2# whoami
whoami
root
bash-3.2#
Reading the output in order:
[*] Setting the Environment ......and[*] Waiting for the install/update process ......are the same two lines as before: setup done, now waiting.[+] Overwrite the Magic Filereports that the file the installer will trust has been overwritten.[*] Waiting for the Attack ......means the exploit is now waiting for the privileged process to reach the vulnerable point.[+] Trigger the Fake GoogleSoftwareUpdateDaemon Servicereports that the fake daemon service is being triggered.[+] Elevation of Privilege ......and[+] Exploit Successfully!!!report the result.[+] Please Enjoy Your ROOT SHELL:is followed by a shell prompt. The#at the end ofbash-3.2#is the conventional sign that this shell isroot.whoamiis a command that prints the current user's name. The outputrootconfirms the escalation.
The output shows the sequence: the magic file is overwritten, the fake daemon service is triggered, and the resulting shell answers root to whoami.
Root cause
Three mistakes combine.
- The lock file path is built under
/tmp/com.google.Keystone, a directory any local user can create, and the only protection against a link attack isO_NOFOLLOW. On macOS a hard link bypasses that check, so the root-run permission change (-rw-rw-rw-) can be aimed at any file. ksinstallonly verifies the code signature of the GoogleSoftwareUpdate bundle when the incoming version is newer than the installed one. On a system without GoogleSoftwareUpdate, the signature check is skipped entirely, so a bundle supplied through the arbitrary write is installed and later executed as root.- When an older component is present, the version check and the signature check operate on different states of the archive. The version is read from
Info.plistinside the tarball, and the signature check happens after decompression, without rejecting symbolic links. An attacker who can rewrite the archive between those points can have a symlink to an attacker-controlled directory moved into/Library/Google/GoogleSoftwareUpdate/.
The existing defences did not stop the chain. The O_NOFOLLOW check covers symbolic links but not hard links. The codesign check is conditional, and the symlink check is missing at the point where the bundle is moved into place. The reporter also notes that Apple's TCC protection on /etc/defaults/periodic.conf prompts the user for approval, which is why the Google components were needed to finish the chain silently on current macOS.
Impact
A low-privileged local user can obtain arbitrary code execution as root. The trigger does not require user interaction and fires in several situations: automatic software updates such as the GoogleSoftwareUpdate.bundle component updating itself, an enterprise administrator deploying the Chrome installation package, or any other scenario in which Keystone is used. The reporter's exploit targets GoogleChrome.pkg, but the issues affect all of those processes. The first issue in 0x02 requires that GoogleSoftwareUpdate is not already installed; the second has no scenario restrictions and works when Chrome is updated or when an enterprise administrator deploys GoogleChrome.pkg. The reporter also states that the two issues in 0x02 cannot be exploited independently, but they provide root code execution once the attacker has arbitrary file write.
Fix
For 0x01, the suggestion is to check for the hard link case.
For 0x02, the reporter suggests strict codesign and symlink checking, or simply fixing the issue in 0x01. The report does not describe a patch that was applied.
Variants to test
- Other lock files under world-writable directories. Look for privileged installers that build lock or state paths under
/tmpor similar directories and rely onO_NOFOLLOW. A positive result is a hard link in that directory causing a root-run process to change the mode of a file the attacker chose. - Conditional signature checks. Search installer code for signature verification that only runs when a version comparison succeeds. A positive result is a bundle installed and later executed as root without a signature check on a system where the component is absent.
- Time-of-check to time-of-use on archives. Where an installer reads a version from an archive and verifies the signature after extraction, try swapping the archive contents between the two operations. A positive result is a symlink or modified bundle moved into a root-owned location.
- Symlinks in privileged move operations. Check whether installers reject symbolic links when moving extracted bundles into
/Libraryor similar locations. A positive result is a root-owned symlink pointing to an attacker-controlled directory. - XPC services that launch installed binaries. Enumerate privileged XPC services such as
com.google.Keystone.Daemon.UpdateEngineXPCand check whether the binary they launch can be influenced by a local user. A positive result is a root shell from a low-privileged account after triggering the service.
Glossary
- Arbitrary code execution: the ability to make a machine run a program the attacker supplied.
- Arbitrary file write: the ability to make a privileged program write to, or change the permissions of, a file of the attacker's choosing.
- Bundle: a folder that macOS presents to the user as a single file, such as an application, containing a program and its resources.
- CFBundleVersion: the key in a macOS bundle's
Info.plistthat holds its version number. - Code signature: a cryptographic stamp that confirms who made a program and that it has not been altered.
- Daemon: a background program with no window that the system starts and keeps running.
- Hard link: a second name for the same file on disk; there is no separate shortcut object, both names refer to the same data.
- Info.plist: the metadata file inside a macOS bundle, holding its version and other properties.
- Keystone: Google's software updater component on macOS, used by Chrome and other Google products.
- ksinstall: the installer program that the Chrome Enterprise package's postinstall script runs as root to install the GoogleSoftwareUpdate bundle.
- Local privilege escalation (LPE): climbing from a low-privileged account on a machine to a higher-privileged one, such as
root. - Lock file: a small file a program creates to signal that it is busy, so a second copy knows to wait.
- NSXPC: the Objective-C framework for writing XPC clients and services on macOS.
- O_NOFOLLOW: a flag passed when opening a file that makes the system refuse to follow a symbolic link.
- Postinstall script: a small program that runs automatically at the end of an installer, after files are copied.
- Race condition: a bug that appears only when two operations happen in a particular order or at a particular moment.
- root: the all-powerful account on Unix-like systems, able to change anything on the machine.
- Symbolic link (symlink): a small file that acts as a signpost pointing to another file or folder.
- TCC (Transparency, Consent and Control): the macOS privacy system that shows dialogs asking the user to allow access to sensitive files and actions, independent of Unix permissions.
- Time-of-check to time-of-use: a bug where the thing that was checked is not the thing that is later used, because it changed in between.
- XPC: macOS's mechanism for one program to send messages to another program on the same machine.