Jan 22, 2025
CVE-2025-4961
Carlos Garrido of Pentraze Cybersecurity
A new security issue was identified in a privileged XPC service following recent changes intended to fix a previously reported vulnerability (CVE-2024-7457). While the original issue was addressed, the updated implementation still allows unauthorized processes to establish a valid XPC connection under specific timing conditions.
The service relies on process-related information for client validation, which is not suitable for security decisions. As a result, untrusted clients may interact with the service as if they were legitimate, leading to unintended privileged behavior.
The vulnerability is caused by relying on the process identifier (PID) to authenticate XPC clients. Since PIDs can be reused, an attacker can exploit a race condition to send malicious XPC messages and then spawn a trusted process that assumes the same PID.
If the service validates the client after this transition, it may incorrectly treat the malicious messages as originating from a trusted process. This allows unauthorized clients to perform privileged actions, including modifying system network settings.
When reviewing the listener:shouldAcceptNewConnection: function, the connectionIsValid: function is invoked. At this point, it becomes evident that connection validity is determined based on the process identifier (PID) rather than the auditToken. This design choice introduces a PID Reuse Attack vulnerability.
This race condition is possible due to the following behavior: when invoking posix_spawn to create a new process, the POSIX_SPAWN_SETEXEC flag is used, causing posix_spawn to effectively behave like an execv call and reuse the existing process identifier (PID). In addition, the POSIX_SPAWN_START_SUSPENDED flag is specified to ensure the process is created in a suspended state.
| |
| |
Terminate the connection upon receiving an unrecognized message.
Perform authorization checks before accepting a connection whenever possible.
If authorization checks are not feasible at that stage, use xpc_dictionary_get_audit_token.
Alternatively, save the audit token during the accept handler for later use (this method is also effective for NSXPCConnection).
Leverage new APIs for automatic code signing verification before accepting a connection:
[NSXPCConnection setCodeSigningRequirement:] (available since macOS 13.0)
xpc_connection_set_peer_code_signing_requirement (available since macOS 12.0)