xref: /xnu-12377.41.6/bsd/kern/kern_exec_internal.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions  * Copyright (c) 2020-2025 Apple Computer, Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions  *
4*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions  *
6*bbb1b6f9SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*bbb1b6f9SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*bbb1b6f9SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions  *
15*bbb1b6f9SApple OSS Distributions  * Please obtain a copy of the License at
16*bbb1b6f9SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions  *
18*bbb1b6f9SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*bbb1b6f9SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*bbb1b6f9SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*bbb1b6f9SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*bbb1b6f9SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*bbb1b6f9SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions  * limitations under the License.
25*bbb1b6f9SApple OSS Distributions  *
26*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*bbb1b6f9SApple OSS Distributions  */
28*bbb1b6f9SApple OSS Distributions 
29*bbb1b6f9SApple OSS Distributions #ifndef _KERN_EXEC_INTERNAL_H_
30*bbb1b6f9SApple OSS Distributions #define _KERN_EXEC_INTERNAL_H_
31*bbb1b6f9SApple OSS Distributions 
32*bbb1b6f9SApple OSS Distributions #include <sys/imgact.h>
33*bbb1b6f9SApple OSS Distributions #include <sys/kernel_types.h>
34*bbb1b6f9SApple OSS Distributions #include <kern/mach_loader.h>
35*bbb1b6f9SApple OSS Distributions 
36*bbb1b6f9SApple OSS Distributions /*
37*bbb1b6f9SApple OSS Distributions  * Set p->p_comm and p->p_name to the name passed to exec
38*bbb1b6f9SApple OSS Distributions  */
39*bbb1b6f9SApple OSS Distributions extern void
40*bbb1b6f9SApple OSS Distributions set_proc_name(struct image_params *imgp, proc_t p);
41*bbb1b6f9SApple OSS Distributions 
42*bbb1b6f9SApple OSS Distributions /*
43*bbb1b6f9SApple OSS Distributions  * Runtime security mitigations in production are primarily controlled by
44*bbb1b6f9SApple OSS Distributions  * entitlements. Third party processes/daemons on MacOS aren't allowed to use
45*bbb1b6f9SApple OSS Distributions  * the com.apple.developer entitlement without a profile, whereby a special carve out
46*bbb1b6f9SApple OSS Distributions  * exists for com.apple.security.
47*bbb1b6f9SApple OSS Distributions  *
48*bbb1b6f9SApple OSS Distributions  * Progressively we expect internal first party software to shift towards the com.apple.security
49*bbb1b6f9SApple OSS Distributions  * format, but until then we support both cases, with a strict rule that only one can
50*bbb1b6f9SApple OSS Distributions  * be present.
51*bbb1b6f9SApple OSS Distributions  */
52*bbb1b6f9SApple OSS Distributions __enum_decl(exec_security_mitigation_entitlement_t, uint8_t, {
53*bbb1b6f9SApple OSS Distributions /*
54*bbb1b6f9SApple OSS Distributions  * Hardened-process.
55*bbb1b6f9SApple OSS Distributions  *
56*bbb1b6f9SApple OSS Distributions  * Security mitigations follow the notion of "hardened-process": binaries that we
57*bbb1b6f9SApple OSS Distributions  * have identified as being security critical. They are identified by the
58*bbb1b6f9SApple OSS Distributions  * com.apple.{developer|security}.hardened-process entitlement, which is required to further
59*bbb1b6f9SApple OSS Distributions  * configure the other security mitigations.
60*bbb1b6f9SApple OSS Distributions  */
61*bbb1b6f9SApple OSS Distributions 	HARDENED_PROCESS = 0,
62*bbb1b6f9SApple OSS Distributions /*
63*bbb1b6f9SApple OSS Distributions  * Hardened-Heap.
64*bbb1b6f9SApple OSS Distributions  *
65*bbb1b6f9SApple OSS Distributions  * This mitigation extends libmalloc xzone with a number of security features,
66*bbb1b6f9SApple OSS Distributions  * most notably increasing the number of buckets and adding guard pages.
67*bbb1b6f9SApple OSS Distributions  * The presence of the entitlement opts the binary into the feature.
68*bbb1b6f9SApple OSS Distributions  */
69*bbb1b6f9SApple OSS Distributions 	HARDENED_HEAP,
70*bbb1b6f9SApple OSS Distributions /*
71*bbb1b6f9SApple OSS Distributions  * TPRO - Trusted-Path Read-Only
72*bbb1b6f9SApple OSS Distributions  *
73*bbb1b6f9SApple OSS Distributions  * The TPRO mitigation allows to create memory regions that are read-only
74*bbb1b6f9SApple OSS Distributions  * but that can be rapidly, locally, modified by trusted-paths to be temporarily
75*bbb1b6f9SApple OSS Distributions  * read-write. TPRO is "enabled by default" (with the caveats in the exec_setup_tpro())
76*bbb1b6f9SApple OSS Distributions  * starting with the SDK versions below.
77*bbb1b6f9SApple OSS Distributions  */
78*bbb1b6f9SApple OSS Distributions 	TPRO,
79*bbb1b6f9SApple OSS Distributions #if HAS_MTE
80*bbb1b6f9SApple OSS Distributions 	CHECKED_ALLOCATIONS,
81*bbb1b6f9SApple OSS Distributions /*
82*bbb1b6f9SApple OSS Distributions  * For performance reasons, userland allocators are not required to tag pure data regions. This is
83*bbb1b6f9SApple OSS Distributions  * mostly a libmalloc xzone concept, which has separated zones for pointer-containing vs pure-data
84*bbb1b6f9SApple OSS Distributions  * allocations. We consider the former more "security-interesting" and therefore focus our
85*bbb1b6f9SApple OSS Distributions  * protection on them. This allows to save on perforfmance, although for certain processes we
86*bbb1b6f9SApple OSS Distributions  * can swallow the trade-off (both in stability and perf) and enable the extra feature.
87*bbb1b6f9SApple OSS Distributions  */
88*bbb1b6f9SApple OSS Distributions 	CHECKED_ALLOCATIONS_PURE_DATA,
89*bbb1b6f9SApple OSS Distributions /*
90*bbb1b6f9SApple OSS Distributions  * Certain first-party actors (such as WCP and BlastDoor) are modeled untrustworthy, and should never
91*bbb1b6f9SApple OSS Distributions  * be allowed to receive untagged aliases to tagged memory from other actors. This entitlement (and a
92*bbb1b6f9SApple OSS Distributions  *  corresponding hard-coded bundle ID list in AMFI, for secrecy) expresses this constraint.
93*bbb1b6f9SApple OSS Distributions  */
94*bbb1b6f9SApple OSS Distributions 	CHECKED_ALLOCATIONS_NO_TAGGED_RECEIVE,
95*bbb1b6f9SApple OSS Distributions /*
96*bbb1b6f9SApple OSS Distributions  * First and third party processes may want to have a form of "soaking time" where their process
97*bbb1b6f9SApple OSS Distributions  * is battle-tested with MTE without crashing on tag check faults. We call this mode soft-mode.
98*bbb1b6f9SApple OSS Distributions  * Note that after the first tag check fault, tag checking is completely disabled on the process.
99*bbb1b6f9SApple OSS Distributions  */
100*bbb1b6f9SApple OSS Distributions 	CHECKED_ALLOCATIONS_SOFT_MODE,
101*bbb1b6f9SApple OSS Distributions #endif /* HAS_MTE */
102*bbb1b6f9SApple OSS Distributions });
103*bbb1b6f9SApple OSS Distributions 
104*bbb1b6f9SApple OSS Distributions /*
105*bbb1b6f9SApple OSS Distributions  * exec_check_security_entitlement verifies whether a given entitlement is
106*bbb1b6f9SApple OSS Distributions  * associated to the to-be-run process. It verifies both legacy and current
107*bbb1b6f9SApple OSS Distributions  * format and returns:
108*bbb1b6f9SApple OSS Distributions  *   EXEC_SECURITY_NOT_ENTITLED   - if no entitlement is present
109*bbb1b6f9SApple OSS Distributions  *   EXEC_SECURITY_ENTITLED       - if the entitlement is present
110*bbb1b6f9SApple OSS Distributions  *   EXEC_SECURITY_INVALID_CONFIG - if _both_ entitlements are present (fatal condition)
111*bbb1b6f9SApple OSS Distributions  */
112*bbb1b6f9SApple OSS Distributions __enum_decl(exec_security_err_t, uint8_t, {
113*bbb1b6f9SApple OSS Distributions 	EXEC_SECURITY_NOT_ENTITLED,
114*bbb1b6f9SApple OSS Distributions 	EXEC_SECURITY_ENTITLED,
115*bbb1b6f9SApple OSS Distributions 	EXEC_SECURITY_INVALID_CONFIG
116*bbb1b6f9SApple OSS Distributions });
117*bbb1b6f9SApple OSS Distributions 
118*bbb1b6f9SApple OSS Distributions extern exec_security_err_t exec_check_security_entitlement(struct image_params *imgp,
119*bbb1b6f9SApple OSS Distributions     exec_security_mitigation_entitlement_t entitlement);
120*bbb1b6f9SApple OSS Distributions 
121*bbb1b6f9SApple OSS Distributions #endif /* _KERN_EXEC_INTERNAL_H_ */
122