2 * Copyright (c) 2014 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include <pexpert/pexpert.h>
31 #include <sys/errno.h>
32 #include <sys/sysproto.h>
33 #include <sys/systm.h>
34 #include <sys/types.h>
36 /* enable enforcement by default */
37 static int csr_allow_all
= 0;
42 boot_args
*args
= (boot_args
*)PE_state
.bootArgs
;
43 if (args
->flags
& kBootArgsFlagCSRBoot
) {
44 /* special booter; allow everything */
50 csr_get_active_config(csr_config_t
*config
)
52 boot_args
*args
= (boot_args
*)PE_state
.bootArgs
;
53 if (args
->flags
& kBootArgsFlagCSRActiveConfig
) {
54 *config
= args
->csrActiveConfig
& CSR_VALID_FLAGS
;
63 csr_check(csr_config_t mask
)
65 boot_args
*args
= (boot_args
*)PE_state
.bootArgs
;
66 if ((mask
& CSR_ALLOW_DEVICE_CONFIGURATION
) && !(args
->flags
& kBootArgsFlagCSRConfigMode
))
74 int error
= csr_get_active_config(&config
);
80 /* pass 0 to check if Rootless enforcement is active */
84 error
= (config
& mask
) ? 0 : EPERM
;
92 int syscall_csr_check(struct csrctl_args
*args
);
93 int syscall_csr_get_active_config(struct csrctl_args
*args
);
97 syscall_csr_check(struct csrctl_args
*args
)
99 csr_config_t mask
= 0;
102 if (args
->useraddr
== 0 || args
->usersize
!= sizeof(mask
))
105 error
= copyin(args
->useraddr
, &mask
, sizeof(mask
));
109 return csr_check(mask
);
113 syscall_csr_get_active_config(struct csrctl_args
*args
)
115 csr_config_t config
= 0;
118 if (args
->useraddr
== 0 || args
->usersize
!= sizeof(config
))
121 error
= csr_get_active_config(&config
);
125 return copyout(&config
, args
->useraddr
, sizeof(config
));
133 csrctl(__unused proc_t p
, struct csrctl_args
*args
, __unused
int32_t *retval
)
136 case CSR_SYSCALL_CHECK
:
137 return syscall_csr_check(args
);
138 case CSR_SYSCALL_GET_ACTIVE_CONFIG
:
139 return syscall_csr_get_active_config(args
);