-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathmac_policy.h
More file actions
6656 lines (6509 loc) · 231 KB
/
mac_policy.h
File metadata and controls
6656 lines (6509 loc) · 231 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2007-2016 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
/*-
* Copyright (c) 1999-2002 Robert N. M. Watson
* Copyright (c) 2001-2005 Networks Associates Technology, Inc.
* Copyright (c) 2005-2007 SPARTA, Inc.
* All rights reserved.
*
* This software was developed by Robert Watson for the TrustedBSD Project.
*
* This software was developed for the FreeBSD Project in part by Network
* Associates Laboratories, the Security Research Division of Network
* Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
* as part of the DARPA CHATS research program.
*
* This software was enhanced by SPARTA ISSO under SPAWAR contract
* N66001-04-C-6019 ("SEFOS").
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/sys/sys/mac_policy.h,v 1.39 2003/04/18 19:57:37 rwatson Exp $
*/
/**
* @file mac_policy.h
* @brief Kernel Interfaces for MAC policy modules
*
* This header defines the list of operations that are defined by the
* TrustedBSD MAC Framwork on Darwin. MAC Policy modules register
* with the framework to declare interest in a specific set of
* operations. If interest in an entry point is not declared, then
* the policy will be ignored when the Framework evaluates that entry
* point.
*/
#ifndef _SECURITY_MAC_POLICY_H_
#define _SECURITY_MAC_POLICY_H_
#ifndef PRIVATE
#warning "MAC policy is not KPI, see Technical Q&A QA1574, this header will be removed in next version"
#endif
#include <security/_label.h>
#include <kern/cs_blobs.h>
struct attrlist;
struct auditinfo;
struct bpf_d;
struct cs_blob;
struct devnode;
struct exception_action;
struct fileglob;
struct ifnet;
struct inpcb;
struct ipq;
struct label;
struct mac_policy_conf;
struct mbuf;
struct mount;
struct msg;
struct msqid_kernel;
struct pipe;
struct pseminfo;
struct pshminfo;
struct sbuf;
struct semid_kernel;
struct shmid_kernel;
struct socket;
struct sockopt;
struct task;
struct thread;
struct tty;
struct ucred;
struct vfs_attr;
struct vnode;
struct sockaddr;
/** @struct dummy */
/*
* proc_ident_t support, see: rdar://problem/58928152
* Should be removed once all dependent parties adopt
* proc_ident_t.
*/
#define MAC_PROC_IDENT_SUPPORT 1
/*
* rdar://146696727
*
* Support for opaque lookup policy on proc_ident
* when using proc_find_ident
*/
#define MAC_PROC_IDENT_POLICY_SUPPORT 1
#ifndef _KAUTH_CRED_T
#define _KAUTH_CRED_T
typedef struct ucred *kauth_cred_t;
#endif /* !_KAUTH_CRED_T */
#ifndef __IOKIT_PORTS_DEFINED__
#define __IOKIT_PORTS_DEFINED__
#ifdef __cplusplus
class OSObject;
typedef OSObject *io_object_t;
#else
struct OSObject;
typedef struct OSObject *io_object_t;
#endif
#endif /* __IOKIT_PORTS_DEFINED__ */
/*-
* MAC entry points are generally named using the following template:
*
* mpo_<object>_<operation>()
*
* or:
*
* mpo_<object>_check_<operation>()
*
* Entry points are sorted by object type.
*
* It may be desirable also to consider some subsystems as "objects", such
* as system, iokit, etc.
*/
/**
* @name Entry Points for Label Management
*
* These are the entry points corresponding to the life cycle events for
* kernel objects, such as initialization, creation, and destruction.
*
* Most policies (that use labels) will initialize labels by allocating
* space for policy-specific data. In most cases, it is permitted to
* sleep during label initialization operations; it will be noted when
* it is not permitted.
*
* Initialization usually will not require doing more than allocating a
* generic label for the given object. What follows initialization is
* creation, where a label is made specific to the object it is associated
* with. Destruction occurs when the label is no longer needed, such as
* when the corresponding object is destroyed. All necessary cleanup should
* be performed in label destroy operations.
*
* Where possible, the label entry points have identical parameters. If
* the policy module does not require structure-specific label
* information, the same function may be registered in the policy
* operation vector. Many policies will implement two such generic
* allocation calls: one to handle sleepable requests, and one to handle
* potentially non-sleepable requests.
*/
/**
* @brief Audit event postselection
* @param cred Subject credential
* @param syscode Syscall number
* @param args Syscall arguments
* @param error Syscall errno
* @param retval Syscall return value
*
* This is the MAC Framework audit postselect, which is called before
* exiting a syscall to determine if an audit event should be committed.
* A return value of MAC_AUDIT_NO forces the audit record to be suppressed.
* Any other return value results in the audit record being committed.
*
* @warning The suppression behavior will probably go away in Apple's
* future version of the audit implementation.
*
* @return Return MAC_AUDIT_NO to force suppression of the audit record.
* Any other value results in the audit record being committed.
*
*/
typedef int mpo_audit_check_postselect_t(
kauth_cred_t cred,
unsigned short syscode,
void *args,
int error,
int retval
);
/**
* @brief Audit event preselection
* @param cred Subject credential
* @param syscode Syscall number
* @param args Syscall arguments
*
* This is the MAC Framework audit preselect, which is called before a
* syscall is entered to determine if an audit event should be created.
* If the MAC policy forces the syscall to be audited, MAC_AUDIT_YES should be
* returned. A return value of MAC_AUDIT_NO causes the audit record to
* be suppressed. Returning MAC_POLICY_DEFAULT indicates that the policy wants
* to defer to the system's existing preselection mechanism.
*
* When policies return different preferences, the Framework decides what action
* to take based on the following policy. If any policy returns MAC_AUDIT_YES,
* then create an audit record, else if any policy returns MAC_AUDIT_NO, then
* suppress the creations of an audit record, else defer to the system's
* existing preselection mechanism.
*
* @warning The audit implementation in Apple's current version is
* incomplete, so the MAC policies have priority over the system's existing
* mechanisms. This will probably change in the future version where
* the audit implementation is more complete.
*
* @return Return MAC_AUDIT_YES to force auditing of the syscall,
* MAC_AUDIT_NO to force no auditing of the syscall, MAC_AUDIT_DEFAULT
* to allow auditing mechanisms to determine if the syscall is audited.
*
*/
typedef int mpo_audit_check_preselect_t(
kauth_cred_t cred,
unsigned short syscode,
void *args
);
/**
* @brief Indicate desire to change the process label at exec time
* @param old Existing subject credential
* @param vp File being executed
* @param offset Offset of binary within file being executed
* @param scriptvp Script being executed by interpreter, if any.
* @param vnodelabel Label corresponding to vp
* @param scriptvnodelabel Script vnode label
* @param execlabel Userspace provided execution label
* @param p Object process
* @param macpolicyattr MAC policy-specific spawn attribute data
* @param macpolicyattrlen Length of policy-specific spawn attribute data
* @see mac_execve
* @see mpo_cred_label_update_execve_t
* @see mpo_vnode_check_exec_t
*
* Indicate whether this policy intends to update the label of a newly
* created credential from the existing subject credential (old). This
* call occurs when a process executes the passed vnode. If a policy
* returns success from this entry point, the mpo_cred_label_update_execve
* entry point will later be called with the same parameters. Access
* has already been checked via the mpo_vnode_check_exec entry point,
* this entry point is necessary to preserve kernel locking constraints
* during program execution.
*
* The supplied vnode and vnodelabel correspond with the file actually
* being executed; in the case that the file is interpreted (for
* example, a script), the label of the original exec-time vnode has
* been preserved in scriptvnodelabel.
*
* The final label, execlabel, corresponds to a label supplied by a
* user space application through the use of the mac_execve system call.
*
* The vnode lock is held during this operation. No changes should be
* made to the old credential structure.
*
* @warning Even if a policy returns 0, it should behave correctly in
* the presence of an invocation of mpo_cred_label_update_execve, as that
* call may happen as a result of another policy requesting a transition.
*
* @return Non-zero if a transition is required, 0 otherwise.
*/
typedef int mpo_cred_check_label_update_execve_t(
kauth_cred_t old,
struct vnode *vp,
off_t offset,
struct vnode *scriptvp,
struct label *vnodelabel,
struct label *scriptvnodelabel,
struct label *execlabel,
struct proc *p,
void *macpolicyattr,
size_t macpolicyattrlen
);
/**
* @brief Access control check for relabelling processes
* @param cred Subject credential
* @param newlabel New label to apply to the user credential
* @see mpo_cred_label_update_t
* @see mac_set_proc
*
* Determine whether the subject identified by the credential can relabel
* itself to the supplied new label (newlabel). This access control check
* is called when the mac_set_proc system call is invoked. A user space
* application will supply a new value, the value will be internalized
* and provided in newlabel.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned.
*/
typedef int mpo_cred_check_label_update_t(
kauth_cred_t cred,
struct label *newlabel
);
/**
* @brief Access control check for visibility of other subjects
* @param u1 Subject credential
* @param u2 Object credential
*
* Determine whether the subject identified by the credential u1 can
* "see" other subjects with the passed subject credential u2. This call
* may be made in a number of situations, including inter-process status
* sysctls used by ps, and in procfs lookups.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned. Suggested failure: EACCES for label mismatch,
* EPERM for lack of privilege, or ESRCH to hide visibility.
*/
typedef int mpo_cred_check_visible_t(
kauth_cred_t u1,
kauth_cred_t u2
);
/**
* @brief Associate a credential with a new process at fork
* @param cred credential to inherited by new process
* @param proc the new process
*
* Allow a process to associate the credential with a new
* process for reference countng purposes.
* NOTE: the credential can be dis-associated in ways other
* than exit - so this strategy is flawed - should just
* catch label destroy callback.
*/
typedef void mpo_cred_label_associate_fork_t(
kauth_cred_t cred,
proc_t proc
);
/**
* @brief Create the first process
* @param cred Subject credential to be labeled
*
* Create the subject credential of process 0, the parent of all BSD
* kernel processes. Policies should update the label in the
* previously initialized credential structure.
*/
typedef void mpo_cred_label_associate_kernel_t(
kauth_cred_t cred
);
/**
* @brief Create a credential label
* @param parent_cred Parent credential
* @param child_cred Child credential
*
* Set the label of a newly created credential, most likely using the
* information in the supplied parent credential.
*
* @warning This call is made when crcopy or crdup is invoked on a
* newly created struct ucred, and should not be confused with a
* process fork or creation event.
*/
typedef void mpo_cred_label_associate_t(
kauth_cred_t parent_cred,
kauth_cred_t child_cred
);
/**
* @brief Create the first process
* @param cred Subject credential to be labeled
*
* Create the subject credential of process 1, the parent of all BSD
* user processes. Policies should update the label in the previously
* initialized credential structure. This is the 'init' process.
*/
typedef void mpo_cred_label_associate_user_t(
kauth_cred_t cred
);
/**
* @brief Destroy credential label
* @param label The label to be destroyed
*
* Destroy a user credential label. Since the user credential
* is going out of scope, policy modules should free any internal
* storage associated with the label so that it may be destroyed.
*/
typedef void mpo_cred_label_destroy_t(
struct label *label
);
/**
* @brief Externalize a user credential label for auditing
* @param label Label to be externalized
* @param element_name Name of the label namespace for which labels should be
* externalized
* @param sb String buffer to be filled with a text representation of the label
*
* Produce an external representation of the label on a user credential for
* inclusion in an audit record. An externalized label consists of a text
* representation of the label contents that will be added to the audit record
* as part of a text token. Policy-agnostic user space tools will display
* this externalized version.
*
* @return 0 on success, return non-zero if an error occurs while
* externalizing the label data.
*
*/
typedef int mpo_cred_label_externalize_audit_t(
struct label *label,
char *element_name,
struct sbuf *sb
);
/**
* @brief Externalize a user credential label
* @param label Label to be externalized
* @param element_name Name of the label namespace for which labels should be
* externalized
* @param sb String buffer to be filled with a text representation of the label
*
* Produce an external representation of the label on a user
* credential. An externalized label consists of a text representation
* of the label contents that can be used with user applications.
* Policy-agnostic user space tools will display this externalized
* version.
*
* @return 0 on success, return non-zero if an error occurs while
* externalizing the label data.
*
*/
typedef int mpo_cred_label_externalize_t(
struct label *label,
char *element_name,
struct sbuf *sb
);
/**
* @brief Initialize user credential label
* @param label New label to initialize
*
* Initialize the label for a newly instantiated user credential.
* Sleeping is permitted.
*/
typedef void mpo_cred_label_init_t(
struct label *label
);
/**
* @brief Internalize a user credential label
* @param label Label to be internalized
* @param element_name Name of the label namespace for which the label should
* be internalized
* @param element_data Text data to be internalized
*
* Produce a user credential label from an external representation. An
* externalized label consists of a text representation of the label
* contents that can be used with user applications. Policy-agnostic
* user space tools will forward text version to the kernel for
* processing by individual policy modules.
*
* The policy's internalize entry points will be called only if the
* policy has registered interest in the label namespace.
*
* @return 0 on success, Otherwise, return non-zero if an error occurs
* while internalizing the label data.
*
*/
typedef int mpo_cred_label_internalize_t(
struct label *label,
char *element_name,
char *element_data
);
/**
* @brief Update credential at exec time
* @param old_cred Existing subject credential
* @param new_cred New subject credential to be labeled
* @param p Object process.
* @param vp File being executed
* @param offset Offset of binary within file being executed
* @param scriptvp Script being executed by interpreter, if any.
* @param vnodelabel Label corresponding to vp
* @param scriptvnodelabel Script vnode label
* @param execlabel Userspace provided execution label
* @param csflags Code signing flags to be set after exec
* @param macpolicyattr MAC policy-specific spawn attribute data.
* @param macpolicyattrlen Length of policy-specific spawn attribute data.
* @see mac_execve
* @see mpo_cred_check_label_update_execve_t
* @see mpo_vnode_check_exec_t
*
* Update the label of a newly created credential (new) from the
* existing subject credential (old). This call occurs when a process
* executes the passed vnode and one of the loaded policy modules has
* returned success from the mpo_cred_check_label_update_execve entry point.
* Access has already been checked via the mpo_vnode_check_exec entry
* point, this entry point is only used to update any policy state.
*
* The supplied vnode and vnodelabel correspond with the file actually
* being executed; in the case that the file is interpreted (for
* example, a script), the label of the original exec-time vnode has
* been preserved in scriptvnodelabel.
*
* The final label, execlabel, corresponds to a label supplied by a
* user space application through the use of the mac_execve system call.
*
* If non-NULL, the value pointed to by disjointp will be set to 0 to
* indicate that the old and new credentials are not disjoint, or 1 to
* indicate that they are.
*
* The vnode lock is held during this operation. No changes should be
* made to the old credential structure.
* @return 0 on success, Otherwise, return non-zero if update results in
* termination of child.
*/
typedef int mpo_cred_label_update_execve_t(
kauth_cred_t old_cred,
kauth_cred_t new_cred,
struct proc *p,
struct vnode *vp,
off_t offset,
struct vnode *scriptvp,
struct label *vnodelabel,
struct label *scriptvnodelabel,
struct label *execlabel,
u_int *csflags,
void *macpolicyattr,
size_t macpolicyattrlen,
int *disjointp
);
/**
* @brief Update a credential label
* @param cred The existing credential
* @param newlabel A new label to apply to the credential
* @see mpo_cred_check_label_update_t
* @see mac_set_proc
*
* Update the label on a user credential, using the supplied new label.
* This is called as a result of a process relabel operation. Access
* control was already confirmed by mpo_cred_check_label_update.
*/
typedef void mpo_cred_label_update_t(
kauth_cred_t cred,
struct label *newlabel
);
/**
* @brief Access control for launching a process with constraints
* @param curr_p The new process
* @param original_parent_id The pid of the original parent that spawned this process
* @param responsible_pid The pid of the responsible process that spawned this process
* @param macpolicyattr MAC policy-specific spawn attribute data
* @param macpolicyattrlen Length of policy-specific spawn attribute data
* @param fatal_failure_desc Description of fatal failure
* @param fatal_failure_desc_len Failure description len, failure is fatal if non-0
*
* Detemine whether the process being spawned adheres to the launch
* constraints (e.g. whether the process is spawned by launchd) and should
* be allowed to execute. This call occurs during execve or posix_spawn.
*
* @return Return 0 if process can be created, otherwise an appropriate value for
* errno should be returned.
*/
typedef int mpo_proc_check_launch_constraints_t(
proc_t curr_p,
pid_t original_parent_id,
pid_t responsible_pid,
void *macpolicyattr,
size_t macpolicyattrlen,
launch_constraint_data_t lcd,
char **fatal_failure_desc, size_t *fatal_failure_desc_len
);
/**
* @brief Create a new devfs device
* @param dev Major and minor numbers of special file
* @param de "inode" of new device file
* @param label Destination label
* @param fullpath Path relative to mount (e.g. /dev) of new device file
*
* This entry point labels a new devfs device. The label will likely be based
* on the path to the device, or the major and minor numbers.
* The policy should store an appropriate label into 'label'.
*/
typedef void mpo_devfs_label_associate_device_t(
dev_t dev,
struct devnode *de,
struct label *label,
const char *fullpath
);
/**
* @brief Create a new devfs directory
* @param dirname Name of new directory
* @param dirnamelen Length of 'dirname'
* @param de "inode" of new directory
* @param label Destination label
* @param fullpath Path relative to mount (e.g. /dev) of new directory
*
* This entry point labels a new devfs directory. The label will likely be
* based on the path of the new directory. The policy should store an appropriate
* label into 'label'. The devfs root directory is labelled in this way.
*/
typedef void mpo_devfs_label_associate_directory_t(
const char *dirname,
int dirnamelen,
struct devnode *de,
struct label *label,
const char *fullpath
);
/**
* @brief Copy a devfs label
* @param src Source devfs label
* @param dest Destination devfs label
*
* Copy the label information from src to dest. The devfs file system
* often duplicates (splits) existing device nodes rather than creating
* new ones.
*/
typedef void mpo_devfs_label_copy_t(
struct label *src,
struct label *dest
);
/**
* @brief Destroy devfs label
* @param label The label to be destroyed
*
* Destroy a devfs entry label. Since the object is going out
* of scope, policy modules should free any internal storage associated
* with the label so that it may be destroyed.
*/
typedef void mpo_devfs_label_destroy_t(
struct label *label
);
/**
* @brief Initialize devfs label
* @param label New label to initialize
*
* Initialize the label for a newly instantiated devfs entry. Sleeping
* is permitted.
*/
typedef void mpo_devfs_label_init_t(
struct label *label
);
/**
* @brief Update a devfs label after relabelling its vnode
* @param mp Devfs mount point
* @param de Affected devfs directory entry
* @param delabel Label of devfs directory entry
* @param vp Vnode associated with de
* @param vnodelabel New label of vnode
*
* Update a devfs label when its vnode is manually relabelled,
* for example with setfmac(1). Typically, this will simply copy
* the vnode label into the devfs label.
*/
typedef void mpo_devfs_label_update_t(
struct mount *mp,
struct devnode *de,
struct label *delabel,
struct vnode *vp,
struct label *vnodelabel
);
/**
* @brief Access control for sending an exception to an exception action
* @param crashlabel The crashing process's label
* @param action Exception action
* @param exclabel Policy label for exception action
*
* Determine whether the the exception message caused by the victim
* process can be sent to the exception action. The policy may compare
* credentials in the crashlabel, which are derived from the process at
* the time the exception occurs, with the credentials in the exclabel,
* which was set at the time the exception port was set, to determine
* its decision. Note that any process from which the policy derived
* any credentials may not exist anymore at the time of this policy
* operation. Sleeping is permitted.
*
* @return Return 0 if the message can be sent, otherwise an
* appropriate value for errno should be returned.
*/
typedef int mpo_exc_action_check_exception_send_t(
struct label *crashlabel,
struct exception_action *action,
struct label *exclabel
);
/**
* @brief Associate an exception action label
* @param action Exception action to label
* @param exclabel Policy label to be filled in for exception action
*
* Set the label on an exception action.
*/
typedef void mpo_exc_action_label_associate_t(
struct exception_action *action,
struct label *exclabel
);
/**
* @brief Destroy exception action label
* @param label The label to be destroyed
*
* Destroy the label on an exception action. Since the object is going
* out of scope, policy modules should free any internal storage
* associated with the label so that it may be destroyed. Sleeping is
* permitted.
*/
typedef void mpo_exc_action_label_destroy_t(
struct label *label
);
/**
* @brief Populate an exception action label with process credentials
* @param label The label to be populated
* @param proc Process to derive credentials from
*
* Populate a label with credentials derived from a process. At
* exception delivery time, the policy should compare credentials of the
* process that set an exception ports with the credentials of the
* process or corpse that experienced the exception. Note that the
* process that set the port may not exist at that time anymore, so
* labels should carry copies of live credentials if necessary.
*/
typedef void mpo_exc_action_label_populate_t(
struct label *label,
struct proc *proc
);
/**
* @brief Initialize exception action label
* @param label New label to initialize
*
* Initialize a label for an exception action. Usually performs
* policy specific allocations. Sleeping is permitted.
*/
typedef int mpo_exc_action_label_init_t(
struct label *label
);
/**
* @brief Update the label on an exception action
* @param action Exception action that the label belongs to (may be
* NULL if none)
* @param label Policy label to update
* @param newlabel New label for update
*
* Update the credentials of an exception action from the given
* label. The policy should copy over any credentials (process and
* otherwise) from the new label into the label to update. Must not
* sleep, must be quick and can be called with locks held.
*/
typedef int mpo_exc_action_label_update_t(
struct exception_action *action,
struct label *label,
struct label *newlabel
);
/**
* @brief Access control for changing the offset of a file descriptor
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
*
* Determine whether the subject identified by the credential can
* change the offset of the file represented by fg.
*
* @return Return 0 if access if granted, otherwise an appropriate
* value for errno should be returned.
*/
typedef int mpo_file_check_change_offset_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label
);
/**
* @brief Access control for creating a file descriptor
* @param cred Subject credential
*
* Determine whether the subject identified by the credential can
* allocate a new file descriptor.
*
* @return Return 0 if access if granted, otherwise an appropriate
* value for errno should be returned.
*/
typedef int mpo_file_check_create_t(
kauth_cred_t cred
);
/**
* @brief Access control for duplicating a file descriptor
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
* @param newfd New file descriptor number
*
* Determine whether the subject identified by the credential can
* duplicate the fileglob structure represented by fg and as file
* descriptor number newfd.
*
* @return Return 0 if access if granted, otherwise an appropriate
* value for errno should be returned.
*/
typedef int mpo_file_check_dup_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label,
int newfd
);
/**
* @brief Access control check for fcntl
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
* @param cmd Control operation to be performed; see fcntl(2)
* @param arg fcnt arguments; see fcntl(2)
*
* Determine whether the subject identified by the credential can perform
* the file control operation indicated by cmd.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned.
*/
typedef int mpo_file_check_fcntl_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label,
int cmd,
user_long_t arg
);
/**
* @brief Access control check for mac_get_fd
* @param cred Subject credential
* @param fg Fileglob structure
* @param elements Element buffer
* @param len Length of buffer
*
* Determine whether the subject identified by the credential should be allowed
* to get an externalized version of the label on the object indicated by fd.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned.
*/
typedef int mpo_file_check_get_t(
kauth_cred_t cred,
struct fileglob *fg,
char *elements,
size_t len
);
/**
* @brief Access control for getting the offset of a file descriptor
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
*
* Determine whether the subject identified by the credential can
* get the offset of the file represented by fg.
*
* @return Return 0 if access if granted, otherwise an appropriate
* value for errno should be returned.
*/
typedef int mpo_file_check_get_offset_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label
);
/**
* @brief Access control for inheriting a file descriptor
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
*
* Determine whether the subject identified by the credential can
* inherit the fileglob structure represented by fg.
*
* @return Return 0 if access if granted, otherwise an appropriate
* value for errno should be returned.
*/
typedef int mpo_file_check_inherit_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label
);
/**
* @brief Access control check for file ioctl
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
* @param cmd The ioctl command; see ioctl(2)
*
* Determine whether the subject identified by the credential can perform
* the ioctl operation indicated by cmd.
*
* @warning Since ioctl data is opaque from the standpoint of the MAC
* framework, policies must exercise extreme care when implementing
* access control checks.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned.
*
*/
typedef int mpo_file_check_ioctl_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label,
unsigned long cmd
);
/**
* @brief Access control check for file locking
* @param cred Subject credential
* @param fg Fileglob structure
* @param label Policy label for fg
* @param op The lock operation (F_GETLK, F_SETLK, F_UNLK)
* @param fl The flock structure
*
* Determine whether the subject identified by the credential can perform
* the lock operation indicated by op and fl on the file represented by fg.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned.
*
*/
typedef int mpo_file_check_lock_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label,
int op,
struct flock *fl
);
/**
* @brief Check with library validation if a Mach-O slice is allowed to be combined into a proc.
* @param p Subject process
* @param fg Fileglob structure
* @param slice_offset offset of the code slice
* @param error_message error message returned to user-space in case of error (userspace pointer)
* @param error_message_size error message size
*
* It's a little odd that the MAC/kext writes into userspace since this
* implies there is only one MAC module that implements this, however
* the alternative is to allocate memory in xnu, in the hope that
* the MAC module will use it, or allocate in the MAC module and then
* free it in xnu. Neither of these is very appealing, so let's go with
* the slightly more hacky way.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned.
*/
typedef int mpo_file_check_library_validation_t(
struct proc *p,
struct fileglob *fg,
off_t slice_offset,
user_long_t error_message,
size_t error_message_size
);
/**
* @brief Access control check for mapping a file
* @param cred Subject credential
* @param fg fileglob representing file to map
* @param label Policy label associated with vp
* @param prot mmap protections; see mmap(2)
* @param flags Type of mapped object; see mmap(2)
* @param maxprot Maximum rights
*
* Determine whether the subject identified by the credential should be
* allowed to map the file represented by fg with the protections specified
* in prot. The maxprot field holds the maximum permissions on the new
* mapping, a combination of VM_PROT_READ, VM_PROT_WRITE, and VM_PROT_EXECUTE.
* To avoid overriding prior access control checks, a policy should only
* remove flags from maxprot.
*
* @return Return 0 if access is granted, otherwise an appropriate value for
* errno should be returned. Suggested failure: EACCES for label mismatch or
* EPERM for lack of privilege.
*/
typedef int mpo_file_check_mmap_t(
kauth_cred_t cred,
struct fileglob *fg,
struct label *label,
int prot,
int flags,
uint64_t file_pos,
int *maxprot
);
/**
* @brief Downgrade the mmap protections
* @param cred Subject credential
* @param fg file to map
* @param label Policy label associated with vp
* @param prot mmap protections to be downgraded
*
* Downgrade the mmap protections based on the subject and object labels.