1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions * Copyright (c) 2022 Apple Computer, Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions *
4*bbb1b6f9SApple OSS Distributions * @APPLE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions *
6*bbb1b6f9SApple OSS Distributions * The contents of this file constitute Original Code as defined in and
7*bbb1b6f9SApple OSS Distributions * are subject to the Apple Public Source License Version 1.1 (the
8*bbb1b6f9SApple OSS Distributions * "License"). You may not use this file except in compliance with the
9*bbb1b6f9SApple OSS Distributions * License. Please obtain a copy of the License at
10*bbb1b6f9SApple OSS Distributions * http://www.apple.com/publicsource and read it before using this file.
11*bbb1b6f9SApple OSS Distributions *
12*bbb1b6f9SApple OSS Distributions * This Original Code and all software distributed under the License are
13*bbb1b6f9SApple OSS Distributions * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14*bbb1b6f9SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15*bbb1b6f9SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16*bbb1b6f9SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17*bbb1b6f9SApple OSS Distributions * License for the specific language governing rights and limitations
18*bbb1b6f9SApple OSS Distributions * under the License.
19*bbb1b6f9SApple OSS Distributions *
20*bbb1b6f9SApple OSS Distributions * @APPLE_LICENSE_HEADER_END@
21*bbb1b6f9SApple OSS Distributions */
22*bbb1b6f9SApple OSS Distributions
23*bbb1b6f9SApple OSS Distributions #include <os/overflow.h>
24*bbb1b6f9SApple OSS Distributions #include <machine/atomic.h>
25*bbb1b6f9SApple OSS Distributions #include <mach/vm_param.h>
26*bbb1b6f9SApple OSS Distributions #include <vm/vm_kern.h>
27*bbb1b6f9SApple OSS Distributions #include <kern/zalloc.h>
28*bbb1b6f9SApple OSS Distributions #include <kern/kalloc.h>
29*bbb1b6f9SApple OSS Distributions #include <kern/assert.h>
30*bbb1b6f9SApple OSS Distributions #include <kern/locks.h>
31*bbb1b6f9SApple OSS Distributions #include <kern/lock_rw.h>
32*bbb1b6f9SApple OSS Distributions #include <libkern/libkern.h>
33*bbb1b6f9SApple OSS Distributions #include <libkern/section_keywords.h>
34*bbb1b6f9SApple OSS Distributions #include <libkern/coretrust/coretrust.h>
35*bbb1b6f9SApple OSS Distributions #include <pexpert/pexpert.h>
36*bbb1b6f9SApple OSS Distributions #include <sys/vm.h>
37*bbb1b6f9SApple OSS Distributions #include <sys/proc.h>
38*bbb1b6f9SApple OSS Distributions #include <sys/codesign.h>
39*bbb1b6f9SApple OSS Distributions #include <sys/code_signing.h>
40*bbb1b6f9SApple OSS Distributions #include <uuid/uuid.h>
41*bbb1b6f9SApple OSS Distributions #include <IOKit/IOBSD.h>
42*bbb1b6f9SApple OSS Distributions
43*bbb1b6f9SApple OSS Distributions #if !CODE_SIGNING_MONITOR
44*bbb1b6f9SApple OSS Distributions /*
45*bbb1b6f9SApple OSS Distributions * We don't have a monitor environment available. This means someone with a kernel
46*bbb1b6f9SApple OSS Distributions * memory exploit will be able to corrupt code signing state. There is not much we
47*bbb1b6f9SApple OSS Distributions * can do here, since this is older HW.
48*bbb1b6f9SApple OSS Distributions */
49*bbb1b6f9SApple OSS Distributions LCK_GRP_DECLARE(xnu_codesigning_lck_grp, "xnu_codesigning_lck_grp");
50*bbb1b6f9SApple OSS Distributions
51*bbb1b6f9SApple OSS Distributions #pragma mark Initialization
52*bbb1b6f9SApple OSS Distributions
53*bbb1b6f9SApple OSS Distributions static decl_lck_mtx_data(, compilation_service_lock);
54*bbb1b6f9SApple OSS Distributions
55*bbb1b6f9SApple OSS Distributions void
code_signing_init()56*bbb1b6f9SApple OSS Distributions code_signing_init()
57*bbb1b6f9SApple OSS Distributions {
58*bbb1b6f9SApple OSS Distributions /* Initialize compilation service lock */
59*bbb1b6f9SApple OSS Distributions lck_mtx_init(&compilation_service_lock, &xnu_codesigning_lck_grp, 0);
60*bbb1b6f9SApple OSS Distributions }
61*bbb1b6f9SApple OSS Distributions
62*bbb1b6f9SApple OSS Distributions kern_return_t
xnu_secure_channel_shared_page(__unused uint64_t * secure_channel_phys,__unused size_t * secure_channel_size)63*bbb1b6f9SApple OSS Distributions xnu_secure_channel_shared_page(
64*bbb1b6f9SApple OSS Distributions __unused uint64_t *secure_channel_phys,
65*bbb1b6f9SApple OSS Distributions __unused size_t *secure_channel_size)
66*bbb1b6f9SApple OSS Distributions {
67*bbb1b6f9SApple OSS Distributions return KERN_NOT_SUPPORTED;
68*bbb1b6f9SApple OSS Distributions }
69*bbb1b6f9SApple OSS Distributions
70*bbb1b6f9SApple OSS Distributions #pragma mark Developer Mode
71*bbb1b6f9SApple OSS Distributions
72*bbb1b6f9SApple OSS Distributions static bool developer_mode_storage = true;
73*bbb1b6f9SApple OSS Distributions SECURITY_READ_ONLY_LATE(bool*) developer_mode_enabled = &developer_mode_storage;
74*bbb1b6f9SApple OSS Distributions
75*bbb1b6f9SApple OSS Distributions void
xnu_toggle_developer_mode(bool state)76*bbb1b6f9SApple OSS Distributions xnu_toggle_developer_mode(
77*bbb1b6f9SApple OSS Distributions bool state)
78*bbb1b6f9SApple OSS Distributions {
79*bbb1b6f9SApple OSS Distributions /* No extra validation needed within XNU */
80*bbb1b6f9SApple OSS Distributions os_atomic_store(developer_mode_enabled, state, relaxed);
81*bbb1b6f9SApple OSS Distributions }
82*bbb1b6f9SApple OSS Distributions
83*bbb1b6f9SApple OSS Distributions #pragma mark Restricted Execution Mode
84*bbb1b6f9SApple OSS Distributions
85*bbb1b6f9SApple OSS Distributions kern_return_t
xnu_rem_enable(void)86*bbb1b6f9SApple OSS Distributions xnu_rem_enable(void)
87*bbb1b6f9SApple OSS Distributions {
88*bbb1b6f9SApple OSS Distributions return KERN_NOT_SUPPORTED;
89*bbb1b6f9SApple OSS Distributions }
90*bbb1b6f9SApple OSS Distributions
91*bbb1b6f9SApple OSS Distributions kern_return_t
xnu_rem_state(void)92*bbb1b6f9SApple OSS Distributions xnu_rem_state(void)
93*bbb1b6f9SApple OSS Distributions {
94*bbb1b6f9SApple OSS Distributions return KERN_NOT_SUPPORTED;
95*bbb1b6f9SApple OSS Distributions }
96*bbb1b6f9SApple OSS Distributions
97*bbb1b6f9SApple OSS Distributions #pragma mark Device State
98*bbb1b6f9SApple OSS Distributions
99*bbb1b6f9SApple OSS Distributions void
xnu_update_device_state(void)100*bbb1b6f9SApple OSS Distributions xnu_update_device_state(void)
101*bbb1b6f9SApple OSS Distributions {
102*bbb1b6f9SApple OSS Distributions /* Does nothing */
103*bbb1b6f9SApple OSS Distributions }
104*bbb1b6f9SApple OSS Distributions
105*bbb1b6f9SApple OSS Distributions void
xnu_complete_security_boot_mode(__unused uint32_t security_boot_mode)106*bbb1b6f9SApple OSS Distributions xnu_complete_security_boot_mode(
107*bbb1b6f9SApple OSS Distributions __unused uint32_t security_boot_mode)
108*bbb1b6f9SApple OSS Distributions {
109*bbb1b6f9SApple OSS Distributions /* Does nothing */
110*bbb1b6f9SApple OSS Distributions }
111*bbb1b6f9SApple OSS Distributions
112*bbb1b6f9SApple OSS Distributions #pragma mark Code Signing
113*bbb1b6f9SApple OSS Distributions
114*bbb1b6f9SApple OSS Distributions static uint8_t compilation_service_cdhash[CS_CDHASH_LEN] = {0};
115*bbb1b6f9SApple OSS Distributions
116*bbb1b6f9SApple OSS Distributions void
xnu_set_compilation_service_cdhash(const uint8_t cdhash[CS_CDHASH_LEN])117*bbb1b6f9SApple OSS Distributions xnu_set_compilation_service_cdhash(
118*bbb1b6f9SApple OSS Distributions const uint8_t cdhash[CS_CDHASH_LEN])
119*bbb1b6f9SApple OSS Distributions {
120*bbb1b6f9SApple OSS Distributions lck_mtx_lock(&compilation_service_lock);
121*bbb1b6f9SApple OSS Distributions memcpy(compilation_service_cdhash, cdhash, CS_CDHASH_LEN);
122*bbb1b6f9SApple OSS Distributions lck_mtx_unlock(&compilation_service_lock);
123*bbb1b6f9SApple OSS Distributions }
124*bbb1b6f9SApple OSS Distributions
125*bbb1b6f9SApple OSS Distributions bool
xnu_match_compilation_service_cdhash(const uint8_t cdhash[CS_CDHASH_LEN])126*bbb1b6f9SApple OSS Distributions xnu_match_compilation_service_cdhash(
127*bbb1b6f9SApple OSS Distributions const uint8_t cdhash[CS_CDHASH_LEN])
128*bbb1b6f9SApple OSS Distributions {
129*bbb1b6f9SApple OSS Distributions bool match = false;
130*bbb1b6f9SApple OSS Distributions
131*bbb1b6f9SApple OSS Distributions lck_mtx_lock(&compilation_service_lock);
132*bbb1b6f9SApple OSS Distributions if (bcmp(compilation_service_cdhash, cdhash, CS_CDHASH_LEN) == 0) {
133*bbb1b6f9SApple OSS Distributions match = true;
134*bbb1b6f9SApple OSS Distributions }
135*bbb1b6f9SApple OSS Distributions lck_mtx_unlock(&compilation_service_lock);
136*bbb1b6f9SApple OSS Distributions
137*bbb1b6f9SApple OSS Distributions return match;
138*bbb1b6f9SApple OSS Distributions }
139*bbb1b6f9SApple OSS Distributions
140*bbb1b6f9SApple OSS Distributions static bool local_signing_key_set = false;
141*bbb1b6f9SApple OSS Distributions static uint8_t local_signing_public_key[XNU_LOCAL_SIGNING_KEY_SIZE] = {0};
142*bbb1b6f9SApple OSS Distributions
143*bbb1b6f9SApple OSS Distributions void
xnu_set_local_signing_public_key(const uint8_t public_key[XNU_LOCAL_SIGNING_KEY_SIZE])144*bbb1b6f9SApple OSS Distributions xnu_set_local_signing_public_key(
145*bbb1b6f9SApple OSS Distributions const uint8_t public_key[XNU_LOCAL_SIGNING_KEY_SIZE])
146*bbb1b6f9SApple OSS Distributions {
147*bbb1b6f9SApple OSS Distributions bool key_set = false;
148*bbb1b6f9SApple OSS Distributions
149*bbb1b6f9SApple OSS Distributions /*
150*bbb1b6f9SApple OSS Distributions * os_atomic_cmpxchg returns true in case the exchange was successful. For us,
151*bbb1b6f9SApple OSS Distributions * a successful exchange means that the local signing public key has _not_ been
152*bbb1b6f9SApple OSS Distributions * set. In case the key has been set, we panic as we would never expect the
153*bbb1b6f9SApple OSS Distributions * kernel to attempt to set the key more than once.
154*bbb1b6f9SApple OSS Distributions */
155*bbb1b6f9SApple OSS Distributions key_set = !os_atomic_cmpxchg(&local_signing_key_set, false, true, relaxed);
156*bbb1b6f9SApple OSS Distributions
157*bbb1b6f9SApple OSS Distributions if (key_set) {
158*bbb1b6f9SApple OSS Distributions panic("attempted to set the local signing public key multiple times");
159*bbb1b6f9SApple OSS Distributions }
160*bbb1b6f9SApple OSS Distributions
161*bbb1b6f9SApple OSS Distributions memcpy(local_signing_public_key, public_key, sizeof(local_signing_public_key));
162*bbb1b6f9SApple OSS Distributions }
163*bbb1b6f9SApple OSS Distributions
164*bbb1b6f9SApple OSS Distributions uint8_t*
xnu_get_local_signing_public_key(void)165*bbb1b6f9SApple OSS Distributions xnu_get_local_signing_public_key(void)
166*bbb1b6f9SApple OSS Distributions {
167*bbb1b6f9SApple OSS Distributions bool key_set = os_atomic_load(&local_signing_key_set, relaxed);
168*bbb1b6f9SApple OSS Distributions
169*bbb1b6f9SApple OSS Distributions if (key_set) {
170*bbb1b6f9SApple OSS Distributions return local_signing_public_key;
171*bbb1b6f9SApple OSS Distributions }
172*bbb1b6f9SApple OSS Distributions
173*bbb1b6f9SApple OSS Distributions return NULL;
174*bbb1b6f9SApple OSS Distributions }
175*bbb1b6f9SApple OSS Distributions
176*bbb1b6f9SApple OSS Distributions #pragma mark Image4
177*bbb1b6f9SApple OSS Distributions
178*bbb1b6f9SApple OSS Distributions static uint8_t __attribute__((aligned(8)))
179*bbb1b6f9SApple OSS Distributions _xnu_image4_storage[IMG4_PMAP_DATA_SIZE_RECOMMENDED] = {0};
180*bbb1b6f9SApple OSS Distributions
181*bbb1b6f9SApple OSS Distributions void*
xnu_image4_storage_data(size_t * allocated_size)182*bbb1b6f9SApple OSS Distributions xnu_image4_storage_data(
183*bbb1b6f9SApple OSS Distributions size_t *allocated_size)
184*bbb1b6f9SApple OSS Distributions {
185*bbb1b6f9SApple OSS Distributions if (allocated_size) {
186*bbb1b6f9SApple OSS Distributions *allocated_size = sizeof(_xnu_image4_storage);
187*bbb1b6f9SApple OSS Distributions }
188*bbb1b6f9SApple OSS Distributions return _xnu_image4_storage;
189*bbb1b6f9SApple OSS Distributions }
190*bbb1b6f9SApple OSS Distributions
191*bbb1b6f9SApple OSS Distributions void
xnu_image4_set_nonce(const img4_nonce_domain_index_t ndi,const img4_nonce_t * nonce)192*bbb1b6f9SApple OSS Distributions xnu_image4_set_nonce(
193*bbb1b6f9SApple OSS Distributions const img4_nonce_domain_index_t ndi,
194*bbb1b6f9SApple OSS Distributions const img4_nonce_t *nonce)
195*bbb1b6f9SApple OSS Distributions {
196*bbb1b6f9SApple OSS Distributions /*
197*bbb1b6f9SApple OSS Distributions * As a hold over from legacy code, AppleImage4 only ever manages nonces
198*bbb1b6f9SApple OSS Distributions * from the kernel interface through the PMAP_CS runtime. So even though
199*bbb1b6f9SApple OSS Distributions * we don't have a PMAP_CS monitor, we still pass in the PMAP_CS runtime.
200*bbb1b6f9SApple OSS Distributions */
201*bbb1b6f9SApple OSS Distributions
202*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS->i4rt_set_nonce(
203*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS,
204*bbb1b6f9SApple OSS Distributions ndi,
205*bbb1b6f9SApple OSS Distributions nonce);
206*bbb1b6f9SApple OSS Distributions }
207*bbb1b6f9SApple OSS Distributions
208*bbb1b6f9SApple OSS Distributions void
xnu_image4_roll_nonce(const img4_nonce_domain_index_t ndi)209*bbb1b6f9SApple OSS Distributions xnu_image4_roll_nonce(
210*bbb1b6f9SApple OSS Distributions const img4_nonce_domain_index_t ndi)
211*bbb1b6f9SApple OSS Distributions {
212*bbb1b6f9SApple OSS Distributions /*
213*bbb1b6f9SApple OSS Distributions * As a hold over from legacy code, AppleImage4 only ever manages nonces
214*bbb1b6f9SApple OSS Distributions * from the kernel interface through the PMAP_CS runtime. So even though
215*bbb1b6f9SApple OSS Distributions * we don't have a PMAP_CS monitor, we still pass in the PMAP_CS runtime.
216*bbb1b6f9SApple OSS Distributions */
217*bbb1b6f9SApple OSS Distributions
218*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS->i4rt_roll_nonce(
219*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS,
220*bbb1b6f9SApple OSS Distributions ndi);
221*bbb1b6f9SApple OSS Distributions }
222*bbb1b6f9SApple OSS Distributions
223*bbb1b6f9SApple OSS Distributions errno_t
xnu_image4_copy_nonce(const img4_nonce_domain_index_t ndi,img4_nonce_t * nonce_out)224*bbb1b6f9SApple OSS Distributions xnu_image4_copy_nonce(
225*bbb1b6f9SApple OSS Distributions const img4_nonce_domain_index_t ndi,
226*bbb1b6f9SApple OSS Distributions img4_nonce_t *nonce_out)
227*bbb1b6f9SApple OSS Distributions {
228*bbb1b6f9SApple OSS Distributions errno_t ret = EPERM;
229*bbb1b6f9SApple OSS Distributions
230*bbb1b6f9SApple OSS Distributions /*
231*bbb1b6f9SApple OSS Distributions * As a hold over from legacy code, AppleImage4 only ever manages nonces
232*bbb1b6f9SApple OSS Distributions * from the kernel interface through the PMAP_CS runtime. So even though
233*bbb1b6f9SApple OSS Distributions * we don't have a PMAP_CS monitor, we still pass in the PMAP_CS runtime.
234*bbb1b6f9SApple OSS Distributions */
235*bbb1b6f9SApple OSS Distributions
236*bbb1b6f9SApple OSS Distributions ret = IMG4_RUNTIME_PMAP_CS->i4rt_copy_nonce(
237*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS,
238*bbb1b6f9SApple OSS Distributions ndi,
239*bbb1b6f9SApple OSS Distributions nonce_out);
240*bbb1b6f9SApple OSS Distributions
241*bbb1b6f9SApple OSS Distributions if (ret != 0) {
242*bbb1b6f9SApple OSS Distributions printf("unable to copy image4 nonce: %llu | %d\n", ndi, ret);
243*bbb1b6f9SApple OSS Distributions }
244*bbb1b6f9SApple OSS Distributions
245*bbb1b6f9SApple OSS Distributions return ret;
246*bbb1b6f9SApple OSS Distributions }
247*bbb1b6f9SApple OSS Distributions
248*bbb1b6f9SApple OSS Distributions errno_t
xnu_image4_execute_object(img4_runtime_object_spec_index_t obj_spec_index,const img4_buff_t * payload,const img4_buff_t * manifest)249*bbb1b6f9SApple OSS Distributions xnu_image4_execute_object(
250*bbb1b6f9SApple OSS Distributions img4_runtime_object_spec_index_t obj_spec_index,
251*bbb1b6f9SApple OSS Distributions const img4_buff_t *payload,
252*bbb1b6f9SApple OSS Distributions const img4_buff_t *manifest)
253*bbb1b6f9SApple OSS Distributions {
254*bbb1b6f9SApple OSS Distributions errno_t ret = EPERM;
255*bbb1b6f9SApple OSS Distributions const img4_runtime_object_spec_t *obj_spec = NULL;
256*bbb1b6f9SApple OSS Distributions
257*bbb1b6f9SApple OSS Distributions obj_spec = image4_get_object_spec_from_index(obj_spec_index);
258*bbb1b6f9SApple OSS Distributions if (obj_spec == NULL) {
259*bbb1b6f9SApple OSS Distributions return ENOENT;
260*bbb1b6f9SApple OSS Distributions }
261*bbb1b6f9SApple OSS Distributions
262*bbb1b6f9SApple OSS Distributions /*
263*bbb1b6f9SApple OSS Distributions * As a hold over from legacy code, AppleImage4 only ever executes objects
264*bbb1b6f9SApple OSS Distributions * through the kernel interface through the PMAP_CS runtime. So even though
265*bbb1b6f9SApple OSS Distributions * we don't have a PMAP_CS monitor, we still pass in the PMAP_CS runtime.
266*bbb1b6f9SApple OSS Distributions */
267*bbb1b6f9SApple OSS Distributions
268*bbb1b6f9SApple OSS Distributions ret = img4_runtime_execute_object(
269*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS,
270*bbb1b6f9SApple OSS Distributions obj_spec,
271*bbb1b6f9SApple OSS Distributions payload,
272*bbb1b6f9SApple OSS Distributions manifest);
273*bbb1b6f9SApple OSS Distributions
274*bbb1b6f9SApple OSS Distributions if (ret != 0) {
275*bbb1b6f9SApple OSS Distributions printf("unable to execute image4 object: %d\n", ret);
276*bbb1b6f9SApple OSS Distributions }
277*bbb1b6f9SApple OSS Distributions
278*bbb1b6f9SApple OSS Distributions return ret;
279*bbb1b6f9SApple OSS Distributions }
280*bbb1b6f9SApple OSS Distributions
281*bbb1b6f9SApple OSS Distributions errno_t
xnu_image4_copy_object(img4_runtime_object_spec_index_t obj_spec_index,vm_address_t object_out,size_t * object_length)282*bbb1b6f9SApple OSS Distributions xnu_image4_copy_object(
283*bbb1b6f9SApple OSS Distributions img4_runtime_object_spec_index_t obj_spec_index,
284*bbb1b6f9SApple OSS Distributions vm_address_t object_out,
285*bbb1b6f9SApple OSS Distributions size_t *object_length)
286*bbb1b6f9SApple OSS Distributions {
287*bbb1b6f9SApple OSS Distributions errno_t ret = EPERM;
288*bbb1b6f9SApple OSS Distributions img4_buff_t object_payload = IMG4_BUFF_INIT;
289*bbb1b6f9SApple OSS Distributions size_t object_payload_length = 0;
290*bbb1b6f9SApple OSS Distributions const img4_runtime_object_spec_t *obj_spec = NULL;
291*bbb1b6f9SApple OSS Distributions
292*bbb1b6f9SApple OSS Distributions obj_spec = image4_get_object_spec_from_index(obj_spec_index);
293*bbb1b6f9SApple OSS Distributions if (obj_spec == NULL) {
294*bbb1b6f9SApple OSS Distributions return ENOENT;
295*bbb1b6f9SApple OSS Distributions }
296*bbb1b6f9SApple OSS Distributions
297*bbb1b6f9SApple OSS Distributions /*
298*bbb1b6f9SApple OSS Distributions * The object length is used as an in/out parameter, so we require that this parameter
299*bbb1b6f9SApple OSS Distributions * is used to specify the length of the buffer.
300*bbb1b6f9SApple OSS Distributions */
301*bbb1b6f9SApple OSS Distributions object_payload_length = *object_length;
302*bbb1b6f9SApple OSS Distributions
303*bbb1b6f9SApple OSS Distributions object_payload.i4b_bytes = (void*)object_out;
304*bbb1b6f9SApple OSS Distributions object_payload.i4b_len = object_payload_length;
305*bbb1b6f9SApple OSS Distributions
306*bbb1b6f9SApple OSS Distributions /*
307*bbb1b6f9SApple OSS Distributions * As a hold over from legacy code, AppleImage4 only ever copies objects
308*bbb1b6f9SApple OSS Distributions * through the kernel interface through the PMAP_CS runtime. So even though
309*bbb1b6f9SApple OSS Distributions * we don't have a PMAP_CS monitor, we still pass in the PMAP_CS runtime.
310*bbb1b6f9SApple OSS Distributions */
311*bbb1b6f9SApple OSS Distributions
312*bbb1b6f9SApple OSS Distributions ret = img4_runtime_copy_object(
313*bbb1b6f9SApple OSS Distributions IMG4_RUNTIME_PMAP_CS,
314*bbb1b6f9SApple OSS Distributions obj_spec,
315*bbb1b6f9SApple OSS Distributions &object_payload,
316*bbb1b6f9SApple OSS Distributions &object_payload_length);
317*bbb1b6f9SApple OSS Distributions if (ret != 0) {
318*bbb1b6f9SApple OSS Distributions printf("unable to copy image4 object: %d\n", ret);
319*bbb1b6f9SApple OSS Distributions }
320*bbb1b6f9SApple OSS Distributions
321*bbb1b6f9SApple OSS Distributions /* Update the length with what we received from the image4 runtime */
322*bbb1b6f9SApple OSS Distributions *object_length = object_payload_length;
323*bbb1b6f9SApple OSS Distributions
324*bbb1b6f9SApple OSS Distributions return ret;
325*bbb1b6f9SApple OSS Distributions }
326*bbb1b6f9SApple OSS Distributions
327*bbb1b6f9SApple OSS Distributions const void*
xnu_image4_get_monitor_exports(void)328*bbb1b6f9SApple OSS Distributions xnu_image4_get_monitor_exports(void)
329*bbb1b6f9SApple OSS Distributions {
330*bbb1b6f9SApple OSS Distributions printf("monitor exports not supported without a monitor\n");
331*bbb1b6f9SApple OSS Distributions return NULL;
332*bbb1b6f9SApple OSS Distributions }
333*bbb1b6f9SApple OSS Distributions
334*bbb1b6f9SApple OSS Distributions errno_t
xnu_image4_set_release_type(__unused const char * release_type)335*bbb1b6f9SApple OSS Distributions xnu_image4_set_release_type(
336*bbb1b6f9SApple OSS Distributions __unused const char *release_type)
337*bbb1b6f9SApple OSS Distributions {
338*bbb1b6f9SApple OSS Distributions /*
339*bbb1b6f9SApple OSS Distributions * We don't need to inform the monitor about the release type when there
340*bbb1b6f9SApple OSS Distributions * is no monitor environment available.
341*bbb1b6f9SApple OSS Distributions */
342*bbb1b6f9SApple OSS Distributions
343*bbb1b6f9SApple OSS Distributions printf("explicit release-type-set not supported without a monitor\n");
344*bbb1b6f9SApple OSS Distributions return ENOTSUP;
345*bbb1b6f9SApple OSS Distributions }
346*bbb1b6f9SApple OSS Distributions
347*bbb1b6f9SApple OSS Distributions errno_t
xnu_image4_set_bnch_shadow(__unused const img4_nonce_domain_index_t ndi)348*bbb1b6f9SApple OSS Distributions xnu_image4_set_bnch_shadow(
349*bbb1b6f9SApple OSS Distributions __unused const img4_nonce_domain_index_t ndi)
350*bbb1b6f9SApple OSS Distributions {
351*bbb1b6f9SApple OSS Distributions /*
352*bbb1b6f9SApple OSS Distributions * We don't need to inform the monitor about the BNCH shadow when there
353*bbb1b6f9SApple OSS Distributions * is no monitor environment available.
354*bbb1b6f9SApple OSS Distributions */
355*bbb1b6f9SApple OSS Distributions
356*bbb1b6f9SApple OSS Distributions printf("explicit BNCH-shadow-set not supported without a monitor\n");
357*bbb1b6f9SApple OSS Distributions return ENOTSUP;
358*bbb1b6f9SApple OSS Distributions }
359*bbb1b6f9SApple OSS Distributions
360*bbb1b6f9SApple OSS Distributions #pragma mark Image4 - New
361*bbb1b6f9SApple OSS Distributions
362*bbb1b6f9SApple OSS Distributions kern_return_t
xnu_image4_transfer_region(image4_cs_trap_t selector,__unused vm_address_t region_addr,__unused vm_size_t region_size)363*bbb1b6f9SApple OSS Distributions xnu_image4_transfer_region(
364*bbb1b6f9SApple OSS Distributions image4_cs_trap_t selector,
365*bbb1b6f9SApple OSS Distributions __unused vm_address_t region_addr,
366*bbb1b6f9SApple OSS Distributions __unused vm_size_t region_size)
367*bbb1b6f9SApple OSS Distributions {
368*bbb1b6f9SApple OSS Distributions panic("image4 dispatch: transfer without code signing monitor: %llu", selector);
369*bbb1b6f9SApple OSS Distributions }
370*bbb1b6f9SApple OSS Distributions
371*bbb1b6f9SApple OSS Distributions kern_return_t
xnu_image4_reclaim_region(image4_cs_trap_t selector,__unused vm_address_t region_addr,__unused vm_size_t region_size)372*bbb1b6f9SApple OSS Distributions xnu_image4_reclaim_region(
373*bbb1b6f9SApple OSS Distributions image4_cs_trap_t selector,
374*bbb1b6f9SApple OSS Distributions __unused vm_address_t region_addr,
375*bbb1b6f9SApple OSS Distributions __unused vm_size_t region_size)
376*bbb1b6f9SApple OSS Distributions {
377*bbb1b6f9SApple OSS Distributions panic("image4 dispatch: reclaim without code signing monitor: %llu", selector);
378*bbb1b6f9SApple OSS Distributions }
379*bbb1b6f9SApple OSS Distributions
380*bbb1b6f9SApple OSS Distributions errno_t
xnu_image4_monitor_trap(image4_cs_trap_t selector,__unused const void * input_data,__unused size_t input_size)381*bbb1b6f9SApple OSS Distributions xnu_image4_monitor_trap(
382*bbb1b6f9SApple OSS Distributions image4_cs_trap_t selector,
383*bbb1b6f9SApple OSS Distributions __unused const void *input_data,
384*bbb1b6f9SApple OSS Distributions __unused size_t input_size)
385*bbb1b6f9SApple OSS Distributions {
386*bbb1b6f9SApple OSS Distributions panic("image4 dispatch: trap without code signing monitor: %llu", selector);
387*bbb1b6f9SApple OSS Distributions }
388*bbb1b6f9SApple OSS Distributions
389*bbb1b6f9SApple OSS Distributions #endif /* !CODE_SIGNING_MONITOR */
390