1*699cd480SApple OSS Distributions /*
2*699cd480SApple OSS Distributions * Copyright (c) 2020 Apple Computer, Inc. All rights reserved.
3*699cd480SApple OSS Distributions *
4*699cd480SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*699cd480SApple OSS Distributions *
6*699cd480SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*699cd480SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*699cd480SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*699cd480SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*699cd480SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*699cd480SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*699cd480SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*699cd480SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*699cd480SApple OSS Distributions *
15*699cd480SApple OSS Distributions * Please obtain a copy of the License at
16*699cd480SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*699cd480SApple OSS Distributions *
18*699cd480SApple OSS Distributions * The Original Code and all software distributed under the License are
19*699cd480SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*699cd480SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*699cd480SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*699cd480SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*699cd480SApple OSS Distributions * Please see the License for the specific language governing rights and
24*699cd480SApple OSS Distributions * limitations under the License.
25*699cd480SApple OSS Distributions *
26*699cd480SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*699cd480SApple OSS Distributions */
28*699cd480SApple OSS Distributions
29*699cd480SApple OSS Distributions #ifndef _KERN_MACH_FILTER_H_
30*699cd480SApple OSS Distributions #define _KERN_MACH_FILTER_H_
31*699cd480SApple OSS Distributions
32*699cd480SApple OSS Distributions #if KERNEL_PRIVATE
33*699cd480SApple OSS Distributions
34*699cd480SApple OSS Distributions #include <sys/cdefs.h>
35*699cd480SApple OSS Distributions #include <mach/message.h>
36*699cd480SApple OSS Distributions #include <mach/port.h>
37*699cd480SApple OSS Distributions
38*699cd480SApple OSS Distributions /* Sandbox-specific calls for task based message filtering */
39*699cd480SApple OSS Distributions typedef boolean_t (*mach_msg_fetch_filter_policy_cbfunc_t) (struct task *task, void *portlabel,
40*699cd480SApple OSS Distributions mach_msg_id_t msgid, mach_msg_filter_id *fpid);
41*699cd480SApple OSS Distributions
42*699cd480SApple OSS Distributions typedef kern_return_t (*mach_msg_filter_alloc_service_port_sblabel_cbfunc_t) (mach_service_port_info_t service_port_info,
43*699cd480SApple OSS Distributions void **sblabel);
44*699cd480SApple OSS Distributions
45*699cd480SApple OSS Distributions typedef void (*mach_msg_filter_dealloc_service_port_sblabel_cbfunc_t) (void *sblabel);
46*699cd480SApple OSS Distributions
47*699cd480SApple OSS Distributions typedef void* (*mach_msg_filter_derive_sblabel_from_service_port_cbfunc_t) (void *service_port_sblabel,
48*699cd480SApple OSS Distributions boolean_t *send_side_filtering);
49*699cd480SApple OSS Distributions
50*699cd480SApple OSS Distributions typedef kern_return_t (*mach_msg_filter_get_connection_port_filter_policy_cbfunc_t) (void *service_port_sblabel,
51*699cd480SApple OSS Distributions void *connection_port_sblabel, uint64_t *fpid);
52*699cd480SApple OSS Distributions
53*699cd480SApple OSS Distributions /* Will be called with the port lock held */
54*699cd480SApple OSS Distributions typedef void (*mach_msg_filter_retain_sblabel_cbfunc_t) (void * sblabel);
55*699cd480SApple OSS Distributions
56*699cd480SApple OSS Distributions struct mach_msg_filter_callbacks {
57*699cd480SApple OSS Distributions unsigned int version;
58*699cd480SApple OSS Distributions /* v0 */
59*699cd480SApple OSS Distributions const mach_msg_fetch_filter_policy_cbfunc_t fetch_filter_policy;
60*699cd480SApple OSS Distributions
61*699cd480SApple OSS Distributions /* v1 */
62*699cd480SApple OSS Distributions const mach_msg_filter_alloc_service_port_sblabel_cbfunc_t alloc_service_port_sblabel;
63*699cd480SApple OSS Distributions const mach_msg_filter_dealloc_service_port_sblabel_cbfunc_t dealloc_service_port_sblabel;
64*699cd480SApple OSS Distributions const mach_msg_filter_derive_sblabel_from_service_port_cbfunc_t derive_sblabel_from_service_port;
65*699cd480SApple OSS Distributions const mach_msg_filter_get_connection_port_filter_policy_cbfunc_t get_connection_port_filter_policy;
66*699cd480SApple OSS Distributions const mach_msg_filter_retain_sblabel_cbfunc_t retain_sblabel;
67*699cd480SApple OSS Distributions };
68*699cd480SApple OSS Distributions
69*699cd480SApple OSS Distributions #define MACH_MSG_FILTER_CALLBACKS_VERSION_0 (0) /* up-to fetch_filter_policy */
70*699cd480SApple OSS Distributions #define MACH_MSG_FILTER_CALLBACKS_VERSION_1 (1) /* up-to derive_sblabel_from_service_port */
71*699cd480SApple OSS Distributions #define MACH_MSG_FILTER_CALLBACKS_CURRENT MACH_MSG_FILTER_CALLBACKS_VERSION_1
72*699cd480SApple OSS Distributions
73*699cd480SApple OSS Distributions __BEGIN_DECLS
74*699cd480SApple OSS Distributions
75*699cd480SApple OSS Distributions int mach_msg_filter_register_callback(const struct mach_msg_filter_callbacks *callbacks);
76*699cd480SApple OSS Distributions
77*699cd480SApple OSS Distributions __END_DECLS
78*699cd480SApple OSS Distributions
79*699cd480SApple OSS Distributions #endif /* KERNEL_PRIVATE */
80*699cd480SApple OSS Distributions
81*699cd480SApple OSS Distributions #if XNU_KERNEL_PRIVATE
82*699cd480SApple OSS Distributions extern struct mach_msg_filter_callbacks mach_msg_filter_callbacks;
83*699cd480SApple OSS Distributions
84*699cd480SApple OSS Distributions static inline bool __pure2
mach_msg_filter_at_least(unsigned int version)85*699cd480SApple OSS Distributions mach_msg_filter_at_least(unsigned int version)
86*699cd480SApple OSS Distributions {
87*699cd480SApple OSS Distributions if (version == 0) {
88*699cd480SApple OSS Distributions /*
89*699cd480SApple OSS Distributions * a non initialized cb struct looks the same as v0
90*699cd480SApple OSS Distributions * so we need a null check for that one
91*699cd480SApple OSS Distributions */
92*699cd480SApple OSS Distributions return mach_msg_filter_callbacks.fetch_filter_policy != NULL;
93*699cd480SApple OSS Distributions }
94*699cd480SApple OSS Distributions return mach_msg_filter_callbacks.version >= version;
95*699cd480SApple OSS Distributions }
96*699cd480SApple OSS Distributions
97*699cd480SApple OSS Distributions /* v0 */
98*699cd480SApple OSS Distributions #define mach_msg_fetch_filter_policy_callback \
99*699cd480SApple OSS Distributions (mach_msg_filter_callbacks.fetch_filter_policy)
100*699cd480SApple OSS Distributions
101*699cd480SApple OSS Distributions /* v1 */
102*699cd480SApple OSS Distributions #define mach_msg_filter_alloc_service_port_sblabel_callback \
103*699cd480SApple OSS Distributions (mach_msg_filter_callbacks.alloc_service_port_sblabel)
104*699cd480SApple OSS Distributions #define mach_msg_filter_dealloc_service_port_sblabel_callback \
105*699cd480SApple OSS Distributions (mach_msg_filter_callbacks.dealloc_service_port_sblabel)
106*699cd480SApple OSS Distributions #define mach_msg_filter_derive_sblabel_from_service_port_callback \
107*699cd480SApple OSS Distributions (mach_msg_filter_callbacks.derive_sblabel_from_service_port)
108*699cd480SApple OSS Distributions #define mach_msg_filter_get_connection_port_filter_policy_callback \
109*699cd480SApple OSS Distributions (mach_msg_filter_callbacks.get_connection_port_filter_policy)
110*699cd480SApple OSS Distributions #define mach_msg_filter_retain_sblabel_callback \
111*699cd480SApple OSS Distributions (mach_msg_filter_callbacks.retain_sblabel)
112*699cd480SApple OSS Distributions
113*699cd480SApple OSS Distributions extern
114*699cd480SApple OSS Distributions boolean_t mach_msg_fetch_filter_policy(void *portlabel, mach_msg_id_t msgh_id, mach_msg_filter_id *fid);
115*699cd480SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
116*699cd480SApple OSS Distributions
117*699cd480SApple OSS Distributions #endif /* _KERN_MACH_FILTER_H_ */
118