Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | /* * Copyright (c) 2022 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ #ifndef _SYS_TRUST_CACHES_H_ #define _SYS_TRUST_CACHES_H_ #ifdef KERNEL_PRIVATE #include <mach/kern_return.h> #include <sys/cdefs.h> #include <TrustCache/API.h> #if (DEVELOPMENT || DEBUG) #define TRUST_CACHE_INCLUDE_INTERNAL_CODE 1 #endif /* Availability macros to check for support */ #define XNU_HAS_TRUST_CACHE_LOADING 1 #define XNU_HAS_TRUST_CACHE_CHECK_RUNTIME_FOR_UUID 1 #define XNU_HAS_TRUST_CACHE_QUERY_FOR_REM 1 #define XNU_HAS_TRUST_CACHE_UNLOADING 1 #ifdef XNU_PLATFORM_BridgeOS #define XNU_HAS_LEGACY_TRUST_CACHE_LOADING 1 #elif defined(TARGET_OS_BRIDGE) && TARGET_OS_BRIDGE #define XNU_HAS_LEGACY_TRUST_CACHE_LOADING 1 #else #define XNU_HAS_LEGACY_TRUST_CACHE_LOADING 0 #endif __BEGIN_DECLS #if XNU_KERNEL_PRIVATE /* Common variables which represent the number of loaded trust caches */ extern uint32_t num_static_trust_caches; extern uint32_t num_engineering_trust_caches; extern uint32_t num_loadable_trust_caches; /* Temporary definition until we get a proper shared one */ typedef struct DTTrustCacheRange { vm_offset_t paddr; size_t length; } DTTrustCacheRange; /* This is the structure iBoot uses to deliver the trust caches to the system */ typedef struct _trust_cache_offsets { /* The number of trust caches provided */ uint32_t num_caches; /* Offset of each from beginning of the structure */ uint32_t offsets[0]; } __attribute__((__packed__)) trust_cache_offsets_t; /** * Initialize the trust cache runtime for the system environment. */ void trust_cache_runtime_init(void); /** * Load the static and engineering trust caches passed over to the system by the boot loader. */ void load_static_trust_cache(void); #endif /* XNU_KERNEL_PRIVATE */ /** * Check the capabilities of the static trust caches on the system. Since the static trust * caches are loaded at boot, kernel extensions don't get a chance to observe their format * and miss out on the information. * * This function can be queried to obtain this information. */ kern_return_t static_trust_cache_capabilities( uint32_t *num_static_trust_caches_ret, TCCapabilities_t *capabilities0_ret, TCCapabilities_t *capabilities1_ret); /** * Check if a particular trust cache has already been loaded into the system on the basis * of a provided UUID. * * Based on the system environment, this request may trap into the kernel's code signing * monitor environment as the trust cache data structures need to be locked down. */ kern_return_t check_trust_cache_runtime_for_uuid( const uint8_t check_uuid[kUUIDSize]); /** * Unload a trust cache from the system given a UUID. Depending on the implementation, this * may eiher genuinely unload the trust cache from the system, or it may simply tombstone * the trust cache such that it can't be used any more. */ kern_return_t unload_trust_cache(uuid_t uuid); /** * Load an image4 trust cache. Since the type of trust cache isn't specified, this interface * attempts to validate the trust cache through all known types. Therefore, this evaluation * can be expensive. * * This is a deprecated interface and should no longer be used. It also doesn't support usage * of the auxiliary manifest. Please use the newer interface "load_trust_cache_with_type". */ kern_return_t load_trust_cache( const uint8_t *img4_object, const size_t img4_object_len, const uint8_t *img4_ext_manifest, const size_t img4_ext_manifest_len); /** * Load an image4 based trust cache of a particular type. This function performs an entitlement * check on the calling process to ensure it has the entitlement for loading the specified trust * cache. * * Based on the system environment, the trust cache may be loaded into kernel memory, or it may * be loaded into memory controlled by the kernel monitor environment. In either case, this * function creates its own allocations for the data, and the caller may free their allocations, * if any. */ kern_return_t load_trust_cache_with_type( TCType_t type, const uint8_t *img4_object, const size_t img4_object_len, const uint8_t *img4_ext_manifest, const size_t img4_ext_manifest_len, const uint8_t *img4_aux_manifest, const size_t img4_aux_manifest_len); /** * Load a legacy trust cache module for supported platforms. Availability for the KPI can * be checked by querying the macro "XNU_HAS_LEGACY_TRUST_CACHE_LOADING". Using this KPI * on an unsupported platform will panic the system. */ kern_return_t load_legacy_trust_cache( const uint8_t *module_data, const size_t module_size); /** * Query a trust cache based on the type passed in. * * Based on the system environment, the trust cache may be queried from kernel memory, or it may * be queried from memory controlled by the kernel monitor environment. */ kern_return_t query_trust_cache( TCQueryType_t query_type, const uint8_t cdhash[kTCEntryHashSize], TrustCacheQueryToken_t *query_token); /** * Query the set of loaded trust caches to find the most relevant REM permissions for a given * CDHash. * * Based on the system environment, the trust cache may be queried from kernel memory, or it may * be queried from memory controlled by the kernel monitor environment. */ kern_return_t query_trust_cache_for_rem( const uint8_t cdhash[kTCEntryHashSize], uint8_t *rem_perms); __END_DECLS #endif /* KERNEL_PRIVATE */ #endif /* _SYS_TRUST_CACHES_H_ */ |