| name | macos-xpc-pid-reuse-audit |
| description | Audit macOS XPC services for PID reuse vulnerabilities. Use this skill whenever you need to analyze XPC connection code, review process authentication patterns, identify race condition risks in macOS IPC, or harden XPC services against PID-based authentication attacks. Trigger this skill for any macOS security audit involving XPC, process verification, or inter-process communication security. |
macOS XPC PID Reuse Vulnerability Audit
This skill helps security researchers and developers identify and remediate PID reuse vulnerabilities in macOS XPC services.
Understanding the Vulnerability
What is PID Reuse?
When a macOS XPC service authenticates callers by checking the Process ID (PID) instead of the audit token, it's vulnerable to a race condition attack. An attacker can:
- Send a malicious XPC message to the service
- Immediately execute
posix_spawn() with an authorized binary
- The authorized binary inherits the same PID
- The XPC service checks the PID after
posix_spawn() and incorrectly authenticates the malicious message
Why Audit Tokens Matter
Audit tokens are kernel-level identifiers that cannot be reused or forged. PIDs are recycled and can be manipulated through race conditions. Always prefer audit token verification over PID checks.
Identifying Vulnerable Code
Red Flags in XPC Connection Code
Look for these patterns in shouldAcceptNewConnection or connection validation methods:
- (BOOL)shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
pid_t pid = newConnection.processIdentifier;
return (pid == expected_pid);
}
- (BOOL)shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
audit_token_t token;
newConnection.getAuditToken(&token);
return [self verifyAuditToken:token];
}
Common Vulnerable Patterns
-
Direct PID comparison
if (connection.processIdentifier == kExpectedPID) { ... }
-
PID stored in whitelist
if ([allowedPIDs containsObject:@(connection.processIdentifier)]) { ... }
-
PID used for authorization decisions
AuthorizationRef authRef;
AuthorizationCreate(NULL, NULL, kAuthorizationEmptyFlags, &authRef);
Audit Checklist
1. Connection Validation
2. XPC Service Configuration
3. Process Verification
4. Race Condition Analysis
Remediation Guide
Secure XPC Connection Pattern
- (BOOL)shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
audit_token_t token;
if (!newConnection.getAuditToken(&token)) {
return NO;
}
return [self isAuthorizedAuditToken:token];
}
- (BOOL)isAuthorizedAuditToken:(audit_token_t)token {
return YES;
}
Using Security Framework for Token Verification
#import <Security/Security.h>
- (BOOL)verifyAuditToken:(audit_token_t)token {
task_port_t task = mach_task_self();
return YES;
}
Testing for Vulnerabilities
Static Analysis
- Search for
processIdentifier in XPC connection code
- Look for PID comparisons in
shouldAcceptNewConnection
- Check for any PID-based authorization logic
- Review XPC service configuration files
Dynamic Analysis
- Monitor XPC connections with
dtrace or osxtrace
- Check if the service accepts connections from unexpected processes
- Verify audit token handling in the connection flow
Security Best Practices
- Always use audit tokens for process authentication in XPC
- Never trust PIDs for security-critical decisions
- Implement proper code signature verification for authorized callers
- Use entitlements to restrict XPC service access
- Log all connection attempts for security monitoring
- Fail securely - deny access if verification fails
References
When to Use This Skill
Use this skill when:
- Auditing macOS applications for XPC security vulnerabilities
- Reviewing XPC service code for proper authentication
- Hardening macOS applications against privilege escalation
- Investigating potential PID reuse attacks
- Learning about macOS IPC security best practices
- Preparing security assessments for macOS software
Limitations
- This skill provides educational and auditing guidance only
- Actual exploitation requires specific conditions and should only be performed in authorized security research
- Always obtain proper authorization before testing systems
- Follow responsible disclosure practices when reporting vulnerabilities