]>
Commit | Line | Data |
---|---|---|
2d21ac55 | 1 | /* |
6d2010ae | 2 | * Copyright (c) 2007-2010 Apple Inc. All rights reserved. |
2d21ac55 A |
3 | * |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
0a7de745 | 5 | * |
2d21ac55 A |
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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 A |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
27 | */ | |
28 | ||
29 | /*- | |
30 | * Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson | |
31 | * Copyright (c) 2001 Ilmar S. Habibulin | |
32 | * Copyright (c) 2001, 2002, 2003, 2004 Networks Associates Technology, Inc. | |
33 | * | |
34 | * This software was developed by Robert Watson and Ilmar Habibulin for the | |
35 | * TrustedBSD Project. | |
36 | * | |
37 | * This software was developed for the FreeBSD Project in part by Network | |
38 | * Associates Laboratories, the Security Research Division of Network | |
39 | * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), | |
40 | * as part of the DARPA CHATS research program. | |
41 | * | |
42 | * Redistribution and use in source and binary forms, with or without | |
43 | * modification, are permitted provided that the following conditions | |
44 | * are met: | |
45 | * 1. Redistributions of source code must retain the above copyright | |
46 | * notice, this list of conditions and the following disclaimer. | |
47 | * 2. Redistributions in binary form must reproduce the above copyright | |
48 | * notice, this list of conditions and the following disclaimer in the | |
49 | * documentation and/or other materials provided with the distribution. | |
50 | * | |
51 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
52 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
53 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
54 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
55 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
56 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
61 | * SUCH DAMAGE. | |
62 | * | |
63 | */ | |
64 | ||
65 | #include <string.h> | |
66 | #include <sys/param.h> | |
67 | #include <sys/ucred.h> | |
68 | #include <sys/malloc.h> | |
69 | #include <sys/sbuf.h> | |
70 | #include <sys/vnode.h> | |
71 | #include <sys/proc.h> | |
72 | #include <sys/proc_internal.h> | |
73 | #include <sys/kauth.h> | |
74 | #include <sys/imgact.h> | |
316670eb | 75 | #include <mach/mach_types.h> |
3e170ce0 | 76 | #include <kern/task.h> |
2d21ac55 | 77 | |
c3c9b80d A |
78 | #include <os/hash.h> |
79 | ||
2d21ac55 | 80 | #include <security/mac_internal.h> |
316670eb | 81 | #include <security/mac_mach_internal.h> |
2d21ac55 | 82 | |
b0d623f7 | 83 | #include <bsd/security/audit/audit.h> |
2d21ac55 A |
84 | |
85 | struct label * | |
86 | mac_cred_label_alloc(void) | |
87 | { | |
88 | struct label *label; | |
89 | ||
90 | label = mac_labelzone_alloc(MAC_WAITOK); | |
0a7de745 A |
91 | if (label == NULL) { |
92 | return NULL; | |
93 | } | |
2d21ac55 | 94 | MAC_PERFORM(cred_label_init, label); |
0a7de745 | 95 | return label; |
2d21ac55 A |
96 | } |
97 | ||
98 | void | |
99 | mac_cred_label_init(struct ucred *cred) | |
100 | { | |
101 | cred->cr_label = mac_cred_label_alloc(); | |
102 | } | |
103 | ||
104 | void | |
105 | mac_cred_label_free(struct label *label) | |
106 | { | |
107 | MAC_PERFORM(cred_label_destroy, label); | |
108 | mac_labelzone_free(label); | |
109 | } | |
110 | ||
c3c9b80d A |
111 | bool |
112 | mac_cred_label_is_equal(const struct label *a, const struct label *b) | |
113 | { | |
114 | if (a->l_flags != b->l_flags) { | |
115 | return false; | |
116 | } | |
117 | for (int slot = 0; slot < MAC_MAX_SLOTS; slot++) { | |
118 | const void *pa = a->l_perpolicy[slot].l_ptr; | |
119 | const void *pb = b->l_perpolicy[slot].l_ptr; | |
120 | ||
121 | if (pa != pb) { | |
122 | return false; | |
123 | } | |
124 | } | |
125 | return true; | |
126 | } | |
127 | ||
128 | uint32_t | |
129 | mac_cred_label_hash_update(const struct label *a, uint32_t hash) | |
316670eb | 130 | { |
c3c9b80d A |
131 | hash = os_hash_jenkins_update(&a->l_flags, |
132 | sizeof(a->l_flags), hash); | |
133 | #if __has_feature(ptrauth_calls) | |
134 | for (int slot = 0; slot < MAC_MAX_SLOTS; slot++) { | |
135 | const void *ptr = a->l_perpolicy[slot].l_ptr; | |
136 | hash = os_hash_jenkins_update(&ptr, sizeof(ptr), hash); | |
137 | } | |
138 | #else | |
139 | hash = os_hash_jenkins_update(&a->l_perpolicy, | |
140 | sizeof(a->l_perpolicy), hash); | |
141 | #endif | |
142 | return hash; | |
316670eb A |
143 | } |
144 | ||
2d21ac55 A |
145 | int |
146 | mac_cred_label_externalize_audit(struct proc *p, struct mac *mac) | |
147 | { | |
148 | kauth_cred_t cr; | |
149 | int error; | |
150 | ||
151 | cr = kauth_cred_proc_ref(p); | |
152 | ||
153 | error = MAC_EXTERNALIZE_AUDIT(cred, cr->cr_label, | |
154 | mac->m_string, mac->m_buflen); | |
155 | ||
156 | kauth_cred_unref(&cr); | |
0a7de745 | 157 | return error; |
2d21ac55 A |
158 | } |
159 | ||
160 | void | |
161 | mac_cred_label_destroy(kauth_cred_t cred) | |
162 | { | |
2d21ac55 A |
163 | mac_cred_label_free(cred->cr_label); |
164 | cred->cr_label = NULL; | |
165 | } | |
166 | ||
167 | int | |
168 | mac_cred_label_externalize(struct label *label, char *elements, | |
169 | char *outbuf, size_t outbuflen, int flags __unused) | |
170 | { | |
171 | int error = 0; | |
172 | ||
173 | error = MAC_EXTERNALIZE(cred, label, elements, outbuf, outbuflen); | |
174 | ||
0a7de745 | 175 | return error; |
2d21ac55 A |
176 | } |
177 | ||
178 | int | |
179 | mac_cred_label_internalize(struct label *label, char *string) | |
180 | { | |
181 | int error; | |
182 | ||
183 | error = MAC_INTERNALIZE(cred, label, string); | |
184 | ||
0a7de745 | 185 | return error; |
2d21ac55 A |
186 | } |
187 | ||
188 | /* | |
189 | * By default, fork just adds a reference to the parent | |
190 | * credential. Policies may need to know about this reference | |
191 | * if they are tracking exit calls to know when to free the | |
192 | * label. | |
193 | */ | |
194 | void | |
195 | mac_cred_label_associate_fork(kauth_cred_t cred, proc_t proc) | |
196 | { | |
197 | MAC_PERFORM(cred_label_associate_fork, cred, proc); | |
198 | } | |
0a7de745 | 199 | |
2d21ac55 A |
200 | /* |
201 | * Initialize MAC label for the first kernel process, from which other | |
202 | * kernel processes and threads are spawned. | |
203 | */ | |
204 | void | |
205 | mac_cred_label_associate_kernel(kauth_cred_t cred) | |
206 | { | |
2d21ac55 A |
207 | MAC_PERFORM(cred_label_associate_kernel, cred); |
208 | } | |
209 | ||
210 | /* | |
211 | * Initialize MAC label for the first userland process, from which other | |
212 | * userland processes and threads are spawned. | |
213 | */ | |
214 | void | |
215 | mac_cred_label_associate_user(kauth_cred_t cred) | |
216 | { | |
2d21ac55 A |
217 | MAC_PERFORM(cred_label_associate_user, cred); |
218 | } | |
219 | ||
220 | /* | |
221 | * When a new process is created, its label must be initialized. Generally, | |
222 | * this involves inheritence from the parent process, modulo possible | |
223 | * deltas. This function allows that processing to take place. | |
224 | */ | |
225 | void | |
226 | mac_cred_label_associate(struct ucred *parent_cred, struct ucred *child_cred) | |
227 | { | |
2d21ac55 A |
228 | MAC_PERFORM(cred_label_associate, parent_cred, child_cred); |
229 | } | |
230 | ||
231 | int | |
232 | mac_execve_enter(user_addr_t mac_p, struct image_params *imgp) | |
233 | { | |
234 | struct user_mac mac; | |
235 | struct label *execlabel; | |
236 | char *buffer; | |
237 | int error; | |
238 | size_t ulen; | |
239 | ||
0a7de745 A |
240 | if (mac_p == USER_ADDR_NULL) { |
241 | return 0; | |
242 | } | |
2d21ac55 A |
243 | |
244 | if (IS_64BIT_PROCESS(current_proc())) { | |
6d2010ae A |
245 | struct user64_mac mac64; |
246 | error = copyin(mac_p, &mac64, sizeof(mac64)); | |
247 | mac.m_buflen = mac64.m_buflen; | |
248 | mac.m_string = mac64.m_string; | |
2d21ac55 | 249 | } else { |
6d2010ae | 250 | struct user32_mac mac32; |
2d21ac55 A |
251 | error = copyin(mac_p, &mac32, sizeof(mac32)); |
252 | mac.m_buflen = mac32.m_buflen; | |
6d2010ae | 253 | mac.m_string = mac32.m_string; |
2d21ac55 | 254 | } |
0a7de745 A |
255 | if (error) { |
256 | return error; | |
257 | } | |
2d21ac55 A |
258 | |
259 | error = mac_check_structmac_consistent(&mac); | |
0a7de745 A |
260 | if (error) { |
261 | return error; | |
262 | } | |
2d21ac55 A |
263 | |
264 | execlabel = mac_cred_label_alloc(); | |
265 | MALLOC(buffer, char *, mac.m_buflen, M_MACTEMP, M_WAITOK); | |
266 | error = copyinstr(CAST_USER_ADDR_T(mac.m_string), buffer, mac.m_buflen, &ulen); | |
0a7de745 | 267 | if (error) { |
2d21ac55 | 268 | goto out; |
0a7de745 | 269 | } |
2d21ac55 A |
270 | AUDIT_ARG(mac_string, buffer); |
271 | ||
272 | error = mac_cred_label_internalize(execlabel, buffer); | |
273 | out: | |
274 | if (error) { | |
275 | mac_cred_label_free(execlabel); | |
276 | execlabel = NULL; | |
277 | } | |
278 | imgp->ip_execlabelp = execlabel; | |
279 | FREE(buffer, M_MACTEMP); | |
0a7de745 | 280 | return error; |
2d21ac55 A |
281 | } |
282 | ||
283 | /* | |
284 | * When the subject's label changes, it may require revocation of privilege | |
285 | * to mapped objects. This can't be done on-the-fly later with a unified | |
286 | * buffer cache. | |
6d2010ae A |
287 | * |
288 | * XXX: CRF_MAC_ENFORCE should be in a kauth_cred_t field, rather | |
289 | * XXX: than a posix_cred_t field. | |
2d21ac55 A |
290 | */ |
291 | void | |
292 | mac_cred_label_update(kauth_cred_t cred, struct label *newlabel) | |
293 | { | |
6d2010ae | 294 | posix_cred_t pcred = posix_cred_get(cred); |
2d21ac55 A |
295 | |
296 | /* force label to be part of "matching" for credential */ | |
6d2010ae | 297 | pcred->cr_flags |= CRF_MAC_ENFORCE; |
2d21ac55 A |
298 | |
299 | /* inform the policies of the update */ | |
300 | MAC_PERFORM(cred_label_update, cred, newlabel); | |
301 | } | |
302 | ||
303 | int | |
304 | mac_cred_check_label_update(kauth_cred_t cred, struct label *newlabel) | |
305 | { | |
306 | int error; | |
307 | ||
3e170ce0 | 308 | #if SECURITY_MAC_CHECK_ENFORCE |
0a7de745 A |
309 | /* 21167099 - only check if we allow write */ |
310 | if (!mac_proc_enforce) { | |
311 | return 0; | |
312 | } | |
3e170ce0 | 313 | #endif |
2d21ac55 A |
314 | |
315 | MAC_CHECK(cred_check_label_update, cred, newlabel); | |
316 | ||
0a7de745 | 317 | return error; |
2d21ac55 A |
318 | } |
319 | ||
320 | int | |
321 | mac_cred_check_visible(kauth_cred_t u1, kauth_cred_t u2) | |
322 | { | |
323 | int error; | |
324 | ||
3e170ce0 | 325 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 326 | /* 21167099 - only check if we allow write */ |
0a7de745 | 327 | if (!mac_proc_enforce) { |
39037602 | 328 | return 0; |
0a7de745 | 329 | } |
3e170ce0 | 330 | #endif |
2d21ac55 A |
331 | |
332 | MAC_CHECK(cred_check_visible, u1, u2); | |
333 | ||
0a7de745 | 334 | return error; |
2d21ac55 A |
335 | } |
336 | ||
2d21ac55 | 337 | int |
f427ee49 | 338 | mac_proc_check_debug(proc_ident_t tracing_ident, kauth_cred_t tracing_cred, proc_ident_t traced_ident) |
2d21ac55 | 339 | { |
2d21ac55 | 340 | int error; |
f427ee49 A |
341 | bool enforce; |
342 | proc_t tracingp; | |
2d21ac55 | 343 | |
3e170ce0 | 344 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 345 | /* 21167099 - only check if we allow write */ |
0a7de745 | 346 | if (!mac_proc_enforce) { |
39037602 | 347 | return 0; |
0a7de745 | 348 | } |
3e170ce0 | 349 | #endif |
f427ee49 A |
350 | /* |
351 | * Once all mac hooks adopt proc_ident_t, finding proc_t and releasing | |
352 | * it below should go to mac_proc_check_enforce(). | |
353 | */ | |
354 | if ((tracingp = proc_find_ident(tracing_ident)) == PROC_NULL) { | |
355 | return ESRCH; | |
0a7de745 | 356 | } |
f427ee49 A |
357 | enforce = mac_proc_check_enforce(tracingp); |
358 | proc_rele(tracingp); | |
2d21ac55 | 359 | |
f427ee49 A |
360 | if (!enforce) { |
361 | return 0; | |
362 | } | |
363 | MAC_CHECK(proc_check_debug, tracing_cred, traced_ident); | |
2d21ac55 | 364 | |
0a7de745 | 365 | return error; |
2d21ac55 A |
366 | } |
367 | ||
c6bf4f31 A |
368 | int |
369 | mac_proc_check_dump_core(struct proc *proc) | |
370 | { | |
371 | int error; | |
372 | ||
373 | #if SECURITY_MAC_CHECK_ENFORCE | |
374 | /* 21167099 - only check if we allow write */ | |
375 | if (!mac_proc_enforce) { | |
376 | return 0; | |
377 | } | |
378 | #endif | |
379 | if (!mac_proc_check_enforce(proc)) { | |
380 | return 0; | |
381 | } | |
382 | ||
383 | MAC_CHECK(proc_check_dump_core, proc); | |
384 | ||
385 | return error; | |
386 | } | |
387 | ||
f427ee49 A |
388 | int |
389 | mac_proc_check_remote_thread_create(struct task *task, int flavor, thread_state_t new_state, mach_msg_type_number_t new_state_count) | |
390 | { | |
391 | proc_t curp = current_proc(); | |
392 | proc_t proc; | |
393 | kauth_cred_t cred; | |
394 | int error; | |
395 | ||
396 | #if SECURITY_MAC_CHECK_ENFORCE | |
397 | /* 21167099 - only check if we allow write */ | |
398 | if (!mac_proc_enforce) { | |
399 | return 0; | |
400 | } | |
401 | #endif | |
402 | if (!mac_proc_check_enforce(curp)) { | |
403 | return 0; | |
404 | } | |
405 | ||
406 | proc = proc_find(task_pid(task)); | |
407 | if (proc == PROC_NULL) { | |
408 | return ESRCH; | |
409 | } | |
410 | ||
411 | cred = kauth_cred_proc_ref(curp); | |
412 | MAC_CHECK(proc_check_remote_thread_create, cred, proc, flavor, new_state, new_state_count); | |
413 | kauth_cred_unref(&cred); | |
414 | proc_rele(proc); | |
415 | ||
416 | return error; | |
417 | } | |
418 | ||
2d21ac55 A |
419 | int |
420 | mac_proc_check_fork(proc_t curp) | |
421 | { | |
422 | kauth_cred_t cred; | |
423 | int error; | |
424 | ||
3e170ce0 | 425 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 426 | /* 21167099 - only check if we allow write */ |
0a7de745 | 427 | if (!mac_proc_enforce) { |
39037602 | 428 | return 0; |
0a7de745 | 429 | } |
3e170ce0 | 430 | #endif |
0a7de745 | 431 | if (!mac_proc_check_enforce(curp)) { |
39037602 | 432 | return 0; |
0a7de745 | 433 | } |
2d21ac55 A |
434 | |
435 | cred = kauth_cred_proc_ref(curp); | |
436 | MAC_CHECK(proc_check_fork, cred, curp); | |
437 | kauth_cred_unref(&cred); | |
438 | ||
0a7de745 | 439 | return error; |
2d21ac55 A |
440 | } |
441 | ||
442 | int | |
c3c9b80d | 443 | mac_proc_check_get_task(struct ucred *cred, proc_ident_t pident, mach_task_flavor_t flavor) |
2d21ac55 A |
444 | { |
445 | int error; | |
446 | ||
c3c9b80d | 447 | assert(flavor <= TASK_FLAVOR_NAME); |
2d21ac55 | 448 | |
c3c9b80d A |
449 | /* Also call the old hook for compatability, deprecating in rdar://66356944. */ |
450 | if (flavor == TASK_FLAVOR_CONTROL) { | |
451 | MAC_CHECK(proc_check_get_task, cred, pident); | |
452 | if (error) { | |
453 | return error; | |
454 | } | |
455 | } | |
2d21ac55 | 456 | |
c3c9b80d A |
457 | if (flavor == TASK_FLAVOR_NAME) { |
458 | MAC_CHECK(proc_check_get_task_name, cred, pident); | |
459 | if (error) { | |
460 | return error; | |
461 | } | |
462 | } | |
2d21ac55 | 463 | |
c3c9b80d | 464 | MAC_CHECK(proc_check_get_task_with_flavor, cred, pident, flavor); |
2d21ac55 | 465 | |
0a7de745 | 466 | return error; |
2d21ac55 A |
467 | } |
468 | ||
3e170ce0 | 469 | int |
c3c9b80d | 470 | mac_proc_check_expose_task(struct ucred *cred, proc_ident_t pident, mach_task_flavor_t flavor) |
3e170ce0 A |
471 | { |
472 | int error; | |
473 | ||
c3c9b80d A |
474 | assert(flavor <= TASK_FLAVOR_NAME); |
475 | ||
476 | /* Also call the old hook for compatability, deprecating in rdar://66356944. */ | |
477 | if (flavor == TASK_FLAVOR_CONTROL) { | |
478 | MAC_CHECK(proc_check_expose_task, cred, pident); | |
479 | if (error) { | |
480 | return error; | |
481 | } | |
482 | } | |
483 | ||
484 | MAC_CHECK(proc_check_expose_task_with_flavor, cred, pident, flavor); | |
3e170ce0 | 485 | |
0a7de745 | 486 | return error; |
3e170ce0 A |
487 | } |
488 | ||
fe8ab488 A |
489 | int |
490 | mac_proc_check_inherit_ipc_ports(struct proc *p, struct vnode *cur_vp, off_t cur_offset, struct vnode *img_vp, off_t img_offset, struct vnode *scriptvp) | |
491 | { | |
492 | int error; | |
493 | ||
494 | MAC_CHECK(proc_check_inherit_ipc_ports, p, cur_vp, cur_offset, img_vp, img_offset, scriptvp); | |
495 | ||
0a7de745 | 496 | return error; |
fe8ab488 A |
497 | } |
498 | ||
6d2010ae A |
499 | /* |
500 | * The type of maxprot in proc_check_map_anon must be equivalent to vm_prot_t | |
501 | * (defined in <mach/vm_prot.h>). mac_policy.h does not include any header | |
502 | * files, so cannot use the typedef itself. | |
503 | */ | |
504 | int | |
505 | mac_proc_check_map_anon(proc_t proc, user_addr_t u_addr, | |
506 | user_size_t u_size, int prot, int flags, int *maxprot) | |
507 | { | |
508 | kauth_cred_t cred; | |
509 | int error; | |
510 | ||
3e170ce0 | 511 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 512 | /* 21167099 - only check if we allow write */ |
0a7de745 | 513 | if (!mac_vm_enforce) { |
39037602 | 514 | return 0; |
0a7de745 | 515 | } |
3e170ce0 | 516 | #endif |
0a7de745 A |
517 | if (!mac_proc_check_enforce(proc)) { |
518 | return 0; | |
519 | } | |
6d2010ae A |
520 | |
521 | cred = kauth_cred_proc_ref(proc); | |
522 | MAC_CHECK(proc_check_map_anon, proc, cred, u_addr, u_size, prot, flags, maxprot); | |
523 | kauth_cred_unref(&cred); | |
524 | ||
0a7de745 | 525 | return error; |
6d2010ae A |
526 | } |
527 | ||
2d21ac55 A |
528 | int |
529 | mac_proc_check_mprotect(proc_t proc, | |
530 | user_addr_t addr, user_size_t size, int prot) | |
531 | { | |
532 | kauth_cred_t cred; | |
533 | int error; | |
534 | ||
3e170ce0 | 535 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 536 | /* 21167099 - only check if we allow write */ |
0a7de745 | 537 | if (!mac_vm_enforce) { |
39037602 | 538 | return 0; |
0a7de745 | 539 | } |
3e170ce0 | 540 | #endif |
0a7de745 A |
541 | if (!mac_proc_check_enforce(proc)) { |
542 | return 0; | |
543 | } | |
2d21ac55 A |
544 | |
545 | cred = kauth_cred_proc_ref(proc); | |
546 | MAC_CHECK(proc_check_mprotect, cred, proc, addr, size, prot); | |
547 | kauth_cred_unref(&cred); | |
548 | ||
0a7de745 | 549 | return error; |
2d21ac55 A |
550 | } |
551 | ||
593a1d5f | 552 | int |
b0d623f7 | 553 | mac_proc_check_run_cs_invalid(proc_t proc) |
593a1d5f | 554 | { |
593a1d5f | 555 | int error; |
0a7de745 | 556 | |
3e170ce0 | 557 | #if SECURITY_MAC_CHECK_ENFORCE |
0a7de745 A |
558 | /* 21167099 - only check if we allow write */ |
559 | if (!mac_vm_enforce) { | |
560 | return 0; | |
561 | } | |
3e170ce0 | 562 | #endif |
0a7de745 | 563 | |
b0d623f7 | 564 | MAC_CHECK(proc_check_run_cs_invalid, proc); |
0a7de745 A |
565 | |
566 | return error; | |
593a1d5f | 567 | } |
0a7de745 | 568 | |
f427ee49 A |
569 | void |
570 | mac_proc_notify_cs_invalidated(proc_t proc) | |
571 | { | |
572 | MAC_PERFORM(proc_notify_cs_invalidated, proc); | |
573 | } | |
574 | ||
2d21ac55 A |
575 | int |
576 | mac_proc_check_sched(proc_t curp, struct proc *proc) | |
577 | { | |
578 | kauth_cred_t cred; | |
579 | int error; | |
580 | ||
3e170ce0 | 581 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 582 | /* 21167099 - only check if we allow write */ |
0a7de745 | 583 | if (!mac_proc_enforce) { |
39037602 | 584 | return 0; |
0a7de745 | 585 | } |
3e170ce0 | 586 | #endif |
0a7de745 | 587 | if (!mac_proc_check_enforce(curp)) { |
39037602 | 588 | return 0; |
0a7de745 | 589 | } |
2d21ac55 A |
590 | |
591 | cred = kauth_cred_proc_ref(curp); | |
592 | MAC_CHECK(proc_check_sched, cred, proc); | |
593 | kauth_cred_unref(&cred); | |
594 | ||
0a7de745 | 595 | return error; |
2d21ac55 A |
596 | } |
597 | ||
598 | int | |
599 | mac_proc_check_signal(proc_t curp, struct proc *proc, int signum) | |
600 | { | |
601 | kauth_cred_t cred; | |
602 | int error; | |
603 | ||
3e170ce0 | 604 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 605 | /* 21167099 - only check if we allow write */ |
0a7de745 | 606 | if (!mac_proc_enforce) { |
39037602 | 607 | return 0; |
0a7de745 | 608 | } |
3e170ce0 | 609 | #endif |
0a7de745 | 610 | if (!mac_proc_check_enforce(curp)) { |
39037602 | 611 | return 0; |
0a7de745 | 612 | } |
2d21ac55 A |
613 | |
614 | cred = kauth_cred_proc_ref(curp); | |
615 | MAC_CHECK(proc_check_signal, cred, proc, signum); | |
616 | kauth_cred_unref(&cred); | |
617 | ||
0a7de745 | 618 | return error; |
2d21ac55 A |
619 | } |
620 | ||
cb323159 A |
621 | int |
622 | mac_proc_check_syscall_unix(proc_t curp, int scnum) | |
623 | { | |
624 | int error; | |
625 | ||
626 | #if SECURITY_MAC_CHECK_ENFORCE | |
627 | /* 21167099 - only check if we allow write */ | |
628 | if (!mac_proc_enforce) { | |
629 | return 0; | |
630 | } | |
631 | #endif | |
632 | if (!mac_proc_check_enforce(curp)) { | |
633 | return 0; | |
634 | } | |
635 | ||
636 | MAC_CHECK(proc_check_syscall_unix, curp, scnum); | |
637 | ||
638 | return error; | |
639 | } | |
640 | ||
2d21ac55 A |
641 | int |
642 | mac_proc_check_wait(proc_t curp, struct proc *proc) | |
643 | { | |
644 | kauth_cred_t cred; | |
645 | int error; | |
646 | ||
3e170ce0 | 647 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 648 | /* 21167099 - only check if we allow write */ |
0a7de745 | 649 | if (!mac_proc_enforce) { |
39037602 | 650 | return 0; |
0a7de745 | 651 | } |
3e170ce0 | 652 | #endif |
0a7de745 | 653 | if (!mac_proc_check_enforce(curp)) { |
39037602 | 654 | return 0; |
0a7de745 | 655 | } |
2d21ac55 A |
656 | |
657 | cred = kauth_cred_proc_ref(curp); | |
658 | MAC_CHECK(proc_check_wait, cred, proc); | |
659 | kauth_cred_unref(&cred); | |
660 | ||
0a7de745 | 661 | return error; |
2d21ac55 A |
662 | } |
663 | ||
5ba3f43e A |
664 | void |
665 | mac_proc_notify_exit(struct proc *proc) | |
666 | { | |
667 | MAC_PERFORM(proc_notify_exit, proc); | |
668 | } | |
669 | ||
d1ecb069 | 670 | int |
f427ee49 | 671 | mac_proc_check_suspend_resume(proc_t proc, int sr) |
d1ecb069 A |
672 | { |
673 | kauth_cred_t cred; | |
674 | int error; | |
675 | ||
3e170ce0 | 676 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 677 | /* 21167099 - only check if we allow write */ |
0a7de745 | 678 | if (!mac_proc_enforce) { |
39037602 | 679 | return 0; |
0a7de745 | 680 | } |
3e170ce0 | 681 | #endif |
f427ee49 | 682 | if (!mac_proc_check_enforce(current_proc())) { |
39037602 | 683 | return 0; |
0a7de745 | 684 | } |
d1ecb069 | 685 | |
f427ee49 A |
686 | cred = kauth_cred_proc_ref(current_proc()); |
687 | MAC_CHECK(proc_check_suspend_resume, cred, proc, sr); | |
d1ecb069 A |
688 | kauth_cred_unref(&cred); |
689 | ||
0a7de745 | 690 | return error; |
d1ecb069 | 691 | } |
316670eb A |
692 | |
693 | int | |
694 | mac_proc_check_ledger(proc_t curp, proc_t proc, int ledger_op) | |
695 | { | |
696 | kauth_cred_t cred; | |
697 | int error = 0; | |
698 | ||
3e170ce0 | 699 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 700 | /* 21167099 - only check if we allow write */ |
0a7de745 | 701 | if (!mac_proc_enforce) { |
39037602 | 702 | return 0; |
0a7de745 | 703 | } |
3e170ce0 | 704 | #endif |
0a7de745 | 705 | if (!mac_proc_check_enforce(curp)) { |
39037602 | 706 | return 0; |
0a7de745 | 707 | } |
316670eb A |
708 | |
709 | cred = kauth_cred_proc_ref(curp); | |
710 | MAC_CHECK(proc_check_ledger, cred, proc, ledger_op); | |
711 | kauth_cred_unref(&cred); | |
712 | ||
0a7de745 | 713 | return error; |
316670eb A |
714 | } |
715 | ||
39236c6e A |
716 | int |
717 | mac_proc_check_proc_info(proc_t curp, proc_t target, int callnum, int flavor) | |
718 | { | |
719 | kauth_cred_t cred; | |
720 | int error = 0; | |
721 | ||
3e170ce0 | 722 | #if SECURITY_MAC_CHECK_ENFORCE |
39037602 | 723 | /* 21167099 - only check if we allow write */ |
0a7de745 | 724 | if (!mac_proc_enforce) { |
39037602 | 725 | return 0; |
0a7de745 | 726 | } |
3e170ce0 | 727 | #endif |
0a7de745 | 728 | if (!mac_proc_check_enforce(curp)) { |
39037602 | 729 | return 0; |
0a7de745 | 730 | } |
39236c6e A |
731 | |
732 | cred = kauth_cred_proc_ref(curp); | |
733 | MAC_CHECK(proc_check_proc_info, cred, target, callnum, flavor); | |
734 | kauth_cred_unref(&cred); | |
735 | ||
0a7de745 | 736 | return error; |
39236c6e A |
737 | } |
738 | ||
7e41aa88 A |
739 | int |
740 | mac_proc_check_get_cs_info(proc_t curp, proc_t target, unsigned int op) | |
741 | { | |
742 | kauth_cred_t cred; | |
743 | int error = 0; | |
744 | ||
745 | #if SECURITY_MAC_CHECK_ENFORCE | |
746 | /* 21167099 - only check if we allow write */ | |
0a7de745 | 747 | if (!mac_proc_enforce) { |
7e41aa88 | 748 | return 0; |
0a7de745 | 749 | } |
7e41aa88 | 750 | #endif |
0a7de745 | 751 | if (!mac_proc_check_enforce(curp)) { |
7e41aa88 | 752 | return 0; |
0a7de745 | 753 | } |
7e41aa88 A |
754 | |
755 | cred = kauth_cred_proc_ref(curp); | |
756 | MAC_CHECK(proc_check_get_cs_info, cred, target, op); | |
757 | kauth_cred_unref(&cred); | |
758 | ||
0a7de745 | 759 | return error; |
7e41aa88 A |
760 | } |
761 | ||
762 | int | |
763 | mac_proc_check_set_cs_info(proc_t curp, proc_t target, unsigned int op) | |
764 | { | |
765 | kauth_cred_t cred; | |
766 | int error = 0; | |
767 | ||
768 | #if SECURITY_MAC_CHECK_ENFORCE | |
769 | /* 21167099 - only check if we allow write */ | |
0a7de745 | 770 | if (!mac_proc_enforce) { |
7e41aa88 | 771 | return 0; |
0a7de745 | 772 | } |
7e41aa88 | 773 | #endif |
0a7de745 | 774 | if (!mac_proc_check_enforce(curp)) { |
7e41aa88 | 775 | return 0; |
0a7de745 | 776 | } |
7e41aa88 A |
777 | |
778 | cred = kauth_cred_proc_ref(curp); | |
779 | MAC_CHECK(proc_check_set_cs_info, cred, target, op); | |
780 | kauth_cred_unref(&cred); | |
781 | ||
0a7de745 | 782 | return error; |
7e41aa88 | 783 | } |