Skip to content
BSD syscall#169

svc · unix #169

csops

Reads or modifies code-signing state for the calling or target process.

Prototype

int csops(pid_t pid, uint32_t ops, user_addr_t useraddr, user_size_t usersize);

Returns: int

Arguments

NameTypeDirDescription
pidpid_t-
opsuint32_t-
useraddruser_addr_t-
usersizeuser_size_t-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard169
xnu-1699.24.8macOS 10.7 Lion169
xnu-2050.18.24macOS 10.8 Mountain Lion169
xnu-2422.115.4macOS 10.9 Mavericks169
xnu-2782.40.9macOS 10.10 Yosemite169
xnu-3247.1.106macOS 10.11 El Capitan169
xnu-3789.1.32macOS 10.12 Sierra169
xnu-4570.1.46macOS 10.13 High Sierra169
xnu-4903.221.2macOS 10.14 Mojave169
xnu-6153.11.26macOS 10.15 Catalina169
xnu-7195.50.7.100.1macOS 11.0 Big Sur169
xnu-8019.41.5macOS 12.0 Monterey169
xnu-8792.41.9macOS 13.0 Ventura169
xnu-10002.1.13macOS 14.0 Sonoma169
xnu-11215.1.10macOS 15.0 Sequoia169
xnu-11417.101.15macOS 15.4 Sequoia169
xnu-12377.1.9macOS 26.0 Tahoe169
xnu-10002.41.9169
xnu-10002.61.3169
xnu-10002.81.5169
xnu-10063.101.15169
xnu-10063.121.3169
xnu-10063.141.1169
xnu-11215.41.3169
xnu-11215.61.5169
xnu-11215.81.4169
xnu-11417.121.6169
xnu-11417.140.69169
xnu-12377.101.15169
xnu-12377.41.6169
xnu-12377.61.12169
xnu-12377.81.4169
xnu-1486.2.11169
xnu-1504.15.3169
xnu-1504.3.12169
xnu-1504.7.4169
xnu-1504.9.17169
xnu-1504.9.26169
xnu-1504.9.37169
xnu-1699.22.73169
xnu-1699.22.81169
xnu-1699.24.23169
xnu-1699.26.8169
xnu-1699.32.7169
xnu-2050.22.13169
xnu-2050.24.15169
xnu-2050.48.11169
xnu-2050.7.9169
xnu-2050.9.2169
xnu-2422.1.72169
xnu-2422.100.13169
xnu-2422.110.17169
xnu-2422.90.20169
xnu-2782.1.97169
xnu-2782.10.72169
xnu-2782.20.48169
xnu-2782.30.5169
xnu-3247.10.11169
xnu-3248.20.55169
xnu-3248.30.4169
xnu-3248.40.184169
xnu-3248.50.21169
xnu-3248.60.10169
xnu-3789.21.4169
xnu-3789.31.2169
xnu-3789.41.3169
xnu-3789.51.2169
xnu-3789.60.24169
xnu-3789.70.16169
xnu-4570.20.62169
xnu-4570.31.3169
xnu-4570.41.2169
xnu-4570.51.1169
xnu-4570.61.1169
xnu-4570.71.2169
xnu-4903.231.4169
xnu-4903.241.1169
xnu-4903.270.47169
xnu-6153.101.6169
xnu-6153.121.1169
xnu-6153.141.1169
xnu-6153.41.3169
xnu-6153.61.1169
xnu-6153.81.5169
xnu-7195.101.1169
xnu-7195.121.3169
xnu-7195.141.2169
xnu-7195.60.75169
xnu-7195.81.3169
xnu-8019.61.5169
xnu-8019.80.24169
xnu-8020.101.4169
xnu-8020.121.3169
xnu-8020.140.41169
xnu-8792.61.2169
xnu-8792.81.2169
xnu-8796.101.5169
xnu-8796.121.2169
xnu-8796.141.3169

Examples

C — read cs_flags for a target PID

#include <sys/codesign.h>
uint32_t flags = 0;
if (csops(target_pid, CS_OPS_STATUS, &flags, sizeof(flags)) == 0) {
    bool platform = (flags & CS_PLATFORM_BINARY) != 0;
}

Notes

csops(pid, op, buf, len) is the kernel surface behind every code-signing query on macOS: CS_OPS_STATUS for the cs_flags bitmap, CS_OPS_CDHASH for the binary's hash, CS_OPS_TEAMID for the developer team, CS_OPS_ENTITLEMENTS_BLOB for the signed entitlements blob, plus mutating ops like CS_OPS_MARKINVALID. Querying another process generally requires the same authority needed to inspect that task; mutating ops are gated by AMFI and the platform-binary check.

Detection

Massively legitimate (every codesign(1), every Gatekeeper check, every XPC connection's audit-token validation), so volume alone is uninformative. Alert on CS_OPS_MARKINVALID, CS_OPS_CLEARINSTALLER, CS_OPS_CLEARPLATFORM and any mutator from non-system PIDs. DTrace probe fbt::csops:entry plus arg1 yields the operation code.

Related APIs

csops_audittokenproc_uuid_policySecCodeCopyGuestWithAttributesamfid