⬆️ Take Graft 0.4.0, whose SDK declares set_block

Graft 0.4.0 (74c1829cd768) declares set_block in its IOMobileFramebufferLegacy
stand-in, so a synthesized display can override the block calls its user
client passes on, such as the ICC curves and matrices WindowServer sets for a
colour profile; the live class answers them unsupported. On arm64e a client
can also route a MAC policy's policy_syscall. x86-64 is unchanged, no route or
override changes, Graft.h and the manifest format are unchanged, and
OSBundleCompatibleVersion stays 0.1.0. The same kexts, staged at 74c1829,
passed the arm64 ICC proof boots of 14.6.1, 15.6.1, 26.6.2, 27.0.1 and 27.2.1
(m3-max-36510, 36511, 36512, 36514 and 36515).

Copied by Graft's tools/vendor.py from graft-0.4.0.zip, SHA-256
1f08d9459eb16ddaa5a83e7600f1b1d33e2e1f88da603708a20410b79029d3a6, the zip of
the release at tag v0.4.0. The prebuilt sets carry 0.3.1 until they are
rebuilt.
This commit is contained in:
Anees Iqbal committed 2026-11-16 09:13:17 -08:00
1 parent 7e74041aa3
commit 2290b47ede
20 files changed
+206 -87

No files matched your search

+33
View File
@@ -5,6 +5,39 @@ Each release of Graft, newest first. A version is the kext's
that lists `ai.aneesiqbal.graft` 0.1.0 in its `OSBundleLibraries` loads with
each later release that keeps it.
## 0.4.0
**Upgrading**
- No consumer or client needs a rebuild, and no existing route or override
changes. Graft still declares `OSBundleCompatibleVersion` 0.1.0, and `Graft.h`
and the manifest format are unchanged. To route `policy_syscall`, a client
names it in a route symbol, such as `Sandbox:policy_syscall`; to override
`set_block`, a synthesized display declares it against this release's SDK.
- The arm64 boot firmware hands over nothing new.
**The kext**
- On arm64e, a client can route a MAC policy's `policy_syscall` beside the three
admission operations. It is the policy's `mac_syscall(2)` entry, so a client
can answer or observe the queries a policy serves through it, such as a
rootless-trust query, and pass every other call to the policy. Unlike the
admission hooks, whose arguments are kernel objects, its argument is a
user-space address, so a replacement copies the argument in and the answer out
from the calling task. Graft routes it by the same ABI rule as the other
operations, deriving its slot and discriminator from `mpo_policy_syscall_t` in
the public `security/mac_policy.h`. x86-64 is unchanged.
**The SDK**
- The `IOMobileFramebufferLegacy` stand-in declares `set_block`, so a
synthesized display can override it. A display's user client passes it the
block calls its clients make, such as the ICC curves and colour matrices
WindowServer sets for a colour profile, Night Shift and True Tone. The live
class's own `set_block` answers them unsupported. Its symbol is the same on
macOS 13.6 to 27.2.1, and Graft places the override on its live slot as it
does each other method's.
## 0.3.1
**Upgrading**
@@ -5,8 +5,8 @@
<key>CFBundleIdentifier</key><string>ai.aneesiqbal.graft</string>
<key>CFBundleName</key><string>Graft</string>
<key>CFBundlePackageType</key><string>KEXT</string>
<key>CFBundleVersion</key><string>0.3.1</string>
<key>CFBundleShortVersionString</key><string>0.3.1</string>
<key>CFBundleVersion</key><string>0.4.0</string>
<key>CFBundleShortVersionString</key><string>0.4.0</string>
<key>OSBundleCompatibleVersion</key><string>0.1.0</string>
<key>OSBundleRequired</key><string>Root</string>
<key>IOKitPersonalities</key><dict>
Binary file not shown.
+2 -2
View File
@@ -5,8 +5,8 @@
<key>CFBundleIdentifier</key><string>ai.aneesiqbal.graft</string>
<key>CFBundleName</key><string>Graft</string>
<key>CFBundlePackageType</key><string>KEXT</string>
<key>CFBundleVersion</key><string>0.3.1</string>
<key>CFBundleShortVersionString</key><string>0.3.1</string>
<key>CFBundleVersion</key><string>0.4.0</string>
<key>CFBundleShortVersionString</key><string>0.4.0</string>
<key>OSBundleCompatibleVersion</key><string>0.1.0</string>
<key>OSBundleRequired</key><string>Root</string>
<key>IOKitPersonalities</key><dict>
Binary file not shown.
+1 -1
View File
@@ -28,7 +28,7 @@
# Build intermediates stay in build/, and releases in dist/.
BUILD ?= build
VERSION = 0.3.1
VERSION = 0.4.0
HOSTCXX = xcrun --sdk macosx clang++ -std=c++17 -Wall -Wextra -Werror
HOSTCC = xcrun --sdk macosx clang -Wall -Wextra -Werror
SDK = $(shell xcrun --sdk macosx --show-sdk-path)
+18 -6
View File
@@ -42,11 +42,22 @@ own.
## Status
This is release 0.3.1. It passes the host tests and the build checks
([CONTRIBUTING.md](CONTRIBUTING.md#checks)). On x86-64 it binds a consumer whose
call cannot reach its import with the call's 32-bit displacement, by writing the
call to a branch island ([docs/design.md](docs/design.md#branch-islands)). A
call in reach is written as before, and arm64e is unchanged.
This is release 0.4.0. It passes the host tests and the build checks
([CONTRIBUTING.md](CONTRIBUTING.md#checks)). On arm64e a client can now route a
MAC policy's `policy_syscall`, the policy's `mac_syscall(2)` entry, beside the
three admission operations it could already route; a client can answer or
observe the queries a policy serves through that syscall and pass every other
call to the policy. The SDK's `IOMobileFramebufferLegacy` stand-in also declares
`set_block`, so a synthesized arm64 display can override the framebuffer call
that carries a display's ICC curves and colour matrices — the colour profile,
Night Shift and True Tone — which the live class otherwise refuses. The arm64e
kext gains the one operation; the x86-64 kext is byte for byte release 0.3.1's
but for the version it carries.
Release 0.3.1 binds, on x86-64, a consumer whose call cannot reach its import
with the call's 32-bit displacement, by writing the call to a branch island
([docs/design.md](docs/design.md#branch-islands)). A call in reach is written as
before, and arm64e is unchanged.
reims-vgpu, a paravirtual GPU for macOS virtual machines, verified the branch
islands in its guests, with SIP on and no boot-arg. In Apple's macOS 15.4 and
@@ -67,7 +78,8 @@ profile otherwise refuses to map executable then loaded, so Safari's WebGL ran
where it had been dead, and a control mapping the profile denies stayed denied.
Release 0.2.0's kexts, which later releases leave unchanged but for 0.3.0's route
layer, 0.3.1's branch islands and the version they carry, passed the boots
layer, 0.3.1's branch islands, 0.4.0's arm64e `policy_syscall` operation and the
version they carry, passed the boots
below, with SIP on (`csr-active-config`
0) and no boot-arg for Graft or the kexts it serves. Several used the guest
kexts of reims-vgpu: its display and Metal driver is a bound consumer, and the
+1 -1
View File
@@ -38,7 +38,7 @@ An owned client is an ordinary kext with four additions:
2. The SDK's start glue, `sdk/Start.cpp`, which declares the kmod and calls
the client's `graft_client_initialize()` from its start routine.
3. A dependency on Graft: `ai.aneesiqbal.graft` at version `0.1.0` in
`OSBundleLibraries`. Release 0.3.1 declares `OSBundleCompatibleVersion`
`OSBundleLibraries`. Release 0.4.0 declares `OSBundleCompatibleVersion`
`0.1.0`, so a client that lists `0.1.0` loads with it.
4. An `IOService` subclass and one personality that matches `IOResources`,
because an injected kext is not started for `OSBundleRequired` Root alone.
+7 -3
View File
@@ -167,9 +167,13 @@ the core probe ([tests/kexts/](../tests/kexts/README.md)).
read-only by the time Graft starts. Graft routes by shadowing the policy
instead of patching code. Each route names a MAC policy operation, such as
`vnode_check_signature`, and the replacement and original have that
operation's `mpo_*_t` prototype from XNU's `security/mac_policy.h`. Three
operations are routable: `file_check_mmap`, `file_check_library_validation`
and `vnode_check_signature`. The operation is AMFI's by default; to route
operation's `mpo_*_t` prototype from XNU's `security/mac_policy.h`. Four
operations are routable: the admission hooks `file_check_mmap`,
`file_check_library_validation` and `vnode_check_signature`, and
`policy_syscall`, the policy's `mac_syscall(2)` entry. The first three are
called with kernel objects; `policy_syscall`'s argument is a user-space
address, so a client that routes it copies the argument in and the answer out
from the calling task itself. The operation is AMFI's by default; to route
another policy's operation, the symbol carries a `<policy>:` prefix, as in
`Sandbox:file_check_mmap`. Every route in one call names the same policy,
since the install swaps that policy's one list element. To install the
@@ -224,7 +224,7 @@ arm64e route refusals, in the order Graft checks:
| `mac_policy_register is not resolvable`, `mac_policy_list is not resolvable`, `mac_policy_list is not in the kernel's data segments`, `mac_policy_list entries pointer is invalid` | Graft could not find the kernel's list of MAC policies. The list must lie in a segment the kernel maps writable, and its entries pointer must be a canonical, 8-byte aligned kernel address |
| `<policy> policy not found in the list`, `<policy> policy ambiguous in the list (N matches)` | Graft could not find the policy's one registered element: AMFI by its admission ops, any other by its `mpc_name` within its image |
| `<name>: route input` | Graft could not build its copy of the current ops table |
| `<name>: operation not routable on arm64` | the request names an operation other than `file_check_mmap`, `file_check_library_validation` or `vnode_check_signature` |
| `<name>: operation not routable on arm64` | the request names an operation other than `file_check_mmap`, `file_check_library_validation`, `vnode_check_signature` or `policy_syscall` |
| `<name>: staged copy too small for the structure` | the operation's slot lies past the end of Graft's copy of the policy's ops table |
| `<name>: operation routed twice in one request` | two requests name the same operation |
| `<name>: live ops slot does not point into the policy's text` | the slot Graft would replace in the policy's table does not hold a pointer into the policy's code, so Graft does not trust the table |
+17 -7
View File
@@ -131,11 +131,12 @@ kernel functions this way.
Kernel text and a MAC policy's table are read-only when Graft starts, so
Graft routes by shadowing the policy. A route names a MAC policy operation,
one of `file_check_mmap`, `file_check_library_validation` and
`vnode_check_signature`. The replacement and original have the operation's
`mpo_*_t` prototype from XNU's `security/mac_policy.h`, and the original is
the policy's handler for the operation. The operation is AMFI's by default.
The macOS SDK does not ship that header, so declare the prototype yourself:
one of `file_check_mmap`, `file_check_library_validation`,
`vnode_check_signature` and `policy_syscall`. The replacement and original have
the operation's `mpo_*_t` prototype from XNU's `security/mac_policy.h`, and the
original is the policy's handler for the operation. The operation is AMFI's by
default. The macOS SDK does not ship that header, so declare the prototype
yourself:
```cpp
#include <sys/kauth.h>
@@ -191,15 +192,24 @@ A client that routes the same operation on two policies, as here, holds a
separate original for each. Every route in one `graft_route_kernel` call names
one policy; route a second policy in a second call.
`policy_syscall` is the policy's `mac_syscall(2)` entry, not an admission hook:
its `mpo_policy_syscall_t` prototype is `int(struct proc *p, int call,
user_addr_t arg)`, and `arg` is a user-space address, not a kernel object. A
client that routes it reads the argument and writes the answer with
`copyin`/`copyout` against the calling task, decides only the calls it owns, and
passes every other `call` on to the original. A route that only inspects kernel
objects, such as `file_check_mmap` above, needs none of this.
[tests/kexts/route-probe](../../tests/kexts/README.md#route-probe) routes all
three AMFI operations, and the Sandbox policy's `file_check_mmap`.
three AMFI operations, and the Sandbox policy's `file_check_mmap` and
`policy_syscall`.
## Limits
- One call installs at most sixteen routes, all of them or none, and names one
policy. On x86-64 Graft has room for 32 routes per boot, shared first come
first served: two of its own, and up to 30 more across every client. On arm64e
each client routes at most one of each of the three operations per policy, and
each client routes at most one of each of the four operations per policy, and
several clients route one after another; an operation on a policy that one
client holds is refused to the next.
- On x86-64, routes must be installed before BSD starts, so install them from
+1 -1
View File
@@ -73,7 +73,7 @@ to catch a copy that drifted from its record.
## 3. Depend on the right version
Graft's bundle identifier is `ai.aneesiqbal.graft`, and release 0.3.1 declares
Graft's bundle identifier is `ai.aneesiqbal.graft`, and release 0.4.0 declares
`OSBundleCompatibleVersion` `0.1.0`. An owned client lists
`ai.aneesiqbal.graft` at `0.1.0` in its `OSBundleLibraries`, and then loads
with this release and with any later one that keeps that compatible version. A
+7
View File
@@ -29,6 +29,13 @@
// not all name one policy. The separator never appears in an x86-64 kernel symbol,
// so x86-64 is unaffected.
//
// Most arm64e operations are admission hooks the MAC framework calls with kernel
// objects. "policy_syscall" is the exception: it is the policy's mac_syscall(2)
// entry (mpo_policy_syscall_t, int(struct proc *, int call, user_addr_t arg)),
// and `arg` is a user-space address. A replacement for it copies the argument in
// and the answer out against the calling task, and passes every call it does not
// handle to the original.
//
// Graft writes the original as a void *. Keep it in a void * and convert it to
// the prototype where you call it, on both architectures. Do not point
// `original` at a typed function-pointer variable: an arm64e kext built with
@@ -149,6 +149,9 @@ public:
uint32_t field_2);
virtual graft_iomfb_word set_parameter(IOMFBParameterName name, const uint64_t *values,
uint32_t count);
virtual graft_iomfb_word set_block(task *owner, uint32_t type, uint32_t offset,
const uint64_t *scalars, uint32_t count, const uint8_t *data,
size_t size);
virtual graft_iomfb_word do_power_state_change_gated();
// A non-virtual method a consumer may call. Graft resolves its symbol in the
+22 -22
View File
@@ -1,7 +1,7 @@
# Graft 0.3.1, copied from its release zip by Graft's tools/vendor.py.
# Graft 0.4.0, copied from its release zip by Graft's tools/vendor.py.
# Replace the directory and this record together; do not edit either.
version = "0.3.1"
commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
version = "0.4.0"
commit = "74c1829cd768951912d29e67ed860ed564ea8d6c"
[files]
".clang-format" = "2d5ad08d63f40c9aa1e456bafd2490906b65a8b792ed84fea192ec4c158e23f0"
@@ -10,27 +10,27 @@ commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
".gitignore" = "6d8daa439263c4a75977bd7d09b855453dc49d8465894a2b9a435ac92e4e0af7"
".xcode-version" = "af91d88fb361d2ae36f27a5aa1845545751eb55d1569d9818440f386ff9d57d5"
"AGENTS.md" = "6b32e50201674616a5db0b8c70a21353967fce91e501e1c9a93218eb8499f13b"
"CHANGELOG.md" = "481a56e4b98f8f0dfc516fc038ac1d4d1bcc491e83be1c392c67d62d92bdbdc2"
"CHANGELOG.md" = "49fdb89945d0e4da76ffbb647a9b0b3b3ec86bebdca446010b89ce77a9ac3554"
"CONTRIBUTING.md" = "6e613c846e8c6bc803b9fd9444bdbb6168b6a6e89605e3bc050c032498e5665a"
"Graft-arm64e.kext/Contents/Info.plist" = "a61d9e9844847db66f099b6a1e9d7d7463323a175bf2c9adf33d36908a7d3d42"
"Graft-arm64e.kext/Contents/MacOS/Graft" = "f9861542db328c75790bbbc5e09a9793042f59165d3a663fbe18b8aefcf69ae4"
"Graft.kext/Contents/Info.plist" = "a61d9e9844847db66f099b6a1e9d7d7463323a175bf2c9adf33d36908a7d3d42"
"Graft.kext/Contents/MacOS/Graft" = "1f5c4d79ad933272e904168ada4d66d5b4d651c193c5fe4c17b4c7a4665a342a"
"Graft-arm64e.kext/Contents/Info.plist" = "fa8533d5ec06430f3ede502e6f9e739e9c8c3f6b6909c46d854effe6028cbc7f"
"Graft-arm64e.kext/Contents/MacOS/Graft" = "2f405e84ddd1414b6ac32e813a4369a6d4681d9c6e7331b933bb719761b1a31a"
"Graft.kext/Contents/Info.plist" = "fa8533d5ec06430f3ede502e6f9e739e9c8c3f6b6909c46d854effe6028cbc7f"
"Graft.kext/Contents/MacOS/Graft" = "04a1d44c0c80c20a71f3a662c46b56a1732b8134f095fb2ac57ec790f72baf72"
"LICENSE" = "aa03754de05115e6218873f65ec1a6a4c95c550742dafca7ce8d4c4b627e50e3"
"LICENSES/GPL-2.0-or-later.txt" = "8177f97513213526df2cf6184d8ff986c675afb514d4e68a404010521b880643"
"LICENSES/GPL-3.0-or-later.txt" = "3972dc9744f6499f0f9b2dbf76696f2ae7ad8af9b23dde66d6af86c9dfb36986"
"LICENSES/LGPL-3.0-or-later.txt" = "e3a994d82e644b03a792a930f574002658412f62407f5fee083f2555c5f23118"
"Makefile" = "039d0121e8d58c280c0198bb2247dcef2042c2b0a3332b66549e0b20d3a156e8"
"README.md" = "806b3ede285768af01e60e0180d8419b14049b449530fcabc302c348e33070c3"
"Makefile" = "e5a508ca60b8086cad802f77acca66925a7808fb2b2f6000524145be5d495aaa"
"README.md" = "700b96062330a86fd7c770c670708067f65a95ba46a70219eacfbcf0ec7cedcb"
"docs/README.md" = "4865ac4d884939e8fb37a706351dc14e08cc5b9e7c52818a3fe32174f7e75c67"
"docs/consumers.md" = "93131ba583ed7e499acfdc1f05308f640f8713687684ce3a578777385c91740e"
"docs/design.md" = "a15ec1136a92d0fd727d294aa114dbc274b87f2addbd726a6167ec6b19c2ec15"
"docs/consumers.md" = "090b8ca7316aef884d40c739f1fbf061f582c328112e574fe2cd82df13b45ca2"
"docs/design.md" = "244b9a6dd12e4fa16e7dacd12af158b92386d961b7c30d2e0329f682aff82432"
"docs/guides/bound-consumer.md" = "91bdfae03bca4687af11322413ec80023a70f59a9566864ca69ad1abd2c5f098"
"docs/guides/debugging-refusals.md" = "4e04feed62af2681603818e18ad64a07d78abd4d7c9d194dfbcf55b32f94b670"
"docs/guides/owned-client.md" = "cca6ee031a677664d12c7a5d2d52a552873fece758496c8d7422bcb10a420818"
"docs/guides/debugging-refusals.md" = "4af7e5177503edacdd5cd22bebc572e530c400e613b3bd584a034e18656bf51a"
"docs/guides/owned-client.md" = "5ecbfa2e19905edc2b0f072ab43ddb8d266207ca7c8d9e66a291654640e5a403"
"docs/guides/releasing.md" = "9fa13fdbe230195d2aecf06a39ecf67013af04b13028cc029ccb19d2b6d53e4c"
"docs/guides/synthesized-class.md" = "e80f6a6b92530ecb955200b1ad494d679000cbd6cb55444e43d23d5d64143a02"
"docs/guides/taking-a-release.md" = "0086ca85a777e6b07881510ed18435ca22f8047f7269edd291dbe76038a7be13"
"docs/guides/taking-a-release.md" = "b5b42467577fa08c9738b66f5135dc526ae5ce64eb89a521093180899b8a9cd2"
"docs/lessons-learned.md" = "3a15e41ad40102cce665c90dfd85ac238dd8a36e1531ba75c9dd6ca5f18aa9e3"
"docs/manifest.md" = "52f8c8f344bb1df2f992680b6e47417ec1d284f62f8a39f7745bf8be5139e7d5"
"examples/README.md" = "9c6161c5e65c3668fdb28ccf3133c4c8c9a43b4adf7e74071cbf5fe6233273b0"
@@ -48,8 +48,8 @@ commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
"sdk/README.md" = "e648c3b7864495c04df4c2800ab3b4c22bd86cb8d99843b047e41c5d5161cfca"
"sdk/Start.cpp" = "d442ab1f6403ec72b952f595463e7fc479362414c39dad5effec71332ccb9055"
"sdk/consumer.mk" = "f0ca2a3c17b8d8d86eb3b3a474c3c6f5b6b8ea90a6d9ccd5aeaffd28f68c6fae"
"sdk/include/graft/Graft.h" = "87379db9434186e1f470e54e3c10423343eccc2c7989628a694cd7396760b073"
"sdk/include/graft/IOMobileFramebufferLegacy.h" = "18f017079712c507899afd832e0a73d35be0faa44cf971a620c1fe2456102acd"
"sdk/include/graft/Graft.h" = "acd72e8dc94e410f64a5eac96f18ce174a05cf446fc4094ede02eb53f966530f"
"sdk/include/graft/IOMobileFramebufferLegacy.h" = "6e3d0dd26a5b903c1c117b95c29a45b858a3659c2d5dbef3a6c4e9c1fe56b2ab"
"sdk/include/graft/ManifestFormat.h" = "934def6e2cd33cd4d6879df66143ebff2447035b6ace2394839637c4637528ab"
"sdk/tool/base.cpp" = "899c4876fb1e480f27c86d8184869811a6b0bdd6f41a1ebb0ef4093565978208"
"sdk/tool/base.h" = "ac14b11a425a39d9bb56a1f12349a1044e4e8afdb5958208d6616e799b825562"
@@ -93,7 +93,7 @@ commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
"src/Start.cpp" = "defc0268cb42c965ed3131801b082d3548ddbfe7fa9bcd212fbf9b20d0c1dd58"
"src/Vtable.h" = "fe96ecc9022228911529123da5edd1e8bd283691c9450f22ddc12a5b1a6bca48"
"src/WritePlan.h" = "e2f16d134b0c0aeea350cafb5bc61a61905a55eb137578183f7a4c4625758a91"
"src/arm64e/Arm64Route.h" = "6a3e2fcf0a2a0194871bd11abfbef73ccada943c96dcafa6d6472327524dbb5e"
"src/arm64e/Arm64Route.h" = "2b5efc18f2a0652cc907e6aa42694a75a37fc5d8757c2b45bbc2d3098672e78c"
"src/arm64e/BindingPlacement.cpp" = "be26195dbf508de82ea6a5c864719f2ca8bcf51245463a21d8ed46df42471c50"
"src/arm64e/Fixup.h" = "25d2309167b4620d785ce7f0b3f2d4d1a7b3889692fa60ef662fc138f2afa3a2"
"src/arm64e/Island.cpp" = "b6e94ca997d09eab754df53ea669cd906a21e05123a897d8690fb65a282c4086"
@@ -115,7 +115,7 @@ commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
"tests/README.md" = "1f1e26e7d3cb57f3c7bf1c3432d8da9a9e1522ac99424871de16706758bf470b"
"tests/ToolTest.h" = "37e17f58d62b2646349df216c4eba9f4f70a98d87a8d1ae807fd2ac470e7bde2"
"tests/arm64e_fixup_test.cpp" = "171aeafc062ff98f28285319ec310814decd4cd2d6cf9e7c2a788eb644acd785"
"tests/arm64e_route_test.cpp" = "3052a00abbaea4d0d84354014ade4a79cd61429e7580dc8e92ce68f9fbfeae74"
"tests/arm64e_route_test.cpp" = "21df8f57530c140ce0b9b725a1750d54ce8f0c2ba1a9483587a516c2c92bd4c6"
"tests/arm64e_synthesize_test.cpp" = "0d43a864371b8067ec147434f3bc987ab8fcf66b790eea50368036155c3f6258"
"tests/arm64e_synthesize_vtable_test.cpp" = "b7760c2ffc20725a8f5efb4b0610c71f688a66abd34a1c9a19a71179b22fce5a"
"tests/arm64e_vtable_disc_test.cpp" = "7a648a2631b3463a80a774f67f5c2b06b5971940f61cd29c1dc379007430e1de"
@@ -129,7 +129,7 @@ commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
"tests/graft_kext_test.py" = "733438b8d5b8ad63348d56bf68a574f0090cbbe32ca68d96d568d859afffacce"
"tests/hook_symbols_test.py" = "4b99cbefd7c356f2140efc6ab8369be13f98efe36ef0b3df8d0780409b9b71d5"
"tests/kernel_fixture.cpp" = "d7ef5a9fade315a064c87a334473c798b6301479608a8524eb98074992f5c353"
"tests/kexts/README.md" = "2d95f5422ba40488969524162c4b593188516012877c8d9bd7dfaa44fa48ce95"
"tests/kexts/README.md" = "8861a5ef40f5e24deb8191b19ca727f5456b2fef9fd346694be1845edd54877d"
"tests/kexts/core-probe/CoreProbe.cpp" = "8d617d12fe1b45e2f550c51dac9a57a2776e958159ea6609b53e07635d77a0b5"
"tests/kexts/core-probe/Info.plist" = "6f1596de6b7faa0fed787455e8ed033e4b62ff1634688682140677243ecddf12"
"tests/kexts/gate-probe/Makefile" = "2cd2e54456ad4fb86d1fc54f13c4b061770a78ff7175e55632d282f5de7d68eb"
@@ -139,14 +139,14 @@ commit = "ea0616e971b7c3225a3f37edebb9f0e46de3e62e"
"tests/kexts/gate-probe/src/graft-refuse.json" = "7c6e5bc716c06b8035473f954898a48f1942c9ab530384e216df19a138892528"
"tests/kexts/gate-probe/src/graft.json" = "dd82d1b7dfb52204bfc22bc233b21eb6286dad942cfcbe735f406be1667b8189"
"tests/kexts/route-probe/Info.plist" = "32b57726b56f7a7be17ad04274b1983e1ce7e4387860b0aeb00fd2a7c58b40c3"
"tests/kexts/route-probe/RouteProbe.cpp" = "5bca35af3d604ae80f7256a4d6cfd14fba2badd9c2fd5ed893dd9c196832d493"
"tests/kexts/route-probe/RouteProbe.cpp" = "f8e5623a0547221a5849b2e86c54da74fbddfb1cc3777e645c492306686b61af"
"tests/lint_test.py" = "5272afe7ea6b49137d7ac66f6a608fa34d775521a14870f798bf74573b4a8086"
"tests/macho_test.cpp" = "fe4c4d9412013a740a72ddd7986b93d7fb6aa9149e7938340b88c4b9d66e4bb9"
"tests/manifest_test.cpp" = "110abc372a4743ee3a9e276348833b00eeb4fd96691d2612942c3ed2b1091682"
"tests/prelink_test.cpp" = "b639e8599fe259b54a0e8bff96f45d4f3b69359ef623bdc3d1b400c49d6ecacb"
"tests/release_fixture.py" = "3aec3474b8e45d2f9f59760c9706c839977129f23740dafb352277ac798a25f7"
"tests/release_test.py" = "ceaad413f2a3de662004d8a13b3c657b4c41f901664f106645672445a9cea03b"
"tests/sdk_standin_test.py" = "d458fa0f34fbf27259aaf8d98a9582d84ec9325818e33e7588a940a2ff3649df"
"tests/sdk_standin_test.py" = "2099560cd22e8632af3c631c2de604bd9716c6b752d0d90a7f36534e90bd11aa"
"tests/staging_test.cpp" = "c2da2d045cdab62a593d33126b76f3eb6318a72e48db66cfb65bdd4820616126"
"tests/synth_emit_test.cpp" = "ae59a938b9220de319cfda8c3fe2a33ea46ef7ff61434352d54ab1d91fc33fb0"
"tests/synthesized/Info.plist" = "982f8e5cac86dc5b3104f818683dce3c48321d484073d56dd98b571b750cedc5"
+16 -3
View File
@@ -26,7 +26,7 @@
namespace graft {
namespace arm64 {
// The three mac_policy_ops entries an owned client may route on arm64, named by
// The mac_policy_ops entries an owned client may route on arm64, named by
// operation (not by a policy's local, unstable op symbols). The arm64e ABI signs
// each ops slot with key IA, the slot type's function-pointer discriminator and
// no address diversity -- AMFI's table and any other policy's alike; the
@@ -37,18 +37,29 @@ namespace arm64 {
// against the live slot's signature before routing. The prototypes are written
// with pointer parameters standing in for the kernel struct types, since the
// function-pointer type discriminator ignores pointee types; they are the
// prototypes of mpo_file_check_mmap_t, mpo_file_check_library_validation_t and
// mpo_vnode_check_signature_t in XNU's public security/mac_policy.h.
// prototypes of mpo_file_check_mmap_t, mpo_file_check_library_validation_t,
// mpo_vnode_check_signature_t and mpo_policy_syscall_t in XNU's public
// security/mac_policy.h.
//
// The first three are admission hooks the MAC framework calls with kernel
// objects. policy_syscall is different in kind: it is the policy's mac_syscall(2)
// entry (reached by policy name), and its `arg` is a user-space address, not a
// kernel object. A client that routes it copies the argument in and the answer
// out itself, from the calling task, and chains every call it does not handle to
// the original. Graft routes it the same way regardless, by the one ABI rule
// above; what the call carries is the client's to interpret.
using FileCheckMmapFn = int(void *, void *, void *, int, int, uint64_t, int *);
using FileCheckLibraryValidationFn = int(void *, void *, long long, long long, unsigned long);
using VnodeCheckSignatureFn = int(void *, void *, int, void *, unsigned *, unsigned *, int,
unsigned, char **, unsigned long *);
using PolicySyscallFn = int(void *, int, uint64_t);
// Field indices in struct mac_policy_ops (security/mac_policy.h). Every field is
// a pointer, so a field's byte offset in the table is its index times 8.
inline constexpr uint32_t FileCheckMmapIndex = 36;
inline constexpr uint32_t FileCheckLibraryValidationIndex = 64;
inline constexpr uint32_t VnodeCheckSignatureIndex = 304;
inline constexpr uint32_t PolicySyscallIndex = 117;
struct Operation {
const char *name;
@@ -64,6 +75,8 @@ inline constexpr Operation Operations[] = {
__builtin_ptrauth_type_discriminator(FileCheckLibraryValidationFn)},
{"vnode_check_signature", VnodeCheckSignatureIndex * 8, 0,
__builtin_ptrauth_type_discriminator(VnodeCheckSignatureFn)},
{"policy_syscall", PolicySyscallIndex * 8, 0,
__builtin_ptrauth_type_discriminator(PolicySyscallFn)},
};
inline constexpr size_t OperationCount = sizeof(Operations) / sizeof(Operations[0]);
+21 -12
View File
@@ -48,25 +48,30 @@ void stage(uint8_t *ops, const uint64_t *originals) {
}
void shadowBuilt() {
uint64_t originals[arm64::OperationCount] = {TextLo + 0x1000, TextLo + 0x2000, TextLo + 0x3000};
uint64_t originals[arm64::OperationCount] = {TextLo + 0x1000, TextLo + 0x2000, TextLo + 0x3000,
TextLo + 0x4000};
uint8_t ops[arm64::OpsSize];
stage(ops, originals);
// Route all three, in an order different from the table's, to a set of
// replacement targets (raw addresses, as a client's stripped pointers).
// Route every routable operation, in an order different from the table's, to a
// set of replacement targets (raw addresses, as a client's stripped pointers).
const char *names[] = {"vnode_check_signature", "file_check_mmap",
"file_check_library_validation"};
uint64_t targets[] = {0xFFFFFE0008000000ULL, 0xFFFFFE0008001000ULL, 0xFFFFFE0008002000ULL};
arm64::Slot slots[3]{};
"file_check_library_validation", "policy_syscall"};
uint64_t targets[] = {0xFFFFFE0008000000ULL, 0xFFFFFE0008001000ULL, 0xFFFFFE0008002000ULL,
0xFFFFFE0008003000ULL};
static_assert(sizeof(names) / sizeof(names[0]) == arm64::OperationCount,
"route every operation");
arm64::Slot slots[arm64::OperationCount]{};
// A sentinel slot that no operation names, to confirm it is left untouched.
uint64_t before8;
memcpy(&before8, ops + 0x8, sizeof(before8));
auto f = arm64::buildShadowOps(ops, sizeof(ops), names, targets, 3, TextLo, TextHi, slots);
auto f = arm64::buildShadowOps(ops, sizeof(ops), names, targets, arm64::OperationCount, TextLo,
TextHi, slots);
CHECK(f.error == Error::None);
for (size_t i = 0; i < 3; ++i) {
for (size_t i = 0; i < arm64::OperationCount; ++i) {
const arm64::Operation *op = arm64::operationFor(names[i]);
CHECK(op != nullptr);
CHECK(slots[i].offset == op->offset);
@@ -86,7 +91,7 @@ void shadowBuilt() {
// The discriminator is actually used: signing the same target under a
// different operation's discriminator yields a different slot value. (We
// never authenticate with a wrong discriminator -- that traps under FPAC.)
uint64_t other = arm64::Operations[(i + 1) % 3].discriminator;
uint64_t other = arm64::Operations[(i + 1) % arm64::OperationCount].discriminator;
CHECK(value != refSignIA(targets[i], other));
}
@@ -97,7 +102,8 @@ void shadowBuilt() {
}
void guards() {
uint64_t originals[arm64::OperationCount] = {TextLo + 0x1000, TextLo + 0x2000, TextLo + 0x3000};
uint64_t originals[arm64::OperationCount] = {TextLo + 0x1000, TextLo + 0x2000, TextLo + 0x3000,
TextLo + 0x4000};
uint8_t ops[arm64::OpsSize];
arm64::Slot slots[3]{};
uint64_t targets[] = {0xFFFFFE0008000000ULL, 0xFFFFFE0008001000ULL, 0xFFFFFE0008002000ULL};
@@ -113,7 +119,7 @@ void guards() {
// offset is wrong or the table was mis-read, so refuse rather than mis-swap.
{
uint64_t strayed[arm64::OperationCount] = {TextLo + 0x1000, TextHi + 0x4000,
TextLo + 0x3000};
TextLo + 0x3000, TextLo + 0x5000};
stage(ops, strayed);
const char *names[] = {"file_check_mmap", "file_check_library_validation"};
auto f = arm64::buildShadowOps(ops, sizeof(ops), names, targets, 2, TextLo, TextHi, slots);
@@ -165,7 +171,8 @@ void chainedShadows() {
// The live chaining -- the swap from the current conf, the routed-operation
// bookkeeping -- is in src/arm64e/Route.cpp and proven by booting the route
// probe; here the ops-carrying property and the re-route guard are checked.
uint64_t originals[arm64::OperationCount] = {TextLo + 0x1000, TextLo + 0x2000, TextLo + 0x3000};
uint64_t originals[arm64::OperationCount] = {TextLo + 0x1000, TextLo + 0x2000, TextLo + 0x3000,
TextLo + 0x4000};
uint8_t ops[arm64::OpsSize];
stage(ops, originals);
@@ -381,9 +388,11 @@ void constants() {
CHECK(arm64::operationFor("file_check_mmap")->discriminator == 0x438d);
CHECK(arm64::operationFor("file_check_library_validation")->discriminator == 0x9e37);
CHECK(arm64::operationFor("vnode_check_signature")->discriminator == 0xcbd2);
CHECK(arm64::operationFor("policy_syscall")->discriminator == 0xfee3);
CHECK(arm64::operationFor("file_check_mmap")->offset == 0x120);
CHECK(arm64::operationFor("file_check_library_validation")->offset == 0x200);
CHECK(arm64::operationFor("vnode_check_signature")->offset == 0x980);
CHECK(arm64::operationFor("policy_syscall")->offset == 0x3a8);
CHECK(arm64::OpsSize == 0xa78);
CHECK(arm64::ConfSize == 0x50);
CHECK(arm64::ConfNameOffset == 0x0);
+6 -4
View File
@@ -35,10 +35,12 @@ wrappers that count the call and tail-branch the authenticated original. It
verifies that Graft resolves AMFI, builds the shadow policy and repoints the list
entry, and that the shadow sits in the live dispatch path, so every routed
operation is entered. A wrong original faults under pointer authentication, so
the branch also checks the handed-back pointer. It then routes the Sandbox
policy's own `file_check_mmap` by naming the policy (`Sandbox:file_check_mmap`),
to exercise a second policy's shadow in one boot and hold its original apart from
AMFI's; that leg reports under its own `GraftRouteProbeSandbox*` registry keys.
the branch also checks the handed-back pointer. It then routes two of the Sandbox
policy's own operations by naming the policy, `Sandbox:file_check_mmap` and
`Sandbox:policy_syscall`, to exercise a second policy's shadow in one boot, hold
its originals apart from AMFI's, and cover `policy_syscall`, whose live slot and
discriminator differ from the admission hooks'; that leg reports under its own
`GraftRouteProbeSandbox*` registry keys.
It is built by the top Makefile for arm64e:
@@ -5,10 +5,14 @@
// argument types and proves two things on a real boot: that Graft resolves AMFI,
// builds the shadow policy and repoints the list entry ("routed"), and that the
// shadow sits in the live MAC dispatch path (every routed op is entered). It then
// routes the Sandbox policy's own file_check_mmap the same way, naming the policy,
// to exercise a second policy's shadow in one boot and hold its original apart
// from AMFI's; that leg reports on its own GraftRouteProbeSandbox* keys. arm64e
// only; the x86-64 owned-client probe is tests/kexts/core-probe/CoreProbe.cpp.
// routes two of the Sandbox policy's own operations the same way, naming the
// policy: file_check_mmap, an admission hook, and policy_syscall, the policy's
// mac_syscall(2) entry. This exercises a second policy's shadow in one boot,
// holds its originals apart from AMFI's, and covers policy_syscall, whose live
// slot and discriminator differ from the admission hooks'. The wrappers only
// count and tail-branch the original, so the probe never touches policy_syscall's
// user-space argument. That leg reports on its own GraftRouteProbeSandbox* keys.
// arm64e only; the x86-64 owned-client probe is tests/kexts/core-probe/CoreProbe.cpp.
#include <IOKit/IOLib.h>
#include <IOKit/IORegistryEntry.h>
#include <IOKit/IOService.h>
@@ -22,8 +26,8 @@ class GraftRouteProbe final : public IOService {
OSDefineMetaClassAndStructors(GraftRouteProbe, IOService);
extern "C" {
void *graft_route_probe_originals[4]{};
alignas(8) uint64_t graft_route_probe_calls[4]{};
void *graft_route_probe_originals[5]{};
alignas(8) uint64_t graft_route_probe_calls[5]{};
}
// Each wrapper increments its call counter, then tail-branches to the original
@@ -52,6 +56,7 @@ ROUTE_WRAPPER(0) // file_check_mmap (AMFI)
ROUTE_WRAPPER(1) // file_check_library_validation (AMFI)
ROUTE_WRAPPER(2) // vnode_check_signature (AMFI)
ROUTE_WRAPPER(3) // file_check_mmap (Sandbox)
ROUTE_WRAPPER(4) // policy_syscall (Sandbox)
#undef ROUTE_WRAPPER
namespace {
@@ -70,8 +75,12 @@ void state(const char *value) {
// The Sandbox leg's own state, kept apart from the AMFI legs so its outcome does
// not gate theirs. Set true when the Sandbox route installs, so lateCheck knows
// to look for its call.
// to look for its calls. The Sandbox operations, routed together in one call,
// with originals and wrappers at indices 3 and 4.
bool sandboxRouted;
const char *const sandboxOperations[] = {"Sandbox:file_check_mmap", "Sandbox:policy_syscall"};
constexpr unsigned SandboxBase = 3;
constexpr unsigned SandboxCount = 2;
void sandboxState(const char *value) {
IOLog("graft route probe (Sandbox): %s\n", value);
@@ -98,12 +107,21 @@ void lateCheck(void *, wait_result_t) {
}
state(observed ? "passed" : "refused: a routed op was never entered");
// The Sandbox leg, if it installed: file_check_mmap fires as soon as code is
// mapped, so its counter is non-zero on a live boot. Reported on its own key.
// mapped, and policy_syscall on every sandbox mac_syscall, so both counters
// are non-zero on a live boot. Each is reported on its own key, and the leg
// passes only when every Sandbox op was entered through its shadow.
if (sandboxRouted) {
uint64_t count = __atomic_load_n(graft_route_probe_calls + 3, __ATOMIC_RELAXED);
if (root)
root->setProperty("GraftRouteProbeCalls.Sandbox.file_check_mmap", count, 64);
sandboxState(count ? "passed" : "refused: the Sandbox route was never entered");
bool sandboxObserved = true;
for (unsigned i = 0; i < SandboxCount; ++i) {
uint64_t count =
__atomic_load_n(graft_route_probe_calls + SandboxBase + i, __ATOMIC_RELAXED);
sandboxObserved = count != 0 && sandboxObserved;
char key[96];
snprintf(key, sizeof(key), "GraftRouteProbeCalls.%s", sandboxOperations[i]);
if (root)
root->setProperty(key, count, 64);
}
sandboxState(sandboxObserved ? "passed" : "refused: a Sandbox route was never entered");
}
thread_terminate(current_thread());
}
@@ -123,13 +141,16 @@ void graft_client_initialize() {
state("refused: routes");
return;
}
// Also route the Sandbox policy's own file_check_mmap, naming the policy in a
// second call. Its original is held apart from AMFI's, in its own slot. The
// leg reports on its own keys and does not gate the AMFI result.
graft_route_request sandbox{"Sandbox:file_check_mmap",
reinterpret_cast<void *>(graft_route_probe_3),
graft_route_probe_originals + 3};
sandboxRouted = graft_route_kernel(Client, &sandbox, 1);
// Also route two of the Sandbox policy's own operations, naming the policy, in
// a second call: file_check_mmap and policy_syscall. Their originals are held
// apart from AMFI's, in their own slots. The leg reports on its own keys and
// does not gate the AMFI result.
void (*sandboxWrappers[])() = {graft_route_probe_3, graft_route_probe_4};
graft_route_request sandbox[SandboxCount]{};
for (unsigned i = 0; i < SandboxCount; ++i)
sandbox[i] = {sandboxOperations[i], reinterpret_cast<void *>(sandboxWrappers[i]),
graft_route_probe_originals + SandboxBase + i};
sandboxRouted = graft_route_kernel(Client, sandbox, SandboxCount);
sandboxState(sandboxRouted ? "waiting: route-entry check" : "refused: route");
state("waiting: route-entry check");
thread_t thread = THREAD_NULL;
+8 -3
View File
@@ -11,7 +11,7 @@ flags for both architectures and checks two invariants the arm64 display synthes
fill it in place (docs/guides/synthesized-class.md). We count the reserved stubs.
* Overriding the class's methods emits exactly the selectors (name + parameter manglings)
the live kernel names, so each override resolves to the right live slot. We freeze the 31
the live kernel names, so each override resolves to the right live slot. We freeze the 32
manglings the stand-in's own declarations produce; a parameter-type edit that shifted a
mangling would break the match with the live class, and this catches it. The strings are
the compiler's deterministic output for our header, re-derived here, not Apple data.
@@ -28,7 +28,7 @@ from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
HEADER = ROOT / "sdk/include/graft/IOMobileFramebufferLegacy.h"
# A concrete subclass overriding all 31 of the stand-in's methods, so each emits a
# A concrete subclass overriding all 32 of the stand-in's methods, so each emits a
# Display-qualified selector. The bodies are trivial; synthesis overwrites the vtable at
# bind and never calls these.
SOURCE = """#include <graft/IOMobileFramebufferLegacy.h>
@@ -69,6 +69,8 @@ public:
graft_iomfb_word swap_set_color_matrix(IOMFBColorFixedMatrix *, IOMFBColorMatrixFunction,
uint32_t) override;
graft_iomfb_word set_parameter(IOMFBParameterName, const uint64_t *, uint32_t) override;
graft_iomfb_word set_block(task *, uint32_t, uint32_t, const uint64_t *, uint32_t,
const uint8_t *, size_t) override;
graft_iomfb_word do_power_state_change_gated() override;
};
OSDefineMetaClassAndStructors(Display, IOMobileFramebufferLegacy);
@@ -110,10 +112,12 @@ graft_iomfb_word Display::swap_set_color_matrix(IOMFBColorFixedMatrix *, IOMFBCo
uint32_t) { return 0; }
graft_iomfb_word Display::set_parameter(IOMFBParameterName, const uint64_t *, uint32_t)
{ return 0; }
graft_iomfb_word Display::set_block(task *, uint32_t, uint32_t, const uint64_t *, uint32_t,
const uint8_t *, size_t) { return 0; }
graft_iomfb_word Display::do_power_state_change_gated() { return 0; }
"""
# The 31 selectors the stand-in's declarations mangle to, qualified onto the test subclass
# The 32 selectors the stand-in's declarations mangle to, qualified onto the test subclass
# "Display". Regenerated by compiling SOURCE; frozen so a signature edit that shifts a
# mangling fails the test. are_timings_enabled and get_color_remap_mode are const, so they
# carry the __ZNK prefix.
@@ -149,6 +153,7 @@ EXPECTED_OVERRIDES = {
"__ZNK7Display20get_color_remap_modeEP21DisplayColorRemapMode",
"__ZN7Display21swap_set_color_matrixEP21IOMFBColorFixedMatrix24IOMFBColorMatrixFunctionj",
"__ZN7Display13set_parameterE18IOMFBParameterNamePKyj",
"__ZN7Display9set_blockEP4taskjjPKyjPKhm",
"__ZN7Display27do_power_state_change_gatedEv",
}