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