1 /* 2 * Copyright (c) 2019 Apple Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 /*! 30 * @header 31 * Interfaces to register the AppleImage4 interface with xnu-proper to avoid a 32 * build-time layering inversion. 33 */ 34 #ifndef __IMG4_INTERFACE_H 35 #define __IMG4_INTERFACE_H 36 37 #include <os/base.h> 38 #include <sys/cdefs.h> 39 40 /* 41 * We rely on firmware.h's logic for either including sys/types.h or declaring 42 * errno_t ourselves. So when building the kernel, include firmware.h from our 43 * external headers. Avoid this inclusion if we're building AppleImage4, which 44 * will have included its own internal version of the header. 45 */ 46 #if MACH_KERNEL_PRIVATE || !_DARWIN_BUILDING_PROJECT_APPLEIMAGE4 47 #include <img4/firmware.h> 48 #include <img4/nonce.h> 49 #endif 50 51 /*! 52 * @const IMG4_INTERFACE_VERSION 53 * The version of the interface supported by the implementation. As new 54 * functions are added to the interface, this value will be incremented so that 55 * it can be tested at build-time and not require rev-locked submissions of xnu 56 * and AppleImage4. 57 */ 58 #define IMG4_INTERFACE_VERSION (13u) 59 60 /*! 61 * @typegroup 62 * Type definitions for all exported functions and constants in the AppleImage4 63 * kext. 64 */ 65 typedef const void *img4_retired_t; 66 67 typedef errno_t (*const img4_nonce_domain_copy_nonce_t)( 68 const img4_nonce_domain_t *nd, 69 img4_nonce_t *n 70 ); 71 72 typedef errno_t (*const img4_nonce_domain_roll_nonce_t)( 73 const img4_nonce_domain_t *nd 74 ); 75 76 typedef img4_chip_t *(*img4_chip_init_from_buff_t)( 77 void *buff, 78 size_t len 79 ); 80 81 typedef const img4_chip_t *(*img4_chip_select_personalized_ap_t)( 82 void 83 ); 84 85 typedef const img4_chip_t *(*img4_chip_select_effective_ap_t)( 86 void 87 ); 88 89 typedef errno_t (*img4_chip_instantiate_t)( 90 const img4_chip_t *chip, 91 img4_chip_instance_t *chip_instance 92 ); 93 94 typedef const img4_chip_t *(*img4_chip_custom_t)( 95 const img4_chip_instance_t *chip_instance, 96 img4_chip_t *chip 97 ); 98 99 typedef img4_firmware_t (*img4_firmware_new_t)( 100 const img4_runtime_t *rt, 101 const img4_firmware_execution_context_t *exec, 102 img4_4cc_t _4cc, 103 img4_buff_t *buff, 104 img4_firmware_flags_t flags 105 ); 106 107 typedef img4_firmware_t (*img4_firmware_new_from_vnode_4xnu_t)( 108 const img4_runtime_t *rt, 109 const img4_firmware_execution_context_t *exec, 110 img4_4cc_t _4cc, 111 vnode_t vn, 112 img4_firmware_flags_t flags 113 ); 114 115 typedef img4_firmware_t (*img4_firmware_init_from_buff_t)( 116 void *buff, 117 size_t len 118 ); 119 120 typedef void (*img4_firmware_init_t)( 121 img4_firmware_t fw, 122 const img4_runtime_t *rt, 123 const img4_firmware_execution_context_t *exec, 124 img4_4cc_t _4cc, 125 img4_buff_t *buff, 126 img4_firmware_flags_t flags 127 ); 128 129 typedef void (*img4_firmware_attach_manifest_t)( 130 img4_firmware_t fw, 131 img4_buff_t *buff 132 ); 133 134 typedef void (*img4_firmware_execute_t)( 135 img4_firmware_t fw, 136 const img4_chip_t *chip, 137 const img4_nonce_t *nonce 138 ); 139 140 typedef void (*img4_firmware_destroy_t)( 141 img4_firmware_t *fw 142 ); 143 144 typedef const img4_buff_t *(*img4_image_get_bytes_t)( 145 img4_image_t image 146 ); 147 148 typedef const bool *(*img4_image_get_property_bool_t)( 149 img4_image_t image, 150 img4_4cc_t _4cc, 151 bool *storage 152 ); 153 154 typedef const uint32_t *(*img4_image_get_property_uint32_t)( 155 img4_image_t image, 156 img4_4cc_t _4cc, 157 uint32_t *storage 158 ); 159 160 typedef const uint64_t *(*img4_image_get_property_uint64_t)( 161 img4_image_t image, 162 img4_4cc_t _4cc, 163 uint64_t *storage 164 ); 165 166 typedef const img4_buff_t *(*img4_image_get_property_data_t)( 167 img4_image_t image, 168 img4_4cc_t _4cc, 169 img4_buff_t *storage 170 ); 171 172 typedef void (*img4_buff_dealloc_t)( 173 img4_buff_t *buff 174 ); 175 176 typedef errno_t (*img4_firmware_evaluate_t)( 177 img4_firmware_t fw, 178 const img4_chip_t *chip, 179 const img4_nonce_t *nonce 180 ); 181 182 typedef const img4_chip_t *(*img4_firmware_select_chip_t)( 183 const img4_firmware_t fw, 184 const img4_chip_select_array_t acceptable_chips, 185 size_t acceptable_chips_cnt 186 ); 187 188 typedef const img4_runtime_object_spec_t *(*img4_runtime_find_object_spec_t)( 189 img4_4cc_t _4cc 190 ); 191 192 typedef struct _img4_interface { 193 const uint32_t i4if_version; 194 img4_retired_t i4if_init; 195 img4_retired_t i4if_set_nonce; 196 img4_retired_t i4if_get_trusted_payload; 197 img4_retired_t i4if_get_trusted_external_payload; 198 img4_retired_t i4if_destroy; 199 img4_retired_t i4if_payload_init; 200 img4_retired_t i4if_payload_destroy; 201 img4_retired_t i4if_environment_platform; 202 img4_retired_t i4if_environment_reserved; 203 img4_retired_t i4if_environment_trust_cache; 204 struct { 205 img4_retired_t set_nonce_domain; 206 img4_nonce_domain_copy_nonce_t nonce_domain_copy_nonce; 207 img4_nonce_domain_roll_nonce_t nonce_domain_roll_nonce; 208 const img4_nonce_domain_t *nonce_domain_trust_cache; 209 } i4if_v1; 210 struct { 211 img4_retired_t payload_init_with_vnode_4xnu; 212 } i4if_v2; 213 struct { 214 const img4_nonce_domain_t *nonce_domain_pdi; 215 const img4_nonce_domain_t *nonce_domain_cryptex; 216 } i4if_v3; 217 struct { 218 img4_retired_t environment_init_identity; 219 } i4if_v4; 220 struct { 221 img4_retired_t environment_t2; 222 img4_retired_t environment_init_from_identity; 223 img4_retired_t identity_init_from_environment; 224 } i4if_v5; 225 struct { 226 img4_retired_t environment_x86; 227 } i4if_v6; 228 struct { 229 const img4_chip_t *chip_ap_sha1; 230 const img4_chip_t *chip_ap_sha2_384; 231 const img4_chip_t *chip_ap_hybrid; 232 const img4_chip_t *chip_ap_reduced; 233 const img4_chip_t *chip_ap_software_ff00; 234 const img4_chip_t *chip_ap_software_ff01; 235 const img4_chip_t *chip_x86; 236 const img4_chip_t *chip_x86_software_8012; 237 img4_chip_init_from_buff_t chip_init_from_buff; 238 img4_chip_select_personalized_ap_t chip_select_personalized_ap; 239 img4_chip_select_effective_ap_t chip_select_effective_ap; 240 img4_chip_instantiate_t chip_instantiate; 241 img4_chip_custom_t chip_custom; 242 img4_firmware_new_t firmware_new; 243 img4_firmware_new_from_vnode_4xnu_t firmware_new_from_vnode_4xnu; 244 img4_firmware_init_from_buff_t firmware_init_from_buff; 245 img4_firmware_init_t firmware_init; 246 img4_firmware_attach_manifest_t firmware_attach_manifest; 247 img4_firmware_execute_t firmware_execute; 248 img4_firmware_destroy_t firmware_destroy; 249 img4_image_get_bytes_t image_get_bytes; 250 img4_image_get_property_bool_t image_get_property_bool; 251 img4_image_get_property_uint32_t image_get_property_uint32; 252 img4_image_get_property_uint64_t image_get_property_uint64; 253 img4_image_get_property_data_t image_get_property_data; 254 const img4_object_spec_t *firmware_spec; 255 const img4_object_spec_t *chip_spec; 256 const img4_runtime_t *runtime_default; 257 const img4_runtime_t *runtime_pmap_cs; 258 img4_buff_dealloc_t buff_dealloc; 259 } i4if_v7; 260 struct { 261 const img4_chip_t *chip_ap_permissive; 262 const img4_chip_t *chip_ap_hybrid_medium; 263 const img4_chip_t *chip_ap_hybrid_relaxed; 264 } i4if_v8; 265 struct { 266 img4_firmware_evaluate_t firmware_evaluate; 267 } i4if_v9; 268 struct { 269 img4_firmware_select_chip_t firmware_select_chip; 270 } i4if_v10; 271 struct { 272 // The following fields are ultimately going to be NULL and unused due 273 // to development churn 274 // 275 // chip_ap_datacenter_development 276 // chip_ap_category 277 // chip_ap_ddi 278 // chip_ap_developer_disk_image 279 const img4_chip_t *chip_ap_datacenter_development; 280 const img4_chip_t *chip_ap_intransigent; 281 const img4_chip_t *chip_ap_category; 282 const img4_chip_t *chip_ap_ddi; 283 const img4_chip_t *chip_ap_developer_disk_image; 284 const img4_chip_t *chip_ap_software_ff06; 285 const img4_chip_t *chip_ap_supplemental; 286 const img4_runtime_object_spec_t *runtime_object_spec_supplemental_root; 287 img4_runtime_find_object_spec_t runtime_find_object_spec; 288 img4_runtime_execute_object_t runtime_execute_object; 289 img4_runtime_copy_object_t runtime_copy_object; 290 } i4if_v11; 291 struct { 292 const img4_nonce_domain_t *nonce_domain_ddi; 293 const img4_nonce_domain_t *nonce_domain_ephemeral_cryptex; 294 const img4_chip_t *chip_ap_category_ff02; 295 const img4_chip_t *chip_ap_category_ff03; 296 const img4_chip_t *chip_ap_category_ff04_f0; 297 const img4_chip_t *chip_ap_category_ff04_f1; 298 const img4_chip_t *chip_ap_category_ff04_f2; 299 const img4_chip_t *chip_ap_category_ff04_f3; 300 img4_chip_select_personalized_ap_t chip_select_categorized_ap; 301 } i4if_v12; 302 struct { 303 const img4_chip_t *chip_ap_vma2; 304 const img4_chip_t *chip_ap_vma2_clone; 305 const img4_object_spec_t *pmap_data_spec; 306 } i4if_v13; 307 } img4_interface_t; 308 309 __BEGIN_DECLS 310 311 /*! 312 * @const img4if 313 * The AppleImage4 interface that was registered. 314 */ 315 extern const img4_interface_t *img4if; 316 317 /*! 318 * @function img4_interface_register 319 * Registers the AppleImage4 kext interface for use within the kernel proper. 320 * 321 * @param i4 322 * The interface to register. 323 * 324 * @discussion 325 * This routine may only be called once and must be called before late-const has 326 * been applied to kernel memory. 327 */ 328 OS_EXPORT OS_NONNULL1 329 void 330 img4_interface_register(const img4_interface_t *i4); 331 332 __END_DECLS 333 334 #endif // __IMG4_INTERFACE_H 335