xref: /xnu-8792.41.9/bsd/sys/code_signing.h (revision 5c2921b07a2480ab43ec66f5b9e41cb872bc554f)
1*5c2921b0SApple OSS Distributions /*
2*5c2921b0SApple OSS Distributions  * Copyright (c) 2022 Apple Computer, Inc. All rights reserved.
3*5c2921b0SApple OSS Distributions  *
4*5c2921b0SApple OSS Distributions  * @APPLE_LICENSE_HEADER_START@
5*5c2921b0SApple OSS Distributions  *
6*5c2921b0SApple OSS Distributions  * The contents of this file constitute Original Code as defined in and
7*5c2921b0SApple OSS Distributions  * are subject to the Apple Public Source License Version 1.1 (the
8*5c2921b0SApple OSS Distributions  * "License").  You may not use this file except in compliance with the
9*5c2921b0SApple OSS Distributions  * License.  Please obtain a copy of the License at
10*5c2921b0SApple OSS Distributions  * http://www.apple.com/publicsource and read it before using this file.
11*5c2921b0SApple OSS Distributions  *
12*5c2921b0SApple OSS Distributions  * This Original Code and all software distributed under the License are
13*5c2921b0SApple OSS Distributions  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14*5c2921b0SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15*5c2921b0SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16*5c2921b0SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17*5c2921b0SApple OSS Distributions  * License for the specific language governing rights and limitations
18*5c2921b0SApple OSS Distributions  * under the License.
19*5c2921b0SApple OSS Distributions  *
20*5c2921b0SApple OSS Distributions  * @APPLE_LICENSE_HEADER_END@
21*5c2921b0SApple OSS Distributions  */
22*5c2921b0SApple OSS Distributions 
23*5c2921b0SApple OSS Distributions #ifndef _SYS_CODE_SIGNING_H_
24*5c2921b0SApple OSS Distributions #define _SYS_CODE_SIGNING_H_
25*5c2921b0SApple OSS Distributions 
26*5c2921b0SApple OSS Distributions #include <sys/cdefs.h>
27*5c2921b0SApple OSS Distributions __BEGIN_DECLS
28*5c2921b0SApple OSS Distributions 
29*5c2921b0SApple OSS Distributions #ifdef KERNEL_PRIVATE
30*5c2921b0SApple OSS Distributions /* All definitions for XNU and kernel extensions */
31*5c2921b0SApple OSS Distributions 
32*5c2921b0SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE
33*5c2921b0SApple OSS Distributions /* All definitions for XNU only */
34*5c2921b0SApple OSS Distributions 
35*5c2921b0SApple OSS Distributions #include <vm/pmap_cs.h>
36*5c2921b0SApple OSS Distributions 
37*5c2921b0SApple OSS Distributions #if   PMAP_CS_PPL_MONITOR
38*5c2921b0SApple OSS Distributions #define CODE_SIGNING_MONITOR 1
39*5c2921b0SApple OSS Distributions #else
40*5c2921b0SApple OSS Distributions #define CODE_SIGNING_MONITOR 0
41*5c2921b0SApple OSS Distributions #endif
42*5c2921b0SApple OSS Distributions 
43*5c2921b0SApple OSS Distributions #if CODE_SIGNING_MONITOR
44*5c2921b0SApple OSS Distributions /* All definitions which are only required for monitor-specific code */
45*5c2921b0SApple OSS Distributions 
46*5c2921b0SApple OSS Distributions /**
47*5c2921b0SApple OSS Distributions  * This function is used to initialize the state of the locks for managing provisioning
48*5c2921b0SApple OSS Distributions  * profiles on the system. It should be called by the kernel bootstrap thread during the
49*5c2921b0SApple OSS Distributions  * early kernel initialization.
50*5c2921b0SApple OSS Distributions  */
51*5c2921b0SApple OSS Distributions void
52*5c2921b0SApple OSS Distributions initialize_provisioning_profiles(void);
53*5c2921b0SApple OSS Distributions 
54*5c2921b0SApple OSS Distributions /**
55*5c2921b0SApple OSS Distributions  * Register a provisioning profile with the monitor environment available on the
56*5c2921b0SApple OSS Distributions  * system. This function will allocate its own memory for managing the profile and
57*5c2921b0SApple OSS Distributions  * the caller is allowed to free their own allocation.
58*5c2921b0SApple OSS Distributions  */
59*5c2921b0SApple OSS Distributions kern_return_t
60*5c2921b0SApple OSS Distributions register_provisioning_profile(
61*5c2921b0SApple OSS Distributions 	const uuid_t profile_uuid,
62*5c2921b0SApple OSS Distributions 	const void *profile, const size_t profile_size);
63*5c2921b0SApple OSS Distributions 
64*5c2921b0SApple OSS Distributions /**
65*5c2921b0SApple OSS Distributions  * Associate a registered profile with a code signature object which is managed by
66*5c2921b0SApple OSS Distributions  * the monitor environment. This incrementes the reference count on the profile object
67*5c2921b0SApple OSS Distributions  * managed by the monitor, preventing the profile from being unregistered.
68*5c2921b0SApple OSS Distributions  */
69*5c2921b0SApple OSS Distributions kern_return_t
70*5c2921b0SApple OSS Distributions associate_provisioning_profile(
71*5c2921b0SApple OSS Distributions 	void *monitor_sig_obj,
72*5c2921b0SApple OSS Distributions 	const uuid_t profile_uuid);
73*5c2921b0SApple OSS Distributions 
74*5c2921b0SApple OSS Distributions /**
75*5c2921b0SApple OSS Distributions  * Disassociate an associated profile with a code signature object which is managed by
76*5c2921b0SApple OSS Distributions  * the monitor environment. This decrements the refernce count on the profile object
77*5c2921b0SApple OSS Distributions  * managed by the monitor, potentially allowing it to be unregistered in case no other
78*5c2921b0SApple OSS Distributions  * signatures hold a reference count to it.
79*5c2921b0SApple OSS Distributions  */
80*5c2921b0SApple OSS Distributions kern_return_t
81*5c2921b0SApple OSS Distributions disassociate_provisioning_profile(
82*5c2921b0SApple OSS Distributions 	void *monitor_sig_obj);
83*5c2921b0SApple OSS Distributions 
84*5c2921b0SApple OSS Distributions /**
85*5c2921b0SApple OSS Distributions  * Trigger the provisioning profile garbage collector to go through each registered
86*5c2921b0SApple OSS Distributions  * profile on the system and unregister it in case it isn't being used.
87*5c2921b0SApple OSS Distributions  */
88*5c2921b0SApple OSS Distributions void
89*5c2921b0SApple OSS Distributions free_provisioning_profiles(void);
90*5c2921b0SApple OSS Distributions 
91*5c2921b0SApple OSS Distributions #endif /* CODE_SIGNING_MONITOR */
92*5c2921b0SApple OSS Distributions 
93*5c2921b0SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
94*5c2921b0SApple OSS Distributions 
95*5c2921b0SApple OSS Distributions #include <mach/boolean.h>
96*5c2921b0SApple OSS Distributions #include <mach/kern_return.h>
97*5c2921b0SApple OSS Distributions 
98*5c2921b0SApple OSS Distributions /* Availability macros for KPI functions */
99*5c2921b0SApple OSS Distributions #define XNU_SUPPORTS_PROFILE_GARBAGE_COLLECTION 1
100*5c2921b0SApple OSS Distributions 
101*5c2921b0SApple OSS Distributions /**
102*5c2921b0SApple OSS Distributions  * Enable developer mode on the system. When the system contains a monitor environment,
103*5c2921b0SApple OSS Distributions  * developer mode is turned on by trapping into the appropriate monitor environment.
104*5c2921b0SApple OSS Distributions  */
105*5c2921b0SApple OSS Distributions void
106*5c2921b0SApple OSS Distributions enable_developer_mode(void);
107*5c2921b0SApple OSS Distributions 
108*5c2921b0SApple OSS Distributions /**
109*5c2921b0SApple OSS Distributions  * Disable developer mode on the system. When the system contains a monitor environment,
110*5c2921b0SApple OSS Distributions  * developer mode is turned off by trapping into the appropriate monitor environment.
111*5c2921b0SApple OSS Distributions  */
112*5c2921b0SApple OSS Distributions void
113*5c2921b0SApple OSS Distributions disable_developer_mode(void);
114*5c2921b0SApple OSS Distributions 
115*5c2921b0SApple OSS Distributions /**
116*5c2921b0SApple OSS Distributions  * Query the current state of developer mode on the system. This call never traps into
117*5c2921b0SApple OSS Distributions  * the monitor environment because XNU can directly read the monitors memory.
118*5c2921b0SApple OSS Distributions  */
119*5c2921b0SApple OSS Distributions bool
120*5c2921b0SApple OSS Distributions developer_mode_state(void);
121*5c2921b0SApple OSS Distributions 
122*5c2921b0SApple OSS Distributions /**
123*5c2921b0SApple OSS Distributions  * Wrapper function which is exposed to kernel extensions. This can be used to trigger
124*5c2921b0SApple OSS Distributions  * a call to the garbage collector for going through and unregistring all unused profiles
125*5c2921b0SApple OSS Distributions  * on the system.
126*5c2921b0SApple OSS Distributions  */
127*5c2921b0SApple OSS Distributions void
128*5c2921b0SApple OSS Distributions garbage_collect_provisioning_profiles(void);
129*5c2921b0SApple OSS Distributions 
130*5c2921b0SApple OSS Distributions #endif /* KERNEL_PRIVATE */
131*5c2921b0SApple OSS Distributions 
132*5c2921b0SApple OSS Distributions __END_DECLS
133*5c2921b0SApple OSS Distributions #endif /* _SYS_CODE_SIGNING_H_ */
134