1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions * Copyright (c) 2022 Apple Computer, Inc. All rights reserved.
3*43a90889SApple OSS Distributions *
4*43a90889SApple OSS Distributions * @APPLE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions *
6*43a90889SApple OSS Distributions * The contents of this file constitute Original Code as defined in and
7*43a90889SApple OSS Distributions * are subject to the Apple Public Source License Version 1.1 (the
8*43a90889SApple OSS Distributions * "License"). You may not use this file except in compliance with the
9*43a90889SApple OSS Distributions * License. Please obtain a copy of the License at
10*43a90889SApple OSS Distributions * http://www.apple.com/publicsource and read it before using this file.
11*43a90889SApple OSS Distributions *
12*43a90889SApple OSS Distributions * This Original Code and all software distributed under the License are
13*43a90889SApple OSS Distributions * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14*43a90889SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15*43a90889SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16*43a90889SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17*43a90889SApple OSS Distributions * License for the specific language governing rights and limitations
18*43a90889SApple OSS Distributions * under the License.
19*43a90889SApple OSS Distributions *
20*43a90889SApple OSS Distributions * @APPLE_LICENSE_HEADER_END@
21*43a90889SApple OSS Distributions */
22*43a90889SApple OSS Distributions
23*43a90889SApple OSS Distributions #ifndef _SYS_CODE_SIGNING_H_
24*43a90889SApple OSS Distributions #define _SYS_CODE_SIGNING_H_
25*43a90889SApple OSS Distributions
26*43a90889SApple OSS Distributions #include <sys/cdefs.h>
27*43a90889SApple OSS Distributions __BEGIN_DECLS
28*43a90889SApple OSS Distributions
29*43a90889SApple OSS Distributions #pragma GCC diagnostic push
30*43a90889SApple OSS Distributions #pragma GCC diagnostic ignored "-Wnullability-completeness"
31*43a90889SApple OSS Distributions #pragma GCC diagnostic ignored "-Wnullability-completeness-on-arrays"
32*43a90889SApple OSS Distributions
33*43a90889SApple OSS Distributions typedef uint32_t code_signing_monitor_type_t;
34*43a90889SApple OSS Distributions typedef uint32_t code_signing_config_t;
35*43a90889SApple OSS Distributions
36*43a90889SApple OSS Distributions /* Monitor Types */
37*43a90889SApple OSS Distributions #define CS_MONITOR_TYPE_NONE (0)
38*43a90889SApple OSS Distributions #define CS_MONITOR_TYPE_PPL (1)
39*43a90889SApple OSS Distributions #define CS_MONITOR_TYPE_TXM (2)
40*43a90889SApple OSS Distributions
41*43a90889SApple OSS Distributions /* Config - Exemptions */
42*43a90889SApple OSS Distributions #define CS_CONFIG_UNRESTRICTED_DEBUGGING (1 << 0)
43*43a90889SApple OSS Distributions #define CS_CONFIG_ALLOW_ANY_SIGNATURE (1 << 1)
44*43a90889SApple OSS Distributions #define CS_CONFIG_ENFORCEMENT_DISABLED (1 << 2)
45*43a90889SApple OSS Distributions #define CS_CONFIG_GET_OUT_OF_MY_WAY (1 << 3)
46*43a90889SApple OSS Distributions #define CS_CONFIG_INTEGRITY_SKIP (1 << 4)
47*43a90889SApple OSS Distributions #define CS_CONFIG_RELAX_PROFILE_TRUST (1 << 5)
48*43a90889SApple OSS Distributions
49*43a90889SApple OSS Distributions /* Config - Features */
50*43a90889SApple OSS Distributions #define CS_CONFIG_REM_SUPPORTED (1 << 25)
51*43a90889SApple OSS Distributions #define CS_CONFIG_MAP_JIT (1 << 26)
52*43a90889SApple OSS Distributions #define CS_CONFIG_DEVELOPER_MODE_SUPPORTED (1 << 27)
53*43a90889SApple OSS Distributions #define CS_CONFIG_COMPILATION_SERVICE (1 << 28)
54*43a90889SApple OSS Distributions #define CS_CONFIG_LOCAL_SIGNING (1 << 29)
55*43a90889SApple OSS Distributions #define CS_CONFIG_OOP_JIT (1 << 30)
56*43a90889SApple OSS Distributions #define CS_CONFIG_CSM_ENABLED (1 << 31)
57*43a90889SApple OSS Distributions
58*43a90889SApple OSS Distributions #ifdef KERNEL_PRIVATE
59*43a90889SApple OSS Distributions /* All definitions for XNU and kernel extensions */
60*43a90889SApple OSS Distributions
61*43a90889SApple OSS Distributions #include <mach/boolean.h>
62*43a90889SApple OSS Distributions #include <mach/kern_return.h>
63*43a90889SApple OSS Distributions #include <img4/firmware.h>
64*43a90889SApple OSS Distributions
65*43a90889SApple OSS Distributions #if !XNU_KERNEL_PRIVATE
66*43a90889SApple OSS Distributions /*
67*43a90889SApple OSS Distributions * This header file is shared across the SDK and the KDK. When we're compiling code
68*43a90889SApple OSS Distributions * for the kernel, but not for XNU, such as a kernel extension, the code signing
69*43a90889SApple OSS Distributions * traps information is found through <image4/cs/traps.h>. When we're within XNU
70*43a90889SApple OSS Distributions * proper, this header shouldn't be directory included and instead we should include
71*43a90889SApple OSS Distributions * <libkern/image4/dlxk.h> instead, which is what we do within XNU_KERNEL_PRIVATE
72*43a90889SApple OSS Distributions * down below.
73*43a90889SApple OSS Distributions */
74*43a90889SApple OSS Distributions #if __has_include(<image4/cs/traps.h>)
75*43a90889SApple OSS Distributions #include <image4/cs/traps.h>
76*43a90889SApple OSS Distributions #else
77*43a90889SApple OSS Distributions typedef uint64_t image4_cs_trap_t;
78*43a90889SApple OSS Distributions #endif /* __has_include(<image4/cs/traps.h>) */
79*43a90889SApple OSS Distributions #endif /* !XNU_KERNEL_PRIVATE */
80*43a90889SApple OSS Distributions
81*43a90889SApple OSS Distributions /* Availability macros for KPI functions */
82*43a90889SApple OSS Distributions #define XNU_SUPPORTS_CSM_TYPE 1
83*43a90889SApple OSS Distributions #define XNU_SUPPORTS_CSM_APPLE_IMAGE4 1
84*43a90889SApple OSS Distributions #define XNU_SUPPORTS_PROFILE_GARBAGE_COLLECTION 1
85*43a90889SApple OSS Distributions #define XNU_SUPPORTS_COMPILATION_SERVICE 1
86*43a90889SApple OSS Distributions #define XNU_SUPPORTS_LOCAL_SIGNING 1
87*43a90889SApple OSS Distributions #define XNU_SUPPORTS_CE_ACCELERATION 1
88*43a90889SApple OSS Distributions #define XNU_SUPPORTS_DISABLE_CODE_SIGNING_FEATURE 1
89*43a90889SApple OSS Distributions #define XNU_SUPPORTS_IMAGE4_MONITOR_TRAP 1
90*43a90889SApple OSS Distributions #define XNU_SUPPORTS_RESTRICTED_EXECUTION_MODE 1
91*43a90889SApple OSS Distributions #define XNU_SUPPORTS_SECURE_CHANNEL_SHARED_PAGE 1
92*43a90889SApple OSS Distributions #define XNU_SUPPORTS_CSM_DEVICE_STATE 1
93*43a90889SApple OSS Distributions #define XNU_SUPPORTS_REGISTER_PROFILE 1
94*43a90889SApple OSS Distributions
95*43a90889SApple OSS Distributions /* Forward declarations */
96*43a90889SApple OSS Distributions struct cs_blob;
97*43a90889SApple OSS Distributions
98*43a90889SApple OSS Distributions /* Local signing public key size */
99*43a90889SApple OSS Distributions #define XNU_LOCAL_SIGNING_KEY_SIZE 97
100*43a90889SApple OSS Distributions
101*43a90889SApple OSS Distributions typedef struct _cs_profile_register_t {
102*43a90889SApple OSS Distributions /*
103*43a90889SApple OSS Distributions * The kernel performs duduplication of registered provisioning profiles
104*43a90889SApple OSS Distributions * in order to optimize the profile loading code-path. The profile Uuid
105*43a90889SApple OSS Distributions * is used as the identifier.
106*43a90889SApple OSS Distributions */
107*43a90889SApple OSS Distributions uuid_t uuid;
108*43a90889SApple OSS Distributions
109*43a90889SApple OSS Distributions /*
110*43a90889SApple OSS Distributions * Counter-signature of the profile used for verifying that the user has
111*43a90889SApple OSS Distributions * opted to trust the profile. This is only required for certain kinds of
112*43a90889SApple OSS Distributions * profiles.
113*43a90889SApple OSS Distributions */
114*43a90889SApple OSS Distributions const void *sig_data;
115*43a90889SApple OSS Distributions size_t sig_size;
116*43a90889SApple OSS Distributions
117*43a90889SApple OSS Distributions /* The profile data itself -- only DER profiles supported */
118*43a90889SApple OSS Distributions const void *data;
119*43a90889SApple OSS Distributions size_t size;
120*43a90889SApple OSS Distributions } cs_profile_register_t;
121*43a90889SApple OSS Distributions
122*43a90889SApple OSS Distributions #if XNU_KERNEL_PRIVATE
123*43a90889SApple OSS Distributions
124*43a90889SApple OSS Distributions #include <sys/code_signing_internal.h>
125*43a90889SApple OSS Distributions #include <libkern/img4/interface.h>
126*43a90889SApple OSS Distributions #include <libkern/image4/dlxk.h>
127*43a90889SApple OSS Distributions
128*43a90889SApple OSS Distributions #if PMAP_CS_INCLUDE_CODE_SIGNING
129*43a90889SApple OSS Distributions #if XNU_LOCAL_SIGNING_KEY_SIZE != PMAP_CS_LOCAL_SIGNING_KEY_SIZE
130*43a90889SApple OSS Distributions #error "XNU local signing key size and PMAP_CS local signing key size differ!"
131*43a90889SApple OSS Distributions #endif
132*43a90889SApple OSS Distributions #endif /* PMAP_CS_INCLUDE_CODE_SIGNING */
133*43a90889SApple OSS Distributions
134*43a90889SApple OSS Distributions /* Common developer mode state variable */
135*43a90889SApple OSS Distributions extern bool *developer_mode_enabled;
136*43a90889SApple OSS Distributions
137*43a90889SApple OSS Distributions /**
138*43a90889SApple OSS Distributions * This function is used to allocate code signing data which in some cases needs to
139*43a90889SApple OSS Distributions * align to a page length. This is a frequent operation, and as a result, a common
140*43a90889SApple OSS Distributions * helper is very useful.
141*43a90889SApple OSS Distributions */
142*43a90889SApple OSS Distributions vm_address_t
143*43a90889SApple OSS Distributions code_signing_allocate(
144*43a90889SApple OSS Distributions size_t alloc_size);
145*43a90889SApple OSS Distributions
146*43a90889SApple OSS Distributions /**
147*43a90889SApple OSS Distributions * This function is used to deallocate data received from code_signing_allocate.
148*43a90889SApple OSS Distributions */
149*43a90889SApple OSS Distributions void
150*43a90889SApple OSS Distributions code_signing_deallocate(
151*43a90889SApple OSS Distributions vm_address_t *alloc_addr,
152*43a90889SApple OSS Distributions size_t alloc_size);
153*43a90889SApple OSS Distributions
154*43a90889SApple OSS Distributions /**
155*43a90889SApple OSS Distributions * AppleImage4 does not provide an API to convert an object specification index to an
156*43a90889SApple OSS Distributions * actual object specification. Since this particular function is used across different
157*43a90889SApple OSS Distributions * places, it makes sense to keep it in a shared header file.
158*43a90889SApple OSS Distributions *
159*43a90889SApple OSS Distributions * This function may be called in contexts where printing is not possible, so do NOT
160*43a90889SApple OSS Distributions * leave a print statement here under any ciscumstances.
161*43a90889SApple OSS Distributions */
162*43a90889SApple OSS Distributions static inline const img4_runtime_object_spec_t*
image4_get_object_spec_from_index(img4_runtime_object_spec_index_t obj_spec_index)163*43a90889SApple OSS Distributions image4_get_object_spec_from_index(
164*43a90889SApple OSS Distributions img4_runtime_object_spec_index_t obj_spec_index)
165*43a90889SApple OSS Distributions {
166*43a90889SApple OSS Distributions const img4_runtime_object_spec_t *__single obj_spec = NULL;
167*43a90889SApple OSS Distributions
168*43a90889SApple OSS Distributions switch (obj_spec_index) {
169*43a90889SApple OSS Distributions case IMG4_RUNTIME_OBJECT_SPEC_INDEX_SUPPLEMENTAL_ROOT:
170*43a90889SApple OSS Distributions obj_spec = IMG4_RUNTIME_OBJECT_SPEC_SUPPLEMENTAL_ROOT;
171*43a90889SApple OSS Distributions break;
172*43a90889SApple OSS Distributions
173*43a90889SApple OSS Distributions case IMG4_RUNTIME_OBJECT_SPEC_INDEX_LOCAL_POLICY:
174*43a90889SApple OSS Distributions obj_spec = IMG4_RUNTIME_OBJECT_SPEC_LOCAL_POLICY;
175*43a90889SApple OSS Distributions break;
176*43a90889SApple OSS Distributions
177*43a90889SApple OSS Distributions default:
178*43a90889SApple OSS Distributions break;
179*43a90889SApple OSS Distributions }
180*43a90889SApple OSS Distributions
181*43a90889SApple OSS Distributions return obj_spec;
182*43a90889SApple OSS Distributions }
183*43a90889SApple OSS Distributions
184*43a90889SApple OSS Distributions /**
185*43a90889SApple OSS Distributions * Perform any initialization required for managing code signing state on the system.
186*43a90889SApple OSS Distributions * This is called within XNU itself and doesn't need to be exported to anything external.
187*43a90889SApple OSS Distributions */
188*43a90889SApple OSS Distributions void
189*43a90889SApple OSS Distributions code_signing_init(void);
190*43a90889SApple OSS Distributions
191*43a90889SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
192*43a90889SApple OSS Distributions
193*43a90889SApple OSS Distributions /**
194*43a90889SApple OSS Distributions * Query the system to understand the code signing configuration of the system. This
195*43a90889SApple OSS Distributions * includes information on what monitor environment is available on the system as well
196*43a90889SApple OSS Distributions * as what the state of the system looks like with the provided boot-args.
197*43a90889SApple OSS Distributions */
198*43a90889SApple OSS Distributions void
199*43a90889SApple OSS Distributions code_signing_configuration(
200*43a90889SApple OSS Distributions code_signing_monitor_type_t *monitor_type,
201*43a90889SApple OSS Distributions code_signing_config_t *config);
202*43a90889SApple OSS Distributions
203*43a90889SApple OSS Distributions /**
204*43a90889SApple OSS Distributions * This function can be called by a component to disable a particular code signing
205*43a90889SApple OSS Distributions * feature on the system. For instance, code_signing_configuration is initialized in
206*43a90889SApple OSS Distributions * early boot, where some kernel extensions which affect code signing aren't online.
207*43a90889SApple OSS Distributions * When these extensions come online, they may choose to call this function to affect
208*43a90889SApple OSS Distributions * the state which was previously initialized within code_signing_configuration.
209*43a90889SApple OSS Distributions */
210*43a90889SApple OSS Distributions void
211*43a90889SApple OSS Distributions disable_code_signing_feature(
212*43a90889SApple OSS Distributions code_signing_config_t feature);
213*43a90889SApple OSS Distributions
214*43a90889SApple OSS Distributions /**
215*43a90889SApple OSS Distributions * AppleSEPManager uses this API to obtain the physical page which must be mapped as
216*43a90889SApple OSS Distributions * the secure channel within the SEP. This API is only supported on systems which have
217*43a90889SApple OSS Distributions * the Trusted Execution Monitor system monitor.
218*43a90889SApple OSS Distributions */
219*43a90889SApple OSS Distributions kern_return_t
220*43a90889SApple OSS Distributions secure_channel_shared_page(
221*43a90889SApple OSS Distributions uint64_t *secure_channel_phys,
222*43a90889SApple OSS Distributions size_t *secure_channel_size);
223*43a90889SApple OSS Distributions
224*43a90889SApple OSS Distributions /**
225*43a90889SApple OSS Distributions * Enable developer mode on the system. When the system contains a monitor environment,
226*43a90889SApple OSS Distributions * developer mode is turned on by trapping into the appropriate monitor environment.
227*43a90889SApple OSS Distributions */
228*43a90889SApple OSS Distributions void
229*43a90889SApple OSS Distributions enable_developer_mode(void);
230*43a90889SApple OSS Distributions
231*43a90889SApple OSS Distributions /**
232*43a90889SApple OSS Distributions * Disable developer mode on the system. When the system contains a monitor environment,
233*43a90889SApple OSS Distributions * developer mode is turned off by trapping into the appropriate monitor environment.
234*43a90889SApple OSS Distributions */
235*43a90889SApple OSS Distributions void
236*43a90889SApple OSS Distributions disable_developer_mode(void);
237*43a90889SApple OSS Distributions
238*43a90889SApple OSS Distributions /**
239*43a90889SApple OSS Distributions * Query the current state of developer mode on the system. This call never traps into
240*43a90889SApple OSS Distributions * the monitor environment because XNU can directly read the monitors memory.
241*43a90889SApple OSS Distributions */
242*43a90889SApple OSS Distributions bool
243*43a90889SApple OSS Distributions developer_mode_state(void);
244*43a90889SApple OSS Distributions
245*43a90889SApple OSS Distributions /**
246*43a90889SApple OSS Distributions * Attempt to enable restricted execution mode on the system. Not all systems support
247*43a90889SApple OSS Distributions * restricted execution mode. If the call is successful, KERN_SUCCESS is returned, or
248*43a90889SApple OSS Distributions * an error.
249*43a90889SApple OSS Distributions */
250*43a90889SApple OSS Distributions kern_return_t
251*43a90889SApple OSS Distributions restricted_execution_mode_enable(void);
252*43a90889SApple OSS Distributions
253*43a90889SApple OSS Distributions /**
254*43a90889SApple OSS Distributions * Query the current state of restricted execution mode on the system. Not all systems
255*43a90889SApple OSS Distributions * support restricted execution mode. If REM is enabled, KERN_SUCCESS is returned. If
256*43a90889SApple OSS Distributions * REM is disabled, KERN_DENIED is returned. If REM is not supported on this platform,
257*43a90889SApple OSS Distributions * then KERN_NOT_SUPPORTED is returned.
258*43a90889SApple OSS Distributions */
259*43a90889SApple OSS Distributions kern_return_t
260*43a90889SApple OSS Distributions restricted_execution_mode_state(void);
261*43a90889SApple OSS Distributions
262*43a90889SApple OSS Distributions /**
263*43a90889SApple OSS Distributions * This function is called whem the kernel wants the code-signing monitor to update its
264*43a90889SApple OSS Distributions * device state which is provided by the SEP using an OOB buffer.
265*43a90889SApple OSS Distributions */
266*43a90889SApple OSS Distributions void
267*43a90889SApple OSS Distributions update_csm_device_state(void);
268*43a90889SApple OSS Distributions
269*43a90889SApple OSS Distributions /*
270*43a90889SApple OSS Distributions * This function called when the kernel wants the code-signing monitor to complete the
271*43a90889SApple OSS Distributions * functionality of a security boot mode.
272*43a90889SApple OSS Distributions */
273*43a90889SApple OSS Distributions void
274*43a90889SApple OSS Distributions complete_security_boot_mode(
275*43a90889SApple OSS Distributions uint32_t security_boot_mode);
276*43a90889SApple OSS Distributions
277*43a90889SApple OSS Distributions /*
278*43a90889SApple OSS Distributions * Register and attempt to associate a provisioning profile with the code signature
279*43a90889SApple OSS Distributions * attached to the csblob. This call is only relevant for systems which have a code
280*43a90889SApple OSS Distributions * signing monitor, but it is exported to kernel extensions since AMFI is the primary
281*43a90889SApple OSS Distributions * consumer.
282*43a90889SApple OSS Distributions */
283*43a90889SApple OSS Distributions int
284*43a90889SApple OSS Distributions csblob_register_profile(
285*43a90889SApple OSS Distributions struct cs_blob *csblob,
286*43a90889SApple OSS Distributions cs_profile_register_t *profile);
287*43a90889SApple OSS Distributions
288*43a90889SApple OSS Distributions /**
289*43a90889SApple OSS Distributions * Wrapper function which is exposed to kernel extensions. This can be used to trigger
290*43a90889SApple OSS Distributions * a call to the garbage collector for going through and unregistring all unused profiles
291*43a90889SApple OSS Distributions * on the system.
292*43a90889SApple OSS Distributions */
293*43a90889SApple OSS Distributions void
294*43a90889SApple OSS Distributions garbage_collect_provisioning_profiles(void);
295*43a90889SApple OSS Distributions
296*43a90889SApple OSS Distributions /**
297*43a90889SApple OSS Distributions * Set the CDHash which is currently being used by the compilation service. This CDHash
298*43a90889SApple OSS Distributions * is compared against when validating the signature of a compilation service library.
299*43a90889SApple OSS Distributions */
300*43a90889SApple OSS Distributions void
301*43a90889SApple OSS Distributions set_compilation_service_cdhash(
302*43a90889SApple OSS Distributions const uint8_t *cdhash);
303*43a90889SApple OSS Distributions
304*43a90889SApple OSS Distributions /**
305*43a90889SApple OSS Distributions * Match a CDHash against the currently stored CDHash for the compilation service.
306*43a90889SApple OSS Distributions */
307*43a90889SApple OSS Distributions bool
308*43a90889SApple OSS Distributions match_compilation_service_cdhash(
309*43a90889SApple OSS Distributions const uint8_t *cdhash);
310*43a90889SApple OSS Distributions
311*43a90889SApple OSS Distributions /**
312*43a90889SApple OSS Distributions * Set the local signing key which is currently being used on the system. This key is used
313*43a90889SApple OSS Distributions * to validate any signatures which are signed on device.
314*43a90889SApple OSS Distributions */
315*43a90889SApple OSS Distributions void
316*43a90889SApple OSS Distributions set_local_signing_public_key(
317*43a90889SApple OSS Distributions const uint8_t public_key[XNU_LOCAL_SIGNING_KEY_SIZE]);
318*43a90889SApple OSS Distributions
319*43a90889SApple OSS Distributions /**
320*43a90889SApple OSS Distributions * Get the local signing key which is currently being used on the system. This API is
321*43a90889SApple OSS Distributions * mostly used by kernel extensions which validate code signatures on the platform.
322*43a90889SApple OSS Distributions */
323*43a90889SApple OSS Distributions uint8_t*
324*43a90889SApple OSS Distributions get_local_signing_public_key(void);
325*43a90889SApple OSS Distributions
326*43a90889SApple OSS Distributions /**
327*43a90889SApple OSS Distributions * Unrestrict a particular CDHash for local signing, allowing it to be loaded and run on
328*43a90889SApple OSS Distributions * the system. This is only required to be done for main binaries, since libraries do not
329*43a90889SApple OSS Distributions * need to be unrestricted.
330*43a90889SApple OSS Distributions */
331*43a90889SApple OSS Distributions void
332*43a90889SApple OSS Distributions unrestrict_local_signing_cdhash(
333*43a90889SApple OSS Distributions const uint8_t *cdhash);
334*43a90889SApple OSS Distributions
335*43a90889SApple OSS Distributions /**
336*43a90889SApple OSS Distributions * The kernel or the monitor environments allocate some data which is used by AppleImage4
337*43a90889SApple OSS Distributions * for storing critical system information such as nonces. AppleImage4 uses this API to
338*43a90889SApple OSS Distributions * get access to this data while abstracting the implementation underneath.
339*43a90889SApple OSS Distributions */
340*43a90889SApple OSS Distributions void*
341*43a90889SApple OSS Distributions kernel_image4_storage_data(
342*43a90889SApple OSS Distributions size_t *allocated_size);
343*43a90889SApple OSS Distributions
344*43a90889SApple OSS Distributions /**
345*43a90889SApple OSS Distributions * AppleImage4 uses this API to store the specified nonce into the nonce storage. This API
346*43a90889SApple OSS Distributions * abstracts away the kernel or monitor implementation used.
347*43a90889SApple OSS Distributions */
348*43a90889SApple OSS Distributions void
349*43a90889SApple OSS Distributions kernel_image4_set_nonce(
350*43a90889SApple OSS Distributions const img4_nonce_domain_index_t ndi,
351*43a90889SApple OSS Distributions const img4_nonce_t *nonce);
352*43a90889SApple OSS Distributions
353*43a90889SApple OSS Distributions /**
354*43a90889SApple OSS Distributions * AppleImage4 uses this API to roll a specified nonce on the next boot. This API abstracts
355*43a90889SApple OSS Distributions * away the kernel or monitor implementation used.
356*43a90889SApple OSS Distributions */
357*43a90889SApple OSS Distributions void
358*43a90889SApple OSS Distributions kernel_image4_roll_nonce(
359*43a90889SApple OSS Distributions const img4_nonce_domain_index_t ndi);
360*43a90889SApple OSS Distributions
361*43a90889SApple OSS Distributions /**
362*43a90889SApple OSS Distributions * AppleImage4 uses this API to copy a specified nonce from the nonce storage. This API
363*43a90889SApple OSS Distributions * abstracts away the kernel or monitor implementation used.
364*43a90889SApple OSS Distributions *
365*43a90889SApple OSS Distributions * We need this API since the nonces use a lock to protect against concurrency, and the
366*43a90889SApple OSS Distributions * lock can only be taken within the monitor environment, if any.
367*43a90889SApple OSS Distributions */
368*43a90889SApple OSS Distributions errno_t
369*43a90889SApple OSS Distributions kernel_image4_copy_nonce(
370*43a90889SApple OSS Distributions const img4_nonce_domain_index_t ndi,
371*43a90889SApple OSS Distributions img4_nonce_t *nonce_out);
372*43a90889SApple OSS Distributions
373*43a90889SApple OSS Distributions /**
374*43a90889SApple OSS Distributions * AppleImage4 uses this API to perform object execution on a particular object type. This
375*43a90889SApple OSS Distributions * API abstracts away the kernel or monitor implementation used.
376*43a90889SApple OSS Distributions */
377*43a90889SApple OSS Distributions errno_t
378*43a90889SApple OSS Distributions kernel_image4_execute_object(
379*43a90889SApple OSS Distributions img4_runtime_object_spec_index_t obj_spec_index,
380*43a90889SApple OSS Distributions const img4_buff_t *payload,
381*43a90889SApple OSS Distributions const img4_buff_t *manifest);
382*43a90889SApple OSS Distributions
383*43a90889SApple OSS Distributions /**
384*43a90889SApple OSS Distributions * AppleImage4 uses this API to copy the contents of an executed object. This API abstracts
385*43a90889SApple OSS Distributions * away the kernel or monitor implementation used.
386*43a90889SApple OSS Distributions */
387*43a90889SApple OSS Distributions errno_t
388*43a90889SApple OSS Distributions kernel_image4_copy_object(
389*43a90889SApple OSS Distributions img4_runtime_object_spec_index_t obj_spec_index,
390*43a90889SApple OSS Distributions vm_address_t object_out,
391*43a90889SApple OSS Distributions size_t *object_length);
392*43a90889SApple OSS Distributions
393*43a90889SApple OSS Distributions /**
394*43a90889SApple OSS Distributions * AppleImage4 uses this API to get a pointer to the structure which is used for exporting
395*43a90889SApple OSS Distributions * monitor locked down data to the rest of the system.
396*43a90889SApple OSS Distributions */
397*43a90889SApple OSS Distributions const void*
398*43a90889SApple OSS Distributions kernel_image4_get_monitor_exports(void);
399*43a90889SApple OSS Distributions
400*43a90889SApple OSS Distributions /**
401*43a90889SApple OSS Distributions * AppleImage4 uses this API to let the monitor environment know the release type for the
402*43a90889SApple OSS Distributions * the current boot. Under some circumstances, the monitor isn't able to gauge this on its
403*43a90889SApple OSS Distributions * own.
404*43a90889SApple OSS Distributions */
405*43a90889SApple OSS Distributions errno_t
406*43a90889SApple OSS Distributions kernel_image4_set_release_type(
407*43a90889SApple OSS Distributions const char *release_type);
408*43a90889SApple OSS Distributions
409*43a90889SApple OSS Distributions /**
410*43a90889SApple OSS Distributions * AppleImage4 uses this API to let the monitor know when a nonce domain is shadowing the
411*43a90889SApple OSS Distributions * AP boot nonce. Since this information is queried from the NVRAM, the monitor cant know
412*43a90889SApple OSS Distributions * this on its own.
413*43a90889SApple OSS Distributions */
414*43a90889SApple OSS Distributions errno_t
415*43a90889SApple OSS Distributions kernel_image4_set_bnch_shadow(
416*43a90889SApple OSS Distributions const img4_nonce_domain_index_t ndi);
417*43a90889SApple OSS Distributions
418*43a90889SApple OSS Distributions /**
419*43a90889SApple OSS Distributions * AppleImage4 uses this API to trap into the code signing monitor on the platform for
420*43a90889SApple OSS Distributions * the image4 dispatch routines. A single entry point is multiplexed into a whole dispatch
421*43a90889SApple OSS Distributions * table.
422*43a90889SApple OSS Distributions */
423*43a90889SApple OSS Distributions errno_t
424*43a90889SApple OSS Distributions kernel_image4_monitor_trap(
425*43a90889SApple OSS Distributions image4_cs_trap_t selector,
426*43a90889SApple OSS Distributions const void *input_data,
427*43a90889SApple OSS Distributions size_t input_size,
428*43a90889SApple OSS Distributions void *output_data,
429*43a90889SApple OSS Distributions size_t *output_size);
430*43a90889SApple OSS Distributions
431*43a90889SApple OSS Distributions /**
432*43a90889SApple OSS Distributions * AMFI uses this API to obtain the OSEntitlements object which is associated with the
433*43a90889SApple OSS Distributions * main binary mapped in for a process.
434*43a90889SApple OSS Distributions *
435*43a90889SApple OSS Distributions * This API is considered safer for resolving the OSEntitlements than through the cred
436*43a90889SApple OSS Distributions * structure on the process because the system maintains a strong binding in the linkage
437*43a90889SApple OSS Distributions * chain from the process structure through the pmap, which ultimately contains the
438*43a90889SApple OSS Distributions * code signing monitors address space information for the process.
439*43a90889SApple OSS Distributions */
440*43a90889SApple OSS Distributions kern_return_t
441*43a90889SApple OSS Distributions csm_resolve_os_entitlements_from_proc(
442*43a90889SApple OSS Distributions const proc_t process,
443*43a90889SApple OSS Distributions const void **os_entitlements);
444*43a90889SApple OSS Distributions
445*43a90889SApple OSS Distributions /**
446*43a90889SApple OSS Distributions * Wrapper function that calls csm_get_trust_level_kdp if there is a CODE_SIGNING_MONITOR
447*43a90889SApple OSS Distributions * or returns KERN_NOT_SUPPORTED if there isn't one.
448*43a90889SApple OSS Distributions */
449*43a90889SApple OSS Distributions kern_return_t
450*43a90889SApple OSS Distributions get_trust_level_kdp(
451*43a90889SApple OSS Distributions pmap_t pmap,
452*43a90889SApple OSS Distributions uint32_t *trust_level);
453*43a90889SApple OSS Distributions
454*43a90889SApple OSS Distributions /**
455*43a90889SApple OSS Distributions * Wrapper function that calls csm_get_jit_address_range_kdp if there is a CODE_SIGNING_MONITOR
456*43a90889SApple OSS Distributions * or returns KERN_NOT_SUPPORTED if there isn't one.
457*43a90889SApple OSS Distributions */
458*43a90889SApple OSS Distributions kern_return_t
459*43a90889SApple OSS Distributions get_jit_address_range_kdp(
460*43a90889SApple OSS Distributions pmap_t pmap,
461*43a90889SApple OSS Distributions uintptr_t *jit_region_start,
462*43a90889SApple OSS Distributions uintptr_t *jit_region_end);
463*43a90889SApple OSS Distributions
464*43a90889SApple OSS Distributions /**
465*43a90889SApple OSS Distributions * Check whether a particular proc is marked as debugged or not. For many use cases, this
466*43a90889SApple OSS Distributions * is a stronger check than simply checking for the enablement of developer mode since
467*43a90889SApple OSS Distributions * an address space can only be marked as debugged if developer mode is already enabled.
468*43a90889SApple OSS Distributions *
469*43a90889SApple OSS Distributions * When the system has a code signing monitor, this function acquires the state of the
470*43a90889SApple OSS Distributions * address space from the monitor.
471*43a90889SApple OSS Distributions */
472*43a90889SApple OSS Distributions kern_return_t
473*43a90889SApple OSS Distributions address_space_debugged_state(
474*43a90889SApple OSS Distributions const proc_t process);
475*43a90889SApple OSS Distributions
476*43a90889SApple OSS Distributions /**
477*43a90889SApple OSS Distributions * Implements the same policy as address_space_debugged_state(), but returns
478*43a90889SApple OSS Distributions * with boolean semantics.
479*43a90889SApple OSS Distributions */
480*43a90889SApple OSS Distributions bool is_address_space_debugged(
481*43a90889SApple OSS Distributions const proc_t process);
482*43a90889SApple OSS Distributions
483*43a90889SApple OSS Distributions #if CODE_SIGNING_MONITOR
484*43a90889SApple OSS Distributions
485*43a90889SApple OSS Distributions struct vm_map_entry;
486*43a90889SApple OSS Distributions
487*43a90889SApple OSS Distributions /**
488*43a90889SApple OSS Distributions * Check to see if the monitor is currently enforcing code signing protections or
489*43a90889SApple OSS Distributions * not. Even when this is disabled, certains artifacts are still protected by the
490*43a90889SApple OSS Distributions * monitor environment.
491*43a90889SApple OSS Distributions */
492*43a90889SApple OSS Distributions bool
493*43a90889SApple OSS Distributions csm_enabled(void);
494*43a90889SApple OSS Distributions
495*43a90889SApple OSS Distributions /**
496*43a90889SApple OSS Distributions * Check and inform the code signing monitor that the system is entering lockdown mode.
497*43a90889SApple OSS Distributions * The code signing monitor then enforces policy based on this state. As part of this,
498*43a90889SApple OSS Distributions * we also update the code signing configuration of the system.
499*43a90889SApple OSS Distributions */
500*43a90889SApple OSS Distributions void
501*43a90889SApple OSS Distributions csm_check_lockdown_mode(void);
502*43a90889SApple OSS Distributions
503*43a90889SApple OSS Distributions /**
504*43a90889SApple OSS Distributions * When a task incurs an unresolvable page fault with execute permissions, and is not
505*43a90889SApple OSS Distributions * being debugged, the task should receive a SIGKILL. This should only happen if the
506*43a90889SApple OSS Distributions * task isn't actively being debugged. This function abstracts all these details.
507*43a90889SApple OSS Distributions */
508*43a90889SApple OSS Distributions void
509*43a90889SApple OSS Distributions csm_code_signing_violation(
510*43a90889SApple OSS Distributions proc_t proc,
511*43a90889SApple OSS Distributions vm_offset_t addr);
512*43a90889SApple OSS Distributions
513*43a90889SApple OSS Distributions /**
514*43a90889SApple OSS Distributions * This function is used to initialize the state of the locks for managing provisioning
515*43a90889SApple OSS Distributions * profiles on the system. It should be called by the kernel bootstrap thread during the
516*43a90889SApple OSS Distributions * early kernel initialization.
517*43a90889SApple OSS Distributions */
518*43a90889SApple OSS Distributions void
519*43a90889SApple OSS Distributions csm_initialize_provisioning_profiles(void);
520*43a90889SApple OSS Distributions
521*43a90889SApple OSS Distributions /**
522*43a90889SApple OSS Distributions * Register a provisioning profile with the monitor environment available on the
523*43a90889SApple OSS Distributions * system. This function will allocate its own memory for managing the profile and
524*43a90889SApple OSS Distributions * the caller is allowed to free their own allocation.
525*43a90889SApple OSS Distributions */
526*43a90889SApple OSS Distributions kern_return_t
527*43a90889SApple OSS Distributions csm_register_provisioning_profile(
528*43a90889SApple OSS Distributions const uuid_t profile_uuid,
529*43a90889SApple OSS Distributions const void *profile,
530*43a90889SApple OSS Distributions const size_t profile_size);
531*43a90889SApple OSS Distributions
532*43a90889SApple OSS Distributions /**
533*43a90889SApple OSS Distributions * Attempt to trust a provisioning profile with the monitor environment available on
534*43a90889SApple OSS Distributions * the system. The provided signature will be passed to the monitor as is, and the
535*43a90889SApple OSS Distributions * caller is responsible for de-allocation of the data, if required.
536*43a90889SApple OSS Distributions */
537*43a90889SApple OSS Distributions kern_return_t
538*43a90889SApple OSS Distributions csm_trust_provisioning_profile(
539*43a90889SApple OSS Distributions const uuid_t profile_uuid,
540*43a90889SApple OSS Distributions const void *sig_data,
541*43a90889SApple OSS Distributions size_t sig_size);
542*43a90889SApple OSS Distributions
543*43a90889SApple OSS Distributions /**
544*43a90889SApple OSS Distributions * Associate a registered profile with a code signature object which is managed by
545*43a90889SApple OSS Distributions * the monitor environment. This incrementes the reference count on the profile object
546*43a90889SApple OSS Distributions * managed by the monitor, preventing the profile from being unregistered.
547*43a90889SApple OSS Distributions */
548*43a90889SApple OSS Distributions kern_return_t
549*43a90889SApple OSS Distributions csm_associate_provisioning_profile(
550*43a90889SApple OSS Distributions void *monitor_sig_obj,
551*43a90889SApple OSS Distributions const uuid_t profile_uuid);
552*43a90889SApple OSS Distributions
553*43a90889SApple OSS Distributions /**
554*43a90889SApple OSS Distributions * Disassociate an associated profile with a code signature object which is managed by
555*43a90889SApple OSS Distributions * the monitor environment. This decrements the refernce count on the profile object
556*43a90889SApple OSS Distributions * managed by the monitor, potentially allowing it to be unregistered in case no other
557*43a90889SApple OSS Distributions * signatures hold a reference count to it.
558*43a90889SApple OSS Distributions */
559*43a90889SApple OSS Distributions kern_return_t
560*43a90889SApple OSS Distributions csm_disassociate_provisioning_profile(
561*43a90889SApple OSS Distributions void *monitor_sig_obj);
562*43a90889SApple OSS Distributions
563*43a90889SApple OSS Distributions /**
564*43a90889SApple OSS Distributions * Trigger the provisioning profile garbage collector to go through each registered
565*43a90889SApple OSS Distributions * profile on the system and unregister it in case it isn't being used.
566*43a90889SApple OSS Distributions */
567*43a90889SApple OSS Distributions void
568*43a90889SApple OSS Distributions csm_free_provisioning_profiles(void);
569*43a90889SApple OSS Distributions
570*43a90889SApple OSS Distributions /**
571*43a90889SApple OSS Distributions * Acquire the largest size for a code signature which the monitor will allocate on
572*43a90889SApple OSS Distributions * its own. Anything larger than this size needs to be page-allocated and aligned and
573*43a90889SApple OSS Distributions * will be locked down by the monitor upon registration.
574*43a90889SApple OSS Distributions */
575*43a90889SApple OSS Distributions vm_size_t
576*43a90889SApple OSS Distributions csm_signature_size_limit(void);
577*43a90889SApple OSS Distributions
578*43a90889SApple OSS Distributions /**
579*43a90889SApple OSS Distributions * Register a code signature with the monitor environment. The monitor will either
580*43a90889SApple OSS Distributions * allocate its own memory for the code signature, or it will lockdown the memory which
581*43a90889SApple OSS Distributions * is given to it. In either case, the signature will be read-only for the kernel.
582*43a90889SApple OSS Distributions *
583*43a90889SApple OSS Distributions * If the monitor doesn't enforce code signing, then this function will return the
584*43a90889SApple OSS Distributions * KERN_SUCCESS condition.
585*43a90889SApple OSS Distributions */
586*43a90889SApple OSS Distributions kern_return_t
587*43a90889SApple OSS Distributions csm_register_code_signature(
588*43a90889SApple OSS Distributions const vm_address_t signature_addr,
589*43a90889SApple OSS Distributions const vm_size_t signature_size,
590*43a90889SApple OSS Distributions const vm_offset_t code_directory_offset,
591*43a90889SApple OSS Distributions const char *signature_path,
592*43a90889SApple OSS Distributions void **monitor_sig_obj,
593*43a90889SApple OSS Distributions vm_address_t *monitor_signature_addr);
594*43a90889SApple OSS Distributions
595*43a90889SApple OSS Distributions /**
596*43a90889SApple OSS Distributions * Unregister a code signature previously registered with the monitor environment.
597*43a90889SApple OSS Distributions * This will free (or unlock) the signature memory held by the monitor.
598*43a90889SApple OSS Distributions *
599*43a90889SApple OSS Distributions * If the monitor doesn't enforce code signing, then this function will return the
600*43a90889SApple OSS Distributions * error KERN_NOT_SUPPORTED.
601*43a90889SApple OSS Distributions */
602*43a90889SApple OSS Distributions kern_return_t
603*43a90889SApple OSS Distributions csm_unregister_code_signature(
604*43a90889SApple OSS Distributions void *monitor_sig_obj);
605*43a90889SApple OSS Distributions
606*43a90889SApple OSS Distributions /**
607*43a90889SApple OSS Distributions * Verify a code signature previously registered with the monitor. After verification,
608*43a90889SApple OSS Distributions * the signature can be used for making code signature associations with address spaces.
609*43a90889SApple OSS Distributions *
610*43a90889SApple OSS Distributions * If the monitor doesn't enforce code signing, then this function will return the
611*43a90889SApple OSS Distributions * KERN_SUCCESS condition.
612*43a90889SApple OSS Distributions */
613*43a90889SApple OSS Distributions kern_return_t
614*43a90889SApple OSS Distributions csm_verify_code_signature(
615*43a90889SApple OSS Distributions void *monitor_sig_obj,
616*43a90889SApple OSS Distributions uint32_t *trust_level);
617*43a90889SApple OSS Distributions
618*43a90889SApple OSS Distributions /**
619*43a90889SApple OSS Distributions * Perform 2nd stage reconstitution through the monitor. This unlocks any unused parts
620*43a90889SApple OSS Distributions * of the code signature, which can then be freed by the kernel. This isn't strictly
621*43a90889SApple OSS Distributions * required, but it helps in conserving system memory.
622*43a90889SApple OSS Distributions *
623*43a90889SApple OSS Distributions * If the monitor doesn't enforce code signing, then this function will return the
624*43a90889SApple OSS Distributions * error KERN_NOT_SUPPORTED.
625*43a90889SApple OSS Distributions */
626*43a90889SApple OSS Distributions kern_return_t
627*43a90889SApple OSS Distributions csm_reconstitute_code_signature(
628*43a90889SApple OSS Distributions void *monitor_sig_obj,
629*43a90889SApple OSS Distributions vm_address_t *unneeded_addr,
630*43a90889SApple OSS Distributions vm_size_t *unneeded_size);
631*43a90889SApple OSS Distributions
632*43a90889SApple OSS Distributions /**
633*43a90889SApple OSS Distributions * Associate a code signature with an address space for a specified region with the
634*43a90889SApple OSS Distributions * monitor environment. The code signature can only be associated if it has been
635*43a90889SApple OSS Distributions * verified before.
636*43a90889SApple OSS Distributions */
637*43a90889SApple OSS Distributions kern_return_t
638*43a90889SApple OSS Distributions csm_associate_code_signature(
639*43a90889SApple OSS Distributions pmap_t pmap,
640*43a90889SApple OSS Distributions void *monitor_sig_obj,
641*43a90889SApple OSS Distributions const vm_address_t region_addr,
642*43a90889SApple OSS Distributions const vm_size_t region_size,
643*43a90889SApple OSS Distributions const vm_offset_t region_offset);
644*43a90889SApple OSS Distributions
645*43a90889SApple OSS Distributions /**
646*43a90889SApple OSS Distributions * Validate that an address space will allow mapping in a JIT region within the monitor
647*43a90889SApple OSS Distributions * environment. An address space can only have a single JIT region, and only when it
648*43a90889SApple OSS Distributions * has the appropriate JIT entitlement.
649*43a90889SApple OSS Distributions */
650*43a90889SApple OSS Distributions kern_return_t
651*43a90889SApple OSS Distributions csm_allow_jit_region(
652*43a90889SApple OSS Distributions pmap_t pmap);
653*43a90889SApple OSS Distributions
654*43a90889SApple OSS Distributions /**
655*43a90889SApple OSS Distributions * Associate a JIT region with an address space in the monitor environment. An address
656*43a90889SApple OSS Distributions * space can only have a JIT region if it has the appropriate JIT entitlement.
657*43a90889SApple OSS Distributions */
658*43a90889SApple OSS Distributions kern_return_t
659*43a90889SApple OSS Distributions csm_associate_jit_region(
660*43a90889SApple OSS Distributions pmap_t pmap,
661*43a90889SApple OSS Distributions const vm_address_t region_addr,
662*43a90889SApple OSS Distributions const vm_size_t region_size);
663*43a90889SApple OSS Distributions
664*43a90889SApple OSS Distributions /**
665*43a90889SApple OSS Distributions * Associate a debug region with an address space in the monitor environment. An address
666*43a90889SApple OSS Distributions * space can only have a debug region if it is currently being debugged.
667*43a90889SApple OSS Distributions */
668*43a90889SApple OSS Distributions kern_return_t
669*43a90889SApple OSS Distributions csm_associate_debug_region(
670*43a90889SApple OSS Distributions pmap_t pmap,
671*43a90889SApple OSS Distributions const vm_address_t region_addr,
672*43a90889SApple OSS Distributions const vm_size_t region_size);
673*43a90889SApple OSS Distributions
674*43a90889SApple OSS Distributions /**
675*43a90889SApple OSS Distributions * Call out to the monitor to inform it that the address space needs to be debugged. The
676*43a90889SApple OSS Distributions * monitor will only allow the address space to be debugged if it has the appropriate
677*43a90889SApple OSS Distributions * entitlements.
678*43a90889SApple OSS Distributions */
679*43a90889SApple OSS Distributions kern_return_t
680*43a90889SApple OSS Distributions csm_allow_invalid_code(
681*43a90889SApple OSS Distributions pmap_t pmap);
682*43a90889SApple OSS Distributions
683*43a90889SApple OSS Distributions /**
684*43a90889SApple OSS Distributions * Acquire the trust level which is placed on the address space within the monitor
685*43a90889SApple OSS Distributions * environment. There is no clear mapping of the 32-bit integer returned to the actual
686*43a90889SApple OSS Distributions * trust level because different code signing monitors use different trust levels.
687*43a90889SApple OSS Distributions *
688*43a90889SApple OSS Distributions * The code signing monitor itself does not depend on this value and instead uses
689*43a90889SApple OSS Distributions * other, more secure methods of checking for trust. In general, we only expect this
690*43a90889SApple OSS Distributions * function to be used for debugging purposes.
691*43a90889SApple OSS Distributions *
692*43a90889SApple OSS Distributions * This function should be careful that any code paths within it do not mutate the
693*43a90889SApple OSS Distributions * state of the system, and as a result, no code paths here should attempt to take
694*43a90889SApple OSS Distributions * locks of any kind.
695*43a90889SApple OSS Distributions */
696*43a90889SApple OSS Distributions kern_return_t
697*43a90889SApple OSS Distributions csm_get_trust_level_kdp(
698*43a90889SApple OSS Distributions pmap_t pmap,
699*43a90889SApple OSS Distributions uint32_t *trust_level);
700*43a90889SApple OSS Distributions
701*43a90889SApple OSS Distributions /**
702*43a90889SApple OSS Distributions * Acquire the address range for the JIT region for this address space.
703*43a90889SApple OSS Distributions *
704*43a90889SApple OSS Distributions * We expect this function to only be used for debugging purposes, and not for
705*43a90889SApple OSS Distributions * enforcing any security policies.
706*43a90889SApple OSS Distributions * This function should be careful that any code paths within it do not mutate the
707*43a90889SApple OSS Distributions * state of the system, and as a result, no code paths here should attempt to take
708*43a90889SApple OSS Distributions * locks of any kind.
709*43a90889SApple OSS Distributions * KERN_SUCCESS is returned if the address space has JIT capability and an address range
710*43a90889SApple OSS Distributions * was returned in the output arguments.
711*43a90889SApple OSS Distributions * KERN_NOT_FOUND is returned if the address space does not have JIT, or on systems where
712*43a90889SApple OSS Distributions * the code signing monitor does not track the JIT range.
713*43a90889SApple OSS Distributions * KERN_NOT_SUPPORTED is returned for environments where this call is not supported.
714*43a90889SApple OSS Distributions */
715*43a90889SApple OSS Distributions kern_return_t
716*43a90889SApple OSS Distributions csm_get_jit_address_range_kdp(
717*43a90889SApple OSS Distributions pmap_t pmap,
718*43a90889SApple OSS Distributions uintptr_t *jit_region_start,
719*43a90889SApple OSS Distributions uintptr_t *jit_region_end);
720*43a90889SApple OSS Distributions
721*43a90889SApple OSS Distributions /**
722*43a90889SApple OSS Distributions * Certain address spaces are exempt from code signing enforcement. This function can be
723*43a90889SApple OSS Distributions * used to check if the specified address space is such or not.
724*43a90889SApple OSS Distributions */
725*43a90889SApple OSS Distributions kern_return_t
726*43a90889SApple OSS Distributions csm_address_space_exempt(
727*43a90889SApple OSS Distributions const pmap_t pmap);
728*43a90889SApple OSS Distributions
729*43a90889SApple OSS Distributions /**
730*43a90889SApple OSS Distributions * Instruct the monitor that an address space is about to be forked. The monitor can then
731*43a90889SApple OSS Distributions * do whatever it needs to do in order to prepare for the fork.
732*43a90889SApple OSS Distributions */
733*43a90889SApple OSS Distributions kern_return_t
734*43a90889SApple OSS Distributions csm_fork_prepare(
735*43a90889SApple OSS Distributions pmap_t old_pmap,
736*43a90889SApple OSS Distributions pmap_t new_pmap);
737*43a90889SApple OSS Distributions
738*43a90889SApple OSS Distributions /**
739*43a90889SApple OSS Distributions * Get the signing identifier which is embedded within the code directory using the
740*43a90889SApple OSS Distributions * code signing monitor's abstract signature object.
741*43a90889SApple OSS Distributions */
742*43a90889SApple OSS Distributions kern_return_t
743*43a90889SApple OSS Distributions csm_acquire_signing_identifier(
744*43a90889SApple OSS Distributions const void *monitor_sig_obj,
745*43a90889SApple OSS Distributions const char **signing_id);
746*43a90889SApple OSS Distributions
747*43a90889SApple OSS Distributions /**
748*43a90889SApple OSS Distributions * This API to associate an OSEntitlements objects with the code signing monitor's
749*43a90889SApple OSS Distributions * signature object. This binding is useful as it can be used to resolve the entitlement
750*43a90889SApple OSS Distributions * object which is used by the kernel for performing queries.
751*43a90889SApple OSS Distributions */
752*43a90889SApple OSS Distributions kern_return_t
753*43a90889SApple OSS Distributions csm_associate_os_entitlements(
754*43a90889SApple OSS Distributions void *monitor_sig_obj,
755*43a90889SApple OSS Distributions const void *os_entitlements);
756*43a90889SApple OSS Distributions
757*43a90889SApple OSS Distributions /**
758*43a90889SApple OSS Distributions * Accelerate the CoreEntitlements context within the code signing monitor's memory
759*43a90889SApple OSS Distributions * in order to speed up all queries for entitlements going through CoreEntitlements.
760*43a90889SApple OSS Distributions */
761*43a90889SApple OSS Distributions kern_return_t
762*43a90889SApple OSS Distributions csm_accelerate_entitlements(
763*43a90889SApple OSS Distributions void *monitor_sig_obj,
764*43a90889SApple OSS Distributions CEQueryContext_t *ce_ctx);
765*43a90889SApple OSS Distributions
766*43a90889SApple OSS Distributions kern_return_t
767*43a90889SApple OSS Distributions vm_map_entry_cs_associate(
768*43a90889SApple OSS Distributions vm_map_t map,
769*43a90889SApple OSS Distributions struct vm_map_entry *entry,
770*43a90889SApple OSS Distributions vm_map_kernel_flags_t vmk_flags);
771*43a90889SApple OSS Distributions
772*43a90889SApple OSS Distributions kern_return_t
773*43a90889SApple OSS Distributions cs_associate_blob_with_mapping(
774*43a90889SApple OSS Distributions void *pmap,
775*43a90889SApple OSS Distributions vm_map_offset_t start,
776*43a90889SApple OSS Distributions vm_map_size_t size,
777*43a90889SApple OSS Distributions vm_object_offset_t offset,
778*43a90889SApple OSS Distributions void *blobs_p);
779*43a90889SApple OSS Distributions
780*43a90889SApple OSS Distributions #endif /* CODE_SIGNING_MONITOR */
781*43a90889SApple OSS Distributions
782*43a90889SApple OSS Distributions #endif /* KERNEL_PRIVATE */
783*43a90889SApple OSS Distributions
784*43a90889SApple OSS Distributions #pragma GCC diagnostic pop
785*43a90889SApple OSS Distributions
786*43a90889SApple OSS Distributions __END_DECLS
787*43a90889SApple OSS Distributions #endif /* _SYS_CODE_SIGNING_H_ */
788