xref: /freebsd/sys/security/mac_test/mac_test.c (revision 41059135ce931c0f1014a999ffabc6bc470ce856)
1 /*-
2  * Copyright (c) 1999-2002, 2007-2011 Robert N. M. Watson
3  * Copyright (c) 2001-2005 McAfee, Inc.
4  * Copyright (c) 2006 SPARTA, Inc.
5  * Copyright (c) 2008 Apple Inc.
6  * All rights reserved.
7  *
8  * This software was developed by Robert Watson for the TrustedBSD Project.
9  *
10  * This software was developed for the FreeBSD Project in part by McAfee
11  * Research, the Security Research Division of McAfee, Inc. under
12  * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
13  * CHATS research program.
14  *
15  * This software was enhanced by SPARTA ISSO under SPAWAR contract
16  * N66001-04-C-6019 ("SEFOS").
17  *
18  * This software was developed at the University of Cambridge Computer
19  * Laboratory with support from a grant from Google, Inc.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40  * SUCH DAMAGE.
41  *
42  * $FreeBSD$
43  */
44 
45 /*
46  * Developed by the TrustedBSD Project.
47  *
48  * MAC Test policy - tests MAC Framework labeling by assigning object class
49  * magic numbers to each label and validates that each time an object label
50  * is passed into the policy, it has a consistent object type, catching
51  * incorrectly passed labels, labels passed after free, etc.
52  */
53 
54 #include <sys/param.h>
55 #include <sys/acl.h>
56 #include <sys/kdb.h>
57 #include <sys/kernel.h>
58 #include <sys/ksem.h>
59 #include <sys/malloc.h>
60 #include <sys/module.h>
61 #include <sys/mount.h>
62 #include <sys/msg.h>
63 #include <sys/proc.h>
64 #include <sys/vnode.h>
65 #include <sys/sem.h>
66 #include <sys/shm.h>
67 #include <sys/socket.h>
68 #include <sys/socketvar.h>
69 #include <sys/sx.h>
70 #include <sys/sysctl.h>
71 
72 #include <fs/devfs/devfs.h>
73 
74 #include <net/bpfdesc.h>
75 #include <net/if.h>
76 #include <net/if_types.h>
77 #include <net/if_var.h>
78 
79 #include <security/mac/mac_policy.h>
80 
81 SYSCTL_DECL(_security_mac);
82 
83 static SYSCTL_NODE(_security_mac, OID_AUTO, test, CTLFLAG_RW, 0,
84     "TrustedBSD mac_test policy controls");
85 
86 #define	MAGIC_BPF	0xfe1ad1b6
87 #define	MAGIC_DEVFS	0x9ee79c32
88 #define	MAGIC_IFNET	0xc218b120
89 #define	MAGIC_INPCB	0x4440f7bb
90 #define	MAGIC_IP6Q	0x0870e1b7
91 #define	MAGIC_IPQ	0x206188ef
92 #define	MAGIC_MBUF	0xbbefa5bb
93 #define	MAGIC_MOUNT	0xc7c46e47
94 #define	MAGIC_SOCKET	0x9199c6cd
95 #define	MAGIC_SYNCACHE	0x7fb838a8
96 #define	MAGIC_SYSV_MSG	0x8bbba61e
97 #define	MAGIC_SYSV_MSQ	0xea672391
98 #define	MAGIC_SYSV_SEM	0x896e8a0b
99 #define	MAGIC_SYSV_SHM	0x76119ab0
100 #define	MAGIC_PIPE	0xdc6c9919
101 #define	MAGIC_POSIX_SEM	0x78ae980c
102 #define	MAGIC_POSIX_SHM	0x4e853fc9
103 #define	MAGIC_PROC	0x3b4be98f
104 #define	MAGIC_CRED	0x9a5a4987
105 #define	MAGIC_VNODE	0x1a67a45c
106 #define	MAGIC_FREE	0x849ba1fd
107 
108 #define	SLOT(x)	mac_label_get((x), test_slot)
109 #define	SLOT_SET(x, v)	mac_label_set((x), test_slot, (v))
110 
111 static int	test_slot;
112 SYSCTL_INT(_security_mac_test, OID_AUTO, slot, CTLFLAG_RD,
113     &test_slot, 0, "Slot allocated by framework");
114 
115 static SYSCTL_NODE(_security_mac_test, OID_AUTO, counter, CTLFLAG_RW, 0,
116     "TrustedBSD mac_test counters controls");
117 
118 #define	COUNTER_DECL(variable)						\
119 	static int counter_##variable;					\
120 	SYSCTL_INT(_security_mac_test_counter, OID_AUTO, variable,	\
121 	CTLFLAG_RD, &counter_##variable, 0, #variable)
122 
123 #define	COUNTER_INC(variable)	atomic_add_int(&counter_##variable, 1)
124 
125 #ifdef KDB
126 #define	DEBUGGER(func, string)	kdb_enter(KDB_WHY_MAC, (string))
127 #else
128 #define	DEBUGGER(func, string)	printf("mac_test: %s: %s\n", (func), (string))
129 #endif
130 
131 #define	LABEL_CHECK(label, magic) do {					\
132 	if (label != NULL) {						\
133 		KASSERT(SLOT(label) == magic ||	SLOT(label) == 0,	\
134 		    ("%s: bad %s label", __func__, #magic));		\
135 	}								\
136 } while (0)
137 
138 #define	LABEL_DESTROY(label, magic) do {				\
139 	if (SLOT(label) == magic || SLOT(label) == 0) {			\
140 		SLOT_SET(label, MAGIC_FREE);				\
141 	} else if (SLOT(label) == MAGIC_FREE) {				\
142 		DEBUGGER("%s: dup destroy", __func__);			\
143 	} else {							\
144 		DEBUGGER("%s: corrupted label", __func__);		\
145 	}								\
146 } while (0)
147 
148 #define	LABEL_INIT(label, magic) do {					\
149 	SLOT_SET(label, magic);						\
150 } while (0)
151 
152 #define	LABEL_NOTFREE(label) do {					\
153 	KASSERT(SLOT(label) != MAGIC_FREE,				\
154 	    ("%s: destroyed label", __func__));				\
155 } while (0)
156 
157 /*
158  * Object-specific entry point implementations are sorted alphabetically by
159  * object type name and then by operation.
160  */
161 COUNTER_DECL(bpfdesc_check_receive);
162 static int
163 test_bpfdesc_check_receive(struct bpf_d *d, struct label *dlabel,
164     struct ifnet *ifp, struct label *ifplabel)
165 {
166 
167 	LABEL_CHECK(dlabel, MAGIC_BPF);
168 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
169 	COUNTER_INC(bpfdesc_check_receive);
170 
171 	return (0);
172 }
173 
174 COUNTER_DECL(bpfdesc_create);
175 static void
176 test_bpfdesc_create(struct ucred *cred, struct bpf_d *d,
177     struct label *dlabel)
178 {
179 
180 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
181 	LABEL_CHECK(dlabel, MAGIC_BPF);
182 	COUNTER_INC(bpfdesc_create);
183 }
184 
185 COUNTER_DECL(bpfdesc_create_mbuf);
186 static void
187 test_bpfdesc_create_mbuf(struct bpf_d *d, struct label *dlabel,
188     struct mbuf *m, struct label *mlabel)
189 {
190 
191 	LABEL_CHECK(dlabel, MAGIC_BPF);
192 	LABEL_CHECK(mlabel, MAGIC_MBUF);
193 	COUNTER_INC(bpfdesc_create_mbuf);
194 }
195 
196 COUNTER_DECL(bpfdesc_destroy_label);
197 static void
198 test_bpfdesc_destroy_label(struct label *label)
199 {
200 
201 	LABEL_DESTROY(label, MAGIC_BPF);
202 	COUNTER_INC(bpfdesc_destroy_label);
203 }
204 
205 COUNTER_DECL(bpfdesc_init_label);
206 static void
207 test_bpfdesc_init_label(struct label *label)
208 {
209 
210 	LABEL_INIT(label, MAGIC_BPF);
211 	COUNTER_INC(bpfdesc_init_label);
212 }
213 
214 COUNTER_DECL(cred_check_relabel);
215 static int
216 test_cred_check_relabel(struct ucred *cred, struct label *newlabel)
217 {
218 
219 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
220 	LABEL_CHECK(newlabel, MAGIC_CRED);
221 	COUNTER_INC(cred_check_relabel);
222 
223 	return (0);
224 }
225 
226 COUNTER_DECL(cred_check_setaudit);
227 static int
228 test_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai)
229 {
230 
231 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
232 	COUNTER_INC(cred_check_setaudit);
233 
234 	return (0);
235 }
236 
237 COUNTER_DECL(cred_check_setaudit_addr);
238 static int
239 test_cred_check_setaudit_addr(struct ucred *cred,
240     struct auditinfo_addr *aia)
241 {
242 
243 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
244 	COUNTER_INC(cred_check_setaudit_addr);
245 
246 	return (0);
247 }
248 
249 COUNTER_DECL(cred_check_setauid);
250 static int
251 test_cred_check_setauid(struct ucred *cred, uid_t auid)
252 {
253 
254 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
255 	COUNTER_INC(cred_check_setauid);
256 
257 	return (0);
258 }
259 
260 COUNTER_DECL(cred_check_setegid);
261 static int
262 test_cred_check_setegid(struct ucred *cred, gid_t egid)
263 {
264 
265 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
266 	COUNTER_INC(cred_check_setegid);
267 
268 	return (0);
269 }
270 
271 COUNTER_DECL(proc_check_euid);
272 static int
273 test_cred_check_seteuid(struct ucred *cred, uid_t euid)
274 {
275 
276 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
277 	COUNTER_INC(proc_check_euid);
278 
279 	return (0);
280 }
281 
282 COUNTER_DECL(cred_check_setregid);
283 static int
284 test_cred_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid)
285 {
286 
287 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
288 	COUNTER_INC(cred_check_setregid);
289 
290 	return (0);
291 }
292 
293 COUNTER_DECL(cred_check_setreuid);
294 static int
295 test_cred_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid)
296 {
297 
298 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
299 	COUNTER_INC(cred_check_setreuid);
300 
301 	return (0);
302 }
303 
304 COUNTER_DECL(cred_check_setgid);
305 static int
306 test_cred_check_setgid(struct ucred *cred, gid_t gid)
307 {
308 
309 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
310 	COUNTER_INC(cred_check_setgid);
311 
312 	return (0);
313 }
314 
315 COUNTER_DECL(cred_check_setgroups);
316 static int
317 test_cred_check_setgroups(struct ucred *cred, int ngroups,
318 	gid_t *gidset)
319 {
320 
321 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
322 	COUNTER_INC(cred_check_setgroups);
323 
324 	return (0);
325 }
326 
327 COUNTER_DECL(cred_check_setresgid);
328 static int
329 test_cred_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid,
330 	gid_t sgid)
331 {
332 
333 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
334 	COUNTER_INC(cred_check_setresgid);
335 
336 	return (0);
337 }
338 
339 COUNTER_DECL(cred_check_setresuid);
340 static int
341 test_cred_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid,
342 	uid_t suid)
343 {
344 
345 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
346 	COUNTER_INC(cred_check_setresuid);
347 
348 	return (0);
349 }
350 
351 COUNTER_DECL(cred_check_setuid);
352 static int
353 test_cred_check_setuid(struct ucred *cred, uid_t uid)
354 {
355 
356 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
357 	COUNTER_INC(cred_check_setuid);
358 
359 	return (0);
360 }
361 
362 COUNTER_DECL(cred_check_visible);
363 static int
364 test_cred_check_visible(struct ucred *u1, struct ucred *u2)
365 {
366 
367 	LABEL_CHECK(u1->cr_label, MAGIC_CRED);
368 	LABEL_CHECK(u2->cr_label, MAGIC_CRED);
369 	COUNTER_INC(cred_check_visible);
370 
371 	return (0);
372 }
373 
374 COUNTER_DECL(cred_copy_label);
375 static void
376 test_cred_copy_label(struct label *src, struct label *dest)
377 {
378 
379 	LABEL_CHECK(src, MAGIC_CRED);
380 	LABEL_CHECK(dest, MAGIC_CRED);
381 	COUNTER_INC(cred_copy_label);
382 }
383 
384 COUNTER_DECL(cred_create_init);
385 static void
386 test_cred_create_init(struct ucred *cred)
387 {
388 
389 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
390 	COUNTER_INC(cred_create_init);
391 }
392 
393 COUNTER_DECL(cred_create_swapper);
394 static void
395 test_cred_create_swapper(struct ucred *cred)
396 {
397 
398 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
399 	COUNTER_INC(cred_create_swapper);
400 }
401 
402 COUNTER_DECL(cred_destroy_label);
403 static void
404 test_cred_destroy_label(struct label *label)
405 {
406 
407 	LABEL_DESTROY(label, MAGIC_CRED);
408 	COUNTER_INC(cred_destroy_label);
409 }
410 
411 COUNTER_DECL(cred_externalize_label);
412 static int
413 test_cred_externalize_label(struct label *label, char *element_name,
414     struct sbuf *sb, int *claimed)
415 {
416 
417 	LABEL_CHECK(label, MAGIC_CRED);
418 	COUNTER_INC(cred_externalize_label);
419 
420 	return (0);
421 }
422 
423 COUNTER_DECL(cred_init_label);
424 static void
425 test_cred_init_label(struct label *label)
426 {
427 
428 	LABEL_INIT(label, MAGIC_CRED);
429 	COUNTER_INC(cred_init_label);
430 }
431 
432 COUNTER_DECL(cred_internalize_label);
433 static int
434 test_cred_internalize_label(struct label *label, char *element_name,
435     char *element_data, int *claimed)
436 {
437 
438 	LABEL_CHECK(label, MAGIC_CRED);
439 	COUNTER_INC(cred_internalize_label);
440 
441 	return (0);
442 }
443 
444 COUNTER_DECL(cred_relabel);
445 static void
446 test_cred_relabel(struct ucred *cred, struct label *newlabel)
447 {
448 
449 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
450 	LABEL_CHECK(newlabel, MAGIC_CRED);
451 	COUNTER_INC(cred_relabel);
452 }
453 
454 COUNTER_DECL(devfs_create_device);
455 static void
456 test_devfs_create_device(struct ucred *cred, struct mount *mp,
457     struct cdev *dev, struct devfs_dirent *de, struct label *delabel)
458 {
459 
460 	if (cred != NULL)
461 		LABEL_CHECK(cred->cr_label, MAGIC_CRED);
462 	LABEL_CHECK(delabel, MAGIC_DEVFS);
463 	COUNTER_INC(devfs_create_device);
464 }
465 
466 COUNTER_DECL(devfs_create_directory);
467 static void
468 test_devfs_create_directory(struct mount *mp, char *dirname,
469     int dirnamelen, struct devfs_dirent *de, struct label *delabel)
470 {
471 
472 	LABEL_CHECK(delabel, MAGIC_DEVFS);
473 	COUNTER_INC(devfs_create_directory);
474 }
475 
476 COUNTER_DECL(devfs_create_symlink);
477 static void
478 test_devfs_create_symlink(struct ucred *cred, struct mount *mp,
479     struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de,
480     struct label *delabel)
481 {
482 
483 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
484 	LABEL_CHECK(ddlabel, MAGIC_DEVFS);
485 	LABEL_CHECK(delabel, MAGIC_DEVFS);
486 	COUNTER_INC(devfs_create_symlink);
487 }
488 
489 COUNTER_DECL(devfs_destroy_label);
490 static void
491 test_devfs_destroy_label(struct label *label)
492 {
493 
494 	LABEL_DESTROY(label, MAGIC_DEVFS);
495 	COUNTER_INC(devfs_destroy_label);
496 }
497 
498 COUNTER_DECL(devfs_init_label);
499 static void
500 test_devfs_init_label(struct label *label)
501 {
502 
503 	LABEL_INIT(label, MAGIC_DEVFS);
504 	COUNTER_INC(devfs_init_label);
505 }
506 
507 COUNTER_DECL(devfs_update);
508 static void
509 test_devfs_update(struct mount *mp, struct devfs_dirent *devfs_dirent,
510     struct label *direntlabel, struct vnode *vp, struct label *vplabel)
511 {
512 
513 	LABEL_CHECK(direntlabel, MAGIC_DEVFS);
514 	LABEL_CHECK(vplabel, MAGIC_VNODE);
515 	COUNTER_INC(devfs_update);
516 }
517 
518 COUNTER_DECL(devfs_vnode_associate);
519 static void
520 test_devfs_vnode_associate(struct mount *mp, struct label *mplabel,
521     struct devfs_dirent *de, struct label *delabel, struct vnode *vp,
522     struct label *vplabel)
523 {
524 
525 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
526 	LABEL_CHECK(delabel, MAGIC_DEVFS);
527 	LABEL_CHECK(vplabel, MAGIC_VNODE);
528 	COUNTER_INC(devfs_vnode_associate);
529 }
530 
531 COUNTER_DECL(ifnet_check_relabel);
532 static int
533 test_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifp,
534     struct label *ifplabel, struct label *newlabel)
535 {
536 
537 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
538 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
539 	LABEL_CHECK(newlabel, MAGIC_IFNET);
540 	COUNTER_INC(ifnet_check_relabel);
541 
542 	return (0);
543 }
544 
545 COUNTER_DECL(ifnet_check_transmit);
546 static int
547 test_ifnet_check_transmit(struct ifnet *ifp, struct label *ifplabel,
548     struct mbuf *m, struct label *mlabel)
549 {
550 
551 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
552 	LABEL_CHECK(mlabel, MAGIC_MBUF);
553 	COUNTER_INC(ifnet_check_transmit);
554 
555 	return (0);
556 }
557 
558 COUNTER_DECL(ifnet_copy_label);
559 static void
560 test_ifnet_copy_label(struct label *src, struct label *dest)
561 {
562 
563 	LABEL_CHECK(src, MAGIC_IFNET);
564 	LABEL_CHECK(dest, MAGIC_IFNET);
565 	COUNTER_INC(ifnet_copy_label);
566 }
567 
568 COUNTER_DECL(ifnet_create);
569 static void
570 test_ifnet_create(struct ifnet *ifp, struct label *ifplabel)
571 {
572 
573 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
574 	COUNTER_INC(ifnet_create);
575 }
576 
577 COUNTER_DECL(ifnet_create_mbuf);
578 static void
579 test_ifnet_create_mbuf(struct ifnet *ifp, struct label *ifplabel,
580     struct mbuf *m, struct label *mlabel)
581 {
582 
583 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
584 	LABEL_CHECK(mlabel, MAGIC_MBUF);
585 	COUNTER_INC(ifnet_create_mbuf);
586 }
587 
588 COUNTER_DECL(ifnet_destroy_label);
589 static void
590 test_ifnet_destroy_label(struct label *label)
591 {
592 
593 	LABEL_DESTROY(label, MAGIC_IFNET);
594 	COUNTER_INC(ifnet_destroy_label);
595 }
596 
597 COUNTER_DECL(ifnet_externalize_label);
598 static int
599 test_ifnet_externalize_label(struct label *label, char *element_name,
600     struct sbuf *sb, int *claimed)
601 {
602 
603 	LABEL_CHECK(label, MAGIC_IFNET);
604 	COUNTER_INC(ifnet_externalize_label);
605 
606 	return (0);
607 }
608 
609 COUNTER_DECL(ifnet_init_label);
610 static void
611 test_ifnet_init_label(struct label *label)
612 {
613 
614 	LABEL_INIT(label, MAGIC_IFNET);
615 	COUNTER_INC(ifnet_init_label);
616 }
617 
618 COUNTER_DECL(ifnet_internalize_label);
619 static int
620 test_ifnet_internalize_label(struct label *label, char *element_name,
621     char *element_data, int *claimed)
622 {
623 
624 	LABEL_CHECK(label, MAGIC_IFNET);
625 	COUNTER_INC(ifnet_internalize_label);
626 
627 	return (0);
628 }
629 
630 COUNTER_DECL(ifnet_relabel);
631 static void
632 test_ifnet_relabel(struct ucred *cred, struct ifnet *ifp,
633     struct label *ifplabel, struct label *newlabel)
634 {
635 
636 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
637 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
638 	LABEL_CHECK(newlabel, MAGIC_IFNET);
639 	COUNTER_INC(ifnet_relabel);
640 }
641 
642 COUNTER_DECL(inpcb_check_deliver);
643 static int
644 test_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel,
645     struct mbuf *m, struct label *mlabel)
646 {
647 
648 	LABEL_CHECK(inplabel, MAGIC_INPCB);
649 	LABEL_CHECK(mlabel, MAGIC_MBUF);
650 	COUNTER_INC(inpcb_check_deliver);
651 
652 	return (0);
653 }
654 
655 COUNTER_DECL(inpcb_check_visible);
656 static int
657 test_inpcb_check_visible(struct ucred *cred, struct inpcb *inp,
658     struct label *inplabel)
659 {
660 
661 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
662 	LABEL_CHECK(inplabel, MAGIC_INPCB);
663 	COUNTER_INC(inpcb_check_visible);
664 
665 	return (0);
666 }
667 
668 COUNTER_DECL(inpcb_create);
669 static void
670 test_inpcb_create(struct socket *so, struct label *solabel,
671     struct inpcb *inp, struct label *inplabel)
672 {
673 
674 	SOCK_LOCK(so);
675 	LABEL_CHECK(solabel, MAGIC_SOCKET);
676 	SOCK_UNLOCK(so);
677 	LABEL_CHECK(inplabel, MAGIC_INPCB);
678 	COUNTER_INC(inpcb_create);
679 }
680 
681 COUNTER_DECL(inpcb_create_mbuf);
682 static void
683 test_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel,
684     struct mbuf *m, struct label *mlabel)
685 {
686 
687 	LABEL_CHECK(inplabel, MAGIC_INPCB);
688 	LABEL_CHECK(mlabel, MAGIC_MBUF);
689 	COUNTER_INC(inpcb_create_mbuf);
690 }
691 
692 COUNTER_DECL(inpcb_destroy_label);
693 static void
694 test_inpcb_destroy_label(struct label *label)
695 {
696 
697 	LABEL_DESTROY(label, MAGIC_INPCB);
698 	COUNTER_INC(inpcb_destroy_label);
699 }
700 
701 COUNTER_DECL(inpcb_init_label);
702 static int
703 test_inpcb_init_label(struct label *label, int flag)
704 {
705 
706 	if (flag & M_WAITOK)
707 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
708 		    "test_inpcb_init_label() at %s:%d", __FILE__,
709 		    __LINE__);
710 
711 	LABEL_INIT(label, MAGIC_INPCB);
712 	COUNTER_INC(inpcb_init_label);
713 	return (0);
714 }
715 
716 COUNTER_DECL(inpcb_sosetlabel);
717 static void
718 test_inpcb_sosetlabel(struct socket *so, struct label *solabel,
719     struct inpcb *inp, struct label *inplabel)
720 {
721 
722 	SOCK_LOCK_ASSERT(so);
723 
724 	LABEL_CHECK(solabel, MAGIC_SOCKET);
725 	LABEL_CHECK(inplabel, MAGIC_INPCB);
726 	COUNTER_INC(inpcb_sosetlabel);
727 }
728 
729 COUNTER_DECL(ip6q_create);
730 static void
731 test_ip6q_create(struct mbuf *fragment, struct label *fragmentlabel,
732     struct ip6q *q6, struct label *q6label)
733 {
734 
735 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
736 	LABEL_CHECK(q6label, MAGIC_IP6Q);
737 	COUNTER_INC(ip6q_create);
738 }
739 
740 COUNTER_DECL(ip6q_destroy_label);
741 static void
742 test_ip6q_destroy_label(struct label *label)
743 {
744 
745 	LABEL_DESTROY(label, MAGIC_IP6Q);
746 	COUNTER_INC(ip6q_destroy_label);
747 }
748 
749 COUNTER_DECL(ip6q_init_label);
750 static int
751 test_ip6q_init_label(struct label *label, int flag)
752 {
753 
754 	if (flag & M_WAITOK)
755 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
756 		    "test_ip6q_init_label() at %s:%d", __FILE__,
757 		    __LINE__);
758 
759 	LABEL_INIT(label, MAGIC_IP6Q);
760 	COUNTER_INC(ip6q_init_label);
761 	return (0);
762 }
763 
764 COUNTER_DECL(ip6q_match);
765 static int
766 test_ip6q_match(struct mbuf *fragment, struct label *fragmentlabel,
767     struct ip6q *q6, struct label *q6label)
768 {
769 
770 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
771 	LABEL_CHECK(q6label, MAGIC_IP6Q);
772 	COUNTER_INC(ip6q_match);
773 
774 	return (1);
775 }
776 
777 COUNTER_DECL(ip6q_reassemble);
778 static void
779 test_ip6q_reassemble(struct ip6q *q6, struct label *q6label, struct mbuf *m,
780    struct label *mlabel)
781 {
782 
783 	LABEL_CHECK(q6label, MAGIC_IP6Q);
784 	LABEL_CHECK(mlabel, MAGIC_MBUF);
785 	COUNTER_INC(ip6q_reassemble);
786 }
787 
788 COUNTER_DECL(ip6q_update);
789 static void
790 test_ip6q_update(struct mbuf *m, struct label *mlabel, struct ip6q *q6,
791     struct label *q6label)
792 {
793 
794 	LABEL_CHECK(mlabel, MAGIC_MBUF);
795 	LABEL_CHECK(q6label, MAGIC_IP6Q);
796 	COUNTER_INC(ip6q_update);
797 }
798 
799 COUNTER_DECL(ipq_create);
800 static void
801 test_ipq_create(struct mbuf *fragment, struct label *fragmentlabel,
802     struct ipq *q, struct label *qlabel)
803 {
804 
805 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
806 	LABEL_CHECK(qlabel, MAGIC_IPQ);
807 	COUNTER_INC(ipq_create);
808 }
809 
810 COUNTER_DECL(ipq_destroy_label);
811 static void
812 test_ipq_destroy_label(struct label *label)
813 {
814 
815 	LABEL_DESTROY(label, MAGIC_IPQ);
816 	COUNTER_INC(ipq_destroy_label);
817 }
818 
819 COUNTER_DECL(ipq_init_label);
820 static int
821 test_ipq_init_label(struct label *label, int flag)
822 {
823 
824 	if (flag & M_WAITOK)
825 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
826 		    "test_ipq_init_label() at %s:%d", __FILE__,
827 		    __LINE__);
828 
829 	LABEL_INIT(label, MAGIC_IPQ);
830 	COUNTER_INC(ipq_init_label);
831 	return (0);
832 }
833 
834 COUNTER_DECL(ipq_match);
835 static int
836 test_ipq_match(struct mbuf *fragment, struct label *fragmentlabel,
837     struct ipq *q, struct label *qlabel)
838 {
839 
840 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
841 	LABEL_CHECK(qlabel, MAGIC_IPQ);
842 	COUNTER_INC(ipq_match);
843 
844 	return (1);
845 }
846 
847 COUNTER_DECL(ipq_reassemble);
848 static void
849 test_ipq_reassemble(struct ipq *q, struct label *qlabel, struct mbuf *m,
850    struct label *mlabel)
851 {
852 
853 	LABEL_CHECK(qlabel, MAGIC_IPQ);
854 	LABEL_CHECK(mlabel, MAGIC_MBUF);
855 	COUNTER_INC(ipq_reassemble);
856 }
857 
858 COUNTER_DECL(ipq_update);
859 static void
860 test_ipq_update(struct mbuf *m, struct label *mlabel, struct ipq *q,
861     struct label *qlabel)
862 {
863 
864 	LABEL_CHECK(mlabel, MAGIC_MBUF);
865 	LABEL_CHECK(qlabel, MAGIC_IPQ);
866 	COUNTER_INC(ipq_update);
867 }
868 
869 COUNTER_DECL(kenv_check_dump);
870 static int
871 test_kenv_check_dump(struct ucred *cred)
872 {
873 
874 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
875 	COUNTER_INC(kenv_check_dump);
876 
877 	return (0);
878 }
879 
880 COUNTER_DECL(kenv_check_get);
881 static int
882 test_kenv_check_get(struct ucred *cred, char *name)
883 {
884 
885 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
886 	COUNTER_INC(kenv_check_get);
887 
888 	return (0);
889 }
890 
891 COUNTER_DECL(kenv_check_set);
892 static int
893 test_kenv_check_set(struct ucred *cred, char *name, char *value)
894 {
895 
896 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
897 	COUNTER_INC(kenv_check_set);
898 
899 	return (0);
900 }
901 
902 COUNTER_DECL(kenv_check_unset);
903 static int
904 test_kenv_check_unset(struct ucred *cred, char *name)
905 {
906 
907 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
908 	COUNTER_INC(kenv_check_unset);
909 
910 	return (0);
911 }
912 
913 COUNTER_DECL(kld_check_load);
914 static int
915 test_kld_check_load(struct ucred *cred, struct vnode *vp,
916     struct label *label)
917 {
918 
919 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
920 	LABEL_CHECK(label, MAGIC_VNODE);
921 	COUNTER_INC(kld_check_load);
922 
923 	return (0);
924 }
925 
926 COUNTER_DECL(kld_check_stat);
927 static int
928 test_kld_check_stat(struct ucred *cred)
929 {
930 
931 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
932 	COUNTER_INC(kld_check_stat);
933 
934 	return (0);
935 }
936 
937 COUNTER_DECL(mbuf_copy_label);
938 static void
939 test_mbuf_copy_label(struct label *src, struct label *dest)
940 {
941 
942 	LABEL_CHECK(src, MAGIC_MBUF);
943 	LABEL_CHECK(dest, MAGIC_MBUF);
944 	COUNTER_INC(mbuf_copy_label);
945 }
946 
947 COUNTER_DECL(mbuf_destroy_label);
948 static void
949 test_mbuf_destroy_label(struct label *label)
950 {
951 
952 	/*
953 	 * If we're loaded dynamically, there may be mbufs in flight that
954 	 * didn't have label storage allocated for them.  Handle this
955 	 * gracefully.
956 	 */
957 	if (label == NULL)
958 		return;
959 
960 	LABEL_DESTROY(label, MAGIC_MBUF);
961 	COUNTER_INC(mbuf_destroy_label);
962 }
963 
964 COUNTER_DECL(mbuf_init_label);
965 static int
966 test_mbuf_init_label(struct label *label, int flag)
967 {
968 
969 	if (flag & M_WAITOK)
970 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
971 		    "test_mbuf_init_label() at %s:%d", __FILE__,
972 		    __LINE__);
973 
974 	LABEL_INIT(label, MAGIC_MBUF);
975 	COUNTER_INC(mbuf_init_label);
976 	return (0);
977 }
978 
979 COUNTER_DECL(mount_check_stat);
980 static int
981 test_mount_check_stat(struct ucred *cred, struct mount *mp,
982     struct label *mplabel)
983 {
984 
985 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
986 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
987 	COUNTER_INC(mount_check_stat);
988 
989 	return (0);
990 }
991 
992 COUNTER_DECL(mount_create);
993 static void
994 test_mount_create(struct ucred *cred, struct mount *mp,
995     struct label *mplabel)
996 {
997 
998 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
999 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
1000 	COUNTER_INC(mount_create);
1001 }
1002 
1003 COUNTER_DECL(mount_destroy_label);
1004 static void
1005 test_mount_destroy_label(struct label *label)
1006 {
1007 
1008 	LABEL_DESTROY(label, MAGIC_MOUNT);
1009 	COUNTER_INC(mount_destroy_label);
1010 }
1011 
1012 COUNTER_DECL(mount_init_label);
1013 static void
1014 test_mount_init_label(struct label *label)
1015 {
1016 
1017 	LABEL_INIT(label, MAGIC_MOUNT);
1018 	COUNTER_INC(mount_init_label);
1019 }
1020 
1021 COUNTER_DECL(netinet_arp_send);
1022 static void
1023 test_netinet_arp_send(struct ifnet *ifp, struct label *ifplabel,
1024     struct mbuf *m, struct label *mlabel)
1025 {
1026 
1027 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
1028 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1029 	COUNTER_INC(netinet_arp_send);
1030 }
1031 
1032 COUNTER_DECL(netinet_fragment);
1033 static void
1034 test_netinet_fragment(struct mbuf *m, struct label *mlabel,
1035     struct mbuf *frag, struct label *fraglabel)
1036 {
1037 
1038 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1039 	LABEL_CHECK(fraglabel, MAGIC_MBUF);
1040 	COUNTER_INC(netinet_fragment);
1041 }
1042 
1043 COUNTER_DECL(netinet_icmp_reply);
1044 static void
1045 test_netinet_icmp_reply(struct mbuf *mrecv, struct label *mrecvlabel,
1046     struct mbuf *msend, struct label *msendlabel)
1047 {
1048 
1049 	LABEL_CHECK(mrecvlabel, MAGIC_MBUF);
1050 	LABEL_CHECK(msendlabel, MAGIC_MBUF);
1051 	COUNTER_INC(netinet_icmp_reply);
1052 }
1053 
1054 COUNTER_DECL(netinet_icmp_replyinplace);
1055 static void
1056 test_netinet_icmp_replyinplace(struct mbuf *m, struct label *mlabel)
1057 {
1058 
1059 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1060 	COUNTER_INC(netinet_icmp_replyinplace);
1061 }
1062 
1063 COUNTER_DECL(netinet_igmp_send);
1064 static void
1065 test_netinet_igmp_send(struct ifnet *ifp, struct label *ifplabel,
1066     struct mbuf *m, struct label *mlabel)
1067 {
1068 
1069 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
1070 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1071 	COUNTER_INC(netinet_igmp_send);
1072 }
1073 
1074 COUNTER_DECL(netinet_tcp_reply);
1075 static void
1076 test_netinet_tcp_reply(struct mbuf *m, struct label *mlabel)
1077 {
1078 
1079 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1080 	COUNTER_INC(netinet_tcp_reply);
1081 }
1082 
1083 COUNTER_DECL(netinet6_nd6_send);
1084 static void
1085 test_netinet6_nd6_send(struct ifnet *ifp, struct label *ifplabel,
1086     struct mbuf *m, struct label *mlabel)
1087 {
1088 
1089 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
1090 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1091 	COUNTER_INC(netinet6_nd6_send);
1092 }
1093 
1094 COUNTER_DECL(pipe_check_ioctl);
1095 static int
1096 test_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
1097     struct label *pplabel, unsigned long cmd, void /* caddr_t */ *data)
1098 {
1099 
1100 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1101 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1102 	COUNTER_INC(pipe_check_ioctl);
1103 
1104 	return (0);
1105 }
1106 
1107 COUNTER_DECL(pipe_check_poll);
1108 static int
1109 test_pipe_check_poll(struct ucred *cred, struct pipepair *pp,
1110     struct label *pplabel)
1111 {
1112 
1113 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1114 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1115 	COUNTER_INC(pipe_check_poll);
1116 
1117 	return (0);
1118 }
1119 
1120 COUNTER_DECL(pipe_check_read);
1121 static int
1122 test_pipe_check_read(struct ucred *cred, struct pipepair *pp,
1123     struct label *pplabel)
1124 {
1125 
1126 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1127 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1128 	COUNTER_INC(pipe_check_read);
1129 
1130 	return (0);
1131 }
1132 
1133 COUNTER_DECL(pipe_check_relabel);
1134 static int
1135 test_pipe_check_relabel(struct ucred *cred, struct pipepair *pp,
1136     struct label *pplabel, struct label *newlabel)
1137 {
1138 
1139 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1140 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1141 	LABEL_CHECK(newlabel, MAGIC_PIPE);
1142 	COUNTER_INC(pipe_check_relabel);
1143 
1144 	return (0);
1145 }
1146 
1147 COUNTER_DECL(pipe_check_stat);
1148 static int
1149 test_pipe_check_stat(struct ucred *cred, struct pipepair *pp,
1150     struct label *pplabel)
1151 {
1152 
1153 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1154 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1155 	COUNTER_INC(pipe_check_stat);
1156 
1157 	return (0);
1158 }
1159 
1160 COUNTER_DECL(pipe_check_write);
1161 static int
1162 test_pipe_check_write(struct ucred *cred, struct pipepair *pp,
1163     struct label *pplabel)
1164 {
1165 
1166 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1167 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1168 	COUNTER_INC(pipe_check_write);
1169 
1170 	return (0);
1171 }
1172 
1173 COUNTER_DECL(pipe_copy_label);
1174 static void
1175 test_pipe_copy_label(struct label *src, struct label *dest)
1176 {
1177 
1178 	LABEL_CHECK(src, MAGIC_PIPE);
1179 	LABEL_CHECK(dest, MAGIC_PIPE);
1180 	COUNTER_INC(pipe_copy_label);
1181 }
1182 
1183 COUNTER_DECL(pipe_create);
1184 static void
1185 test_pipe_create(struct ucred *cred, struct pipepair *pp,
1186    struct label *pplabel)
1187 {
1188 
1189 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1190 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1191 	COUNTER_INC(pipe_create);
1192 }
1193 
1194 COUNTER_DECL(pipe_destroy_label);
1195 static void
1196 test_pipe_destroy_label(struct label *label)
1197 {
1198 
1199 	LABEL_DESTROY(label, MAGIC_PIPE);
1200 	COUNTER_INC(pipe_destroy_label);
1201 }
1202 
1203 COUNTER_DECL(pipe_externalize_label);
1204 static int
1205 test_pipe_externalize_label(struct label *label, char *element_name,
1206     struct sbuf *sb, int *claimed)
1207 {
1208 
1209 	LABEL_CHECK(label, MAGIC_PIPE);
1210 	COUNTER_INC(pipe_externalize_label);
1211 
1212 	return (0);
1213 }
1214 
1215 COUNTER_DECL(pipe_init_label);
1216 static void
1217 test_pipe_init_label(struct label *label)
1218 {
1219 
1220 	LABEL_INIT(label, MAGIC_PIPE);
1221 	COUNTER_INC(pipe_init_label);
1222 }
1223 
1224 COUNTER_DECL(pipe_internalize_label);
1225 static int
1226 test_pipe_internalize_label(struct label *label, char *element_name,
1227     char *element_data, int *claimed)
1228 {
1229 
1230 	LABEL_CHECK(label, MAGIC_PIPE);
1231 	COUNTER_INC(pipe_internalize_label);
1232 
1233 	return (0);
1234 }
1235 
1236 COUNTER_DECL(pipe_relabel);
1237 static void
1238 test_pipe_relabel(struct ucred *cred, struct pipepair *pp,
1239     struct label *pplabel, struct label *newlabel)
1240 {
1241 
1242 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1243 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1244 	LABEL_CHECK(newlabel, MAGIC_PIPE);
1245 	COUNTER_INC(pipe_relabel);
1246 }
1247 
1248 COUNTER_DECL(posixsem_check_getvalue);
1249 static int
1250 test_posixsem_check_getvalue(struct ucred *active_cred, struct ucred *file_cred,
1251     struct ksem *ks, struct label *kslabel)
1252 {
1253 
1254 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1255 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1256 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1257 	COUNTER_INC(posixsem_check_getvalue);
1258 
1259 	return (0);
1260 }
1261 
1262 COUNTER_DECL(posixsem_check_open);
1263 static int
1264 test_posixsem_check_open(struct ucred *cred, struct ksem *ks,
1265     struct label *kslabel)
1266 {
1267 
1268 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1269 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1270 	COUNTER_INC(posixsem_check_open);
1271 
1272 	return (0);
1273 }
1274 
1275 COUNTER_DECL(posixsem_check_post);
1276 static int
1277 test_posixsem_check_post(struct ucred *active_cred, struct ucred *file_cred,
1278     struct ksem *ks, struct label *kslabel)
1279 {
1280 
1281 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1282 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1283 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1284 	COUNTER_INC(posixsem_check_post);
1285 
1286 	return (0);
1287 }
1288 
1289 COUNTER_DECL(posixsem_check_setmode);
1290 static int
1291 test_posixsem_check_setmode(struct ucred *cred, struct ksem *ks,
1292     struct label *kslabel, mode_t mode)
1293 {
1294 
1295 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1296 	LABEL_CHECK(kslabel, MAGIC_POSIX_SHM);
1297 	COUNTER_INC(posixsem_check_setmode);
1298 	return (0);
1299 }
1300 
1301 COUNTER_DECL(posixsem_check_setowner);
1302 static int
1303 test_posixsem_check_setowner(struct ucred *cred, struct ksem *ks,
1304     struct label *kslabel, uid_t uid, gid_t gid)
1305 {
1306 
1307 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1308 	LABEL_CHECK(kslabel, MAGIC_POSIX_SHM);
1309 	COUNTER_INC(posixsem_check_setowner);
1310 	return (0);
1311 }
1312 
1313 COUNTER_DECL(posixsem_check_stat);
1314 static int
1315 test_posixsem_check_stat(struct ucred *active_cred,
1316     struct ucred *file_cred, struct ksem *ks, struct label *kslabel)
1317 {
1318 
1319 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1320 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1321 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1322 	COUNTER_INC(posixsem_check_stat);
1323 	return (0);
1324 }
1325 
1326 COUNTER_DECL(posixsem_check_unlink);
1327 static int
1328 test_posixsem_check_unlink(struct ucred *cred, struct ksem *ks,
1329     struct label *kslabel)
1330 {
1331 
1332 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1333 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1334 	COUNTER_INC(posixsem_check_unlink);
1335 
1336 	return (0);
1337 }
1338 
1339 COUNTER_DECL(posixsem_check_wait);
1340 static int
1341 test_posixsem_check_wait(struct ucred *active_cred, struct ucred *file_cred,
1342     struct ksem *ks, struct label *kslabel)
1343 {
1344 
1345 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1346 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1347 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1348 	COUNTER_INC(posixsem_check_wait);
1349 
1350 	return (0);
1351 }
1352 
1353 COUNTER_DECL(posixsem_create);
1354 static void
1355 test_posixsem_create(struct ucred *cred, struct ksem *ks,
1356    struct label *kslabel)
1357 {
1358 
1359 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1360 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1361 	COUNTER_INC(posixsem_create);
1362 }
1363 
1364 COUNTER_DECL(posixsem_destroy_label);
1365 static void
1366 test_posixsem_destroy_label(struct label *label)
1367 {
1368 
1369 	LABEL_DESTROY(label, MAGIC_POSIX_SEM);
1370 	COUNTER_INC(posixsem_destroy_label);
1371 }
1372 
1373 COUNTER_DECL(posixsem_init_label);
1374 static void
1375 test_posixsem_init_label(struct label *label)
1376 {
1377 
1378 	LABEL_INIT(label, MAGIC_POSIX_SEM);
1379 	COUNTER_INC(posixsem_init_label);
1380 }
1381 
1382 COUNTER_DECL(posixshm_check_create);
1383 static int
1384 test_posixshm_check_create(struct ucred *cred, const char *path)
1385 {
1386 
1387 	COUNTER_INC(posixshm_check_create);
1388 	return (0);
1389 }
1390 
1391 COUNTER_DECL(posixshm_check_mmap);
1392 static int
1393 test_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd,
1394     struct label *shmfdlabel, int prot, int flags)
1395 {
1396 
1397 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1398 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1399 	COUNTER_INC(posixshm_check_mmap);
1400 	return (0);
1401 }
1402 
1403 COUNTER_DECL(posixshm_check_open);
1404 static int
1405 test_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd,
1406     struct label *shmfdlabel, accmode_t accmode)
1407 {
1408 
1409 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1410 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1411 	COUNTER_INC(posixshm_check_open);
1412 	return (0);
1413 }
1414 
1415 COUNTER_DECL(posixshm_check_read);
1416 static int
1417 test_posixshm_check_read(struct ucred *active_cred,
1418     struct ucred *file_cred, struct shmfd *shm, struct label *shmlabel)
1419 {
1420 
1421 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1422 	if (file_cred != NULL)
1423 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1424 	LABEL_CHECK(shmlabel, MAGIC_POSIX_SHM);
1425 	COUNTER_INC(posixshm_check_read);
1426 
1427 	return (0);
1428 }
1429 
1430 COUNTER_DECL(posixshm_check_setmode);
1431 static int
1432 test_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd,
1433     struct label *shmfdlabel, mode_t mode)
1434 {
1435 
1436 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1437 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1438 	COUNTER_INC(posixshm_check_setmode);
1439 	return (0);
1440 }
1441 
1442 COUNTER_DECL(posixshm_check_setowner);
1443 static int
1444 test_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd,
1445     struct label *shmfdlabel, uid_t uid, gid_t gid)
1446 {
1447 
1448 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1449 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1450 	COUNTER_INC(posixshm_check_setowner);
1451 	return (0);
1452 }
1453 
1454 COUNTER_DECL(posixshm_check_stat);
1455 static int
1456 test_posixshm_check_stat(struct ucred *active_cred,
1457     struct ucred *file_cred, struct shmfd *shmfd, struct label *shmfdlabel)
1458 {
1459 
1460 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1461 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1462 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1463 	COUNTER_INC(posixshm_check_stat);
1464 	return (0);
1465 }
1466 
1467 COUNTER_DECL(posixshm_check_truncate);
1468 static int
1469 test_posixshm_check_truncate(struct ucred *active_cred,
1470     struct ucred *file_cred, struct shmfd *shmfd, struct label *shmfdlabel)
1471 {
1472 
1473 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1474 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1475 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1476 	COUNTER_INC(posixshm_check_truncate);
1477 	return (0);
1478 }
1479 
1480 COUNTER_DECL(posixshm_check_unlink);
1481 static int
1482 test_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd,
1483     struct label *shmfdlabel)
1484 {
1485 
1486 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1487 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1488 	COUNTER_INC(posixshm_check_unlink);
1489 	return (0);
1490 }
1491 
1492 COUNTER_DECL(posixshm_check_write);
1493 static int
1494 test_posixshm_check_write(struct ucred *active_cred,
1495     struct ucred *file_cred, struct shmfd *shm, struct label *shmlabel)
1496 {
1497 
1498 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1499 	if (file_cred != NULL)
1500 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1501 	LABEL_CHECK(shmlabel, MAGIC_POSIX_SHM);
1502 	COUNTER_INC(posixshm_check_write);
1503 
1504 	return (0);
1505 }
1506 
1507 COUNTER_DECL(posixshm_create);
1508 static void
1509 test_posixshm_create(struct ucred *cred, struct shmfd *shmfd,
1510    struct label *shmfdlabel)
1511 {
1512 
1513 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1514 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1515 	COUNTER_INC(posixshm_create);
1516 }
1517 
1518 COUNTER_DECL(posixshm_destroy_label);
1519 static void
1520 test_posixshm_destroy_label(struct label *label)
1521 {
1522 
1523 	LABEL_DESTROY(label, MAGIC_POSIX_SHM);
1524 	COUNTER_INC(posixshm_destroy_label);
1525 }
1526 
1527 COUNTER_DECL(posixshm_init_label);
1528 static void
1529 test_posixshm_init_label(struct label *label)
1530 {
1531 
1532 	LABEL_INIT(label, MAGIC_POSIX_SHM);
1533 	COUNTER_INC(posixshm_init_label);
1534 }
1535 
1536 COUNTER_DECL(proc_check_debug);
1537 static int
1538 test_proc_check_debug(struct ucred *cred, struct proc *p)
1539 {
1540 
1541 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1542 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
1543 	COUNTER_INC(proc_check_debug);
1544 
1545 	return (0);
1546 }
1547 
1548 COUNTER_DECL(proc_check_sched);
1549 static int
1550 test_proc_check_sched(struct ucred *cred, struct proc *p)
1551 {
1552 
1553 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1554 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
1555 	COUNTER_INC(proc_check_sched);
1556 
1557 	return (0);
1558 }
1559 
1560 COUNTER_DECL(proc_check_signal);
1561 static int
1562 test_proc_check_signal(struct ucred *cred, struct proc *p, int signum)
1563 {
1564 
1565 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1566 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
1567 	COUNTER_INC(proc_check_signal);
1568 
1569 	return (0);
1570 }
1571 
1572 COUNTER_DECL(proc_check_wait);
1573 static int
1574 test_proc_check_wait(struct ucred *cred, struct proc *p)
1575 {
1576 
1577 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1578 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
1579 	COUNTER_INC(proc_check_wait);
1580 
1581 	return (0);
1582 }
1583 
1584 COUNTER_DECL(proc_destroy_label);
1585 static void
1586 test_proc_destroy_label(struct label *label)
1587 {
1588 
1589 	LABEL_DESTROY(label, MAGIC_PROC);
1590 	COUNTER_INC(proc_destroy_label);
1591 }
1592 
1593 COUNTER_DECL(proc_init_label);
1594 static void
1595 test_proc_init_label(struct label *label)
1596 {
1597 
1598 	LABEL_INIT(label, MAGIC_PROC);
1599 	COUNTER_INC(proc_init_label);
1600 }
1601 
1602 COUNTER_DECL(socket_check_accept);
1603 static int
1604 test_socket_check_accept(struct ucred *cred, struct socket *so,
1605     struct label *solabel)
1606 {
1607 
1608 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1609 	SOCK_LOCK(so);
1610 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1611 	SOCK_UNLOCK(so);
1612 	COUNTER_INC(socket_check_accept);
1613 
1614 	return (0);
1615 }
1616 
1617 COUNTER_DECL(socket_check_bind);
1618 static int
1619 test_socket_check_bind(struct ucred *cred, struct socket *so,
1620     struct label *solabel, struct sockaddr *sa)
1621 {
1622 
1623 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1624 	SOCK_LOCK(so);
1625 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1626 	SOCK_UNLOCK(so);
1627 	COUNTER_INC(socket_check_bind);
1628 
1629 	return (0);
1630 }
1631 
1632 COUNTER_DECL(socket_check_connect);
1633 static int
1634 test_socket_check_connect(struct ucred *cred, struct socket *so,
1635     struct label *solabel, struct sockaddr *sa)
1636 {
1637 
1638 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1639 	SOCK_LOCK(so);
1640 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1641 	SOCK_UNLOCK(so);
1642 	COUNTER_INC(socket_check_connect);
1643 
1644 	return (0);
1645 }
1646 
1647 COUNTER_DECL(socket_check_deliver);
1648 static int
1649 test_socket_check_deliver(struct socket *so, struct label *solabel,
1650     struct mbuf *m, struct label *mlabel)
1651 {
1652 
1653 	SOCK_LOCK(so);
1654 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1655 	SOCK_UNLOCK(so);
1656 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1657 	COUNTER_INC(socket_check_deliver);
1658 
1659 	return (0);
1660 }
1661 
1662 COUNTER_DECL(socket_check_listen);
1663 static int
1664 test_socket_check_listen(struct ucred *cred, struct socket *so,
1665     struct label *solabel)
1666 {
1667 
1668 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1669 	SOCK_LOCK(so);
1670 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1671 	SOCK_UNLOCK(so);
1672 	COUNTER_INC(socket_check_listen);
1673 
1674 	return (0);
1675 }
1676 
1677 COUNTER_DECL(socket_check_poll);
1678 static int
1679 test_socket_check_poll(struct ucred *cred, struct socket *so,
1680     struct label *solabel)
1681 {
1682 
1683 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1684 	SOCK_LOCK(so);
1685 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1686 	SOCK_UNLOCK(so);
1687 	COUNTER_INC(socket_check_poll);
1688 
1689 	return (0);
1690 }
1691 
1692 COUNTER_DECL(socket_check_receive);
1693 static int
1694 test_socket_check_receive(struct ucred *cred, struct socket *so,
1695     struct label *solabel)
1696 {
1697 
1698 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1699 	SOCK_LOCK(so);
1700 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1701 	SOCK_UNLOCK(so);
1702 	COUNTER_INC(socket_check_receive);
1703 
1704 	return (0);
1705 }
1706 
1707 COUNTER_DECL(socket_check_relabel);
1708 static int
1709 test_socket_check_relabel(struct ucred *cred, struct socket *so,
1710     struct label *solabel, struct label *newlabel)
1711 {
1712 
1713 	SOCK_LOCK_ASSERT(so);
1714 
1715 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1716 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1717 	LABEL_CHECK(newlabel, MAGIC_SOCKET);
1718 	COUNTER_INC(socket_check_relabel);
1719 
1720 	return (0);
1721 }
1722 
1723 COUNTER_DECL(socket_check_send);
1724 static int
1725 test_socket_check_send(struct ucred *cred, struct socket *so,
1726     struct label *solabel)
1727 {
1728 
1729 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1730 	SOCK_LOCK(so);
1731 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1732 	SOCK_UNLOCK(so);
1733 	COUNTER_INC(socket_check_send);
1734 
1735 	return (0);
1736 }
1737 
1738 COUNTER_DECL(socket_check_stat);
1739 static int
1740 test_socket_check_stat(struct ucred *cred, struct socket *so,
1741     struct label *solabel)
1742 {
1743 
1744 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1745 	SOCK_LOCK(so);
1746 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1747 	SOCK_UNLOCK(so);
1748 	COUNTER_INC(socket_check_stat);
1749 
1750 	return (0);
1751 }
1752 
1753 COUNTER_DECL(socket_check_visible);
1754 static int
1755 test_socket_check_visible(struct ucred *cred, struct socket *so,
1756     struct label *solabel)
1757 {
1758 
1759 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1760 	SOCK_LOCK(so);
1761 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1762 	SOCK_UNLOCK(so);
1763 	COUNTER_INC(socket_check_visible);
1764 
1765 	return (0);
1766 }
1767 
1768 COUNTER_DECL(socket_copy_label);
1769 static void
1770 test_socket_copy_label(struct label *src, struct label *dest)
1771 {
1772 
1773 	LABEL_CHECK(src, MAGIC_SOCKET);
1774 	LABEL_CHECK(dest, MAGIC_SOCKET);
1775 	COUNTER_INC(socket_copy_label);
1776 }
1777 
1778 COUNTER_DECL(socket_create);
1779 static void
1780 test_socket_create(struct ucred *cred, struct socket *so,
1781     struct label *solabel)
1782 {
1783 
1784 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1785 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1786 	COUNTER_INC(socket_create);
1787 }
1788 
1789 COUNTER_DECL(socket_create_mbuf);
1790 static void
1791 test_socket_create_mbuf(struct socket *so, struct label *solabel,
1792     struct mbuf *m, struct label *mlabel)
1793 {
1794 
1795 	SOCK_LOCK(so);
1796 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1797 	SOCK_UNLOCK(so);
1798 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1799 	COUNTER_INC(socket_create_mbuf);
1800 }
1801 
1802 COUNTER_DECL(socket_destroy_label);
1803 static void
1804 test_socket_destroy_label(struct label *label)
1805 {
1806 
1807 	LABEL_DESTROY(label, MAGIC_SOCKET);
1808 	COUNTER_INC(socket_destroy_label);
1809 }
1810 
1811 COUNTER_DECL(socket_externalize_label);
1812 static int
1813 test_socket_externalize_label(struct label *label, char *element_name,
1814     struct sbuf *sb, int *claimed)
1815 {
1816 
1817 	LABEL_CHECK(label, MAGIC_SOCKET);
1818 	COUNTER_INC(socket_externalize_label);
1819 
1820 	return (0);
1821 }
1822 
1823 COUNTER_DECL(socket_init_label);
1824 static int
1825 test_socket_init_label(struct label *label, int flag)
1826 {
1827 
1828 	if (flag & M_WAITOK)
1829 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1830 		    "test_socket_init_label() at %s:%d", __FILE__,
1831 		    __LINE__);
1832 
1833 	LABEL_INIT(label, MAGIC_SOCKET);
1834 	COUNTER_INC(socket_init_label);
1835 	return (0);
1836 }
1837 
1838 COUNTER_DECL(socket_internalize_label);
1839 static int
1840 test_socket_internalize_label(struct label *label, char *element_name,
1841     char *element_data, int *claimed)
1842 {
1843 
1844 	LABEL_CHECK(label, MAGIC_SOCKET);
1845 	COUNTER_INC(socket_internalize_label);
1846 
1847 	return (0);
1848 }
1849 
1850 COUNTER_DECL(socket_newconn);
1851 static void
1852 test_socket_newconn(struct socket *oldso, struct label *oldsolabel,
1853     struct socket *newso, struct label *newsolabel)
1854 {
1855 
1856 	SOCK_LOCK(oldso);
1857 	LABEL_CHECK(oldsolabel, MAGIC_SOCKET);
1858 	SOCK_UNLOCK(oldso);
1859 	SOCK_LOCK(newso);
1860 	LABEL_CHECK(newsolabel, MAGIC_SOCKET);
1861 	SOCK_UNLOCK(newso);
1862 	COUNTER_INC(socket_newconn);
1863 }
1864 
1865 COUNTER_DECL(socket_relabel);
1866 static void
1867 test_socket_relabel(struct ucred *cred, struct socket *so,
1868     struct label *solabel, struct label *newlabel)
1869 {
1870 
1871 	SOCK_LOCK_ASSERT(so);
1872 
1873 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1874 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1875 	LABEL_CHECK(newlabel, MAGIC_SOCKET);
1876 	COUNTER_INC(socket_relabel);
1877 }
1878 
1879 COUNTER_DECL(socketpeer_destroy_label);
1880 static void
1881 test_socketpeer_destroy_label(struct label *label)
1882 {
1883 
1884 	LABEL_DESTROY(label, MAGIC_SOCKET);
1885 	COUNTER_INC(socketpeer_destroy_label);
1886 }
1887 
1888 COUNTER_DECL(socketpeer_externalize_label);
1889 static int
1890 test_socketpeer_externalize_label(struct label *label, char *element_name,
1891     struct sbuf *sb, int *claimed)
1892 {
1893 
1894 	LABEL_CHECK(label, MAGIC_SOCKET);
1895 	COUNTER_INC(socketpeer_externalize_label);
1896 
1897 	return (0);
1898 }
1899 
1900 COUNTER_DECL(socketpeer_init_label);
1901 static int
1902 test_socketpeer_init_label(struct label *label, int flag)
1903 {
1904 
1905 	if (flag & M_WAITOK)
1906 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1907 		    "test_socketpeer_init_label() at %s:%d", __FILE__,
1908 		    __LINE__);
1909 
1910 	LABEL_INIT(label, MAGIC_SOCKET);
1911 	COUNTER_INC(socketpeer_init_label);
1912 	return (0);
1913 }
1914 
1915 COUNTER_DECL(socketpeer_set_from_mbuf);
1916 static void
1917 test_socketpeer_set_from_mbuf(struct mbuf *m, struct label *mlabel,
1918     struct socket *so, struct label *sopeerlabel)
1919 {
1920 
1921 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1922 	SOCK_LOCK(so);
1923 	LABEL_CHECK(sopeerlabel, MAGIC_SOCKET);
1924 	SOCK_UNLOCK(so);
1925 	COUNTER_INC(socketpeer_set_from_mbuf);
1926 }
1927 
1928 COUNTER_DECL(socketpeer_set_from_socket);
1929 static void
1930 test_socketpeer_set_from_socket(struct socket *oldso,
1931     struct label *oldsolabel, struct socket *newso,
1932     struct label *newsopeerlabel)
1933 {
1934 
1935 	SOCK_LOCK(oldso);
1936 	LABEL_CHECK(oldsolabel, MAGIC_SOCKET);
1937 	SOCK_UNLOCK(oldso);
1938 	SOCK_LOCK(newso);
1939 	LABEL_CHECK(newsopeerlabel, MAGIC_SOCKET);
1940 	SOCK_UNLOCK(newso);
1941 	COUNTER_INC(socketpeer_set_from_socket);
1942 }
1943 
1944 COUNTER_DECL(syncache_create);
1945 static void
1946 test_syncache_create(struct label *label, struct inpcb *inp)
1947 {
1948 
1949 	LABEL_CHECK(label, MAGIC_SYNCACHE);
1950 	COUNTER_INC(syncache_create);
1951 }
1952 
1953 COUNTER_DECL(syncache_create_mbuf);
1954 static void
1955 test_syncache_create_mbuf(struct label *sc_label, struct mbuf *m,
1956     struct label *mlabel)
1957 {
1958 
1959 	LABEL_CHECK(sc_label, MAGIC_SYNCACHE);
1960 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1961 	COUNTER_INC(syncache_create_mbuf);
1962 }
1963 
1964 COUNTER_DECL(syncache_destroy_label);
1965 static void
1966 test_syncache_destroy_label(struct label *label)
1967 {
1968 
1969 	LABEL_DESTROY(label, MAGIC_SYNCACHE);
1970 	COUNTER_INC(syncache_destroy_label);
1971 }
1972 
1973 COUNTER_DECL(syncache_init_label);
1974 static int
1975 test_syncache_init_label(struct label *label, int flag)
1976 {
1977 
1978 	if (flag & M_WAITOK)
1979 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1980 		    "test_syncache_init_label() at %s:%d", __FILE__,
1981 		    __LINE__);
1982 	LABEL_INIT(label, MAGIC_SYNCACHE);
1983 	COUNTER_INC(syncache_init_label);
1984 	return (0);
1985 }
1986 
1987 COUNTER_DECL(system_check_acct);
1988 static int
1989 test_system_check_acct(struct ucred *cred, struct vnode *vp,
1990     struct label *vplabel)
1991 {
1992 
1993 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1994 	LABEL_CHECK(vplabel, MAGIC_VNODE);
1995 	COUNTER_INC(system_check_acct);
1996 
1997 	return (0);
1998 }
1999 
2000 COUNTER_DECL(system_check_audit);
2001 static int
2002 test_system_check_audit(struct ucred *cred, void *record, int length)
2003 {
2004 
2005 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2006 	COUNTER_INC(system_check_audit);
2007 
2008 	return (0);
2009 }
2010 
2011 COUNTER_DECL(system_check_auditctl);
2012 static int
2013 test_system_check_auditctl(struct ucred *cred, struct vnode *vp,
2014     struct label *vplabel)
2015 {
2016 
2017 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2018 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2019 	COUNTER_INC(system_check_auditctl);
2020 
2021 	return (0);
2022 }
2023 
2024 COUNTER_DECL(system_check_auditon);
2025 static int
2026 test_system_check_auditon(struct ucred *cred, int cmd)
2027 {
2028 
2029 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2030 	COUNTER_INC(system_check_auditon);
2031 
2032 	return (0);
2033 }
2034 
2035 COUNTER_DECL(system_check_reboot);
2036 static int
2037 test_system_check_reboot(struct ucred *cred, int how)
2038 {
2039 
2040 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2041 	COUNTER_INC(system_check_reboot);
2042 
2043 	return (0);
2044 }
2045 
2046 COUNTER_DECL(system_check_swapoff);
2047 static int
2048 test_system_check_swapoff(struct ucred *cred, struct vnode *vp,
2049     struct label *vplabel)
2050 {
2051 
2052 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2053 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2054 	COUNTER_INC(system_check_swapoff);
2055 
2056 	return (0);
2057 }
2058 
2059 COUNTER_DECL(system_check_swapon);
2060 static int
2061 test_system_check_swapon(struct ucred *cred, struct vnode *vp,
2062     struct label *vplabel)
2063 {
2064 
2065 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2066 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2067 	COUNTER_INC(system_check_swapon);
2068 
2069 	return (0);
2070 }
2071 
2072 COUNTER_DECL(system_check_sysctl);
2073 static int
2074 test_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
2075     void *arg1, int arg2, struct sysctl_req *req)
2076 {
2077 
2078 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2079 	COUNTER_INC(system_check_sysctl);
2080 
2081 	return (0);
2082 }
2083 
2084 COUNTER_DECL(sysvmsg_cleanup);
2085 static void
2086 test_sysvmsg_cleanup(struct label *msglabel)
2087 {
2088 
2089 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2090 	COUNTER_INC(sysvmsg_cleanup);
2091 }
2092 
2093 COUNTER_DECL(sysvmsg_create);
2094 static void
2095 test_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
2096     struct label *msqlabel, struct msg *msgptr, struct label *msglabel)
2097 {
2098 
2099 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2100 	LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ);
2101 	COUNTER_INC(sysvmsg_create);
2102 }
2103 
2104 COUNTER_DECL(sysvmsg_destroy_label);
2105 static void
2106 test_sysvmsg_destroy_label(struct label *label)
2107 {
2108 
2109 	LABEL_DESTROY(label, MAGIC_SYSV_MSG);
2110 	COUNTER_INC(sysvmsg_destroy_label);
2111 }
2112 
2113 COUNTER_DECL(sysvmsg_init_label);
2114 static void
2115 test_sysvmsg_init_label(struct label *label)
2116 {
2117 	LABEL_INIT(label, MAGIC_SYSV_MSG);
2118 	COUNTER_INC(sysvmsg_init_label);
2119 }
2120 
2121 COUNTER_DECL(sysvmsq_check_msgmsq);
2122 static int
2123 test_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
2124     struct label *msglabel, struct msqid_kernel *msqkptr,
2125     struct label *msqklabel)
2126 {
2127 
2128 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2129 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2130 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2131 	COUNTER_INC(sysvmsq_check_msgmsq);
2132 
2133   	return (0);
2134 }
2135 
2136 COUNTER_DECL(sysvmsq_check_msgrcv);
2137 static int
2138 test_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr,
2139     struct label *msglabel)
2140 {
2141 
2142 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2143 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2144 	COUNTER_INC(sysvmsq_check_msgrcv);
2145 
2146 	return (0);
2147 }
2148 
2149 COUNTER_DECL(sysvmsq_check_msgrmid);
2150 static int
2151 test_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr,
2152     struct label *msglabel)
2153 {
2154 
2155 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2156 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2157 	COUNTER_INC(sysvmsq_check_msgrmid);
2158 
2159 	return (0);
2160 }
2161 
2162 COUNTER_DECL(sysvmsq_check_msqget);
2163 static int
2164 test_sysvmsq_check_msqget(struct ucred *cred,
2165     struct msqid_kernel *msqkptr, struct label *msqklabel)
2166 {
2167 
2168 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2169 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2170 	COUNTER_INC(sysvmsq_check_msqget);
2171 
2172 	return (0);
2173 }
2174 
2175 COUNTER_DECL(sysvmsq_check_msqsnd);
2176 static int
2177 test_sysvmsq_check_msqsnd(struct ucred *cred,
2178     struct msqid_kernel *msqkptr, struct label *msqklabel)
2179 {
2180 
2181 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2182 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2183 	COUNTER_INC(sysvmsq_check_msqsnd);
2184 
2185 	return (0);
2186 }
2187 
2188 COUNTER_DECL(sysvmsq_check_msqrcv);
2189 static int
2190 test_sysvmsq_check_msqrcv(struct ucred *cred,
2191     struct msqid_kernel *msqkptr, struct label *msqklabel)
2192 {
2193 
2194 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2195 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2196 	COUNTER_INC(sysvmsq_check_msqrcv);
2197 
2198 	return (0);
2199 }
2200 
2201 COUNTER_DECL(sysvmsq_check_msqctl);
2202 static int
2203 test_sysvmsq_check_msqctl(struct ucred *cred,
2204     struct msqid_kernel *msqkptr, struct label *msqklabel, int cmd)
2205 {
2206 
2207 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2208 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2209 	COUNTER_INC(sysvmsq_check_msqctl);
2210 
2211 	return (0);
2212 }
2213 
2214 COUNTER_DECL(sysvmsq_cleanup);
2215 static void
2216 test_sysvmsq_cleanup(struct label *msqlabel)
2217 {
2218 
2219 	LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ);
2220 	COUNTER_INC(sysvmsq_cleanup);
2221 }
2222 
2223 COUNTER_DECL(sysvmsq_create);
2224 static void
2225 test_sysvmsq_create(struct ucred *cred,
2226     struct msqid_kernel *msqkptr, struct label *msqlabel)
2227 {
2228 
2229 	LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ);
2230 	COUNTER_INC(sysvmsq_create);
2231 }
2232 
2233 COUNTER_DECL(sysvmsq_destroy_label);
2234 static void
2235 test_sysvmsq_destroy_label(struct label *label)
2236 {
2237 
2238 	LABEL_DESTROY(label, MAGIC_SYSV_MSQ);
2239 	COUNTER_INC(sysvmsq_destroy_label);
2240 }
2241 
2242 COUNTER_DECL(sysvmsq_init_label);
2243 static void
2244 test_sysvmsq_init_label(struct label *label)
2245 {
2246 	LABEL_INIT(label, MAGIC_SYSV_MSQ);
2247 	COUNTER_INC(sysvmsq_init_label);
2248 }
2249 
2250 COUNTER_DECL(sysvsem_check_semctl);
2251 static int
2252 test_sysvsem_check_semctl(struct ucred *cred,
2253     struct semid_kernel *semakptr, struct label *semaklabel, int cmd)
2254 {
2255 
2256 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2257 	LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM);
2258 	COUNTER_INC(sysvsem_check_semctl);
2259 
2260   	return (0);
2261 }
2262 
2263 COUNTER_DECL(sysvsem_check_semget);
2264 static int
2265 test_sysvsem_check_semget(struct ucred *cred,
2266     struct semid_kernel *semakptr, struct label *semaklabel)
2267 {
2268 
2269 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2270 	LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM);
2271 	COUNTER_INC(sysvsem_check_semget);
2272 
2273 	return (0);
2274 }
2275 
2276 COUNTER_DECL(sysvsem_check_semop);
2277 static int
2278 test_sysvsem_check_semop(struct ucred *cred,
2279     struct semid_kernel *semakptr, struct label *semaklabel, size_t accesstype)
2280 {
2281 
2282 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2283 	LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM);
2284 	COUNTER_INC(sysvsem_check_semop);
2285 
2286 	return (0);
2287 }
2288 
2289 COUNTER_DECL(sysvsem_cleanup);
2290 static void
2291 test_sysvsem_cleanup(struct label *semalabel)
2292 {
2293 
2294 	LABEL_CHECK(semalabel, MAGIC_SYSV_SEM);
2295 	COUNTER_INC(sysvsem_cleanup);
2296 }
2297 
2298 COUNTER_DECL(sysvsem_create);
2299 static void
2300 test_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr,
2301     struct label *semalabel)
2302 {
2303 
2304 	LABEL_CHECK(semalabel, MAGIC_SYSV_SEM);
2305 	COUNTER_INC(sysvsem_create);
2306 }
2307 
2308 COUNTER_DECL(sysvsem_destroy_label);
2309 static void
2310 test_sysvsem_destroy_label(struct label *label)
2311 {
2312 
2313 	LABEL_DESTROY(label, MAGIC_SYSV_SEM);
2314 	COUNTER_INC(sysvsem_destroy_label);
2315 }
2316 
2317 COUNTER_DECL(sysvsem_init_label);
2318 static void
2319 test_sysvsem_init_label(struct label *label)
2320 {
2321 	LABEL_INIT(label, MAGIC_SYSV_SEM);
2322 	COUNTER_INC(sysvsem_init_label);
2323 }
2324 
2325 COUNTER_DECL(sysvshm_check_shmat);
2326 static int
2327 test_sysvshm_check_shmat(struct ucred *cred,
2328     struct shmid_kernel *shmsegptr, struct label *shmseglabel, int shmflg)
2329 {
2330 
2331 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2332 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2333 	COUNTER_INC(sysvshm_check_shmat);
2334 
2335   	return (0);
2336 }
2337 
2338 COUNTER_DECL(sysvshm_check_shmctl);
2339 static int
2340 test_sysvshm_check_shmctl(struct ucred *cred,
2341     struct shmid_kernel *shmsegptr, struct label *shmseglabel, int cmd)
2342 {
2343 
2344 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2345 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2346 	COUNTER_INC(sysvshm_check_shmctl);
2347 
2348   	return (0);
2349 }
2350 
2351 COUNTER_DECL(sysvshm_check_shmdt);
2352 static int
2353 test_sysvshm_check_shmdt(struct ucred *cred,
2354     struct shmid_kernel *shmsegptr, struct label *shmseglabel)
2355 {
2356 
2357 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2358 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2359 	COUNTER_INC(sysvshm_check_shmdt);
2360 
2361 	return (0);
2362 }
2363 
2364 COUNTER_DECL(sysvshm_check_shmget);
2365 static int
2366 test_sysvshm_check_shmget(struct ucred *cred,
2367     struct shmid_kernel *shmsegptr, struct label *shmseglabel, int shmflg)
2368 {
2369 
2370 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2371 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2372 	COUNTER_INC(sysvshm_check_shmget);
2373 
2374 	return (0);
2375 }
2376 
2377 COUNTER_DECL(sysvshm_cleanup);
2378 static void
2379 test_sysvshm_cleanup(struct label *shmlabel)
2380 {
2381 
2382 	LABEL_CHECK(shmlabel, MAGIC_SYSV_SHM);
2383 	COUNTER_INC(sysvshm_cleanup);
2384 }
2385 
2386 COUNTER_DECL(sysvshm_create);
2387 static void
2388 test_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr,
2389     struct label *shmlabel)
2390 {
2391 
2392 	LABEL_CHECK(shmlabel, MAGIC_SYSV_SHM);
2393 	COUNTER_INC(sysvshm_create);
2394 }
2395 
2396 COUNTER_DECL(sysvshm_destroy_label);
2397 static void
2398 test_sysvshm_destroy_label(struct label *label)
2399 {
2400 
2401 	LABEL_DESTROY(label, MAGIC_SYSV_SHM);
2402 	COUNTER_INC(sysvshm_destroy_label);
2403 }
2404 
2405 COUNTER_DECL(sysvshm_init_label);
2406 static void
2407 test_sysvshm_init_label(struct label *label)
2408 {
2409 	LABEL_INIT(label, MAGIC_SYSV_SHM);
2410 	COUNTER_INC(sysvshm_init_label);
2411 }
2412 
2413 COUNTER_DECL(thread_userret);
2414 static void
2415 test_thread_userret(struct thread *td)
2416 {
2417 
2418 	COUNTER_INC(thread_userret);
2419 }
2420 
2421 COUNTER_DECL(vnode_associate_extattr);
2422 static int
2423 test_vnode_associate_extattr(struct mount *mp, struct label *mplabel,
2424     struct vnode *vp, struct label *vplabel)
2425 {
2426 
2427 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
2428 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2429 	COUNTER_INC(vnode_associate_extattr);
2430 
2431 	return (0);
2432 }
2433 
2434 COUNTER_DECL(vnode_associate_singlelabel);
2435 static void
2436 test_vnode_associate_singlelabel(struct mount *mp, struct label *mplabel,
2437     struct vnode *vp, struct label *vplabel)
2438 {
2439 
2440 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
2441 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2442 	COUNTER_INC(vnode_associate_singlelabel);
2443 }
2444 
2445 COUNTER_DECL(vnode_check_access);
2446 static int
2447 test_vnode_check_access(struct ucred *cred, struct vnode *vp,
2448     struct label *vplabel, accmode_t accmode)
2449 {
2450 
2451 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2452 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2453 	COUNTER_INC(vnode_check_access);
2454 
2455 	return (0);
2456 }
2457 
2458 COUNTER_DECL(vnode_check_chdir);
2459 static int
2460 test_vnode_check_chdir(struct ucred *cred, struct vnode *dvp,
2461     struct label *dvplabel)
2462 {
2463 
2464 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2465 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2466 	COUNTER_INC(vnode_check_chdir);
2467 
2468 	return (0);
2469 }
2470 
2471 COUNTER_DECL(vnode_check_chroot);
2472 static int
2473 test_vnode_check_chroot(struct ucred *cred, struct vnode *dvp,
2474     struct label *dvplabel)
2475 {
2476 
2477 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2478 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2479 	COUNTER_INC(vnode_check_chroot);
2480 
2481 	return (0);
2482 }
2483 
2484 COUNTER_DECL(vnode_check_create);
2485 static int
2486 test_vnode_check_create(struct ucred *cred, struct vnode *dvp,
2487     struct label *dvplabel, struct componentname *cnp, struct vattr *vap)
2488 {
2489 
2490 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2491 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2492 	COUNTER_INC(vnode_check_create);
2493 
2494 	return (0);
2495 }
2496 
2497 COUNTER_DECL(vnode_check_deleteacl);
2498 static int
2499 test_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
2500     struct label *vplabel, acl_type_t type)
2501 {
2502 
2503 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2504 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2505 	COUNTER_INC(vnode_check_deleteacl);
2506 
2507 	return (0);
2508 }
2509 
2510 COUNTER_DECL(vnode_check_deleteextattr);
2511 static int
2512 test_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
2513     struct label *vplabel, int attrnamespace, const char *name)
2514 {
2515 
2516 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2517 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2518 	COUNTER_INC(vnode_check_deleteextattr);
2519 
2520 	return (0);
2521 }
2522 
2523 COUNTER_DECL(vnode_check_exec);
2524 static int
2525 test_vnode_check_exec(struct ucred *cred, struct vnode *vp,
2526     struct label *vplabel, struct image_params *imgp,
2527     struct label *execlabel)
2528 {
2529 
2530 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2531 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2532 	LABEL_CHECK(execlabel, MAGIC_CRED);
2533 	COUNTER_INC(vnode_check_exec);
2534 
2535 	return (0);
2536 }
2537 
2538 COUNTER_DECL(vnode_check_getacl);
2539 static int
2540 test_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
2541     struct label *vplabel, acl_type_t type)
2542 {
2543 
2544 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2545 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2546 	COUNTER_INC(vnode_check_getacl);
2547 
2548 	return (0);
2549 }
2550 
2551 COUNTER_DECL(vnode_check_getextattr);
2552 static int
2553 test_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
2554     struct label *vplabel, int attrnamespace, const char *name)
2555 {
2556 
2557 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2558 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2559 	COUNTER_INC(vnode_check_getextattr);
2560 
2561 	return (0);
2562 }
2563 
2564 COUNTER_DECL(vnode_check_link);
2565 static int
2566 test_vnode_check_link(struct ucred *cred, struct vnode *dvp,
2567     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2568     struct componentname *cnp)
2569 {
2570 
2571 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2572 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2573 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2574 	COUNTER_INC(vnode_check_link);
2575 
2576 	return (0);
2577 }
2578 
2579 COUNTER_DECL(vnode_check_listextattr);
2580 static int
2581 test_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
2582     struct label *vplabel, int attrnamespace)
2583 {
2584 
2585 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2586 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2587 	COUNTER_INC(vnode_check_listextattr);
2588 
2589 	return (0);
2590 }
2591 
2592 COUNTER_DECL(vnode_check_lookup);
2593 static int
2594 test_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
2595     struct label *dvplabel, struct componentname *cnp)
2596 {
2597 
2598 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2599 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2600 	COUNTER_INC(vnode_check_lookup);
2601 
2602 	return (0);
2603 }
2604 
2605 COUNTER_DECL(vnode_check_mmap);
2606 static int
2607 test_vnode_check_mmap(struct ucred *cred, struct vnode *vp,
2608     struct label *vplabel, int prot, int flags)
2609 {
2610 
2611 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2612 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2613 	COUNTER_INC(vnode_check_mmap);
2614 
2615 	return (0);
2616 }
2617 
2618 COUNTER_DECL(vnode_check_open);
2619 static int
2620 test_vnode_check_open(struct ucred *cred, struct vnode *vp,
2621     struct label *vplabel, accmode_t accmode)
2622 {
2623 
2624 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2625 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2626 	COUNTER_INC(vnode_check_open);
2627 
2628 	return (0);
2629 }
2630 
2631 COUNTER_DECL(vnode_check_poll);
2632 static int
2633 test_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
2634     struct vnode *vp, struct label *vplabel)
2635 {
2636 
2637 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
2638 	if (file_cred != NULL)
2639 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
2640 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2641 	COUNTER_INC(vnode_check_poll);
2642 
2643 	return (0);
2644 }
2645 
2646 COUNTER_DECL(vnode_check_read);
2647 static int
2648 test_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
2649     struct vnode *vp, struct label *vplabel)
2650 {
2651 
2652 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
2653 	if (file_cred != NULL)
2654 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
2655 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2656 	COUNTER_INC(vnode_check_read);
2657 
2658 	return (0);
2659 }
2660 
2661 COUNTER_DECL(vnode_check_readdir);
2662 static int
2663 test_vnode_check_readdir(struct ucred *cred, struct vnode *dvp,
2664     struct label *dvplabel)
2665 {
2666 
2667 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2668 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2669 	COUNTER_INC(vnode_check_readdir);
2670 
2671 	return (0);
2672 }
2673 
2674 COUNTER_DECL(vnode_check_readlink);
2675 static int
2676 test_vnode_check_readlink(struct ucred *cred, struct vnode *vp,
2677     struct label *vplabel)
2678 {
2679 
2680 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2681 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2682 	COUNTER_INC(vnode_check_readlink);
2683 
2684 	return (0);
2685 }
2686 
2687 COUNTER_DECL(vnode_check_relabel);
2688 static int
2689 test_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
2690     struct label *vplabel, struct label *newlabel)
2691 {
2692 
2693 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2694 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2695 	LABEL_CHECK(newlabel, MAGIC_VNODE);
2696 	COUNTER_INC(vnode_check_relabel);
2697 
2698 	return (0);
2699 }
2700 
2701 COUNTER_DECL(vnode_check_rename_from);
2702 static int
2703 test_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
2704     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2705     struct componentname *cnp)
2706 {
2707 
2708 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2709 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2710 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2711 	COUNTER_INC(vnode_check_rename_from);
2712 
2713 	return (0);
2714 }
2715 
2716 COUNTER_DECL(vnode_check_rename_to);
2717 static int
2718 test_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
2719     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2720     int samedir, struct componentname *cnp)
2721 {
2722 
2723 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2724 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2725 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2726 	COUNTER_INC(vnode_check_rename_to);
2727 
2728 	return (0);
2729 }
2730 
2731 COUNTER_DECL(vnode_check_revoke);
2732 static int
2733 test_vnode_check_revoke(struct ucred *cred, struct vnode *vp,
2734     struct label *vplabel)
2735 {
2736 
2737 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2738 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2739 	COUNTER_INC(vnode_check_revoke);
2740 
2741 	return (0);
2742 }
2743 
2744 COUNTER_DECL(vnode_check_setacl);
2745 static int
2746 test_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
2747     struct label *vplabel, acl_type_t type, struct acl *acl)
2748 {
2749 
2750 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2751 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2752 	COUNTER_INC(vnode_check_setacl);
2753 
2754 	return (0);
2755 }
2756 
2757 COUNTER_DECL(vnode_check_setextattr);
2758 static int
2759 test_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
2760     struct label *vplabel, int attrnamespace, const char *name)
2761 {
2762 
2763 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2764 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2765 	COUNTER_INC(vnode_check_setextattr);
2766 
2767 	return (0);
2768 }
2769 
2770 COUNTER_DECL(vnode_check_setflags);
2771 static int
2772 test_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
2773     struct label *vplabel, u_long flags)
2774 {
2775 
2776 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2777 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2778 	COUNTER_INC(vnode_check_setflags);
2779 
2780 	return (0);
2781 }
2782 
2783 COUNTER_DECL(vnode_check_setmode);
2784 static int
2785 test_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
2786     struct label *vplabel, mode_t mode)
2787 {
2788 
2789 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2790 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2791 	COUNTER_INC(vnode_check_setmode);
2792 
2793 	return (0);
2794 }
2795 
2796 COUNTER_DECL(vnode_check_setowner);
2797 static int
2798 test_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
2799     struct label *vplabel, uid_t uid, gid_t gid)
2800 {
2801 
2802 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2803 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2804 	COUNTER_INC(vnode_check_setowner);
2805 
2806 	return (0);
2807 }
2808 
2809 COUNTER_DECL(vnode_check_setutimes);
2810 static int
2811 test_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
2812     struct label *vplabel, struct timespec atime, struct timespec mtime)
2813 {
2814 
2815 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2816 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2817 	COUNTER_INC(vnode_check_setutimes);
2818 
2819 	return (0);
2820 }
2821 
2822 COUNTER_DECL(vnode_check_stat);
2823 static int
2824 test_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
2825     struct vnode *vp, struct label *vplabel)
2826 {
2827 
2828 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
2829 	if (file_cred != NULL)
2830 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
2831 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2832 	COUNTER_INC(vnode_check_stat);
2833 
2834 	return (0);
2835 }
2836 
2837 COUNTER_DECL(vnode_check_unlink);
2838 static int
2839 test_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
2840     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2841     struct componentname *cnp)
2842 {
2843 
2844 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2845 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2846 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2847 	COUNTER_INC(vnode_check_unlink);
2848 
2849 	return (0);
2850 }
2851 
2852 COUNTER_DECL(vnode_check_write);
2853 static int
2854 test_vnode_check_write(struct ucred *active_cred,
2855     struct ucred *file_cred, struct vnode *vp, struct label *vplabel)
2856 {
2857 
2858 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
2859 	if (file_cred != NULL)
2860 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
2861 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2862 	COUNTER_INC(vnode_check_write);
2863 
2864 	return (0);
2865 }
2866 
2867 COUNTER_DECL(vnode_copy_label);
2868 static void
2869 test_vnode_copy_label(struct label *src, struct label *dest)
2870 {
2871 
2872 	LABEL_CHECK(src, MAGIC_VNODE);
2873 	LABEL_CHECK(dest, MAGIC_VNODE);
2874 	COUNTER_INC(vnode_copy_label);
2875 }
2876 
2877 COUNTER_DECL(vnode_create_extattr);
2878 static int
2879 test_vnode_create_extattr(struct ucred *cred, struct mount *mp,
2880     struct label *mplabel, struct vnode *dvp, struct label *dvplabel,
2881     struct vnode *vp, struct label *vplabel, struct componentname *cnp)
2882 {
2883 
2884 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2885 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
2886 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2887 	COUNTER_INC(vnode_create_extattr);
2888 
2889 	return (0);
2890 }
2891 
2892 COUNTER_DECL(vnode_destroy_label);
2893 static void
2894 test_vnode_destroy_label(struct label *label)
2895 {
2896 
2897 	LABEL_DESTROY(label, MAGIC_VNODE);
2898 	COUNTER_INC(vnode_destroy_label);
2899 }
2900 
2901 COUNTER_DECL(vnode_execve_transition);
2902 static void
2903 test_vnode_execve_transition(struct ucred *old, struct ucred *new,
2904     struct vnode *vp, struct label *filelabel,
2905     struct label *interpvplabel, struct image_params *imgp,
2906     struct label *execlabel)
2907 {
2908 
2909 	LABEL_CHECK(old->cr_label, MAGIC_CRED);
2910 	LABEL_CHECK(new->cr_label, MAGIC_CRED);
2911 	LABEL_CHECK(filelabel, MAGIC_VNODE);
2912 	LABEL_CHECK(interpvplabel, MAGIC_VNODE);
2913 	LABEL_CHECK(execlabel, MAGIC_CRED);
2914 	COUNTER_INC(vnode_execve_transition);
2915 }
2916 
2917 COUNTER_DECL(vnode_execve_will_transition);
2918 static int
2919 test_vnode_execve_will_transition(struct ucred *old, struct vnode *vp,
2920     struct label *filelabel, struct label *interpvplabel,
2921     struct image_params *imgp, struct label *execlabel)
2922 {
2923 
2924 	LABEL_CHECK(old->cr_label, MAGIC_CRED);
2925 	LABEL_CHECK(filelabel, MAGIC_VNODE);
2926 	LABEL_CHECK(interpvplabel, MAGIC_VNODE);
2927 	LABEL_CHECK(execlabel, MAGIC_CRED);
2928 	COUNTER_INC(vnode_execve_will_transition);
2929 
2930 	return (0);
2931 }
2932 
2933 COUNTER_DECL(vnode_externalize_label);
2934 static int
2935 test_vnode_externalize_label(struct label *label, char *element_name,
2936     struct sbuf *sb, int *claimed)
2937 {
2938 
2939 	LABEL_CHECK(label, MAGIC_VNODE);
2940 	COUNTER_INC(vnode_externalize_label);
2941 
2942 	return (0);
2943 }
2944 
2945 COUNTER_DECL(vnode_init_label);
2946 static void
2947 test_vnode_init_label(struct label *label)
2948 {
2949 
2950 	LABEL_INIT(label, MAGIC_VNODE);
2951 	COUNTER_INC(vnode_init_label);
2952 }
2953 
2954 COUNTER_DECL(vnode_internalize_label);
2955 static int
2956 test_vnode_internalize_label(struct label *label, char *element_name,
2957     char *element_data, int *claimed)
2958 {
2959 
2960 	LABEL_CHECK(label, MAGIC_VNODE);
2961 	COUNTER_INC(vnode_internalize_label);
2962 
2963 	return (0);
2964 }
2965 
2966 COUNTER_DECL(vnode_relabel);
2967 static void
2968 test_vnode_relabel(struct ucred *cred, struct vnode *vp,
2969     struct label *vplabel, struct label *label)
2970 {
2971 
2972 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2973 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2974 	LABEL_CHECK(label, MAGIC_VNODE);
2975 	COUNTER_INC(vnode_relabel);
2976 }
2977 
2978 COUNTER_DECL(vnode_setlabel_extattr);
2979 static int
2980 test_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp,
2981     struct label *vplabel, struct label *intlabel)
2982 {
2983 
2984 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2985 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2986 	LABEL_CHECK(intlabel, MAGIC_VNODE);
2987 	COUNTER_INC(vnode_setlabel_extattr);
2988 
2989 	return (0);
2990 }
2991 
2992 static struct mac_policy_ops test_ops =
2993 {
2994 	.mpo_bpfdesc_check_receive = test_bpfdesc_check_receive,
2995 	.mpo_bpfdesc_create = test_bpfdesc_create,
2996 	.mpo_bpfdesc_create_mbuf = test_bpfdesc_create_mbuf,
2997 	.mpo_bpfdesc_destroy_label = test_bpfdesc_destroy_label,
2998 	.mpo_bpfdesc_init_label = test_bpfdesc_init_label,
2999 
3000 	.mpo_cred_check_relabel = test_cred_check_relabel,
3001 	.mpo_cred_check_setaudit = test_cred_check_setaudit,
3002 	.mpo_cred_check_setaudit_addr = test_cred_check_setaudit_addr,
3003 	.mpo_cred_check_setauid = test_cred_check_setauid,
3004 	.mpo_cred_check_seteuid = test_cred_check_seteuid,
3005 	.mpo_cred_check_setegid = test_cred_check_setegid,
3006 	.mpo_cred_check_setgid = test_cred_check_setgid,
3007 	.mpo_cred_check_setgroups = test_cred_check_setgroups,
3008 	.mpo_cred_check_setregid = test_cred_check_setregid,
3009 	.mpo_cred_check_setresgid = test_cred_check_setresgid,
3010 	.mpo_cred_check_setresuid = test_cred_check_setresuid,
3011 	.mpo_cred_check_setreuid = test_cred_check_setreuid,
3012 	.mpo_cred_check_setuid = test_cred_check_setuid,
3013 	.mpo_cred_check_visible = test_cred_check_visible,
3014 	.mpo_cred_copy_label = test_cred_copy_label,
3015 	.mpo_cred_create_init = test_cred_create_init,
3016 	.mpo_cred_create_swapper = test_cred_create_swapper,
3017 	.mpo_cred_destroy_label = test_cred_destroy_label,
3018 	.mpo_cred_externalize_label = test_cred_externalize_label,
3019 	.mpo_cred_init_label = test_cred_init_label,
3020 	.mpo_cred_internalize_label = test_cred_internalize_label,
3021 	.mpo_cred_relabel = test_cred_relabel,
3022 
3023 	.mpo_devfs_create_device = test_devfs_create_device,
3024 	.mpo_devfs_create_directory = test_devfs_create_directory,
3025 	.mpo_devfs_create_symlink = test_devfs_create_symlink,
3026 	.mpo_devfs_destroy_label = test_devfs_destroy_label,
3027 	.mpo_devfs_init_label = test_devfs_init_label,
3028 	.mpo_devfs_update = test_devfs_update,
3029 	.mpo_devfs_vnode_associate = test_devfs_vnode_associate,
3030 
3031 	.mpo_ifnet_check_relabel = test_ifnet_check_relabel,
3032 	.mpo_ifnet_check_transmit = test_ifnet_check_transmit,
3033 	.mpo_ifnet_copy_label = test_ifnet_copy_label,
3034 	.mpo_ifnet_create = test_ifnet_create,
3035 	.mpo_ifnet_create_mbuf = test_ifnet_create_mbuf,
3036 	.mpo_ifnet_destroy_label = test_ifnet_destroy_label,
3037 	.mpo_ifnet_externalize_label = test_ifnet_externalize_label,
3038 	.mpo_ifnet_init_label = test_ifnet_init_label,
3039 	.mpo_ifnet_internalize_label = test_ifnet_internalize_label,
3040 	.mpo_ifnet_relabel = test_ifnet_relabel,
3041 
3042 	.mpo_syncache_destroy_label = test_syncache_destroy_label,
3043 	.mpo_syncache_init_label = test_syncache_init_label,
3044 
3045 	.mpo_sysvmsg_destroy_label = test_sysvmsg_destroy_label,
3046 	.mpo_sysvmsg_init_label = test_sysvmsg_init_label,
3047 
3048 	.mpo_sysvmsq_destroy_label = test_sysvmsq_destroy_label,
3049 	.mpo_sysvmsq_init_label = test_sysvmsq_init_label,
3050 
3051 	.mpo_sysvsem_destroy_label = test_sysvsem_destroy_label,
3052 	.mpo_sysvsem_init_label = test_sysvsem_init_label,
3053 
3054 	.mpo_sysvshm_destroy_label = test_sysvshm_destroy_label,
3055 	.mpo_sysvshm_init_label = test_sysvshm_init_label,
3056 
3057 	.mpo_inpcb_check_deliver = test_inpcb_check_deliver,
3058 	.mpo_inpcb_check_visible = test_inpcb_check_visible,
3059 	.mpo_inpcb_create = test_inpcb_create,
3060 	.mpo_inpcb_create_mbuf = test_inpcb_create_mbuf,
3061 	.mpo_inpcb_destroy_label = test_inpcb_destroy_label,
3062 	.mpo_inpcb_init_label = test_inpcb_init_label,
3063 	.mpo_inpcb_sosetlabel = test_inpcb_sosetlabel,
3064 
3065 	.mpo_ip6q_create = test_ip6q_create,
3066 	.mpo_ip6q_destroy_label = test_ip6q_destroy_label,
3067 	.mpo_ip6q_init_label = test_ip6q_init_label,
3068 	.mpo_ip6q_match = test_ip6q_match,
3069 	.mpo_ip6q_reassemble = test_ip6q_reassemble,
3070 	.mpo_ip6q_update = test_ip6q_update,
3071 
3072 	.mpo_ipq_create = test_ipq_create,
3073 	.mpo_ipq_destroy_label = test_ipq_destroy_label,
3074 	.mpo_ipq_init_label = test_ipq_init_label,
3075 	.mpo_ipq_match = test_ipq_match,
3076 	.mpo_ipq_reassemble = test_ipq_reassemble,
3077 	.mpo_ipq_update = test_ipq_update,
3078 
3079 	.mpo_kenv_check_dump = test_kenv_check_dump,
3080 	.mpo_kenv_check_get = test_kenv_check_get,
3081 	.mpo_kenv_check_set = test_kenv_check_set,
3082 	.mpo_kenv_check_unset = test_kenv_check_unset,
3083 
3084 	.mpo_kld_check_load = test_kld_check_load,
3085 	.mpo_kld_check_stat = test_kld_check_stat,
3086 
3087 	.mpo_mbuf_copy_label = test_mbuf_copy_label,
3088 	.mpo_mbuf_destroy_label = test_mbuf_destroy_label,
3089 	.mpo_mbuf_init_label = test_mbuf_init_label,
3090 
3091 	.mpo_mount_check_stat = test_mount_check_stat,
3092 	.mpo_mount_create = test_mount_create,
3093 	.mpo_mount_destroy_label = test_mount_destroy_label,
3094 	.mpo_mount_init_label = test_mount_init_label,
3095 
3096 	.mpo_netinet_arp_send = test_netinet_arp_send,
3097 	.mpo_netinet_fragment = test_netinet_fragment,
3098 	.mpo_netinet_icmp_reply = test_netinet_icmp_reply,
3099 	.mpo_netinet_icmp_replyinplace = test_netinet_icmp_replyinplace,
3100 	.mpo_netinet_igmp_send = test_netinet_igmp_send,
3101 	.mpo_netinet_tcp_reply = test_netinet_tcp_reply,
3102 
3103 	.mpo_netinet6_nd6_send = test_netinet6_nd6_send,
3104 
3105 	.mpo_pipe_check_ioctl = test_pipe_check_ioctl,
3106 	.mpo_pipe_check_poll = test_pipe_check_poll,
3107 	.mpo_pipe_check_read = test_pipe_check_read,
3108 	.mpo_pipe_check_relabel = test_pipe_check_relabel,
3109 	.mpo_pipe_check_stat = test_pipe_check_stat,
3110 	.mpo_pipe_check_write = test_pipe_check_write,
3111 	.mpo_pipe_copy_label = test_pipe_copy_label,
3112 	.mpo_pipe_create = test_pipe_create,
3113 	.mpo_pipe_destroy_label = test_pipe_destroy_label,
3114 	.mpo_pipe_externalize_label = test_pipe_externalize_label,
3115 	.mpo_pipe_init_label = test_pipe_init_label,
3116 	.mpo_pipe_internalize_label = test_pipe_internalize_label,
3117 	.mpo_pipe_relabel = test_pipe_relabel,
3118 
3119 	.mpo_posixsem_check_getvalue = test_posixsem_check_getvalue,
3120 	.mpo_posixsem_check_open = test_posixsem_check_open,
3121 	.mpo_posixsem_check_post = test_posixsem_check_post,
3122 	.mpo_posixsem_check_setmode = test_posixsem_check_setmode,
3123 	.mpo_posixsem_check_setowner = test_posixsem_check_setowner,
3124 	.mpo_posixsem_check_stat = test_posixsem_check_stat,
3125 	.mpo_posixsem_check_unlink = test_posixsem_check_unlink,
3126 	.mpo_posixsem_check_wait = test_posixsem_check_wait,
3127 	.mpo_posixsem_create = test_posixsem_create,
3128 	.mpo_posixsem_destroy_label = test_posixsem_destroy_label,
3129 	.mpo_posixsem_init_label = test_posixsem_init_label,
3130 
3131 	.mpo_posixshm_check_create = test_posixshm_check_create,
3132 	.mpo_posixshm_check_mmap = test_posixshm_check_mmap,
3133 	.mpo_posixshm_check_open = test_posixshm_check_open,
3134 	.mpo_posixshm_check_read = test_posixshm_check_read,
3135 	.mpo_posixshm_check_setmode = test_posixshm_check_setmode,
3136 	.mpo_posixshm_check_setowner = test_posixshm_check_setowner,
3137 	.mpo_posixshm_check_stat = test_posixshm_check_stat,
3138 	.mpo_posixshm_check_truncate = test_posixshm_check_truncate,
3139 	.mpo_posixshm_check_unlink = test_posixshm_check_unlink,
3140 	.mpo_posixshm_check_write = test_posixshm_check_write,
3141 	.mpo_posixshm_create = test_posixshm_create,
3142 	.mpo_posixshm_destroy_label = test_posixshm_destroy_label,
3143 	.mpo_posixshm_init_label = test_posixshm_init_label,
3144 
3145 	.mpo_proc_check_debug = test_proc_check_debug,
3146 	.mpo_proc_check_sched = test_proc_check_sched,
3147 	.mpo_proc_check_signal = test_proc_check_signal,
3148 	.mpo_proc_check_wait = test_proc_check_wait,
3149 	.mpo_proc_destroy_label = test_proc_destroy_label,
3150 	.mpo_proc_init_label = test_proc_init_label,
3151 
3152 	.mpo_socket_check_accept = test_socket_check_accept,
3153 	.mpo_socket_check_bind = test_socket_check_bind,
3154 	.mpo_socket_check_connect = test_socket_check_connect,
3155 	.mpo_socket_check_deliver = test_socket_check_deliver,
3156 	.mpo_socket_check_listen = test_socket_check_listen,
3157 	.mpo_socket_check_poll = test_socket_check_poll,
3158 	.mpo_socket_check_receive = test_socket_check_receive,
3159 	.mpo_socket_check_relabel = test_socket_check_relabel,
3160 	.mpo_socket_check_send = test_socket_check_send,
3161 	.mpo_socket_check_stat = test_socket_check_stat,
3162 	.mpo_socket_check_visible = test_socket_check_visible,
3163 	.mpo_socket_copy_label = test_socket_copy_label,
3164 	.mpo_socket_create = test_socket_create,
3165 	.mpo_socket_create_mbuf = test_socket_create_mbuf,
3166 	.mpo_socket_destroy_label = test_socket_destroy_label,
3167 	.mpo_socket_externalize_label = test_socket_externalize_label,
3168 	.mpo_socket_init_label = test_socket_init_label,
3169 	.mpo_socket_internalize_label = test_socket_internalize_label,
3170 	.mpo_socket_newconn = test_socket_newconn,
3171 	.mpo_socket_relabel = test_socket_relabel,
3172 
3173 	.mpo_socketpeer_destroy_label = test_socketpeer_destroy_label,
3174 	.mpo_socketpeer_externalize_label = test_socketpeer_externalize_label,
3175 	.mpo_socketpeer_init_label = test_socketpeer_init_label,
3176 	.mpo_socketpeer_set_from_mbuf = test_socketpeer_set_from_mbuf,
3177 	.mpo_socketpeer_set_from_socket = test_socketpeer_set_from_socket,
3178 
3179 	.mpo_syncache_create = test_syncache_create,
3180 	.mpo_syncache_create_mbuf = test_syncache_create_mbuf,
3181 
3182 	.mpo_system_check_acct = test_system_check_acct,
3183 	.mpo_system_check_audit = test_system_check_audit,
3184 	.mpo_system_check_auditctl = test_system_check_auditctl,
3185 	.mpo_system_check_auditon = test_system_check_auditon,
3186 	.mpo_system_check_reboot = test_system_check_reboot,
3187 	.mpo_system_check_swapoff = test_system_check_swapoff,
3188 	.mpo_system_check_swapon = test_system_check_swapon,
3189 	.mpo_system_check_sysctl = test_system_check_sysctl,
3190 
3191 	.mpo_vnode_check_access = test_vnode_check_access,
3192 	.mpo_sysvmsg_cleanup = test_sysvmsg_cleanup,
3193 	.mpo_sysvmsg_create = test_sysvmsg_create,
3194 
3195 	.mpo_sysvmsq_check_msgmsq = test_sysvmsq_check_msgmsq,
3196 	.mpo_sysvmsq_check_msgrcv = test_sysvmsq_check_msgrcv,
3197 	.mpo_sysvmsq_check_msgrmid = test_sysvmsq_check_msgrmid,
3198 	.mpo_sysvmsq_check_msqget = test_sysvmsq_check_msqget,
3199 	.mpo_sysvmsq_check_msqsnd = test_sysvmsq_check_msqsnd,
3200 	.mpo_sysvmsq_check_msqrcv = test_sysvmsq_check_msqrcv,
3201 	.mpo_sysvmsq_check_msqctl = test_sysvmsq_check_msqctl,
3202 	.mpo_sysvmsq_cleanup = test_sysvmsq_cleanup,
3203 	.mpo_sysvmsq_create = test_sysvmsq_create,
3204 
3205 	.mpo_sysvsem_check_semctl = test_sysvsem_check_semctl,
3206 	.mpo_sysvsem_check_semget = test_sysvsem_check_semget,
3207 	.mpo_sysvsem_check_semop = test_sysvsem_check_semop,
3208 	.mpo_sysvsem_cleanup = test_sysvsem_cleanup,
3209 	.mpo_sysvsem_create = test_sysvsem_create,
3210 
3211 	.mpo_sysvshm_check_shmat = test_sysvshm_check_shmat,
3212 	.mpo_sysvshm_check_shmctl = test_sysvshm_check_shmctl,
3213 	.mpo_sysvshm_check_shmdt = test_sysvshm_check_shmdt,
3214 	.mpo_sysvshm_check_shmget = test_sysvshm_check_shmget,
3215 	.mpo_sysvshm_cleanup = test_sysvshm_cleanup,
3216 	.mpo_sysvshm_create = test_sysvshm_create,
3217 
3218 	.mpo_thread_userret = test_thread_userret,
3219 
3220 	.mpo_vnode_associate_extattr = test_vnode_associate_extattr,
3221 	.mpo_vnode_associate_singlelabel = test_vnode_associate_singlelabel,
3222 	.mpo_vnode_check_chdir = test_vnode_check_chdir,
3223 	.mpo_vnode_check_chroot = test_vnode_check_chroot,
3224 	.mpo_vnode_check_create = test_vnode_check_create,
3225 	.mpo_vnode_check_deleteacl = test_vnode_check_deleteacl,
3226 	.mpo_vnode_check_deleteextattr = test_vnode_check_deleteextattr,
3227 	.mpo_vnode_check_exec = test_vnode_check_exec,
3228 	.mpo_vnode_check_getacl = test_vnode_check_getacl,
3229 	.mpo_vnode_check_getextattr = test_vnode_check_getextattr,
3230 	.mpo_vnode_check_link = test_vnode_check_link,
3231 	.mpo_vnode_check_listextattr = test_vnode_check_listextattr,
3232 	.mpo_vnode_check_lookup = test_vnode_check_lookup,
3233 	.mpo_vnode_check_mmap = test_vnode_check_mmap,
3234 	.mpo_vnode_check_open = test_vnode_check_open,
3235 	.mpo_vnode_check_poll = test_vnode_check_poll,
3236 	.mpo_vnode_check_read = test_vnode_check_read,
3237 	.mpo_vnode_check_readdir = test_vnode_check_readdir,
3238 	.mpo_vnode_check_readlink = test_vnode_check_readlink,
3239 	.mpo_vnode_check_relabel = test_vnode_check_relabel,
3240 	.mpo_vnode_check_rename_from = test_vnode_check_rename_from,
3241 	.mpo_vnode_check_rename_to = test_vnode_check_rename_to,
3242 	.mpo_vnode_check_revoke = test_vnode_check_revoke,
3243 	.mpo_vnode_check_setacl = test_vnode_check_setacl,
3244 	.mpo_vnode_check_setextattr = test_vnode_check_setextattr,
3245 	.mpo_vnode_check_setflags = test_vnode_check_setflags,
3246 	.mpo_vnode_check_setmode = test_vnode_check_setmode,
3247 	.mpo_vnode_check_setowner = test_vnode_check_setowner,
3248 	.mpo_vnode_check_setutimes = test_vnode_check_setutimes,
3249 	.mpo_vnode_check_stat = test_vnode_check_stat,
3250 	.mpo_vnode_check_unlink = test_vnode_check_unlink,
3251 	.mpo_vnode_check_write = test_vnode_check_write,
3252 	.mpo_vnode_copy_label = test_vnode_copy_label,
3253 	.mpo_vnode_create_extattr = test_vnode_create_extattr,
3254 	.mpo_vnode_destroy_label = test_vnode_destroy_label,
3255 	.mpo_vnode_execve_transition = test_vnode_execve_transition,
3256 	.mpo_vnode_execve_will_transition = test_vnode_execve_will_transition,
3257 	.mpo_vnode_externalize_label = test_vnode_externalize_label,
3258 	.mpo_vnode_init_label = test_vnode_init_label,
3259 	.mpo_vnode_internalize_label = test_vnode_internalize_label,
3260 	.mpo_vnode_relabel = test_vnode_relabel,
3261 	.mpo_vnode_setlabel_extattr = test_vnode_setlabel_extattr,
3262 };
3263 
3264 MAC_POLICY_SET(&test_ops, mac_test, "TrustedBSD MAC/Test",
3265     MPC_LOADTIME_FLAG_UNLOADOK, &test_slot);
3266