]>
Commit | Line | Data |
---|---|---|
2d21ac55 A |
1 | /* |
2 | * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
0a7de745 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
0a7de745 | 25 | * |
2d21ac55 A |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ | |
28 | ||
29 | #ifndef _SYS_CODESIGN_H_ | |
30 | #define _SYS_CODESIGN_H_ | |
31 | ||
5ba3f43e A |
32 | #if KERNEL |
33 | #include <kern/cs_blobs.h> | |
34 | #else | |
35 | #include <System/kern/cs_blobs.h> | |
36 | #endif | |
2d21ac55 | 37 | |
c18c124e A |
38 | /* MAC flags used by F_ADDFILESIGS_* */ |
39 | #define MAC_VNODE_CHECK_DYLD_SIM 0x1 /* tells the MAC framework that dyld-sim is being loaded */ | |
40 | ||
4ba76501 | 41 | #define CLEAR_LV_ENTITLEMENT "com.apple.private.security.clear-library-validation" |
f427ee49 | 42 | #define OVERRIDE_PLUGIN_HOST_ENTITLEMENT "com.apple.private.security.override-plugin-host-detection" |
4ba76501 | 43 | |
2d21ac55 | 44 | /* csops operations */ |
0a7de745 A |
45 | #define CS_OPS_STATUS 0 /* return status */ |
46 | #define CS_OPS_MARKINVALID 1 /* invalidate process */ | |
47 | #define CS_OPS_MARKHARD 2 /* set HARD flag */ | |
48 | #define CS_OPS_MARKKILL 3 /* set KILL flag (sticky) */ | |
39236c6e A |
49 | #ifdef KERNEL_PRIVATE |
50 | /* CS_OPS_PIDPATH 4 */ | |
51 | #endif | |
0a7de745 A |
52 | #define CS_OPS_CDHASH 5 /* get code directory hash */ |
53 | #define CS_OPS_PIDOFFSET 6 /* get offset of active Mach-o slice */ | |
54 | #define CS_OPS_ENTITLEMENTS_BLOB 7 /* get entitlements blob */ | |
55 | #define CS_OPS_MARKRESTRICT 8 /* set RESTRICT flag (sticky) */ | |
56 | #define CS_OPS_SET_STATUS 9 /* set codesign flags */ | |
57 | #define CS_OPS_BLOB 10 /* get codesign blob */ | |
58 | #define CS_OPS_IDENTITY 11 /* get codesign identity */ | |
59 | #define CS_OPS_CLEARINSTALLER 12 /* clear INSTALLER flag */ | |
5ba3f43e | 60 | #define CS_OPS_CLEARPLATFORM 13 /* clear platform binary status (DEVELOPMENT-only) */ |
d9a64523 | 61 | #define CS_OPS_TEAMID 14 /* get team id */ |
4ba76501 | 62 | #define CS_OPS_CLEAR_LV 15 /* clear the library validation flag */ |
39236c6e | 63 | |
0a7de745 | 64 | #define CS_MAX_TEAMID_LEN 64 |
2d21ac55 A |
65 | |
66 | #ifndef KERNEL | |
67 | ||
39236c6e | 68 | #include <sys/types.h> |
fe8ab488 | 69 | #include <mach/message.h> |
2d21ac55 | 70 | |
39236c6e | 71 | __BEGIN_DECLS |
2d21ac55 A |
72 | /* code sign operations */ |
73 | int csops(pid_t pid, unsigned int ops, void * useraddr, size_t usersize); | |
316670eb | 74 | int csops_audittoken(pid_t pid, unsigned int ops, void * useraddr, size_t usersize, audit_token_t * token); |
39236c6e A |
75 | __END_DECLS |
76 | ||
77 | #else /* !KERNEL */ | |
78 | ||
d9a64523 | 79 | #include <mach/machine.h> |
39037602 A |
80 | #include <mach/vm_types.h> |
81 | ||
39236c6e | 82 | #include <sys/cdefs.h> |
fe8ab488 | 83 | #include <sys/_types/_off_t.h> |
39236c6e A |
84 | |
85 | struct vnode; | |
fe8ab488 A |
86 | struct cs_blob; |
87 | struct fileglob; | |
39236c6e | 88 | |
39236c6e | 89 | __BEGIN_DECLS |
0a7de745 A |
90 | int cs_valid(struct proc *); |
91 | int cs_process_enforcement(struct proc *); | |
d9a64523 A |
92 | int cs_process_global_enforcement(void); |
93 | int cs_system_enforcement(void); | |
f427ee49 | 94 | int cs_vm_supports_4k_translations(void); |
0a7de745 | 95 | int cs_require_lv(struct proc *); |
d9a64523 | 96 | int csproc_forced_lv(struct proc* p); |
0a7de745 | 97 | int cs_system_require_lv(void); |
fe8ab488 | 98 | uint32_t cs_entitlement_flags(struct proc *p); |
f427ee49 | 99 | int cs_entitlements_blob_get_vnode(struct vnode *, off_t, void **, size_t *); |
0a7de745 | 100 | int cs_entitlements_blob_get(struct proc *, void **, size_t *); |
cb323159 A |
101 | #ifdef KERNEL_PRIVATE |
102 | int cs_entitlements_dictionary_copy(struct proc *, void **); | |
103 | #endif | |
0a7de745 | 104 | int cs_restricted(struct proc *); |
39236c6e | 105 | uint8_t * cs_get_cdhash(struct proc *); |
2d21ac55 | 106 | |
3e170ce0 A |
107 | struct cs_blob * csproc_get_blob(struct proc *); |
108 | struct cs_blob * csvnode_get_blob(struct vnode *, off_t); | |
0a7de745 A |
109 | void csvnode_print_debug(struct vnode *); |
110 | ||
111 | off_t csblob_get_base_offset(struct cs_blob *); | |
112 | vm_size_t csblob_get_size(struct cs_blob *); | |
113 | vm_address_t csblob_get_addr(struct cs_blob *); | |
114 | const char * csblob_get_teamid(struct cs_blob *); | |
115 | const char * csblob_get_identity(struct cs_blob *); | |
116 | const uint8_t * csblob_get_cdhash(struct cs_blob *); | |
117 | int csblob_get_platform_binary(struct cs_blob *); | |
118 | unsigned int csblob_get_flags(struct cs_blob *); | |
119 | uint8_t csblob_get_hashtype(struct cs_blob const *); | |
120 | unsigned int csblob_get_signer_type(struct cs_blob *); | |
5ba3f43e | 121 | #if DEVELOPMENT || DEBUG |
0a7de745 | 122 | void csproc_clear_platform_binary(struct proc *); |
5ba3f43e | 123 | #endif |
39037602 | 124 | |
d9a64523 A |
125 | void csproc_disable_enforcement(struct proc* p); |
126 | void csproc_mark_invalid_allowed(struct proc* p); | |
127 | int csproc_check_invalid_allowed(struct proc* p); | |
128 | int csproc_hardened_runtime(struct proc* p); | |
129 | ||
0a7de745 | 130 | int csblob_get_entitlements(struct cs_blob *, void **, size_t *); |
39037602 | 131 | |
3e170ce0 | 132 | const CS_GenericBlob * |
0a7de745 | 133 | csblob_find_blob(struct cs_blob *, uint32_t, uint32_t); |
3e170ce0 | 134 | const CS_GenericBlob * |
0a7de745 | 135 | csblob_find_blob_bytes(const uint8_t *, size_t, uint32_t, uint32_t); |
39037602 A |
136 | void * csblob_entitlements_dictionary_copy(struct cs_blob *csblob); |
137 | void csblob_entitlements_dictionary_set(struct cs_blob *csblob, void * entitlements); | |
3e170ce0 A |
138 | |
139 | /* | |
140 | * Mostly convenience functions below | |
141 | */ | |
fe8ab488 | 142 | |
0a7de745 | 143 | const char * csproc_get_teamid(struct proc *); |
f427ee49 | 144 | const char * csproc_get_identity(struct proc *); |
0a7de745 A |
145 | const char * csvnode_get_teamid(struct vnode *, off_t); |
146 | int csproc_get_platform_binary(struct proc *); | |
743345f9 | 147 | int csproc_get_prod_signed(struct proc *); |
0a7de745 | 148 | const char * csfg_get_teamid(struct fileglob *); |
f427ee49 | 149 | const char * csfg_get_supplement_teamid(struct fileglob *); |
0a7de745 A |
150 | int csfg_get_path(struct fileglob *, char *, int *); |
151 | int csfg_get_platform_binary(struct fileglob *); | |
f427ee49 | 152 | int csfg_get_supplement_platform_binary(struct fileglob *); |
3e170ce0 | 153 | uint8_t * csfg_get_cdhash(struct fileglob *, uint64_t, size_t *); |
f427ee49 A |
154 | uint8_t * csfg_get_supplement_cdhash(struct fileglob *, uint64_t, size_t *); |
155 | const uint8_t * csfg_get_supplement_linkage_cdhash(struct fileglob *, uint64_t, size_t *); | |
743345f9 | 156 | int csfg_get_prod_signed(struct fileglob *); |
f427ee49 | 157 | int csfg_get_supplement_prod_signed(struct fileglob *fg); |
5ba3f43e | 158 | unsigned int csfg_get_signer_type(struct fileglob *); |
f427ee49 | 159 | unsigned int csfg_get_supplement_signer_type(struct fileglob *); |
a39ff7e2 | 160 | const char *csfg_get_identity(struct fileglob *fg, off_t offset); |
5ba3f43e | 161 | unsigned int csproc_get_signer_type(struct proc *); |
fe8ab488 | 162 | |
a39ff7e2 A |
163 | uint8_t csfg_get_platform_identifier(struct fileglob *, off_t); |
164 | uint8_t csvnode_get_platform_identifier(struct vnode *, off_t); | |
165 | uint8_t csproc_get_platform_identifier(struct proc *); | |
166 | ||
3e170ce0 | 167 | extern int cs_debug; |
d9a64523 A |
168 | extern int cs_debug_fail_on_unsigned_code; |
169 | extern unsigned int cs_debug_unsigned_exec_failures; | |
170 | extern unsigned int cs_debug_unsigned_mmap_failures; | |
171 | ||
172 | int cs_blob_create_validated(vm_address_t* addr, vm_size_t size, | |
0a7de745 | 173 | struct cs_blob ** ret_blob, CS_CodeDirectory const **ret_cd); |
d9a64523 A |
174 | |
175 | void cs_blob_free(struct cs_blob *blob); | |
2d21ac55 | 176 | |
39236c6e A |
177 | #ifdef XNU_KERNEL_PRIVATE |
178 | ||
0a7de745 A |
179 | int cs_allow_invalid(struct proc *); |
180 | int cs_invalid_page(addr64_t vaddr, boolean_t *cs_killed); | |
f427ee49 | 181 | void cs_process_invalidated(struct proc *); |
0a7de745 | 182 | int csproc_get_platform_path(struct proc *); |
39236c6e | 183 | |
39236c6e A |
184 | #if !SECURE_KERNEL |
185 | extern int cs_enforcement_panic; | |
186 | #endif | |
187 | ||
188 | #endif /* XNU_KERNEL_PRIVATE */ | |
189 | ||
3e170ce0 A |
190 | |
191 | __END_DECLS | |
192 | ||
193 | ||
194 | ||
39236c6e | 195 | #endif /* KERNEL */ |
2d21ac55 A |
196 | |
197 | #endif /* _SYS_CODESIGN_H_ */ |