Skip to content

Commit 5bb1bb0

Browse files
committed
Enhanced csrstat with historically accurate SIP analysis based on Apple XNU kernel source research
- Implemented version-specific CSR disable values (0x67 for Catalina-, 0x6F for Big Sur+) - Added comprehensive XNU kernel source analysis with complete CSR flag evolution timeline - Discovered Apple's transition from dynamic CSR logic to static CSR_DISABLE_FLAGS constant - Updated compilation instructions for universal binary support (ARM64 + x86_64) - Refactored to use official Apple CSR_DISABLE_FLAGS definition with historical accuracy - Enhanced documentation with complete macOS version mapping and XNU source evolution Technical improvements: - Version-aware CSR disable logic based on Darwin kernel version detection - Complete CSR flag evolution documentation from El Capitan through current versions - Accurate handling of kernel debugger flag inclusion changes between macOS versions - Universal binary compilation support for both Intel and Apple Silicon architectures
1 parent 6f08bef commit 5bb1bb0

File tree

2 files changed

+830
-45
lines changed

2 files changed

+830
-45
lines changed

README.md

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ cc csrstat.c -o csrstat
1919

2020
# If you encounter SDK issues on ARM64 systems:
2121
cc -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk csrstat.c -o csrstat
22+
23+
# Cross-compile for specific architecture:
24+
cc -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk csrstat.c -o csrstat-x86_64
25+
cc -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk csrstat.c -o csrstat-arm64
26+
27+
# Universal binary (works on both Intel and Apple Silicon):
28+
cc -arch arm64 -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk csrstat.c -o csrstat-universal
2229
```
2330

2431
## Usage
@@ -31,8 +38,14 @@ cc -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk csrstat.c -o cs
3138

3239
```
3340
csrstat v2.0 Copyright (c) 2015-2017 by Pike R. Alpha, 2017-2025 by Joss Brown, 2021-2025 by Startergo
41+
Enhanced with accurate SIP analysis based on Khronokernel research
42+
Reference: https://github.com/khronokernel/What-is-SIP
43+
44+
✅ Successfully queried SIP status via csr_get_active_config()
3445
System Integrity Protection value: (0x0000006f)
35-
System Integrity Protection status: disabled
46+
System Integrity Protection status: disabled (Recovery Mode)
47+
Configuration Method: Recovery Mode 'csrutil disable'
48+
Note: This is the standard disabled configuration on retail hardware
3649
3750
Current Configuration:
3851
Kext Signing 1 (disabled) [--without kext]
@@ -48,20 +61,26 @@ Current Configuration:
4861
Executable Policy 0 (enabled) [internal only]
4962
Unauthenticated Root 0 (enabled) [authenticated-root disable]
5063
64+
======================================================
65+
Enhanced SIP Capability Analysis:
66+
======================================================
67+
🔐 Root Filesystem Modification: ✅ ALLOWED
68+
🔧 Unsigned Kext Loading: ✅ ALLOWED
69+
🐛 Kernel Debugging: ✅ ALLOWED
70+
💾 NVRAM/Device Tree Modification: ✅ ALLOWED
71+
🍎 Apple Internal Status: ✅ NORMAL (expected on retail hardware)
72+
5173
======================================================
5274
Third-Party Kext Loading Analysis:
5375
======================================================
5476
⚠️ SIP Status: PARTIAL - Untrusted kexts allowed (0x0000006f)
5577
✅ Signed third-party kexts: ALLOWED
5678
✅ Kext loading: SHOULD WORK (if properly signed)
5779
58-
🔍 Additional Boot Arguments for Unsigned Kexts:
59-
kext-dev-mode=1 (allows loading of unsigned/untrusted kexts)
60-
6180
📋 Recommended SIP Configurations for Third-Party Kexts:
6281
• SECURE: csrutil enable --without kext (0x00000001)
6382
• BALANCED: csrutil enable --without kext --without debug (0x00000005)
64-
• PERMISSIVE: csrutil disable (0x0000006f, excludes always-enforced/internal flags)
83+
• PERMISSIVE: csrutil disable (0x0000006f on retail hardware)
6584
```
6685

6786
## Key Improvements
@@ -88,7 +107,49 @@ Third-Party Kext Loading Analysis:
88107

89108
## Technical Notes
90109

91-
Please note that csrstat reads the active SIP configuration directly from the kernel via syscall, not from the NVRAM variable (csr-active-config), as it should. The NVRAM variable is only applied after a reboot.
110+
### CSR Configuration Storage by Architecture
111+
112+
Based on Apple's XNU kernel source analysis:
113+
114+
- **Intel Systems**: Configuration stored in NVRAM variable `csr-active-config` and read via boot arguments
115+
- **Apple Silicon**: Configuration read via `lp-sip0` entry in the Device Tree (`lp-sip1`, `lp-sip2` for additional flags) under `/chosen/asmb` - **NO NVRAM usage**
116+
117+
The kernel code shows this clearly:
118+
```c
119+
// Apple Silicon - Device Tree lookup
120+
if (SecureDTLookupEntry(0, "/chosen/asmb", &entry) == kSuccess &&
121+
_csr_get_dt_uint64(&entry, "lp-sip0", &uint64_value)) {
122+
csr_config = (uint32_t)uint64_value; // Currently only 32 bits used.
123+
config_active = true;
124+
}
125+
```
126+
127+
### Dynamic Kernel Behavior
128+
129+
The kernel includes sophisticated logic that dynamically enables `CSR_ALLOW_KERNEL_DEBUGGER` when other debugging flags are present:
130+
131+
```c
132+
// From XNU kernel source
133+
if ((config & (CSR_ALLOW_UNTRUSTED_KEXTS | CSR_ALLOW_APPLE_INTERNAL)) != 0) {
134+
config |= CSR_ALLOW_KERNEL_DEBUGGER;
135+
}
136+
```
137+
138+
This explains why kernel debugging appears enabled even when not explicitly set.
139+
140+
### Apple Internal Bit Handling
141+
142+
On retail hardware, the kernel automatically strips the Apple Internal bit:
143+
144+
```c
145+
if (!_csr_is_iuou_or_iuos_device()) {
146+
csr_config &= ~CSR_ALLOW_APPLE_INTERNAL;
147+
}
148+
```
149+
150+
### Active Configuration Reading
151+
152+
csrstat reads the active SIP configuration directly from the kernel via syscall (`csr_get_active_config`), not from the stored configuration sources. The stored values (NVRAM on Intel, Device Tree on Apple Silicon) are only applied during boot and after a reboot.
92153

93154
## Version History
94155

@@ -102,7 +163,9 @@ Please note that csrstat reads the active SIP configuration directly from the ke
102163
- **Original Author**: Pike R. Alpha (2015-2017)
103164
- **Enhanced by**: Joss Brown (2017-2018)
104165
- **Further Enhanced by**: Startergo (2021-2025)
105-
- **Apple XNU Reference**: [Darwin XNU Kernel Source](https://github.com/apple/darwin-xnu/blob/main/bsd/sys/csr.h)
166+
- **Kernel Source Research**: Analysis based on Apple's XNU kernel implementation
167+
- **SIP Research Reference**: [Khronokernel's SIP Documentation](https://github.com/khronokernel/What-is-SIP)
168+
- **Apple XNU Reference**: [Darwin XNU Kernel Source](https://github.com/apple-oss-distributions/xnu)
106169

107170
## License
108171

0 commit comments

Comments
 (0)