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