Skip to content
Access control Write-up Advanced

Technical Analysis of CVE-2022-22583: Bypassing macOS System Integrity Protection (SIP)

A macOS SIP bypass allowed an attacker with root to replace a post-install script executed by system_installd, because the script was extracted to a temporary directory under /private/tmp that could be remounted. The attacker could then run arbitrary code with the com.apple.rootless.install.heritable entitlement, fully bypassing SIP filesystem restrictions.

Perception Point Follow

Published on perception-point.io

Perception Point researchers discovered a vulnerability in macOS which allows attackers to bypass Apple’s SIP (System Integrity Protection), and thus take full control over the system, provided that they already managed to achieve code execution with high privileges.

Perception Point, on perception-point.io

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Perception Point researchers found a way to bypass Apple's System Integrity Protection (SIP) on macOS, tracked as CVE-2022-22583. The bypass requires that the attacker has already achieved code execution with high privileges; from there it allows taking full control of the system. The vulnerability was reported to Apple, and the fix shipped on 26 January 2022 in macOS Monterey 12.2, macOS Big Sur 11.6.3 and Security Update 2022-001 Catalina. Apple credited three researchers for the CVE: Mickey Jin (@patch1t), Ron Hass (@ronhass7) of Perception Point and an anonymous researcher.

Context

SIP, also known as "rootless", is a macOS security mechanism introduced in OS X El Capitan (10.11). Its objective is to protect the system as a whole, even from the root user. The restrictions it imposes include:

  • Loading kernel extensions (only signed extensions are allowed)
  • Tampering with critical files and directories
  • Debugging system processes
  • Programmatically setting the startup disk

The restrictions are enforced by the macOS kernel (XNU) and can be disabled only with physical access to the machine, by booting into Recovery OS. SIP can be considered the final defence line between an attacker and full control of the system.

To protect the kernel, SIP has to prevent modifications to critical files and directories. One example is the content of the extension "AppleKextExcludeList", which manages a list of excluded kernel extensions. The SIP restrictions can be observed by using the flag "-O" in the "ls" command.

Apple still needs to be able to modify all files and directories in the system, for example to perform system updates. It does this by giving specific entitlements to the needed executables. Entitlements are pieces of data included inside a signed application, letting the system know the application is entitled to perform specific tasks. The entitlements relevant for SIP are:

  • com.apple.rootless.install: lifts all of SIP's filesystem restrictions
  • com.apple.rootless.install.heritable: the same, but child processes also inherit this entitlement

Apple does not sign arbitrary applications with these entitlements, but a few Apple-signed executables in the system own one of them. One example is "system_installd", part of the PackageKit framework, which is responsible for installing Apple-signed packages. The entitlements of an executable can be observed with the "codesign" utility. "system_installd" has the stronger "com.apple.rootless.install.heritable" entitlement, and that is what the vulnerability uses.

Setup

The work builds on a previously published SIP bypass. On 28 October 2021, Microsoft published a blog post about a SIP bypass it found, fixed in macOS Monterey 12.0.1 and identified as CVE-2021-30892. Microsoft named it "shrootless".

In shrootless, Microsoft researchers noticed that when the user installs an Apple-signed package, it is automatically executed by "system_installd". If the package contains pre/post-install scripts, they are also executed by "system_installd" and therefore inherit the "com.apple.rootless.install.heritable" entitlement, which effectively allows these scripts to fully bypass SIP's filesystem restrictions. The bug was that if one of the pre/post-install scripts was a zsh script (that is, it starts with "#!/bin/zsh"), "system_installd" would execute zsh, which in turn would source the file "/etc/zshenv". That file is not restricted by SIP and can be modified freely by root, so any code inside it would run in this SIP-bypass context whenever an Apple-signed package with a zsh script is installed. Apple's fix was to prevent zsh from sourcing "/etc/zshenv" in this scenario.

To look deeper, the researchers needed an Apple-signed package with some pre/post-install scripts. The "Suspicious Package" application is useful for inspecting a candidate package. The package they found is Apple-signed and contains a perl post-install script. The script executes several more commands, and the command-line utility "Process Monitor" was used to examine its behaviour. The output below is trimmed for clarity, keeping only "ES_EVENT_TYPE_NOTIFY_EXEC" events:

JSON
{"pid":3308,"name":"system_installd"}
{"pid":3321,"name":"perl","arguments":["/usr/bin/perl","/tmp/PKInstallSandbox.QTKhng/Scripts/com.apple.pkg.FxPlugSDK.QCq4LX/postinstall","/private/tmp/FxPlugSDK.pkg","/","/","/"],"ppid":3308}
{"pid":3321,"name":"perl5.30","ppid":3308}
{"pid":3322,"name":"pwd","ppid":3321}
{"pid":3323,"name":"sh","arguments":["sh","-c","logger -p install.info 'Running Install Scripts . . .'"],"ppid":3321}
{"pid":3323,"name":"bash","arguments":["sh","-c","logger -p install.info 'Running Install Scripts . . .'"],"ppid":3321}
{"pid":3323,"name":"logger","ppid":3321}
{"pid":3324,"name":"sh",","arguments":["sh","-c","/bin/ls \/private\/tmp\/PKInstallSandbox\.QTKhng\/Scripts\/com\.apple\.pkg\.FxPlugSDK\.QCq4LX\/postinstall_actions\/"],"ppid":3321}
{"pid":3324,"name":"bash","arguments":["sh","-c","/bin/ls \/private\/tmp\/PKInstallSandbox\.QTKhng\/Scripts\/com\.apple\.pkg\.FxPlugSDK\.QCq4LX\/postinstall_actions\/"],"ppid":3321}
{"pid":3324,"name":"ls","ppid":3321}

Finding it

Something immediately caught the researchers' attention: "system_installd" executed the post-install script from a temporary directory, "/tmp/PKInstallSandbox.QTKhng/Scripts/com.apple.pkg.FxPlugSDK.QCq4LX" in this case. Apparently "system_installd" first extracts the scripts into a temporary directory and then executes them from there. Moreover, there is a significant amount of time between the extraction and the execution; the extraction is probably done before the installation, for both pre- and post-install scripts.

That raised the question of whether the scripts could simply be swapped without "system_installd" ever noticing. Apple had thought about this loophole and made the temporary directory restricted by SIP. However, the researchers found that the "/tmp" directory itself is not restricted by SIP. To be precise, "/tmp" is actually a symbolic link and is restricted, but the directory itself is not.

Exploitation

With that information, the researchers identified how to swap the post-install script between the extraction and the execution. The key is mounting: because "/private/tmp" is not restricted by SIP, a virtual image can be mounted onto this directory at any point, even if the image contains a restricted directory inside it, and its content can then be changed however desired. There are several ways to use this idea to swap the script, but because the temporary directory path contains some random characters, the exploit was implemented as follows.

Step 1: Mount a virtual image onto /private/tmp

Create a virtual image file and mount it onto "/private/tmp".

Step 2: Install an Apple-signed package with post-install scripts

Install an Apple-signed package that carries post-install scripts, so that "system_installd" performs the extraction and later the execution.

Step 3: Wait for extraction and gather the random path

Wait for the installer to finish the extraction of the scripts directory, and gather the random parts of the extracted path.

Step 4: Unmount the image

Unmount the image file, thus reverting to the contents of "/private/tmp" before the extraction.

Step 5: Recreate the scripts directory with our own scripts

Create the scripts directory by ourselves, using the random path gathered earlier, and deposit there whatever scripts are wanted.

Any script placed as the "post-install script" inherits the "com.apple.rootless.install.heritable" entitlement from "system_installd" and is able to fully bypass SIP restrictions.

Timing is very relevant for this vulnerability: the exploit must succeed in swapping the script within the window of opportunity. Even so, the exploit is quite reliable. It usually takes one or two tries to succeed, mostly because the package used has post-install scripts, which provides plenty of time, the whole installation time.

Root cause

First, "system_installd", which owns the "com.apple.rootless.install.heritable" entitlement, extracts package scripts into a temporary directory and executes them later from that same path. Second, the parent directory of that extraction path, "/private/tmp", is not protected by SIP, so its contents can be replaced by mounting a virtual image over it. SIP protects the extracted scripts directory itself, but not the mount point above it, so the protected directory can be swapped out from under the installer between extraction and execution. The existing defence, SIP protection of the temporary scripts directory, therefore did not stop the attack, because it did not cover the directory onto which the image is mounted.

Impact

An attacker who has already achieved code execution with high privileges can use this to bypass SIP and take full control over the system. SIP is the final defence line between an attacker and full control, so defeating it removes the remaining protection of critical files and directories, kernel extension loading restrictions and the other restrictions listed above. The exploit mounts a virtual image onto "/private/tmp" and must swap the script within the window between extraction and execution.

Fix

In macOS 12.2, Apple changed the extraction destination to a new directory: "/Library/Apple/System/Library/InstallerSandboxes". All the directories in this path are restricted, except the first one ("/Library"). Although that looks similar to the situation before, Apple correctly fixed the bug by also preventing mount attempts onto the "/Library" directory when SIP is enabled. The denial appears in the kernel log as:

Text
Error       0x0                  0      0    kernel: (Sandbox) System Policy: diskimages-helpe(725) deny(1) file-mount /Library

Vendor communication

  • 2021-11-05: Reported to Apple Product Security.

  • 2021-12-02: Asked for an update on the issue.

  • 2021-12-03: Apple advised they were planning to address the issue.

  • 2022-01-14: Apple advised the issue would be addressed in an upcoming security update.

  • 2022-01-26: macOS 12.2 released, addressing the reported vulnerability.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

What happened, in plain words

Security researchers at Perception Point found a way to get around a key protection in Apple's macOS operating system. That protection is called System Integrity Protection, or SIP. The problem they found is tracked as CVE-2022-22583. To use it, an attacker must already have a high level of control over the machine, meaning they can run their own code with high privileges. If they have that, this flaw lets them bypass SIP and take full control of the system. The researchers reported the issue to Apple, and Apple fixed it on 26 January 2022 in macOS Monterey 12.2, macOS Big Sur 11.6.3 and Security Update 2022-001 Catalina. Apple gave credit for the finding to three people: Mickey Jin (@patch1t), Ron Hass (@ronhass7) of Perception Point, and an anonymous researcher.

This article explains what SIP is, how the bypass works, and how Apple fixed it. It is written for someone who has never studied computer security, so every term is explained as it comes up.

Background: what SIP is and why it matters

SIP, also called "rootless", is a security feature that Apple introduced in OS X El Capitan (version 10.11). Its job is to protect the core of the operating system, even from the root user. The root user is the most powerful account on a Unix-like system; normally it can do anything. SIP says: not quite everything. It puts limits on what even root can do, including:

  • Loading kernel extensions: these are pieces of code that run inside the kernel, the core of the operating system. SIP allows only extensions that are signed (that is, carrying a cryptographic signature from Apple).
  • Tampering with critical files and directories: SIP prevents changes to important parts of the system.
  • Debugging system processes: SIP restricts attaching a debugger to system processes.
  • Programmatically setting the startup disk: SIP prevents software from changing which disk the machine starts from.

These restrictions are enforced by the macOS kernel, whose name is XNU. They can be turned off only by a person with physical access to the machine, by booting into Recovery OS (a special recovery mode). SIP is often described as the last line of defence between an attacker and full control of the system.

To protect the kernel, SIP must stop changes to critical files and directories. One example is the content of the extension "AppleKextExcludeList", which manages a list of excluded kernel extensions. You can see the SIP restrictions by using the "-O" flag with the "ls" command.

But Apple itself still needs to be able to modify all files and directories, for example to install system updates. It does this by giving special permissions, called entitlements, to the programs that need them. An entitlement is a piece of data inside a signed application that tells the system the application is allowed to perform certain tasks. Think of it like a staff badge that opens doors ordinary visitors cannot open. The entitlements relevant to SIP are:

  • com.apple.rootless.install: lifts all of SIP's filesystem restrictions.
  • com.apple.rootless.install.heritable: the same, but child processes (programs started by this program) also inherit the entitlement.

Apple does not sign just any application with these entitlements. But a few Apple-signed programs in the system have one of them. One example is "system_installd", part of the PackageKit framework, which is responsible for installing Apple-signed packages. You can see the entitlements of a program with the "codesign" utility. "system_installd" has the stronger "com.apple.rootless.install.heritable" entitlement, and that is what this vulnerability uses.

The earlier bug this work builds on

The researchers built on a previously published SIP bypass. On 28 October 2021, Microsoft published a blog post about a SIP bypass it had found, fixed in macOS Monterey 12.0.1 and identified as CVE-2021-30892. Microsoft named it "shrootless".

In shrootless, Microsoft researchers noticed that when a user installs an Apple-signed package, the package is automatically executed by "system_installd". If the package contains pre-install or post-install scripts (small programs that run before or after the main installation), those scripts are also executed by "system_installd" and therefore inherit the "com.apple.rootless.install.heritable" entitlement. That effectively allows the scripts to fully bypass SIP's filesystem restrictions. The bug was that if one of those scripts was a zsh script (that is, it starts with "#!/bin/zsh"), "system_installd" would execute zsh, and zsh in turn would read the file "/etc/zshenv". That file is not restricted by SIP and can be modified freely by root, so any code inside it would run in this SIP-bypass context whenever an Apple-signed package with a zsh script is installed. Apple's fix was to prevent zsh from reading "/etc/zshenv" in this scenario.

To look deeper, the researchers needed an Apple-signed package with some pre-install or post-install scripts. The "Suspicious Package" application is useful for inspecting a candidate package. The package they found is Apple-signed and contains a perl post-install script. The script executes several more commands, and the command-line utility "Process Monitor" was used to examine its behaviour. The output below is trimmed for clarity, keeping only "ES_EVENT_TYPE_NOTIFY_EXEC" events (events that report a program being started):

JSON
{"pid":3308,"name":"system_installd"}
{"pid":3321,"name":"perl","arguments":["/usr/bin/perl","/tmp/PKInstallSandbox.QTKhng/Scripts/com.apple.pkg.FxPlugSDK.QCq4LX/postinstall","/private/tmp/FxPlugSDK.pkg","/","/","/"],"ppid":3308}
{"pid":3321,"name":"perl5.30","ppid":3308}
{"pid":3322,"name":"pwd","ppid":3321}
{"pid":3323,"name":"sh","arguments":["sh","-c","logger -p install.info 'Running Install Scripts . . .'"],"ppid":3321}
{"pid":3323,"name":"bash","arguments":["sh","-c","logger -p install.info 'Running Install Scripts . . .'"],"ppid":3321}
{"pid":3323,"name":"logger","ppid":3321}
{"pid":3324,"name":"sh",","arguments":["sh","-c","/bin/ls \/private\/tmp\/PKInstallSandbox\.QTKhng\/Scripts\/com\.apple\.pkg\.FxPlugSDK\.QCq4LX\/postinstall_actions\/"],"ppid":3321}
{"pid":3324,"name":"bash","arguments":["sh","-c","/bin/ls \/private\/tmp\/PKInstallSandbox\.QTKhng\/Scripts\/com\.apple\.pkg\.FxPlugSDK\.QCq4LX\/postinstall_actions\/"],"ppid":3321}
{"pid":3324,"name":"ls","ppid":3321}

Each line is a JSON object describing one process event. "pid" is the process ID (a number the system gives to each running program), "ppid" is the parent process ID (the process that started it), "name" is the program name, and "arguments" are the command-line arguments passed to it. The first line shows "system_installd" starting with pid 3308. The second line shows that pid 3308 started "perl" (pid 3321) with arguments: the perl interpreter path, then a script path under "/tmp/PKInstallSandbox.QTKhng/Scripts/com.apple.pkg.FxPlugSDK.QCq4LX/postinstall", then the package path and some other arguments. The third line shows "perl5.30" (pid 3321) with parent 3308. The fourth line shows "pwd" (pid 3322) started by perl (pid 3321). The fifth and sixth lines show "sh" and then "bash" (both pid 3323) started by perl (pid 3321) running a command that logs "Running Install Scripts . . .". The seventh line shows "logger" (pid 3323) started by perl. The eighth and ninth lines show "sh" and then "bash" (both pid 3324) started by perl running a command that lists a directory under the same temporary path. The tenth line shows "ls" (pid 3324) started by perl. The key observation is that the post-install script is executed from a temporary directory.

Finding the flaw

Something immediately caught the researchers' attention: "system_installd" executed the post-install script from a temporary directory, "/tmp/PKInstallSandbox.QTKhng/Scripts/com.apple.pkg.FxPlugSDK.QCq4LX" in this case. Apparently "system_installd" first extracts the scripts into a temporary directory and then executes them from there. Moreover, there is a significant amount of time between the extraction and the execution; the extraction is probably done before the installation, for both pre-install and post-install scripts.

That raised the question of whether the scripts could simply be swapped without "system_installd" ever noticing. Apple had thought about this loophole and made the temporary directory restricted by SIP. However, the researchers found that the "/tmp" directory itself is not restricted by SIP. To be precise, "/tmp" is actually a symbolic link (a shortcut that points to another location) and is restricted, but the directory it points to is not.

Exploitation: swapping the script

With that information, the researchers identified how to swap the post-install script between the extraction and the execution. The key is mounting: because "/private/tmp" is not restricted by SIP, a virtual image can be mounted onto this directory at any point, even if the image contains a restricted directory inside it, and its content can then be changed however desired. Mounting means attaching a filesystem (here, a virtual disk image) to a directory so that the directory's contents are replaced by the contents of the image. There are several ways to use this idea to swap the script, but because the temporary directory path contains some random characters, the exploit was implemented as follows.

Step 1: Mount a virtual image onto /private/tmp

Create a virtual image file and mount it onto "/private/tmp". This step is taken so that the researchers control what appears under "/private/tmp" during the installation.

Step 2: Install an Apple-signed package with post-install scripts

Install an Apple-signed package that carries post-install scripts, so that "system_installd" performs the extraction and later the execution. This step is taken to trigger the vulnerable behaviour.

Step 3: Wait for extraction and gather the random path

Wait for the installer to finish the extraction of the scripts directory, and gather the random parts of the extracted path. This step is taken because the path contains random characters that the attacker must know in order to recreate it later.

Step 4: Unmount the image

Unmount the image file, thus reverting to the contents of "/private/tmp" before the extraction. This step is taken to remove the extracted scripts and return to a clean state.

Step 5: Recreate the scripts directory with our own scripts

Create the scripts directory by ourselves, using the random path gathered earlier, and deposit there whatever scripts are wanted. This step is taken so that when "system_installd" later executes the script from that path, it runs the attacker's script instead of the original one.

Any script placed as the "post-install script" inherits the "com.apple.rootless.install.heritable" entitlement from "system_installd" and is able to fully bypass SIP restrictions.

Timing is very relevant for this vulnerability: the exploit must succeed in swapping the script within the window of opportunity. Even so, the exploit is quite reliable. It usually takes one or two tries to succeed, mostly because the package used has post-install scripts, which provides plenty of time, the whole installation time.

Root cause

First, "system_installd", which owns the "com.apple.rootless.install.heritable" entitlement, extracts package scripts into a temporary directory and executes them later from that same path. Second, the parent directory of that extraction path, "/private/tmp", is not protected by SIP, so its contents can be replaced by mounting a virtual image over it. SIP protects the extracted scripts directory itself, but not the mount point above it, so the protected directory can be swapped out from under the installer between extraction and execution. The existing defence, SIP protection of the temporary scripts directory, therefore did not stop the attack, because it did not cover the directory onto which the image is mounted.

Impact

An attacker who has already achieved code execution with high privileges can use this to bypass SIP and take full control over the system. SIP is the final defence line between an attacker and full control, so defeating it removes the remaining protection of critical files and directories, kernel extension loading restrictions and the other restrictions listed above. The exploit mounts a virtual image onto "/private/tmp" and must swap the script within the window between extraction and execution.

Fix

In macOS 12.2, Apple changed the extraction destination to a new directory: "/Library/Apple/System/Library/InstallerSandboxes". All the directories in this path are restricted, except the first one ("/Library"). Although that looks similar to the situation before, Apple correctly fixed the bug by also preventing mount attempts onto the "/Library" directory when SIP is enabled. The denial appears in the kernel log as:

Text
Error       0x0                  0      0    kernel: (Sandbox) System Policy: diskimages-helpe(725) deny(1) file-mount /Library

The report shows this denial in the kernel log:

Vendor communication

  • 2021-11-05: Reported to Apple Product Security.

  • 2021-12-02: Asked for an update on the issue.

  • 2021-12-03: Apple advised they were planning to address the issue.

  • 2022-01-14: Apple advised the issue would be addressed in an upcoming security update.

  • 2022-01-26: macOS 12.2 released, addressing the reported vulnerability.

Glossary

  • SIP (System Integrity Protection): a macOS security feature that restricts what even the root user can do, protecting critical system files and settings.
  • root user: the most powerful user account on a Unix-like system, traditionally able to do anything.
  • kernel: the core part of an operating system that controls hardware and enforces security.
  • XNU: the name of the macOS kernel.
  • kernel extension: a piece of code that runs inside the kernel to add functionality, such as a driver.
  • signed: carrying a cryptographic signature that proves who created it and that it has not been altered.
  • entitlement: a piece of data inside a signed application that grants it specific permissions.
  • com.apple.rootless.install: an entitlement that lifts all of SIP's filesystem restrictions.
  • com.apple.rootless.install.heritable: an entitlement like the above, but also inherited by child processes.
  • system_installd: an Apple program, part of the PackageKit framework, that installs Apple-signed packages.
  • PackageKit: a macOS framework responsible for installing packages.
  • package: a bundle used to install software on macOS, which can include scripts.
  • pre-install script: a small program that runs before the main installation.
  • post-install script: a small program that runs after the main installation.
  • zsh: a Unix shell (command interpreter).
  • shell: a program that reads and executes commands.
  • /etc/zshenv: a configuration file read by zsh at startup.
  • perl: a programming language and its interpreter.
  • Process Monitor: a command-line utility used to observe process events.
  • ES_EVENT_TYPE_NOTIFY_EXEC: an event type that reports a program being started.
  • pid: process ID, a number the system assigns to a running program.
  • ppid: parent process ID, the process ID of the program that started this one.
  • symbolic link: a shortcut that points to another file or directory.
  • mount: to attach a filesystem (such as a disk image) to a directory so its contents appear there.
  • virtual image: a file that contains a filesystem, which can be mounted.
  • CVE: Common Vulnerabilities and Exposures, a standard identifier for a publicly known security flaw.
  • Recovery OS: a special boot mode on macOS used for recovery tasks.
  • codesign: a macOS utility for inspecting code signatures and entitlements.
  • ls: a Unix command that lists directory contents.
  • Suspicious Package: an application for inspecting macOS packages.
  • rootless: another name for SIP.

More from Apple

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.