xref: /freebsd/sys/security/mac_test/mac_test.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1d8a7b7a3SRobert Watson /*-
29b6dd12eSRobert Watson  * Copyright (c) 1999-2002, 2007-2011 Robert N. M. Watson
364094732SRobert Watson  * Copyright (c) 2001-2005 McAfee, Inc.
430d239bcSRobert Watson  * Copyright (c) 2006 SPARTA, Inc.
56356dba0SRobert Watson  * Copyright (c) 2008 Apple Inc.
6d8a7b7a3SRobert Watson  * All rights reserved.
7d8a7b7a3SRobert Watson  *
8d8a7b7a3SRobert Watson  * This software was developed by Robert Watson for the TrustedBSD Project.
9d8a7b7a3SRobert Watson  *
1064094732SRobert Watson  * This software was developed for the FreeBSD Project in part by McAfee
1164094732SRobert Watson  * Research, the Security Research Division of McAfee, Inc. under
1264094732SRobert Watson  * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
1364094732SRobert Watson  * CHATS research program.
14d8a7b7a3SRobert Watson  *
1530d239bcSRobert Watson  * This software was enhanced by SPARTA ISSO under SPAWAR contract
1630d239bcSRobert Watson  * N66001-04-C-6019 ("SEFOS").
1730d239bcSRobert Watson  *
186f6174a7SRobert Watson  * This software was developed at the University of Cambridge Computer
196f6174a7SRobert Watson  * Laboratory with support from a grant from Google, Inc.
206f6174a7SRobert Watson  *
21d8a7b7a3SRobert Watson  * Redistribution and use in source and binary forms, with or without
22d8a7b7a3SRobert Watson  * modification, are permitted provided that the following conditions
23d8a7b7a3SRobert Watson  * are met:
24d8a7b7a3SRobert Watson  * 1. Redistributions of source code must retain the above copyright
25d8a7b7a3SRobert Watson  *    notice, this list of conditions and the following disclaimer.
26d8a7b7a3SRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
27d8a7b7a3SRobert Watson  *    notice, this list of conditions and the following disclaimer in the
28d8a7b7a3SRobert Watson  *    documentation and/or other materials provided with the distribution.
29d8a7b7a3SRobert Watson  *
30d8a7b7a3SRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31d8a7b7a3SRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32d8a7b7a3SRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33d8a7b7a3SRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34d8a7b7a3SRobert Watson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35d8a7b7a3SRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36d8a7b7a3SRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37d8a7b7a3SRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38d8a7b7a3SRobert Watson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39d8a7b7a3SRobert Watson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40d8a7b7a3SRobert Watson  * SUCH DAMAGE.
41d8a7b7a3SRobert Watson  */
42d8a7b7a3SRobert Watson 
43d8a7b7a3SRobert Watson /*
44d8a7b7a3SRobert Watson  * Developed by the TrustedBSD Project.
456827d029SRobert Watson  *
466827d029SRobert Watson  * MAC Test policy - tests MAC Framework labeling by assigning object class
476827d029SRobert Watson  * magic numbers to each label and validates that each time an object label
486827d029SRobert Watson  * is passed into the policy, it has a consistent object type, catching
496827d029SRobert Watson  * incorrectly passed labels, labels passed after free, etc.
50d8a7b7a3SRobert Watson  */
51d8a7b7a3SRobert Watson 
52d8a7b7a3SRobert Watson #include <sys/param.h>
53d8a7b7a3SRobert Watson #include <sys/acl.h>
5432240d08SMarcel Moolenaar #include <sys/kdb.h>
55d8a7b7a3SRobert Watson #include <sys/kernel.h>
566aeb05d7STom Rhodes #include <sys/ksem.h>
570712b254SRobert Watson #include <sys/malloc.h>
587405fcc3SRobert Watson #include <sys/module.h>
59d8a7b7a3SRobert Watson #include <sys/mount.h>
607405fcc3SRobert Watson #include <sys/msg.h>
61d8a7b7a3SRobert Watson #include <sys/proc.h>
62d8a7b7a3SRobert Watson #include <sys/vnode.h>
637405fcc3SRobert Watson #include <sys/sem.h>
647405fcc3SRobert Watson #include <sys/shm.h>
65d8a7b7a3SRobert Watson #include <sys/socket.h>
66d8a7b7a3SRobert Watson #include <sys/socketvar.h>
6736422989SPoul-Henning Kamp #include <sys/sx.h>
68d8a7b7a3SRobert Watson #include <sys/sysctl.h>
69d8a7b7a3SRobert Watson 
70*2449b9e5SMitchell Horne #include <ddb/ddb.h>
71*2449b9e5SMitchell Horne 
72d8a7b7a3SRobert Watson #include <fs/devfs/devfs.h>
73d8a7b7a3SRobert Watson 
74d8a7b7a3SRobert Watson #include <net/bpfdesc.h>
75d8a7b7a3SRobert Watson #include <net/if.h>
76d8a7b7a3SRobert Watson #include <net/if_types.h>
77d8a7b7a3SRobert Watson #include <net/if_var.h>
78d8a7b7a3SRobert Watson 
790efd6615SRobert Watson #include <security/mac/mac_policy.h>
80d8a7b7a3SRobert Watson 
81d8a7b7a3SRobert Watson SYSCTL_DECL(_security_mac);
82d8a7b7a3SRobert Watson 
837029da5cSPawel Biernacki static SYSCTL_NODE(_security_mac, OID_AUTO, test,
847029da5cSPawel Biernacki     CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
85d8a7b7a3SRobert Watson     "TrustedBSD mac_test policy controls");
86d8a7b7a3SRobert Watson 
876827d029SRobert Watson #define	MAGIC_BPF	0xfe1ad1b6
886827d029SRobert Watson #define	MAGIC_DEVFS	0x9ee79c32
896827d029SRobert Watson #define	MAGIC_IFNET	0xc218b120
906827d029SRobert Watson #define	MAGIC_INPCB	0x4440f7bb
91048e1287SRobert Watson #define	MAGIC_IP6Q	0x0870e1b7
926827d029SRobert Watson #define	MAGIC_IPQ	0x206188ef
936827d029SRobert Watson #define	MAGIC_MBUF	0xbbefa5bb
946827d029SRobert Watson #define	MAGIC_MOUNT	0xc7c46e47
956827d029SRobert Watson #define	MAGIC_SOCKET	0x9199c6cd
96f10b1ebcSRobert Watson #define	MAGIC_SYNCACHE	0x7fb838a8
97269ad130SRobert Watson #define	MAGIC_SYSV_MSG	0x8bbba61e
98269ad130SRobert Watson #define	MAGIC_SYSV_MSQ	0xea672391
99269ad130SRobert Watson #define	MAGIC_SYSV_SEM	0x896e8a0b
100269ad130SRobert Watson #define	MAGIC_SYSV_SHM	0x76119ab0
1016827d029SRobert Watson #define	MAGIC_PIPE	0xdc6c9919
102269ad130SRobert Watson #define	MAGIC_POSIX_SEM	0x78ae980c
1038e38aeffSJohn Baldwin #define	MAGIC_POSIX_SHM	0x4e853fc9
1046827d029SRobert Watson #define	MAGIC_PROC	0x3b4be98f
1056827d029SRobert Watson #define	MAGIC_CRED	0x9a5a4987
1066827d029SRobert Watson #define	MAGIC_VNODE	0x1a67a45c
1076827d029SRobert Watson #define	MAGIC_FREE	0x849ba1fd
108d8a7b7a3SRobert Watson 
1090142affcSRobert Watson #define	SLOT(x)	mac_label_get((x), test_slot)
1100142affcSRobert Watson #define	SLOT_SET(x, v)	mac_label_set((x), test_slot, (v))
111250ee706SRobert Watson 
112d8a7b7a3SRobert Watson static int	test_slot;
113d8a7b7a3SRobert Watson SYSCTL_INT(_security_mac_test, OID_AUTO, slot, CTLFLAG_RD,
114d8a7b7a3SRobert Watson     &test_slot, 0, "Slot allocated by framework");
115d8a7b7a3SRobert Watson 
1167029da5cSPawel Biernacki static SYSCTL_NODE(_security_mac_test, OID_AUTO, counter,
1177029da5cSPawel Biernacki     CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
1186827d029SRobert Watson     "TrustedBSD mac_test counters controls");
119d8a7b7a3SRobert Watson 
1206827d029SRobert Watson #define	COUNTER_DECL(variable)						\
1216827d029SRobert Watson 	static int counter_##variable;					\
1226827d029SRobert Watson 	SYSCTL_INT(_security_mac_test_counter, OID_AUTO, variable,	\
1236827d029SRobert Watson 	CTLFLAG_RD, &counter_##variable, 0, #variable)
124d8a7b7a3SRobert Watson 
1256827d029SRobert Watson #define	COUNTER_INC(variable)	atomic_add_int(&counter_##variable, 1)
1266827d029SRobert Watson 
127b2e3811cSRobert Watson #ifdef KDB
1283de213ccSRobert Watson #define	DEBUGGER(func, string)	kdb_enter(KDB_WHY_MAC, (string))
129b2e3811cSRobert Watson #else
1306827d029SRobert Watson #define	DEBUGGER(func, string)	printf("mac_test: %s: %s\n", (func), (string))
131b2e3811cSRobert Watson #endif
132b2e3811cSRobert Watson 
1336827d029SRobert Watson #define	LABEL_CHECK(label, magic) do {					\
1346827d029SRobert Watson 	if (label != NULL) {						\
1356827d029SRobert Watson 		KASSERT(SLOT(label) == magic ||	SLOT(label) == 0,	\
1366827d029SRobert Watson 		    ("%s: bad %s label", __func__, #magic));		\
1376827d029SRobert Watson 	}								\
1386827d029SRobert Watson } while (0)
1396827d029SRobert Watson 
140269ad130SRobert Watson #define	LABEL_DESTROY(label, magic) do {				\
1416827d029SRobert Watson 	if (SLOT(label) == magic || SLOT(label) == 0) {			\
1426827d029SRobert Watson 		SLOT_SET(label, MAGIC_FREE);				\
1436827d029SRobert Watson 	} else if (SLOT(label) == MAGIC_FREE) {				\
1446827d029SRobert Watson 		DEBUGGER("%s: dup destroy", __func__);			\
1456827d029SRobert Watson 	} else {							\
1466827d029SRobert Watson 		DEBUGGER("%s: corrupted label", __func__);		\
1476827d029SRobert Watson 	}								\
1486827d029SRobert Watson } while (0)
1496827d029SRobert Watson 
150269ad130SRobert Watson #define	LABEL_INIT(label, magic) do {					\
151269ad130SRobert Watson 	SLOT_SET(label, magic);						\
152269ad130SRobert Watson } while (0)
153269ad130SRobert Watson 
1546827d029SRobert Watson #define	LABEL_NOTFREE(label) do {					\
1556827d029SRobert Watson 	KASSERT(SLOT(label) != MAGIC_FREE,				\
1566827d029SRobert Watson 	    ("%s: destroyed label", __func__));				\
1576827d029SRobert Watson } while (0)
1586827d029SRobert Watson 
159d8a7b7a3SRobert Watson /*
160eb320b0eSRobert Watson  * Object-specific entry point implementations are sorted alphabetically by
161eb320b0eSRobert Watson  * object type name and then by operation.
162eb320b0eSRobert Watson  */
163eb320b0eSRobert Watson COUNTER_DECL(bpfdesc_check_receive);
164a557af22SRobert Watson static int
test_bpfdesc_check_receive(struct bpf_d * d,struct label * dlabel,struct ifnet * ifp,struct label * ifplabel)165f0336833SRobert Watson test_bpfdesc_check_receive(struct bpf_d *d, struct label *dlabel,
166eb320b0eSRobert Watson     struct ifnet *ifp, struct label *ifplabel)
167d8a7b7a3SRobert Watson {
168d8a7b7a3SRobert Watson 
169f0336833SRobert Watson 	LABEL_CHECK(dlabel, MAGIC_BPF);
170eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
171eb320b0eSRobert Watson 	COUNTER_INC(bpfdesc_check_receive);
1720712b254SRobert Watson 
1735e7ce478SRobert Watson 	return (0);
174d8a7b7a3SRobert Watson }
175d8a7b7a3SRobert Watson 
176eb320b0eSRobert Watson COUNTER_DECL(bpfdesc_create);
177d8a7b7a3SRobert Watson static void
test_bpfdesc_create(struct ucred * cred,struct bpf_d * d,struct label * dlabel)178f0336833SRobert Watson test_bpfdesc_create(struct ucred *cred, struct bpf_d *d,
179f0336833SRobert Watson     struct label *dlabel)
180d8a7b7a3SRobert Watson {
181d8a7b7a3SRobert Watson 
182eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
183f0336833SRobert Watson 	LABEL_CHECK(dlabel, MAGIC_BPF);
184eb320b0eSRobert Watson 	COUNTER_INC(bpfdesc_create);
185d8a7b7a3SRobert Watson }
186d8a7b7a3SRobert Watson 
187eb320b0eSRobert Watson COUNTER_DECL(bpfdesc_create_mbuf);
18896adb909SRobert Watson static void
test_bpfdesc_create_mbuf(struct bpf_d * d,struct label * dlabel,struct mbuf * m,struct label * mlabel)189f0336833SRobert Watson test_bpfdesc_create_mbuf(struct bpf_d *d, struct label *dlabel,
190f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
191d8a7b7a3SRobert Watson {
192d8a7b7a3SRobert Watson 
193f0336833SRobert Watson 	LABEL_CHECK(dlabel, MAGIC_BPF);
194f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
195eb320b0eSRobert Watson 	COUNTER_INC(bpfdesc_create_mbuf);
196d8a7b7a3SRobert Watson }
197d8a7b7a3SRobert Watson 
19830d239bcSRobert Watson COUNTER_DECL(bpfdesc_destroy_label);
199d8a7b7a3SRobert Watson static void
test_bpfdesc_destroy_label(struct label * label)2003f1a7a90SRobert Watson test_bpfdesc_destroy_label(struct label *label)
201d8a7b7a3SRobert Watson {
202d8a7b7a3SRobert Watson 
203269ad130SRobert Watson 	LABEL_DESTROY(label, MAGIC_BPF);
20430d239bcSRobert Watson 	COUNTER_INC(bpfdesc_destroy_label);
205d8a7b7a3SRobert Watson }
206d8a7b7a3SRobert Watson 
207eb320b0eSRobert Watson COUNTER_DECL(bpfdesc_init_label);
208d8a7b7a3SRobert Watson static void
test_bpfdesc_init_label(struct label * label)209eb320b0eSRobert Watson test_bpfdesc_init_label(struct label *label)
210d8a7b7a3SRobert Watson {
211d8a7b7a3SRobert Watson 
212eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_BPF);
213eb320b0eSRobert Watson 	COUNTER_INC(bpfdesc_init_label);
214d8a7b7a3SRobert Watson }
215d8a7b7a3SRobert Watson 
216eb320b0eSRobert Watson COUNTER_DECL(cred_check_relabel);
217eb320b0eSRobert Watson static int
test_cred_check_relabel(struct ucred * cred,struct label * newlabel)218eb320b0eSRobert Watson test_cred_check_relabel(struct ucred *cred, struct label *newlabel)
219d8a7b7a3SRobert Watson {
220d8a7b7a3SRobert Watson 
221eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
222eb320b0eSRobert Watson 	LABEL_CHECK(newlabel, MAGIC_CRED);
223eb320b0eSRobert Watson 	COUNTER_INC(cred_check_relabel);
224eb320b0eSRobert Watson 
225eb320b0eSRobert Watson 	return (0);
226d8a7b7a3SRobert Watson }
227d8a7b7a3SRobert Watson 
2286f6174a7SRobert Watson COUNTER_DECL(cred_check_setaudit);
2296f6174a7SRobert Watson static int
test_cred_check_setaudit(struct ucred * cred,struct auditinfo * ai)2306f6174a7SRobert Watson test_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai)
2316f6174a7SRobert Watson {
2326f6174a7SRobert Watson 
2336f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2346f6174a7SRobert Watson 	COUNTER_INC(cred_check_setaudit);
2356f6174a7SRobert Watson 
2366f6174a7SRobert Watson 	return (0);
2376f6174a7SRobert Watson }
2386f6174a7SRobert Watson 
2396f6174a7SRobert Watson COUNTER_DECL(cred_check_setaudit_addr);
2406f6174a7SRobert Watson static int
test_cred_check_setaudit_addr(struct ucred * cred,struct auditinfo_addr * aia)2416f6174a7SRobert Watson test_cred_check_setaudit_addr(struct ucred *cred,
2426f6174a7SRobert Watson     struct auditinfo_addr *aia)
2436f6174a7SRobert Watson {
2446f6174a7SRobert Watson 
2456f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2466f6174a7SRobert Watson 	COUNTER_INC(cred_check_setaudit_addr);
2476f6174a7SRobert Watson 
2486f6174a7SRobert Watson 	return (0);
2496f6174a7SRobert Watson }
2506f6174a7SRobert Watson 
2516f6174a7SRobert Watson COUNTER_DECL(cred_check_setauid);
2526f6174a7SRobert Watson static int
test_cred_check_setauid(struct ucred * cred,uid_t auid)2536f6174a7SRobert Watson test_cred_check_setauid(struct ucred *cred, uid_t auid)
2546f6174a7SRobert Watson {
2556f6174a7SRobert Watson 
2566f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2576f6174a7SRobert Watson 	COUNTER_INC(cred_check_setauid);
2586f6174a7SRobert Watson 
2596f6174a7SRobert Watson 	return (0);
2606f6174a7SRobert Watson }
2616f6174a7SRobert Watson 
2626f6174a7SRobert Watson COUNTER_DECL(cred_check_setegid);
2636f6174a7SRobert Watson static int
test_cred_check_setegid(struct ucred * cred,gid_t egid)2646f6174a7SRobert Watson test_cred_check_setegid(struct ucred *cred, gid_t egid)
2656f6174a7SRobert Watson {
2666f6174a7SRobert Watson 
2676f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2686f6174a7SRobert Watson 	COUNTER_INC(cred_check_setegid);
2696f6174a7SRobert Watson 
2706f6174a7SRobert Watson 	return (0);
2716f6174a7SRobert Watson }
2726f6174a7SRobert Watson 
2736f6174a7SRobert Watson COUNTER_DECL(proc_check_euid);
2746f6174a7SRobert Watson static int
test_cred_check_seteuid(struct ucred * cred,uid_t euid)2756f6174a7SRobert Watson test_cred_check_seteuid(struct ucred *cred, uid_t euid)
2766f6174a7SRobert Watson {
2776f6174a7SRobert Watson 
2786f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2796f6174a7SRobert Watson 	COUNTER_INC(proc_check_euid);
2806f6174a7SRobert Watson 
2816f6174a7SRobert Watson 	return (0);
2826f6174a7SRobert Watson }
2836f6174a7SRobert Watson 
2846f6174a7SRobert Watson COUNTER_DECL(cred_check_setregid);
2856f6174a7SRobert Watson static int
test_cred_check_setregid(struct ucred * cred,gid_t rgid,gid_t egid)2866f6174a7SRobert Watson test_cred_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid)
2876f6174a7SRobert Watson {
2886f6174a7SRobert Watson 
2896f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2906f6174a7SRobert Watson 	COUNTER_INC(cred_check_setregid);
2916f6174a7SRobert Watson 
2926f6174a7SRobert Watson 	return (0);
2936f6174a7SRobert Watson }
2946f6174a7SRobert Watson 
2956f6174a7SRobert Watson COUNTER_DECL(cred_check_setreuid);
2966f6174a7SRobert Watson static int
test_cred_check_setreuid(struct ucred * cred,uid_t ruid,uid_t euid)2976f6174a7SRobert Watson test_cred_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid)
2986f6174a7SRobert Watson {
2996f6174a7SRobert Watson 
3006f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3016f6174a7SRobert Watson 	COUNTER_INC(cred_check_setreuid);
3026f6174a7SRobert Watson 
3036f6174a7SRobert Watson 	return (0);
3046f6174a7SRobert Watson }
3056f6174a7SRobert Watson 
3066f6174a7SRobert Watson COUNTER_DECL(cred_check_setgid);
3076f6174a7SRobert Watson static int
test_cred_check_setgid(struct ucred * cred,gid_t gid)3086f6174a7SRobert Watson test_cred_check_setgid(struct ucred *cred, gid_t gid)
3096f6174a7SRobert Watson {
3106f6174a7SRobert Watson 
3116f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3126f6174a7SRobert Watson 	COUNTER_INC(cred_check_setgid);
3136f6174a7SRobert Watson 
3146f6174a7SRobert Watson 	return (0);
3156f6174a7SRobert Watson }
3166f6174a7SRobert Watson 
3176f6174a7SRobert Watson COUNTER_DECL(cred_check_setgroups);
3186f6174a7SRobert Watson static int
test_cred_check_setgroups(struct ucred * cred,int ngroups,gid_t * gidset)3196f6174a7SRobert Watson test_cred_check_setgroups(struct ucred *cred, int ngroups,
3206f6174a7SRobert Watson 	gid_t *gidset)
3216f6174a7SRobert Watson {
3226f6174a7SRobert Watson 
3236f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3246f6174a7SRobert Watson 	COUNTER_INC(cred_check_setgroups);
3256f6174a7SRobert Watson 
3266f6174a7SRobert Watson 	return (0);
3276f6174a7SRobert Watson }
3286f6174a7SRobert Watson 
3296f6174a7SRobert Watson COUNTER_DECL(cred_check_setresgid);
3306f6174a7SRobert Watson static int
test_cred_check_setresgid(struct ucred * cred,gid_t rgid,gid_t egid,gid_t sgid)3316f6174a7SRobert Watson test_cred_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid,
3326f6174a7SRobert Watson 	gid_t sgid)
3336f6174a7SRobert Watson {
3346f6174a7SRobert Watson 
3356f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3366f6174a7SRobert Watson 	COUNTER_INC(cred_check_setresgid);
3376f6174a7SRobert Watson 
3386f6174a7SRobert Watson 	return (0);
3396f6174a7SRobert Watson }
3406f6174a7SRobert Watson 
3416f6174a7SRobert Watson COUNTER_DECL(cred_check_setresuid);
3426f6174a7SRobert Watson static int
test_cred_check_setresuid(struct ucred * cred,uid_t ruid,uid_t euid,uid_t suid)3436f6174a7SRobert Watson test_cred_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid,
3446f6174a7SRobert Watson 	uid_t suid)
3456f6174a7SRobert Watson {
3466f6174a7SRobert Watson 
3476f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3486f6174a7SRobert Watson 	COUNTER_INC(cred_check_setresuid);
3496f6174a7SRobert Watson 
3506f6174a7SRobert Watson 	return (0);
3516f6174a7SRobert Watson }
3526f6174a7SRobert Watson 
3536f6174a7SRobert Watson COUNTER_DECL(cred_check_setuid);
3546f6174a7SRobert Watson static int
test_cred_check_setuid(struct ucred * cred,uid_t uid)3556f6174a7SRobert Watson test_cred_check_setuid(struct ucred *cred, uid_t uid)
3566f6174a7SRobert Watson {
3576f6174a7SRobert Watson 
3586f6174a7SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3596f6174a7SRobert Watson 	COUNTER_INC(cred_check_setuid);
3606f6174a7SRobert Watson 
3616f6174a7SRobert Watson 	return (0);
3626f6174a7SRobert Watson }
3636f6174a7SRobert Watson 
364eb320b0eSRobert Watson COUNTER_DECL(cred_check_visible);
365eb320b0eSRobert Watson static int
test_cred_check_visible(struct ucred * u1,struct ucred * u2)366eb320b0eSRobert Watson test_cred_check_visible(struct ucred *u1, struct ucred *u2)
367d8a7b7a3SRobert Watson {
368d8a7b7a3SRobert Watson 
369eb320b0eSRobert Watson 	LABEL_CHECK(u1->cr_label, MAGIC_CRED);
370eb320b0eSRobert Watson 	LABEL_CHECK(u2->cr_label, MAGIC_CRED);
371eb320b0eSRobert Watson 	COUNTER_INC(cred_check_visible);
372d8a7b7a3SRobert Watson 
373eb320b0eSRobert Watson 	return (0);
374d8a7b7a3SRobert Watson }
375d8a7b7a3SRobert Watson 
37630d239bcSRobert Watson COUNTER_DECL(cred_copy_label);
3770196273bSRobert Watson static void
test_cred_copy_label(struct label * src,struct label * dest)3783f1a7a90SRobert Watson test_cred_copy_label(struct label *src, struct label *dest)
37956d9e932SRobert Watson {
38056d9e932SRobert Watson 
3816827d029SRobert Watson 	LABEL_CHECK(src, MAGIC_CRED);
3826827d029SRobert Watson 	LABEL_CHECK(dest, MAGIC_CRED);
38330d239bcSRobert Watson 	COUNTER_INC(cred_copy_label);
38456d9e932SRobert Watson }
38556d9e932SRobert Watson 
386212ab0cfSRobert Watson COUNTER_DECL(cred_create_init);
387212ab0cfSRobert Watson static void
test_cred_create_init(struct ucred * cred)388212ab0cfSRobert Watson test_cred_create_init(struct ucred *cred)
389212ab0cfSRobert Watson {
390212ab0cfSRobert Watson 
391212ab0cfSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
392212ab0cfSRobert Watson 	COUNTER_INC(cred_create_init);
393212ab0cfSRobert Watson }
394212ab0cfSRobert Watson 
395212ab0cfSRobert Watson COUNTER_DECL(cred_create_swapper);
396212ab0cfSRobert Watson static void
test_cred_create_swapper(struct ucred * cred)397212ab0cfSRobert Watson test_cred_create_swapper(struct ucred *cred)
398212ab0cfSRobert Watson {
399212ab0cfSRobert Watson 
400212ab0cfSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
401212ab0cfSRobert Watson 	COUNTER_INC(cred_create_swapper);
402212ab0cfSRobert Watson }
403212ab0cfSRobert Watson 
404eb320b0eSRobert Watson COUNTER_DECL(cred_destroy_label);
40556d9e932SRobert Watson static void
test_cred_destroy_label(struct label * label)406eb320b0eSRobert Watson test_cred_destroy_label(struct label *label)
4072220907bSRobert Watson {
4082220907bSRobert Watson 
409eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_CRED);
410eb320b0eSRobert Watson 	COUNTER_INC(cred_destroy_label);
4110196273bSRobert Watson }
4120196273bSRobert Watson 
413b0f4c777SRobert Watson COUNTER_DECL(cred_externalize_label);
414d8a7b7a3SRobert Watson static int
test_cred_externalize_label(struct label * label,char * element_name,struct sbuf * sb,int * claimed)415b0f4c777SRobert Watson test_cred_externalize_label(struct label *label, char *element_name,
416f51e5803SRobert Watson     struct sbuf *sb, int *claimed)
417d8a7b7a3SRobert Watson {
418d8a7b7a3SRobert Watson 
419b0f4c777SRobert Watson 	LABEL_CHECK(label, MAGIC_CRED);
420b0f4c777SRobert Watson 	COUNTER_INC(cred_externalize_label);
421b0f4c777SRobert Watson 
422b0f4c777SRobert Watson 	return (0);
423b0f4c777SRobert Watson }
424b0f4c777SRobert Watson 
425eb320b0eSRobert Watson COUNTER_DECL(cred_init_label);
426d8a7b7a3SRobert Watson static void
test_cred_init_label(struct label * label)427eb320b0eSRobert Watson test_cred_init_label(struct label *label)
428763bbd2fSRobert Watson {
429763bbd2fSRobert Watson 
430eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_CRED);
431eb320b0eSRobert Watson 	COUNTER_INC(cred_init_label);
432763bbd2fSRobert Watson }
433763bbd2fSRobert Watson 
4341876fb21SRobert Watson COUNTER_DECL(cred_internalize_label);
4351876fb21SRobert Watson static int
test_cred_internalize_label(struct label * label,char * element_name,char * element_data,int * claimed)4361876fb21SRobert Watson test_cred_internalize_label(struct label *label, char *element_name,
4371876fb21SRobert Watson     char *element_data, int *claimed)
4381876fb21SRobert Watson {
4391876fb21SRobert Watson 
4401876fb21SRobert Watson 	LABEL_CHECK(label, MAGIC_CRED);
4411876fb21SRobert Watson 	COUNTER_INC(cred_internalize_label);
4421876fb21SRobert Watson 
4431876fb21SRobert Watson 	return (0);
4441876fb21SRobert Watson }
4451876fb21SRobert Watson 
446eb320b0eSRobert Watson COUNTER_DECL(cred_relabel);
447763bbd2fSRobert Watson static void
test_cred_relabel(struct ucred * cred,struct label * newlabel)448eb320b0eSRobert Watson test_cred_relabel(struct ucred *cred, struct label *newlabel)
449763bbd2fSRobert Watson {
450763bbd2fSRobert Watson 
451eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
452eb320b0eSRobert Watson 	LABEL_CHECK(newlabel, MAGIC_CRED);
453eb320b0eSRobert Watson 	COUNTER_INC(cred_relabel);
454763bbd2fSRobert Watson }
455763bbd2fSRobert Watson 
456*2449b9e5SMitchell Horne COUNTER_DECL(ddb_command_exec);
457*2449b9e5SMitchell Horne static int
test_ddb_command_exec(struct db_command * cmd,db_expr_t addr,bool have_addr,db_expr_t count,char * modif)458*2449b9e5SMitchell Horne test_ddb_command_exec(struct db_command *cmd, db_expr_t addr, bool have_addr,
459*2449b9e5SMitchell Horne     db_expr_t count, char *modif)
460*2449b9e5SMitchell Horne {
461*2449b9e5SMitchell Horne 
462*2449b9e5SMitchell Horne 	COUNTER_INC(ddb_command_exec);
463*2449b9e5SMitchell Horne 
464*2449b9e5SMitchell Horne 	return (0);
465*2449b9e5SMitchell Horne }
466*2449b9e5SMitchell Horne 
467*2449b9e5SMitchell Horne COUNTER_DECL(ddb_command_register);
468*2449b9e5SMitchell Horne static int
test_ddb_command_register(struct db_command_table * table,struct db_command * cmd)469*2449b9e5SMitchell Horne test_ddb_command_register(struct db_command_table *table,
470*2449b9e5SMitchell Horne     struct db_command *cmd)
471*2449b9e5SMitchell Horne {
472*2449b9e5SMitchell Horne 
473*2449b9e5SMitchell Horne 	COUNTER_INC(ddb_command_register);
474*2449b9e5SMitchell Horne 
475*2449b9e5SMitchell Horne 	return (0);
476*2449b9e5SMitchell Horne }
477*2449b9e5SMitchell Horne 
47830d239bcSRobert Watson COUNTER_DECL(devfs_create_device);
479763bbd2fSRobert Watson static void
test_devfs_create_device(struct ucred * cred,struct mount * mp,struct cdev * dev,struct devfs_dirent * de,struct label * delabel)4803f1a7a90SRobert Watson test_devfs_create_device(struct ucred *cred, struct mount *mp,
48178007886SRobert Watson     struct cdev *dev, struct devfs_dirent *de, struct label *delabel)
482d8a7b7a3SRobert Watson {
483d8a7b7a3SRobert Watson 
4846827d029SRobert Watson 	if (cred != NULL)
4856827d029SRobert Watson 		LABEL_CHECK(cred->cr_label, MAGIC_CRED);
48678007886SRobert Watson 	LABEL_CHECK(delabel, MAGIC_DEVFS);
48730d239bcSRobert Watson 	COUNTER_INC(devfs_create_device);
488d8a7b7a3SRobert Watson }
489d8a7b7a3SRobert Watson 
49030d239bcSRobert Watson COUNTER_DECL(devfs_create_directory);
491d8a7b7a3SRobert Watson static void
test_devfs_create_directory(struct mount * mp,char * dirname,int dirnamelen,struct devfs_dirent * de,struct label * delabel)4923f1a7a90SRobert Watson test_devfs_create_directory(struct mount *mp, char *dirname,
49378007886SRobert Watson     int dirnamelen, struct devfs_dirent *de, struct label *delabel)
494990b4b2dSRobert Watson {
495990b4b2dSRobert Watson 
49678007886SRobert Watson 	LABEL_CHECK(delabel, MAGIC_DEVFS);
49730d239bcSRobert Watson 	COUNTER_INC(devfs_create_directory);
498990b4b2dSRobert Watson }
499990b4b2dSRobert Watson 
50030d239bcSRobert Watson COUNTER_DECL(devfs_create_symlink);
501990b4b2dSRobert Watson static void
test_devfs_create_symlink(struct ucred * cred,struct mount * mp,struct devfs_dirent * dd,struct label * ddlabel,struct devfs_dirent * de,struct label * delabel)5023f1a7a90SRobert Watson test_devfs_create_symlink(struct ucred *cred, struct mount *mp,
503990b4b2dSRobert Watson     struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de,
504990b4b2dSRobert Watson     struct label *delabel)
505eea8ea31SRobert Watson {
506eea8ea31SRobert Watson 
5076827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
5086827d029SRobert Watson 	LABEL_CHECK(ddlabel, MAGIC_DEVFS);
5096827d029SRobert Watson 	LABEL_CHECK(delabel, MAGIC_DEVFS);
51030d239bcSRobert Watson 	COUNTER_INC(devfs_create_symlink);
511eea8ea31SRobert Watson }
512eea8ea31SRobert Watson 
513eb320b0eSRobert Watson COUNTER_DECL(devfs_destroy_label);
514d8a7b7a3SRobert Watson static void
test_devfs_destroy_label(struct label * label)515eb320b0eSRobert Watson test_devfs_destroy_label(struct label *label)
516d8a7b7a3SRobert Watson {
517d8a7b7a3SRobert Watson 
518eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_DEVFS);
519eb320b0eSRobert Watson 	COUNTER_INC(devfs_destroy_label);
520d8a7b7a3SRobert Watson }
521d8a7b7a3SRobert Watson 
522eb320b0eSRobert Watson COUNTER_DECL(devfs_init_label);
523d8a7b7a3SRobert Watson static void
test_devfs_init_label(struct label * label)524eb320b0eSRobert Watson test_devfs_init_label(struct label *label)
525d8a7b7a3SRobert Watson {
526d8a7b7a3SRobert Watson 
527eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_DEVFS);
528eb320b0eSRobert Watson 	COUNTER_INC(devfs_init_label);
529d8a7b7a3SRobert Watson }
530d8a7b7a3SRobert Watson 
53130d239bcSRobert Watson COUNTER_DECL(devfs_update);
532d8a7b7a3SRobert Watson static void
test_devfs_update(struct mount * mp,struct devfs_dirent * devfs_dirent,struct label * direntlabel,struct vnode * vp,struct label * vplabel)5333f1a7a90SRobert Watson test_devfs_update(struct mount *mp, struct devfs_dirent *devfs_dirent,
53430575990SRobert Watson     struct label *direntlabel, struct vnode *vp, struct label *vplabel)
535d8a7b7a3SRobert Watson {
536d8a7b7a3SRobert Watson 
5376827d029SRobert Watson 	LABEL_CHECK(direntlabel, MAGIC_DEVFS);
53878007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
53930d239bcSRobert Watson 	COUNTER_INC(devfs_update);
540d8a7b7a3SRobert Watson }
541d8a7b7a3SRobert Watson 
542eb320b0eSRobert Watson COUNTER_DECL(devfs_vnode_associate);
543d8a7b7a3SRobert Watson static void
test_devfs_vnode_associate(struct mount * mp,struct label * mplabel,struct devfs_dirent * de,struct label * delabel,struct vnode * vp,struct label * vplabel)544eb320b0eSRobert Watson test_devfs_vnode_associate(struct mount *mp, struct label *mplabel,
545eb320b0eSRobert Watson     struct devfs_dirent *de, struct label *delabel, struct vnode *vp,
546eb320b0eSRobert Watson     struct label *vplabel)
547d8a7b7a3SRobert Watson {
548d8a7b7a3SRobert Watson 
549eb320b0eSRobert Watson 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
550eb320b0eSRobert Watson 	LABEL_CHECK(delabel, MAGIC_DEVFS);
551eb320b0eSRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
552eb320b0eSRobert Watson 	COUNTER_INC(devfs_vnode_associate);
553d8a7b7a3SRobert Watson }
554d8a7b7a3SRobert Watson 
55530d239bcSRobert Watson COUNTER_DECL(ifnet_check_relabel);
556d8a7b7a3SRobert Watson static int
test_ifnet_check_relabel(struct ucred * cred,struct ifnet * ifp,struct label * ifplabel,struct label * newlabel)5573f1a7a90SRobert Watson test_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifp,
558a7f3aac7SRobert Watson     struct label *ifplabel, struct label *newlabel)
559d8a7b7a3SRobert Watson {
560d8a7b7a3SRobert Watson 
5616827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
562a7f3aac7SRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
5636827d029SRobert Watson 	LABEL_CHECK(newlabel, MAGIC_IFNET);
56430d239bcSRobert Watson 	COUNTER_INC(ifnet_check_relabel);
565269ad130SRobert Watson 
566d8a7b7a3SRobert Watson 	return (0);
567d8a7b7a3SRobert Watson }
568d8a7b7a3SRobert Watson 
56930d239bcSRobert Watson COUNTER_DECL(ifnet_check_transmit);
570d8a7b7a3SRobert Watson static int
test_ifnet_check_transmit(struct ifnet * ifp,struct label * ifplabel,struct mbuf * m,struct label * mlabel)5713f1a7a90SRobert Watson test_ifnet_check_transmit(struct ifnet *ifp, struct label *ifplabel,
572f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
573d8a7b7a3SRobert Watson {
574d8a7b7a3SRobert Watson 
575a7f3aac7SRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
576f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
57730d239bcSRobert Watson 	COUNTER_INC(ifnet_check_transmit);
578250ee706SRobert Watson 
579d8a7b7a3SRobert Watson 	return (0);
580d8a7b7a3SRobert Watson }
581d8a7b7a3SRobert Watson 
582eb320b0eSRobert Watson COUNTER_DECL(ifnet_copy_label);
583eb320b0eSRobert Watson static void
test_ifnet_copy_label(struct label * src,struct label * dest)584eb320b0eSRobert Watson test_ifnet_copy_label(struct label *src, struct label *dest)
585eb320b0eSRobert Watson {
586eb320b0eSRobert Watson 
587eb320b0eSRobert Watson 	LABEL_CHECK(src, MAGIC_IFNET);
588eb320b0eSRobert Watson 	LABEL_CHECK(dest, MAGIC_IFNET);
589eb320b0eSRobert Watson 	COUNTER_INC(ifnet_copy_label);
590eb320b0eSRobert Watson }
591eb320b0eSRobert Watson 
592eb320b0eSRobert Watson COUNTER_DECL(ifnet_create);
593eb320b0eSRobert Watson static void
test_ifnet_create(struct ifnet * ifp,struct label * ifplabel)594eb320b0eSRobert Watson test_ifnet_create(struct ifnet *ifp, struct label *ifplabel)
595eb320b0eSRobert Watson {
596eb320b0eSRobert Watson 
597eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
598eb320b0eSRobert Watson 	COUNTER_INC(ifnet_create);
599eb320b0eSRobert Watson }
600eb320b0eSRobert Watson 
601eb320b0eSRobert Watson COUNTER_DECL(ifnet_create_mbuf);
602eb320b0eSRobert Watson static void
test_ifnet_create_mbuf(struct ifnet * ifp,struct label * ifplabel,struct mbuf * m,struct label * mlabel)603eb320b0eSRobert Watson test_ifnet_create_mbuf(struct ifnet *ifp, struct label *ifplabel,
604f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
605eb320b0eSRobert Watson {
606eb320b0eSRobert Watson 
607eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
608f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
609eb320b0eSRobert Watson 	COUNTER_INC(ifnet_create_mbuf);
610eb320b0eSRobert Watson }
611eb320b0eSRobert Watson 
612eb320b0eSRobert Watson COUNTER_DECL(ifnet_destroy_label);
613eb320b0eSRobert Watson static void
test_ifnet_destroy_label(struct label * label)614eb320b0eSRobert Watson test_ifnet_destroy_label(struct label *label)
615eb320b0eSRobert Watson {
616eb320b0eSRobert Watson 
617eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_IFNET);
618eb320b0eSRobert Watson 	COUNTER_INC(ifnet_destroy_label);
619eb320b0eSRobert Watson }
620eb320b0eSRobert Watson 
621eb320b0eSRobert Watson COUNTER_DECL(ifnet_externalize_label);
622eb320b0eSRobert Watson static int
test_ifnet_externalize_label(struct label * label,char * element_name,struct sbuf * sb,int * claimed)623eb320b0eSRobert Watson test_ifnet_externalize_label(struct label *label, char *element_name,
624eb320b0eSRobert Watson     struct sbuf *sb, int *claimed)
625eb320b0eSRobert Watson {
626eb320b0eSRobert Watson 
627eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_IFNET);
628eb320b0eSRobert Watson 	COUNTER_INC(ifnet_externalize_label);
629eb320b0eSRobert Watson 
630eb320b0eSRobert Watson 	return (0);
631eb320b0eSRobert Watson }
632eb320b0eSRobert Watson 
633eb320b0eSRobert Watson COUNTER_DECL(ifnet_init_label);
634eb320b0eSRobert Watson static void
test_ifnet_init_label(struct label * label)635eb320b0eSRobert Watson test_ifnet_init_label(struct label *label)
636eb320b0eSRobert Watson {
637eb320b0eSRobert Watson 
638eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_IFNET);
639eb320b0eSRobert Watson 	COUNTER_INC(ifnet_init_label);
640eb320b0eSRobert Watson }
641eb320b0eSRobert Watson 
6421876fb21SRobert Watson COUNTER_DECL(ifnet_internalize_label);
6431876fb21SRobert Watson static int
test_ifnet_internalize_label(struct label * label,char * element_name,char * element_data,int * claimed)6441876fb21SRobert Watson test_ifnet_internalize_label(struct label *label, char *element_name,
6451876fb21SRobert Watson     char *element_data, int *claimed)
6461876fb21SRobert Watson {
6471876fb21SRobert Watson 
6481876fb21SRobert Watson 	LABEL_CHECK(label, MAGIC_IFNET);
6491876fb21SRobert Watson 	COUNTER_INC(ifnet_internalize_label);
6501876fb21SRobert Watson 
6511876fb21SRobert Watson 	return (0);
6521876fb21SRobert Watson }
6531876fb21SRobert Watson 
654eb320b0eSRobert Watson COUNTER_DECL(ifnet_relabel);
655eb320b0eSRobert Watson static void
test_ifnet_relabel(struct ucred * cred,struct ifnet * ifp,struct label * ifplabel,struct label * newlabel)656eb320b0eSRobert Watson test_ifnet_relabel(struct ucred *cred, struct ifnet *ifp,
657eb320b0eSRobert Watson     struct label *ifplabel, struct label *newlabel)
658eb320b0eSRobert Watson {
659eb320b0eSRobert Watson 
660eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
661eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
662eb320b0eSRobert Watson 	LABEL_CHECK(newlabel, MAGIC_IFNET);
663eb320b0eSRobert Watson 	COUNTER_INC(ifnet_relabel);
664eb320b0eSRobert Watson }
665eb320b0eSRobert Watson 
66630d239bcSRobert Watson COUNTER_DECL(inpcb_check_deliver);
667d8a7b7a3SRobert Watson static int
test_inpcb_check_deliver(struct inpcb * inp,struct label * inplabel,struct mbuf * m,struct label * mlabel)6683f1a7a90SRobert Watson test_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel,
669a557af22SRobert Watson     struct mbuf *m, struct label *mlabel)
670a557af22SRobert Watson {
671a557af22SRobert Watson 
6726827d029SRobert Watson 	LABEL_CHECK(inplabel, MAGIC_INPCB);
6736827d029SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
67430d239bcSRobert Watson 	COUNTER_INC(inpcb_check_deliver);
675a557af22SRobert Watson 
676a557af22SRobert Watson 	return (0);
677a557af22SRobert Watson }
678a557af22SRobert Watson 
6797fb179baSBjoern A. Zeeb COUNTER_DECL(inpcb_check_visible);
6807fb179baSBjoern A. Zeeb static int
test_inpcb_check_visible(struct ucred * cred,struct inpcb * inp,struct label * inplabel)6817fb179baSBjoern A. Zeeb test_inpcb_check_visible(struct ucred *cred, struct inpcb *inp,
6827fb179baSBjoern A. Zeeb     struct label *inplabel)
6837fb179baSBjoern A. Zeeb {
6847fb179baSBjoern A. Zeeb 
6857fb179baSBjoern A. Zeeb 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
6867fb179baSBjoern A. Zeeb 	LABEL_CHECK(inplabel, MAGIC_INPCB);
6877fb179baSBjoern A. Zeeb 	COUNTER_INC(inpcb_check_visible);
6887fb179baSBjoern A. Zeeb 
6897fb179baSBjoern A. Zeeb 	return (0);
6907fb179baSBjoern A. Zeeb }
6917fb179baSBjoern A. Zeeb 
692eb320b0eSRobert Watson COUNTER_DECL(inpcb_create);
693eb320b0eSRobert Watson static void
test_inpcb_create(struct socket * so,struct label * solabel,struct inpcb * inp,struct label * inplabel)694eb320b0eSRobert Watson test_inpcb_create(struct socket *so, struct label *solabel,
695eb320b0eSRobert Watson     struct inpcb *inp, struct label *inplabel)
6967e400ed1SRobert Watson {
6977e400ed1SRobert Watson 
6983de40469SRobert Watson 	SOCK_LOCK(so);
699eb320b0eSRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
7003de40469SRobert Watson 	SOCK_UNLOCK(so);
701eb320b0eSRobert Watson 	LABEL_CHECK(inplabel, MAGIC_INPCB);
702eb320b0eSRobert Watson 	COUNTER_INC(inpcb_create);
703eb320b0eSRobert Watson }
7047e400ed1SRobert Watson 
705eb320b0eSRobert Watson COUNTER_DECL(inpcb_create_mbuf);
706eb320b0eSRobert Watson static void
test_inpcb_create_mbuf(struct inpcb * inp,struct label * inplabel,struct mbuf * m,struct label * mlabel)707eb320b0eSRobert Watson test_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel,
708eb320b0eSRobert Watson     struct mbuf *m, struct label *mlabel)
709eb320b0eSRobert Watson {
710eb320b0eSRobert Watson 
711eb320b0eSRobert Watson 	LABEL_CHECK(inplabel, MAGIC_INPCB);
712eb320b0eSRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
713eb320b0eSRobert Watson 	COUNTER_INC(inpcb_create_mbuf);
714eb320b0eSRobert Watson }
715eb320b0eSRobert Watson 
716eb320b0eSRobert Watson COUNTER_DECL(inpcb_destroy_label);
717eb320b0eSRobert Watson static void
test_inpcb_destroy_label(struct label * label)718eb320b0eSRobert Watson test_inpcb_destroy_label(struct label *label)
719eb320b0eSRobert Watson {
720eb320b0eSRobert Watson 
721eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_INPCB);
722eb320b0eSRobert Watson 	COUNTER_INC(inpcb_destroy_label);
723eb320b0eSRobert Watson }
724eb320b0eSRobert Watson 
725eb320b0eSRobert Watson COUNTER_DECL(inpcb_init_label);
726eb320b0eSRobert Watson static int
test_inpcb_init_label(struct label * label,int flag)727eb320b0eSRobert Watson test_inpcb_init_label(struct label *label, int flag)
728eb320b0eSRobert Watson {
729eb320b0eSRobert Watson 
730eb320b0eSRobert Watson 	if (flag & M_WAITOK)
731eb320b0eSRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
732eb320b0eSRobert Watson 		    "test_inpcb_init_label() at %s:%d", __FILE__,
733eb320b0eSRobert Watson 		    __LINE__);
734eb320b0eSRobert Watson 
735eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_INPCB);
736eb320b0eSRobert Watson 	COUNTER_INC(inpcb_init_label);
7377e400ed1SRobert Watson 	return (0);
7387e400ed1SRobert Watson }
7397e400ed1SRobert Watson 
740eb320b0eSRobert Watson COUNTER_DECL(inpcb_sosetlabel);
741eb320b0eSRobert Watson static void
test_inpcb_sosetlabel(struct socket * so,struct label * solabel,struct inpcb * inp,struct label * inplabel)742eb320b0eSRobert Watson test_inpcb_sosetlabel(struct socket *so, struct label *solabel,
743eb320b0eSRobert Watson     struct inpcb *inp, struct label *inplabel)
7447e400ed1SRobert Watson {
7457e400ed1SRobert Watson 
7463de40469SRobert Watson 	SOCK_LOCK_ASSERT(so);
7473de40469SRobert Watson 
748eb320b0eSRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
749eb320b0eSRobert Watson 	LABEL_CHECK(inplabel, MAGIC_INPCB);
750eb320b0eSRobert Watson 	COUNTER_INC(inpcb_sosetlabel);
751eb320b0eSRobert Watson }
7527e400ed1SRobert Watson 
753048e1287SRobert Watson COUNTER_DECL(ip6q_create);
754048e1287SRobert Watson static void
test_ip6q_create(struct mbuf * fragment,struct label * fragmentlabel,struct ip6q * q6,struct label * q6label)755048e1287SRobert Watson test_ip6q_create(struct mbuf *fragment, struct label *fragmentlabel,
756048e1287SRobert Watson     struct ip6q *q6, struct label *q6label)
757048e1287SRobert Watson {
758048e1287SRobert Watson 
759048e1287SRobert Watson 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
760048e1287SRobert Watson 	LABEL_CHECK(q6label, MAGIC_IP6Q);
761048e1287SRobert Watson 	COUNTER_INC(ip6q_create);
762048e1287SRobert Watson }
763048e1287SRobert Watson 
764048e1287SRobert Watson COUNTER_DECL(ip6q_destroy_label);
765048e1287SRobert Watson static void
test_ip6q_destroy_label(struct label * label)766048e1287SRobert Watson test_ip6q_destroy_label(struct label *label)
767048e1287SRobert Watson {
768048e1287SRobert Watson 
769048e1287SRobert Watson 	LABEL_DESTROY(label, MAGIC_IP6Q);
770048e1287SRobert Watson 	COUNTER_INC(ip6q_destroy_label);
771048e1287SRobert Watson }
772048e1287SRobert Watson 
773048e1287SRobert Watson COUNTER_DECL(ip6q_init_label);
774048e1287SRobert Watson static int
test_ip6q_init_label(struct label * label,int flag)775048e1287SRobert Watson test_ip6q_init_label(struct label *label, int flag)
776048e1287SRobert Watson {
777048e1287SRobert Watson 
778048e1287SRobert Watson 	if (flag & M_WAITOK)
779048e1287SRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
780048e1287SRobert Watson 		    "test_ip6q_init_label() at %s:%d", __FILE__,
781048e1287SRobert Watson 		    __LINE__);
782048e1287SRobert Watson 
783048e1287SRobert Watson 	LABEL_INIT(label, MAGIC_IP6Q);
784048e1287SRobert Watson 	COUNTER_INC(ip6q_init_label);
785048e1287SRobert Watson 	return (0);
786048e1287SRobert Watson }
787048e1287SRobert Watson 
788048e1287SRobert Watson COUNTER_DECL(ip6q_match);
789048e1287SRobert Watson static int
test_ip6q_match(struct mbuf * fragment,struct label * fragmentlabel,struct ip6q * q6,struct label * q6label)790048e1287SRobert Watson test_ip6q_match(struct mbuf *fragment, struct label *fragmentlabel,
791048e1287SRobert Watson     struct ip6q *q6, struct label *q6label)
792048e1287SRobert Watson {
793048e1287SRobert Watson 
794048e1287SRobert Watson 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
795048e1287SRobert Watson 	LABEL_CHECK(q6label, MAGIC_IP6Q);
796048e1287SRobert Watson 	COUNTER_INC(ip6q_match);
797048e1287SRobert Watson 
798048e1287SRobert Watson 	return (1);
799048e1287SRobert Watson }
800048e1287SRobert Watson 
801048e1287SRobert Watson COUNTER_DECL(ip6q_reassemble);
802048e1287SRobert Watson static void
test_ip6q_reassemble(struct ip6q * q6,struct label * q6label,struct mbuf * m,struct label * mlabel)803048e1287SRobert Watson test_ip6q_reassemble(struct ip6q *q6, struct label *q6label, struct mbuf *m,
804048e1287SRobert Watson    struct label *mlabel)
805048e1287SRobert Watson {
806048e1287SRobert Watson 
807048e1287SRobert Watson 	LABEL_CHECK(q6label, MAGIC_IP6Q);
808048e1287SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
809048e1287SRobert Watson 	COUNTER_INC(ip6q_reassemble);
810048e1287SRobert Watson }
811048e1287SRobert Watson 
812048e1287SRobert Watson COUNTER_DECL(ip6q_update);
813048e1287SRobert Watson static void
test_ip6q_update(struct mbuf * m,struct label * mlabel,struct ip6q * q6,struct label * q6label)814048e1287SRobert Watson test_ip6q_update(struct mbuf *m, struct label *mlabel, struct ip6q *q6,
815048e1287SRobert Watson     struct label *q6label)
816048e1287SRobert Watson {
817048e1287SRobert Watson 
818048e1287SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
819048e1287SRobert Watson 	LABEL_CHECK(q6label, MAGIC_IP6Q);
820048e1287SRobert Watson 	COUNTER_INC(ip6q_update);
821048e1287SRobert Watson }
822048e1287SRobert Watson 
823eb320b0eSRobert Watson COUNTER_DECL(ipq_create);
824eb320b0eSRobert Watson static void
test_ipq_create(struct mbuf * fragment,struct label * fragmentlabel,struct ipq * q,struct label * qlabel)825eb320b0eSRobert Watson test_ipq_create(struct mbuf *fragment, struct label *fragmentlabel,
82637f44cb4SRobert Watson     struct ipq *q, struct label *qlabel)
827eb320b0eSRobert Watson {
828eb320b0eSRobert Watson 
829eb320b0eSRobert Watson 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
83037f44cb4SRobert Watson 	LABEL_CHECK(qlabel, MAGIC_IPQ);
831eb320b0eSRobert Watson 	COUNTER_INC(ipq_create);
832eb320b0eSRobert Watson }
833eb320b0eSRobert Watson 
834eb320b0eSRobert Watson COUNTER_DECL(ipq_destroy_label);
835eb320b0eSRobert Watson static void
test_ipq_destroy_label(struct label * label)836eb320b0eSRobert Watson test_ipq_destroy_label(struct label *label)
837eb320b0eSRobert Watson {
838eb320b0eSRobert Watson 
839eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_IPQ);
840eb320b0eSRobert Watson 	COUNTER_INC(ipq_destroy_label);
841eb320b0eSRobert Watson }
842eb320b0eSRobert Watson 
843eb320b0eSRobert Watson COUNTER_DECL(ipq_init_label);
844eb320b0eSRobert Watson static int
test_ipq_init_label(struct label * label,int flag)845eb320b0eSRobert Watson test_ipq_init_label(struct label *label, int flag)
846eb320b0eSRobert Watson {
847eb320b0eSRobert Watson 
848eb320b0eSRobert Watson 	if (flag & M_WAITOK)
849eb320b0eSRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
850eb320b0eSRobert Watson 		    "test_ipq_init_label() at %s:%d", __FILE__,
851eb320b0eSRobert Watson 		    __LINE__);
852eb320b0eSRobert Watson 
853eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_IPQ);
854eb320b0eSRobert Watson 	COUNTER_INC(ipq_init_label);
8557e400ed1SRobert Watson 	return (0);
8567e400ed1SRobert Watson }
8577e400ed1SRobert Watson 
858eb320b0eSRobert Watson COUNTER_DECL(ipq_match);
8597e400ed1SRobert Watson static int
test_ipq_match(struct mbuf * fragment,struct label * fragmentlabel,struct ipq * q,struct label * qlabel)860eb320b0eSRobert Watson test_ipq_match(struct mbuf *fragment, struct label *fragmentlabel,
86137f44cb4SRobert Watson     struct ipq *q, struct label *qlabel)
8627e400ed1SRobert Watson {
8637e400ed1SRobert Watson 
864eb320b0eSRobert Watson 	LABEL_CHECK(fragmentlabel, MAGIC_MBUF);
86537f44cb4SRobert Watson 	LABEL_CHECK(qlabel, MAGIC_IPQ);
866eb320b0eSRobert Watson 	COUNTER_INC(ipq_match);
8677e400ed1SRobert Watson 
868eb320b0eSRobert Watson 	return (1);
8697e400ed1SRobert Watson }
8707e400ed1SRobert Watson 
871eb320b0eSRobert Watson COUNTER_DECL(ipq_reassemble);
872eb320b0eSRobert Watson static void
test_ipq_reassemble(struct ipq * q,struct label * qlabel,struct mbuf * m,struct label * mlabel)87337f44cb4SRobert Watson test_ipq_reassemble(struct ipq *q, struct label *qlabel, struct mbuf *m,
874f0336833SRobert Watson    struct label *mlabel)
8757e400ed1SRobert Watson {
8767e400ed1SRobert Watson 
87737f44cb4SRobert Watson 	LABEL_CHECK(qlabel, MAGIC_IPQ);
878f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
879eb320b0eSRobert Watson 	COUNTER_INC(ipq_reassemble);
8807e400ed1SRobert Watson }
8817e400ed1SRobert Watson 
882eb320b0eSRobert Watson COUNTER_DECL(ipq_update);
883eb320b0eSRobert Watson static void
test_ipq_update(struct mbuf * m,struct label * mlabel,struct ipq * q,struct label * qlabel)88437f44cb4SRobert Watson test_ipq_update(struct mbuf *m, struct label *mlabel, struct ipq *q,
88537f44cb4SRobert Watson     struct label *qlabel)
8867e400ed1SRobert Watson {
8877e400ed1SRobert Watson 
888f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
88937f44cb4SRobert Watson 	LABEL_CHECK(qlabel, MAGIC_IPQ);
890eb320b0eSRobert Watson 	COUNTER_INC(ipq_update);
8917e400ed1SRobert Watson }
8927e400ed1SRobert Watson 
893*2449b9e5SMitchell Horne COUNTER_DECL(kdb_backend_check);
894*2449b9e5SMitchell Horne static int
test_kdb_check_backend(struct kdb_dbbe * be)895*2449b9e5SMitchell Horne test_kdb_check_backend(struct kdb_dbbe *be)
896*2449b9e5SMitchell Horne {
897*2449b9e5SMitchell Horne 
898*2449b9e5SMitchell Horne 	COUNTER_INC(kdb_backend_check);
899*2449b9e5SMitchell Horne 
900*2449b9e5SMitchell Horne 	return (0);
901*2449b9e5SMitchell Horne }
902*2449b9e5SMitchell Horne 
90330d239bcSRobert Watson COUNTER_DECL(kenv_check_dump);
9047e400ed1SRobert Watson static int
test_kenv_check_dump(struct ucred * cred)9053f1a7a90SRobert Watson test_kenv_check_dump(struct ucred *cred)
906ca26e8baSRobert Watson {
907ca26e8baSRobert Watson 
9086827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
90930d239bcSRobert Watson 	COUNTER_INC(kenv_check_dump);
910250ee706SRobert Watson 
911ca26e8baSRobert Watson 	return (0);
912ca26e8baSRobert Watson }
913ca26e8baSRobert Watson 
91430d239bcSRobert Watson COUNTER_DECL(kenv_check_get);
915ca26e8baSRobert Watson static int
test_kenv_check_get(struct ucred * cred,char * name)9163f1a7a90SRobert Watson test_kenv_check_get(struct ucred *cred, char *name)
917ca26e8baSRobert Watson {
918ca26e8baSRobert Watson 
9196827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
92030d239bcSRobert Watson 	COUNTER_INC(kenv_check_get);
921250ee706SRobert Watson 
922ca26e8baSRobert Watson 	return (0);
923ca26e8baSRobert Watson }
924ca26e8baSRobert Watson 
92530d239bcSRobert Watson COUNTER_DECL(kenv_check_set);
926ca26e8baSRobert Watson static int
test_kenv_check_set(struct ucred * cred,char * name,char * value)9273f1a7a90SRobert Watson test_kenv_check_set(struct ucred *cred, char *name, char *value)
928ca26e8baSRobert Watson {
929ca26e8baSRobert Watson 
9306827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
93130d239bcSRobert Watson 	COUNTER_INC(kenv_check_set);
932250ee706SRobert Watson 
933ca26e8baSRobert Watson 	return (0);
934ca26e8baSRobert Watson }
935ca26e8baSRobert Watson 
93630d239bcSRobert Watson COUNTER_DECL(kenv_check_unset);
937ca26e8baSRobert Watson static int
test_kenv_check_unset(struct ucred * cred,char * name)9383f1a7a90SRobert Watson test_kenv_check_unset(struct ucred *cred, char *name)
939ca26e8baSRobert Watson {
940ca26e8baSRobert Watson 
9416827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
94230d239bcSRobert Watson 	COUNTER_INC(kenv_check_unset);
943250ee706SRobert Watson 
944ca26e8baSRobert Watson 	return (0);
945ca26e8baSRobert Watson }
946ca26e8baSRobert Watson 
94730d239bcSRobert Watson COUNTER_DECL(kld_check_load);
948ca26e8baSRobert Watson static int
test_kld_check_load(struct ucred * cred,struct vnode * vp,struct label * label)9493f1a7a90SRobert Watson test_kld_check_load(struct ucred *cred, struct vnode *vp,
950ca26e8baSRobert Watson     struct label *label)
951ca26e8baSRobert Watson {
952ca26e8baSRobert Watson 
9536827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
9546827d029SRobert Watson 	LABEL_CHECK(label, MAGIC_VNODE);
95530d239bcSRobert Watson 	COUNTER_INC(kld_check_load);
956250ee706SRobert Watson 
957ca26e8baSRobert Watson 	return (0);
958ca26e8baSRobert Watson }
959ca26e8baSRobert Watson 
96030d239bcSRobert Watson COUNTER_DECL(kld_check_stat);
961ca26e8baSRobert Watson static int
test_kld_check_stat(struct ucred * cred)9623f1a7a90SRobert Watson test_kld_check_stat(struct ucred *cred)
963ca26e8baSRobert Watson {
964ca26e8baSRobert Watson 
9656827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
96630d239bcSRobert Watson 	COUNTER_INC(kld_check_stat);
967250ee706SRobert Watson 
968ca26e8baSRobert Watson 	return (0);
969ca26e8baSRobert Watson }
970ca26e8baSRobert Watson 
971eb320b0eSRobert Watson COUNTER_DECL(mbuf_copy_label);
972eb320b0eSRobert Watson static void
test_mbuf_copy_label(struct label * src,struct label * dest)973eb320b0eSRobert Watson test_mbuf_copy_label(struct label *src, struct label *dest)
974eb320b0eSRobert Watson {
975eb320b0eSRobert Watson 
976eb320b0eSRobert Watson 	LABEL_CHECK(src, MAGIC_MBUF);
977eb320b0eSRobert Watson 	LABEL_CHECK(dest, MAGIC_MBUF);
978eb320b0eSRobert Watson 	COUNTER_INC(mbuf_copy_label);
979eb320b0eSRobert Watson }
980eb320b0eSRobert Watson 
981eb320b0eSRobert Watson COUNTER_DECL(mbuf_destroy_label);
982eb320b0eSRobert Watson static void
test_mbuf_destroy_label(struct label * label)983eb320b0eSRobert Watson test_mbuf_destroy_label(struct label *label)
984eb320b0eSRobert Watson {
985eb320b0eSRobert Watson 
986eb320b0eSRobert Watson 	/*
987eb320b0eSRobert Watson 	 * If we're loaded dynamically, there may be mbufs in flight that
988eb320b0eSRobert Watson 	 * didn't have label storage allocated for them.  Handle this
989eb320b0eSRobert Watson 	 * gracefully.
990eb320b0eSRobert Watson 	 */
991eb320b0eSRobert Watson 	if (label == NULL)
992eb320b0eSRobert Watson 		return;
993eb320b0eSRobert Watson 
994eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_MBUF);
995eb320b0eSRobert Watson 	COUNTER_INC(mbuf_destroy_label);
996eb320b0eSRobert Watson }
997eb320b0eSRobert Watson 
998eb320b0eSRobert Watson COUNTER_DECL(mbuf_init_label);
999eb320b0eSRobert Watson static int
test_mbuf_init_label(struct label * label,int flag)1000eb320b0eSRobert Watson test_mbuf_init_label(struct label *label, int flag)
1001eb320b0eSRobert Watson {
1002eb320b0eSRobert Watson 
1003eb320b0eSRobert Watson 	if (flag & M_WAITOK)
1004eb320b0eSRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1005eb320b0eSRobert Watson 		    "test_mbuf_init_label() at %s:%d", __FILE__,
1006eb320b0eSRobert Watson 		    __LINE__);
1007eb320b0eSRobert Watson 
1008eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_MBUF);
1009eb320b0eSRobert Watson 	COUNTER_INC(mbuf_init_label);
1010eb320b0eSRobert Watson 	return (0);
1011eb320b0eSRobert Watson }
1012eb320b0eSRobert Watson 
101330d239bcSRobert Watson COUNTER_DECL(mount_check_stat);
1014ca26e8baSRobert Watson static int
test_mount_check_stat(struct ucred * cred,struct mount * mp,struct label * mplabel)10153f1a7a90SRobert Watson test_mount_check_stat(struct ucred *cred, struct mount *mp,
101678007886SRobert Watson     struct label *mplabel)
1017d8a7b7a3SRobert Watson {
1018d8a7b7a3SRobert Watson 
10196827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
102078007886SRobert Watson 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
102130d239bcSRobert Watson 	COUNTER_INC(mount_check_stat);
1022250ee706SRobert Watson 
1023d8a7b7a3SRobert Watson 	return (0);
1024d8a7b7a3SRobert Watson }
1025d8a7b7a3SRobert Watson 
1026eb320b0eSRobert Watson COUNTER_DECL(mount_create);
1027eb320b0eSRobert Watson static void
test_mount_create(struct ucred * cred,struct mount * mp,struct label * mplabel)1028eb320b0eSRobert Watson test_mount_create(struct ucred *cred, struct mount *mp,
1029eb320b0eSRobert Watson     struct label *mplabel)
1030eb320b0eSRobert Watson {
1031eb320b0eSRobert Watson 
1032eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1033eb320b0eSRobert Watson 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
1034eb320b0eSRobert Watson 	COUNTER_INC(mount_create);
1035eb320b0eSRobert Watson }
1036eb320b0eSRobert Watson 
1037eb320b0eSRobert Watson COUNTER_DECL(mount_destroy_label);
1038eb320b0eSRobert Watson static void
test_mount_destroy_label(struct label * label)1039eb320b0eSRobert Watson test_mount_destroy_label(struct label *label)
1040eb320b0eSRobert Watson {
1041eb320b0eSRobert Watson 
1042eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_MOUNT);
1043eb320b0eSRobert Watson 	COUNTER_INC(mount_destroy_label);
1044eb320b0eSRobert Watson }
1045eb320b0eSRobert Watson 
1046eb320b0eSRobert Watson COUNTER_DECL(mount_init_label);
1047eb320b0eSRobert Watson static void
test_mount_init_label(struct label * label)1048eb320b0eSRobert Watson test_mount_init_label(struct label *label)
1049eb320b0eSRobert Watson {
1050eb320b0eSRobert Watson 
1051eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_MOUNT);
1052eb320b0eSRobert Watson 	COUNTER_INC(mount_init_label);
1053eb320b0eSRobert Watson }
1054eb320b0eSRobert Watson 
1055eb320b0eSRobert Watson COUNTER_DECL(netinet_arp_send);
1056eb320b0eSRobert Watson static void
test_netinet_arp_send(struct ifnet * ifp,struct label * ifplabel,struct mbuf * m,struct label * mlabel)1057eb320b0eSRobert Watson test_netinet_arp_send(struct ifnet *ifp, struct label *ifplabel,
1058f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
1059eb320b0eSRobert Watson {
1060eb320b0eSRobert Watson 
1061eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
1062f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1063eb320b0eSRobert Watson 	COUNTER_INC(netinet_arp_send);
1064eb320b0eSRobert Watson }
1065eb320b0eSRobert Watson 
1066eb320b0eSRobert Watson COUNTER_DECL(netinet_fragment);
1067eb320b0eSRobert Watson static void
test_netinet_fragment(struct mbuf * m,struct label * mlabel,struct mbuf * frag,struct label * fraglabel)1068f0336833SRobert Watson test_netinet_fragment(struct mbuf *m, struct label *mlabel,
1069f0336833SRobert Watson     struct mbuf *frag, struct label *fraglabel)
1070eb320b0eSRobert Watson {
1071eb320b0eSRobert Watson 
1072f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1073f0336833SRobert Watson 	LABEL_CHECK(fraglabel, MAGIC_MBUF);
1074eb320b0eSRobert Watson 	COUNTER_INC(netinet_fragment);
1075eb320b0eSRobert Watson }
1076eb320b0eSRobert Watson 
1077eb320b0eSRobert Watson COUNTER_DECL(netinet_icmp_reply);
1078eb320b0eSRobert Watson static void
test_netinet_icmp_reply(struct mbuf * mrecv,struct label * mrecvlabel,struct mbuf * msend,struct label * msendlabel)1079eb320b0eSRobert Watson test_netinet_icmp_reply(struct mbuf *mrecv, struct label *mrecvlabel,
1080eb320b0eSRobert Watson     struct mbuf *msend, struct label *msendlabel)
1081eb320b0eSRobert Watson {
1082eb320b0eSRobert Watson 
1083eb320b0eSRobert Watson 	LABEL_CHECK(mrecvlabel, MAGIC_MBUF);
1084eb320b0eSRobert Watson 	LABEL_CHECK(msendlabel, MAGIC_MBUF);
1085eb320b0eSRobert Watson 	COUNTER_INC(netinet_icmp_reply);
1086eb320b0eSRobert Watson }
1087eb320b0eSRobert Watson 
1088eb320b0eSRobert Watson COUNTER_DECL(netinet_icmp_replyinplace);
1089eb320b0eSRobert Watson static void
test_netinet_icmp_replyinplace(struct mbuf * m,struct label * mlabel)1090eb320b0eSRobert Watson test_netinet_icmp_replyinplace(struct mbuf *m, struct label *mlabel)
1091eb320b0eSRobert Watson {
1092eb320b0eSRobert Watson 
1093eb320b0eSRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1094eb320b0eSRobert Watson 	COUNTER_INC(netinet_icmp_replyinplace);
1095eb320b0eSRobert Watson }
1096eb320b0eSRobert Watson 
1097eb320b0eSRobert Watson COUNTER_DECL(netinet_igmp_send);
1098eb320b0eSRobert Watson static void
test_netinet_igmp_send(struct ifnet * ifp,struct label * ifplabel,struct mbuf * m,struct label * mlabel)1099eb320b0eSRobert Watson test_netinet_igmp_send(struct ifnet *ifp, struct label *ifplabel,
1100f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
1101eb320b0eSRobert Watson {
1102eb320b0eSRobert Watson 
1103eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
1104f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1105eb320b0eSRobert Watson 	COUNTER_INC(netinet_igmp_send);
1106eb320b0eSRobert Watson }
1107eb320b0eSRobert Watson 
1108eb320b0eSRobert Watson COUNTER_DECL(netinet_tcp_reply);
1109eb320b0eSRobert Watson static void
test_netinet_tcp_reply(struct mbuf * m,struct label * mlabel)1110eb320b0eSRobert Watson test_netinet_tcp_reply(struct mbuf *m, struct label *mlabel)
1111eb320b0eSRobert Watson {
1112eb320b0eSRobert Watson 
1113eb320b0eSRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1114eb320b0eSRobert Watson 	COUNTER_INC(netinet_tcp_reply);
1115eb320b0eSRobert Watson }
1116eb320b0eSRobert Watson 
1117eb320b0eSRobert Watson COUNTER_DECL(netinet6_nd6_send);
1118eb320b0eSRobert Watson static void
test_netinet6_nd6_send(struct ifnet * ifp,struct label * ifplabel,struct mbuf * m,struct label * mlabel)1119eb320b0eSRobert Watson test_netinet6_nd6_send(struct ifnet *ifp, struct label *ifplabel,
1120f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
1121eb320b0eSRobert Watson {
1122eb320b0eSRobert Watson 
1123eb320b0eSRobert Watson 	LABEL_CHECK(ifplabel, MAGIC_IFNET);
1124f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1125eb320b0eSRobert Watson 	COUNTER_INC(netinet6_nd6_send);
1126eb320b0eSRobert Watson }
1127eb320b0eSRobert Watson 
112830d239bcSRobert Watson COUNTER_DECL(pipe_check_ioctl);
1129d8a7b7a3SRobert Watson static int
test_pipe_check_ioctl(struct ucred * cred,struct pipepair * pp,struct label * pplabel,unsigned long cmd,void * data)11303f1a7a90SRobert Watson test_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp,
1131f0336833SRobert Watson     struct label *pplabel, unsigned long cmd, void /* caddr_t */ *data)
1132d8a7b7a3SRobert Watson {
1133d8a7b7a3SRobert Watson 
11346827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1135f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
113630d239bcSRobert Watson 	COUNTER_INC(pipe_check_ioctl);
1137250ee706SRobert Watson 
1138d8a7b7a3SRobert Watson 	return (0);
1139d8a7b7a3SRobert Watson }
1140d8a7b7a3SRobert Watson 
114130d239bcSRobert Watson COUNTER_DECL(pipe_check_poll);
1142d8a7b7a3SRobert Watson static int
test_pipe_check_poll(struct ucred * cred,struct pipepair * pp,struct label * pplabel)11433f1a7a90SRobert Watson test_pipe_check_poll(struct ucred *cred, struct pipepair *pp,
1144f0336833SRobert Watson     struct label *pplabel)
1145c024c3eeSRobert Watson {
1146c024c3eeSRobert Watson 
11476827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1148f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
114930d239bcSRobert Watson 	COUNTER_INC(pipe_check_poll);
1150250ee706SRobert Watson 
1151c024c3eeSRobert Watson 	return (0);
1152c024c3eeSRobert Watson }
1153c024c3eeSRobert Watson 
115430d239bcSRobert Watson COUNTER_DECL(pipe_check_read);
1155c024c3eeSRobert Watson static int
test_pipe_check_read(struct ucred * cred,struct pipepair * pp,struct label * pplabel)11563f1a7a90SRobert Watson test_pipe_check_read(struct ucred *cred, struct pipepair *pp,
1157f0336833SRobert Watson     struct label *pplabel)
1158d8a7b7a3SRobert Watson {
1159d8a7b7a3SRobert Watson 
11606827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1161f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
116230d239bcSRobert Watson 	COUNTER_INC(pipe_check_read);
1163250ee706SRobert Watson 
1164d8a7b7a3SRobert Watson 	return (0);
1165d8a7b7a3SRobert Watson }
1166d8a7b7a3SRobert Watson 
116730d239bcSRobert Watson COUNTER_DECL(pipe_check_relabel);
1168d8a7b7a3SRobert Watson static int
test_pipe_check_relabel(struct ucred * cred,struct pipepair * pp,struct label * pplabel,struct label * newlabel)11693f1a7a90SRobert Watson test_pipe_check_relabel(struct ucred *cred, struct pipepair *pp,
1170f0336833SRobert Watson     struct label *pplabel, struct label *newlabel)
1171d8a7b7a3SRobert Watson {
1172d8a7b7a3SRobert Watson 
11736827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1174f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
11756827d029SRobert Watson 	LABEL_CHECK(newlabel, MAGIC_PIPE);
117630d239bcSRobert Watson 	COUNTER_INC(pipe_check_relabel);
1177250ee706SRobert Watson 
1178d8a7b7a3SRobert Watson 	return (0);
1179d8a7b7a3SRobert Watson }
1180d8a7b7a3SRobert Watson 
118130d239bcSRobert Watson COUNTER_DECL(pipe_check_stat);
1182d8a7b7a3SRobert Watson static int
test_pipe_check_stat(struct ucred * cred,struct pipepair * pp,struct label * pplabel)11833f1a7a90SRobert Watson test_pipe_check_stat(struct ucred *cred, struct pipepair *pp,
1184f0336833SRobert Watson     struct label *pplabel)
1185c024c3eeSRobert Watson {
1186c024c3eeSRobert Watson 
11876827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1188f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
118930d239bcSRobert Watson 	COUNTER_INC(pipe_check_stat);
1190250ee706SRobert Watson 
1191c024c3eeSRobert Watson 	return (0);
1192c024c3eeSRobert Watson }
1193c024c3eeSRobert Watson 
119430d239bcSRobert Watson COUNTER_DECL(pipe_check_write);
1195c024c3eeSRobert Watson static int
test_pipe_check_write(struct ucred * cred,struct pipepair * pp,struct label * pplabel)11963f1a7a90SRobert Watson test_pipe_check_write(struct ucred *cred, struct pipepair *pp,
1197f0336833SRobert Watson     struct label *pplabel)
1198c024c3eeSRobert Watson {
1199c024c3eeSRobert Watson 
12006827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1201f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
120230d239bcSRobert Watson 	COUNTER_INC(pipe_check_write);
1203250ee706SRobert Watson 
1204c024c3eeSRobert Watson 	return (0);
1205c024c3eeSRobert Watson }
1206c024c3eeSRobert Watson 
1207eb320b0eSRobert Watson COUNTER_DECL(pipe_copy_label);
1208eb320b0eSRobert Watson static void
test_pipe_copy_label(struct label * src,struct label * dest)1209eb320b0eSRobert Watson test_pipe_copy_label(struct label *src, struct label *dest)
1210eb320b0eSRobert Watson {
1211eb320b0eSRobert Watson 
1212eb320b0eSRobert Watson 	LABEL_CHECK(src, MAGIC_PIPE);
1213eb320b0eSRobert Watson 	LABEL_CHECK(dest, MAGIC_PIPE);
1214eb320b0eSRobert Watson 	COUNTER_INC(pipe_copy_label);
1215eb320b0eSRobert Watson }
1216eb320b0eSRobert Watson 
1217eb320b0eSRobert Watson COUNTER_DECL(pipe_create);
1218eb320b0eSRobert Watson static void
test_pipe_create(struct ucred * cred,struct pipepair * pp,struct label * pplabel)1219eb320b0eSRobert Watson test_pipe_create(struct ucred *cred, struct pipepair *pp,
1220f0336833SRobert Watson    struct label *pplabel)
1221eb320b0eSRobert Watson {
1222eb320b0eSRobert Watson 
1223eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1224f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1225eb320b0eSRobert Watson 	COUNTER_INC(pipe_create);
1226eb320b0eSRobert Watson }
1227eb320b0eSRobert Watson 
1228eb320b0eSRobert Watson COUNTER_DECL(pipe_destroy_label);
1229eb320b0eSRobert Watson static void
test_pipe_destroy_label(struct label * label)1230eb320b0eSRobert Watson test_pipe_destroy_label(struct label *label)
1231eb320b0eSRobert Watson {
1232eb320b0eSRobert Watson 
1233eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_PIPE);
1234eb320b0eSRobert Watson 	COUNTER_INC(pipe_destroy_label);
1235eb320b0eSRobert Watson }
1236eb320b0eSRobert Watson 
1237eb320b0eSRobert Watson COUNTER_DECL(pipe_externalize_label);
1238eb320b0eSRobert Watson static int
test_pipe_externalize_label(struct label * label,char * element_name,struct sbuf * sb,int * claimed)1239eb320b0eSRobert Watson test_pipe_externalize_label(struct label *label, char *element_name,
1240eb320b0eSRobert Watson     struct sbuf *sb, int *claimed)
1241eb320b0eSRobert Watson {
1242eb320b0eSRobert Watson 
1243eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_PIPE);
1244eb320b0eSRobert Watson 	COUNTER_INC(pipe_externalize_label);
1245eb320b0eSRobert Watson 
1246eb320b0eSRobert Watson 	return (0);
1247eb320b0eSRobert Watson }
1248eb320b0eSRobert Watson 
1249eb320b0eSRobert Watson COUNTER_DECL(pipe_init_label);
1250eb320b0eSRobert Watson static void
test_pipe_init_label(struct label * label)1251eb320b0eSRobert Watson test_pipe_init_label(struct label *label)
1252eb320b0eSRobert Watson {
1253eb320b0eSRobert Watson 
1254eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_PIPE);
1255eb320b0eSRobert Watson 	COUNTER_INC(pipe_init_label);
1256eb320b0eSRobert Watson }
1257eb320b0eSRobert Watson 
12581876fb21SRobert Watson COUNTER_DECL(pipe_internalize_label);
12591876fb21SRobert Watson static int
test_pipe_internalize_label(struct label * label,char * element_name,char * element_data,int * claimed)12601876fb21SRobert Watson test_pipe_internalize_label(struct label *label, char *element_name,
12611876fb21SRobert Watson     char *element_data, int *claimed)
12621876fb21SRobert Watson {
12631876fb21SRobert Watson 
12641876fb21SRobert Watson 	LABEL_CHECK(label, MAGIC_PIPE);
12651876fb21SRobert Watson 	COUNTER_INC(pipe_internalize_label);
12661876fb21SRobert Watson 
12671876fb21SRobert Watson 	return (0);
12681876fb21SRobert Watson }
12691876fb21SRobert Watson 
1270eb320b0eSRobert Watson COUNTER_DECL(pipe_relabel);
1271eb320b0eSRobert Watson static void
test_pipe_relabel(struct ucred * cred,struct pipepair * pp,struct label * pplabel,struct label * newlabel)1272eb320b0eSRobert Watson test_pipe_relabel(struct ucred *cred, struct pipepair *pp,
1273f0336833SRobert Watson     struct label *pplabel, struct label *newlabel)
1274eb320b0eSRobert Watson {
1275eb320b0eSRobert Watson 
1276eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1277f0336833SRobert Watson 	LABEL_CHECK(pplabel, MAGIC_PIPE);
1278eb320b0eSRobert Watson 	LABEL_CHECK(newlabel, MAGIC_PIPE);
1279eb320b0eSRobert Watson 	COUNTER_INC(pipe_relabel);
1280eb320b0eSRobert Watson }
1281eb320b0eSRobert Watson 
1282438aeadfSRobert Watson COUNTER_DECL(posixsem_check_getvalue);
1283438aeadfSRobert Watson static int
test_posixsem_check_getvalue(struct ucred * active_cred,struct ucred * file_cred,struct ksem * ks,struct label * kslabel)12846bc1e9cdSJohn Baldwin test_posixsem_check_getvalue(struct ucred *active_cred, struct ucred *file_cred,
12856bc1e9cdSJohn Baldwin     struct ksem *ks, struct label *kslabel)
1286438aeadfSRobert Watson {
1287438aeadfSRobert Watson 
12886bc1e9cdSJohn Baldwin 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
12896bc1e9cdSJohn Baldwin 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1290438aeadfSRobert Watson 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1291438aeadfSRobert Watson 	COUNTER_INC(posixsem_check_getvalue);
1292438aeadfSRobert Watson 
1293438aeadfSRobert Watson 	return (0);
1294438aeadfSRobert Watson }
1295438aeadfSRobert Watson 
1296438aeadfSRobert Watson COUNTER_DECL(posixsem_check_open);
1297438aeadfSRobert Watson static int
test_posixsem_check_open(struct ucred * cred,struct ksem * ks,struct label * kslabel)1298438aeadfSRobert Watson test_posixsem_check_open(struct ucred *cred, struct ksem *ks,
1299438aeadfSRobert Watson     struct label *kslabel)
1300438aeadfSRobert Watson {
1301438aeadfSRobert Watson 
1302438aeadfSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1303438aeadfSRobert Watson 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1304438aeadfSRobert Watson 	COUNTER_INC(posixsem_check_open);
1305438aeadfSRobert Watson 
1306438aeadfSRobert Watson 	return (0);
1307438aeadfSRobert Watson }
1308438aeadfSRobert Watson 
1309438aeadfSRobert Watson COUNTER_DECL(posixsem_check_post);
1310438aeadfSRobert Watson static int
test_posixsem_check_post(struct ucred * active_cred,struct ucred * file_cred,struct ksem * ks,struct label * kslabel)13116bc1e9cdSJohn Baldwin test_posixsem_check_post(struct ucred *active_cred, struct ucred *file_cred,
13126bc1e9cdSJohn Baldwin     struct ksem *ks, struct label *kslabel)
1313438aeadfSRobert Watson {
1314438aeadfSRobert Watson 
13156bc1e9cdSJohn Baldwin 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
13166bc1e9cdSJohn Baldwin 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1317438aeadfSRobert Watson 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1318438aeadfSRobert Watson 	COUNTER_INC(posixsem_check_post);
1319438aeadfSRobert Watson 
1320438aeadfSRobert Watson 	return (0);
1321438aeadfSRobert Watson }
1322438aeadfSRobert Watson 
13239c00bb91SKonstantin Belousov COUNTER_DECL(posixsem_check_setmode);
13249c00bb91SKonstantin Belousov static int
test_posixsem_check_setmode(struct ucred * cred,struct ksem * ks,struct label * kslabel,mode_t mode)13259c00bb91SKonstantin Belousov test_posixsem_check_setmode(struct ucred *cred, struct ksem *ks,
13269c00bb91SKonstantin Belousov     struct label *kslabel, mode_t mode)
13279c00bb91SKonstantin Belousov {
13289c00bb91SKonstantin Belousov 
13299c00bb91SKonstantin Belousov 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
13309c00bb91SKonstantin Belousov 	LABEL_CHECK(kslabel, MAGIC_POSIX_SHM);
13319c00bb91SKonstantin Belousov 	COUNTER_INC(posixsem_check_setmode);
13329c00bb91SKonstantin Belousov 	return (0);
13339c00bb91SKonstantin Belousov }
13349c00bb91SKonstantin Belousov 
13359c00bb91SKonstantin Belousov COUNTER_DECL(posixsem_check_setowner);
13369c00bb91SKonstantin Belousov static int
test_posixsem_check_setowner(struct ucred * cred,struct ksem * ks,struct label * kslabel,uid_t uid,gid_t gid)13379c00bb91SKonstantin Belousov test_posixsem_check_setowner(struct ucred *cred, struct ksem *ks,
13389c00bb91SKonstantin Belousov     struct label *kslabel, uid_t uid, gid_t gid)
13399c00bb91SKonstantin Belousov {
13409c00bb91SKonstantin Belousov 
13419c00bb91SKonstantin Belousov 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
13429c00bb91SKonstantin Belousov 	LABEL_CHECK(kslabel, MAGIC_POSIX_SHM);
13439c00bb91SKonstantin Belousov 	COUNTER_INC(posixsem_check_setowner);
13449c00bb91SKonstantin Belousov 	return (0);
13459c00bb91SKonstantin Belousov }
13469c00bb91SKonstantin Belousov 
13476bc1e9cdSJohn Baldwin COUNTER_DECL(posixsem_check_stat);
13486bc1e9cdSJohn Baldwin static int
test_posixsem_check_stat(struct ucred * active_cred,struct ucred * file_cred,struct ksem * ks,struct label * kslabel)13496bc1e9cdSJohn Baldwin test_posixsem_check_stat(struct ucred *active_cred,
13506bc1e9cdSJohn Baldwin     struct ucred *file_cred, struct ksem *ks, struct label *kslabel)
13516bc1e9cdSJohn Baldwin {
13526bc1e9cdSJohn Baldwin 
13536bc1e9cdSJohn Baldwin 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
13546bc1e9cdSJohn Baldwin 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
13556bc1e9cdSJohn Baldwin 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
13566bc1e9cdSJohn Baldwin 	COUNTER_INC(posixsem_check_stat);
13576bc1e9cdSJohn Baldwin 	return (0);
13586bc1e9cdSJohn Baldwin }
13596bc1e9cdSJohn Baldwin 
1360438aeadfSRobert Watson COUNTER_DECL(posixsem_check_unlink);
1361438aeadfSRobert Watson static int
test_posixsem_check_unlink(struct ucred * cred,struct ksem * ks,struct label * kslabel)1362438aeadfSRobert Watson test_posixsem_check_unlink(struct ucred *cred, struct ksem *ks,
1363438aeadfSRobert Watson     struct label *kslabel)
1364438aeadfSRobert Watson {
1365438aeadfSRobert Watson 
1366438aeadfSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1367438aeadfSRobert Watson 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1368438aeadfSRobert Watson 	COUNTER_INC(posixsem_check_unlink);
1369438aeadfSRobert Watson 
1370438aeadfSRobert Watson 	return (0);
1371438aeadfSRobert Watson }
1372438aeadfSRobert Watson 
1373438aeadfSRobert Watson COUNTER_DECL(posixsem_check_wait);
1374438aeadfSRobert Watson static int
test_posixsem_check_wait(struct ucred * active_cred,struct ucred * file_cred,struct ksem * ks,struct label * kslabel)13756bc1e9cdSJohn Baldwin test_posixsem_check_wait(struct ucred *active_cred, struct ucred *file_cred,
13766bc1e9cdSJohn Baldwin     struct ksem *ks, struct label *kslabel)
1377438aeadfSRobert Watson {
1378438aeadfSRobert Watson 
13796bc1e9cdSJohn Baldwin 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
13806bc1e9cdSJohn Baldwin 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1381438aeadfSRobert Watson 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1382438aeadfSRobert Watson 	COUNTER_INC(posixsem_check_wait);
138352648411SRobert Watson 
138452648411SRobert Watson 	return (0);
138552648411SRobert Watson }
138652648411SRobert Watson 
1387eb320b0eSRobert Watson COUNTER_DECL(posixsem_create);
1388eb320b0eSRobert Watson static void
test_posixsem_create(struct ucred * cred,struct ksem * ks,struct label * kslabel)1389eb320b0eSRobert Watson test_posixsem_create(struct ucred *cred, struct ksem *ks,
1390eb320b0eSRobert Watson    struct label *kslabel)
1391eb320b0eSRobert Watson {
1392eb320b0eSRobert Watson 
1393eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1394eb320b0eSRobert Watson 	LABEL_CHECK(kslabel, MAGIC_POSIX_SEM);
1395eb320b0eSRobert Watson 	COUNTER_INC(posixsem_create);
1396eb320b0eSRobert Watson }
1397eb320b0eSRobert Watson 
1398eb320b0eSRobert Watson COUNTER_DECL(posixsem_destroy_label);
1399eb320b0eSRobert Watson static void
test_posixsem_destroy_label(struct label * label)1400eb320b0eSRobert Watson test_posixsem_destroy_label(struct label *label)
1401eb320b0eSRobert Watson {
1402eb320b0eSRobert Watson 
1403eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_POSIX_SEM);
1404eb320b0eSRobert Watson 	COUNTER_INC(posixsem_destroy_label);
1405eb320b0eSRobert Watson }
1406eb320b0eSRobert Watson 
1407eb320b0eSRobert Watson COUNTER_DECL(posixsem_init_label);
1408eb320b0eSRobert Watson static void
test_posixsem_init_label(struct label * label)1409eb320b0eSRobert Watson test_posixsem_init_label(struct label *label)
1410eb320b0eSRobert Watson {
1411eb320b0eSRobert Watson 
1412eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_POSIX_SEM);
1413eb320b0eSRobert Watson 	COUNTER_INC(posixsem_init_label);
1414eb320b0eSRobert Watson }
1415eb320b0eSRobert Watson 
14169b6dd12eSRobert Watson COUNTER_DECL(posixshm_check_create);
14179b6dd12eSRobert Watson static int
test_posixshm_check_create(struct ucred * cred,const char * path)14189b6dd12eSRobert Watson test_posixshm_check_create(struct ucred *cred, const char *path)
14199b6dd12eSRobert Watson {
14209b6dd12eSRobert Watson 
14219b6dd12eSRobert Watson 	COUNTER_INC(posixshm_check_create);
14229b6dd12eSRobert Watson 	return (0);
14239b6dd12eSRobert Watson }
14249b6dd12eSRobert Watson 
14258e38aeffSJohn Baldwin COUNTER_DECL(posixshm_check_mmap);
14268e38aeffSJohn Baldwin static int
test_posixshm_check_mmap(struct ucred * cred,struct shmfd * shmfd,struct label * shmfdlabel,int prot,int flags)14278e38aeffSJohn Baldwin test_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd,
14288e38aeffSJohn Baldwin     struct label *shmfdlabel, int prot, int flags)
14298e38aeffSJohn Baldwin {
14308e38aeffSJohn Baldwin 
14318e38aeffSJohn Baldwin 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
14328e38aeffSJohn Baldwin 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1433127cc767SJohn Baldwin 	COUNTER_INC(posixshm_check_mmap);
14348e38aeffSJohn Baldwin 	return (0);
14358e38aeffSJohn Baldwin }
14368e38aeffSJohn Baldwin 
14378e38aeffSJohn Baldwin COUNTER_DECL(posixshm_check_open);
14388e38aeffSJohn Baldwin static int
test_posixshm_check_open(struct ucred * cred,struct shmfd * shmfd,struct label * shmfdlabel,accmode_t accmode)14398e38aeffSJohn Baldwin test_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd,
14409b6dd12eSRobert Watson     struct label *shmfdlabel, accmode_t accmode)
14418e38aeffSJohn Baldwin {
14428e38aeffSJohn Baldwin 
14438e38aeffSJohn Baldwin 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
14448e38aeffSJohn Baldwin 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1445127cc767SJohn Baldwin 	COUNTER_INC(posixshm_check_open);
14468e38aeffSJohn Baldwin 	return (0);
14478e38aeffSJohn Baldwin }
14488e38aeffSJohn Baldwin 
1449940cb0e2SKonstantin Belousov COUNTER_DECL(posixshm_check_read);
1450940cb0e2SKonstantin Belousov static int
test_posixshm_check_read(struct ucred * active_cred,struct ucred * file_cred,struct shmfd * shm,struct label * shmlabel)1451940cb0e2SKonstantin Belousov test_posixshm_check_read(struct ucred *active_cred,
1452940cb0e2SKonstantin Belousov     struct ucred *file_cred, struct shmfd *shm, struct label *shmlabel)
1453940cb0e2SKonstantin Belousov {
1454940cb0e2SKonstantin Belousov 
1455940cb0e2SKonstantin Belousov 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1456940cb0e2SKonstantin Belousov 	if (file_cred != NULL)
1457940cb0e2SKonstantin Belousov 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1458940cb0e2SKonstantin Belousov 	LABEL_CHECK(shmlabel, MAGIC_POSIX_SHM);
1459940cb0e2SKonstantin Belousov 	COUNTER_INC(posixshm_check_read);
1460940cb0e2SKonstantin Belousov 
1461940cb0e2SKonstantin Belousov 	return (0);
1462940cb0e2SKonstantin Belousov }
1463940cb0e2SKonstantin Belousov 
14649c00bb91SKonstantin Belousov COUNTER_DECL(posixshm_check_setmode);
14659c00bb91SKonstantin Belousov static int
test_posixshm_check_setmode(struct ucred * cred,struct shmfd * shmfd,struct label * shmfdlabel,mode_t mode)14669c00bb91SKonstantin Belousov test_posixshm_check_setmode(struct ucred *cred, struct shmfd *shmfd,
14679c00bb91SKonstantin Belousov     struct label *shmfdlabel, mode_t mode)
14689c00bb91SKonstantin Belousov {
14699c00bb91SKonstantin Belousov 
14709c00bb91SKonstantin Belousov 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
14719c00bb91SKonstantin Belousov 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
14729c00bb91SKonstantin Belousov 	COUNTER_INC(posixshm_check_setmode);
14739c00bb91SKonstantin Belousov 	return (0);
14749c00bb91SKonstantin Belousov }
14759c00bb91SKonstantin Belousov 
14769c00bb91SKonstantin Belousov COUNTER_DECL(posixshm_check_setowner);
14779c00bb91SKonstantin Belousov static int
test_posixshm_check_setowner(struct ucred * cred,struct shmfd * shmfd,struct label * shmfdlabel,uid_t uid,gid_t gid)14789c00bb91SKonstantin Belousov test_posixshm_check_setowner(struct ucred *cred, struct shmfd *shmfd,
14799c00bb91SKonstantin Belousov     struct label *shmfdlabel, uid_t uid, gid_t gid)
14809c00bb91SKonstantin Belousov {
14819c00bb91SKonstantin Belousov 
14829c00bb91SKonstantin Belousov 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
14839c00bb91SKonstantin Belousov 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
14849c00bb91SKonstantin Belousov 	COUNTER_INC(posixshm_check_setowner);
14859c00bb91SKonstantin Belousov 	return (0);
14869c00bb91SKonstantin Belousov }
14879c00bb91SKonstantin Belousov 
14888e38aeffSJohn Baldwin COUNTER_DECL(posixshm_check_stat);
14898e38aeffSJohn Baldwin static int
test_posixshm_check_stat(struct ucred * active_cred,struct ucred * file_cred,struct shmfd * shmfd,struct label * shmfdlabel)14908e38aeffSJohn Baldwin test_posixshm_check_stat(struct ucred *active_cred,
14918e38aeffSJohn Baldwin     struct ucred *file_cred, struct shmfd *shmfd, struct label *shmfdlabel)
14928e38aeffSJohn Baldwin {
14938e38aeffSJohn Baldwin 
14948e38aeffSJohn Baldwin 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
14958e38aeffSJohn Baldwin 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
14968e38aeffSJohn Baldwin 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1497127cc767SJohn Baldwin 	COUNTER_INC(posixshm_check_stat);
14988e38aeffSJohn Baldwin 	return (0);
14998e38aeffSJohn Baldwin }
15008e38aeffSJohn Baldwin 
15018e38aeffSJohn Baldwin COUNTER_DECL(posixshm_check_truncate);
15028e38aeffSJohn Baldwin static int
test_posixshm_check_truncate(struct ucred * active_cred,struct ucred * file_cred,struct shmfd * shmfd,struct label * shmfdlabel)15038e38aeffSJohn Baldwin test_posixshm_check_truncate(struct ucred *active_cred,
15048e38aeffSJohn Baldwin     struct ucred *file_cred, struct shmfd *shmfd, struct label *shmfdlabel)
15058e38aeffSJohn Baldwin {
15068e38aeffSJohn Baldwin 
15078e38aeffSJohn Baldwin 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
15088e38aeffSJohn Baldwin 	LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
15098e38aeffSJohn Baldwin 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1510127cc767SJohn Baldwin 	COUNTER_INC(posixshm_check_truncate);
15118e38aeffSJohn Baldwin 	return (0);
15128e38aeffSJohn Baldwin }
15138e38aeffSJohn Baldwin 
15148e38aeffSJohn Baldwin COUNTER_DECL(posixshm_check_unlink);
15158e38aeffSJohn Baldwin static int
test_posixshm_check_unlink(struct ucred * cred,struct shmfd * shmfd,struct label * shmfdlabel)15168e38aeffSJohn Baldwin test_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd,
15178e38aeffSJohn Baldwin     struct label *shmfdlabel)
15188e38aeffSJohn Baldwin {
15198e38aeffSJohn Baldwin 
15208e38aeffSJohn Baldwin 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
15218e38aeffSJohn Baldwin 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
1522127cc767SJohn Baldwin 	COUNTER_INC(posixshm_check_unlink);
15238e38aeffSJohn Baldwin 	return (0);
15248e38aeffSJohn Baldwin }
15258e38aeffSJohn Baldwin 
1526940cb0e2SKonstantin Belousov COUNTER_DECL(posixshm_check_write);
1527940cb0e2SKonstantin Belousov static int
test_posixshm_check_write(struct ucred * active_cred,struct ucred * file_cred,struct shmfd * shm,struct label * shmlabel)1528940cb0e2SKonstantin Belousov test_posixshm_check_write(struct ucred *active_cred,
1529940cb0e2SKonstantin Belousov     struct ucred *file_cred, struct shmfd *shm, struct label *shmlabel)
1530940cb0e2SKonstantin Belousov {
1531940cb0e2SKonstantin Belousov 
1532940cb0e2SKonstantin Belousov 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
1533940cb0e2SKonstantin Belousov 	if (file_cred != NULL)
1534940cb0e2SKonstantin Belousov 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
1535940cb0e2SKonstantin Belousov 	LABEL_CHECK(shmlabel, MAGIC_POSIX_SHM);
1536940cb0e2SKonstantin Belousov 	COUNTER_INC(posixshm_check_write);
1537940cb0e2SKonstantin Belousov 
1538940cb0e2SKonstantin Belousov 	return (0);
1539940cb0e2SKonstantin Belousov }
1540940cb0e2SKonstantin Belousov 
15418e38aeffSJohn Baldwin COUNTER_DECL(posixshm_create);
15428e38aeffSJohn Baldwin static void
test_posixshm_create(struct ucred * cred,struct shmfd * shmfd,struct label * shmfdlabel)15438e38aeffSJohn Baldwin test_posixshm_create(struct ucred *cred, struct shmfd *shmfd,
15448e38aeffSJohn Baldwin    struct label *shmfdlabel)
15458e38aeffSJohn Baldwin {
15468e38aeffSJohn Baldwin 
15478e38aeffSJohn Baldwin 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
15488e38aeffSJohn Baldwin 	LABEL_CHECK(shmfdlabel, MAGIC_POSIX_SHM);
15498e38aeffSJohn Baldwin 	COUNTER_INC(posixshm_create);
15508e38aeffSJohn Baldwin }
15518e38aeffSJohn Baldwin 
15528e38aeffSJohn Baldwin COUNTER_DECL(posixshm_destroy_label);
15538e38aeffSJohn Baldwin static void
test_posixshm_destroy_label(struct label * label)15548e38aeffSJohn Baldwin test_posixshm_destroy_label(struct label *label)
15558e38aeffSJohn Baldwin {
15568e38aeffSJohn Baldwin 
15578e38aeffSJohn Baldwin 	LABEL_DESTROY(label, MAGIC_POSIX_SHM);
15588e38aeffSJohn Baldwin 	COUNTER_INC(posixshm_destroy_label);
15598e38aeffSJohn Baldwin }
15608e38aeffSJohn Baldwin 
15618e38aeffSJohn Baldwin COUNTER_DECL(posixshm_init_label);
15628e38aeffSJohn Baldwin static void
test_posixshm_init_label(struct label * label)15638e38aeffSJohn Baldwin test_posixshm_init_label(struct label *label)
15648e38aeffSJohn Baldwin {
15658e38aeffSJohn Baldwin 
15668e38aeffSJohn Baldwin 	LABEL_INIT(label, MAGIC_POSIX_SHM);
15678e38aeffSJohn Baldwin 	COUNTER_INC(posixshm_init_label);
15688e38aeffSJohn Baldwin }
15698e38aeffSJohn Baldwin 
157030d239bcSRobert Watson COUNTER_DECL(proc_check_debug);
157152648411SRobert Watson static int
test_proc_check_debug(struct ucred * cred,struct proc * p)15723f1a7a90SRobert Watson test_proc_check_debug(struct ucred *cred, struct proc *p)
1573d8a7b7a3SRobert Watson {
1574d8a7b7a3SRobert Watson 
15756827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
157678007886SRobert Watson 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
157730d239bcSRobert Watson 	COUNTER_INC(proc_check_debug);
1578250ee706SRobert Watson 
1579d8a7b7a3SRobert Watson 	return (0);
1580d8a7b7a3SRobert Watson }
1581d8a7b7a3SRobert Watson 
158230d239bcSRobert Watson COUNTER_DECL(proc_check_sched);
1583d8a7b7a3SRobert Watson static int
test_proc_check_sched(struct ucred * cred,struct proc * p)15843f1a7a90SRobert Watson test_proc_check_sched(struct ucred *cred, struct proc *p)
1585d8a7b7a3SRobert Watson {
1586d8a7b7a3SRobert Watson 
15876827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
158878007886SRobert Watson 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
158930d239bcSRobert Watson 	COUNTER_INC(proc_check_sched);
1590250ee706SRobert Watson 
1591d8a7b7a3SRobert Watson 	return (0);
1592d8a7b7a3SRobert Watson }
1593d8a7b7a3SRobert Watson 
159430d239bcSRobert Watson COUNTER_DECL(proc_check_signal);
1595d8a7b7a3SRobert Watson static int
test_proc_check_signal(struct ucred * cred,struct proc * p,int signum)15963f1a7a90SRobert Watson test_proc_check_signal(struct ucred *cred, struct proc *p, int signum)
1597d8a7b7a3SRobert Watson {
1598d8a7b7a3SRobert Watson 
15996827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
160078007886SRobert Watson 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
160130d239bcSRobert Watson 	COUNTER_INC(proc_check_signal);
1602250ee706SRobert Watson 
1603d8a7b7a3SRobert Watson 	return (0);
1604d8a7b7a3SRobert Watson }
1605d8a7b7a3SRobert Watson 
160630d239bcSRobert Watson COUNTER_DECL(proc_check_wait);
1607030a28b3SRobert Watson static int
test_proc_check_wait(struct ucred * cred,struct proc * p)16083f1a7a90SRobert Watson test_proc_check_wait(struct ucred *cred, struct proc *p)
1609babe9a2bSRobert Watson {
1610babe9a2bSRobert Watson 
16116827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
161278007886SRobert Watson 	LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED);
161330d239bcSRobert Watson 	COUNTER_INC(proc_check_wait);
1614babe9a2bSRobert Watson 
1615babe9a2bSRobert Watson 	return (0);
1616babe9a2bSRobert Watson }
1617babe9a2bSRobert Watson 
1618eb320b0eSRobert Watson COUNTER_DECL(proc_destroy_label);
1619eb320b0eSRobert Watson static void
test_proc_destroy_label(struct label * label)1620eb320b0eSRobert Watson test_proc_destroy_label(struct label *label)
1621eb320b0eSRobert Watson {
1622eb320b0eSRobert Watson 
1623eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_PROC);
1624eb320b0eSRobert Watson 	COUNTER_INC(proc_destroy_label);
1625eb320b0eSRobert Watson }
1626eb320b0eSRobert Watson 
1627eb320b0eSRobert Watson COUNTER_DECL(proc_init_label);
1628eb320b0eSRobert Watson static void
test_proc_init_label(struct label * label)1629eb320b0eSRobert Watson test_proc_init_label(struct label *label)
1630eb320b0eSRobert Watson {
1631eb320b0eSRobert Watson 
1632eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_PROC);
1633eb320b0eSRobert Watson 	COUNTER_INC(proc_init_label);
1634eb320b0eSRobert Watson }
1635eb320b0eSRobert Watson 
163630d239bcSRobert Watson COUNTER_DECL(socket_check_accept);
1637babe9a2bSRobert Watson static int
test_socket_check_accept(struct ucred * cred,struct socket * so,struct label * solabel)16383f1a7a90SRobert Watson test_socket_check_accept(struct ucred *cred, struct socket *so,
163978007886SRobert Watson     struct label *solabel)
16407f53207bSRobert Watson {
16417f53207bSRobert Watson 
16426827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
16433de40469SRobert Watson 	SOCK_LOCK(so);
164478007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
16453de40469SRobert Watson 	SOCK_UNLOCK(so);
164630d239bcSRobert Watson 	COUNTER_INC(socket_check_accept);
16477f53207bSRobert Watson 
16487f53207bSRobert Watson 	return (0);
16497f53207bSRobert Watson }
16507f53207bSRobert Watson 
165130d239bcSRobert Watson COUNTER_DECL(socket_check_bind);
16527f53207bSRobert Watson static int
test_socket_check_bind(struct ucred * cred,struct socket * so,struct label * solabel,struct sockaddr * sa)16533f1a7a90SRobert Watson test_socket_check_bind(struct ucred *cred, struct socket *so,
165478007886SRobert Watson     struct label *solabel, struct sockaddr *sa)
1655d8a7b7a3SRobert Watson {
1656d8a7b7a3SRobert Watson 
16576827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
16583de40469SRobert Watson 	SOCK_LOCK(so);
165978007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
16603de40469SRobert Watson 	SOCK_UNLOCK(so);
166130d239bcSRobert Watson 	COUNTER_INC(socket_check_bind);
1662250ee706SRobert Watson 
1663d8a7b7a3SRobert Watson 	return (0);
1664d8a7b7a3SRobert Watson }
1665d8a7b7a3SRobert Watson 
166630d239bcSRobert Watson COUNTER_DECL(socket_check_connect);
1667d8a7b7a3SRobert Watson static int
test_socket_check_connect(struct ucred * cred,struct socket * so,struct label * solabel,struct sockaddr * sa)16683f1a7a90SRobert Watson test_socket_check_connect(struct ucred *cred, struct socket *so,
166978007886SRobert Watson     struct label *solabel, struct sockaddr *sa)
1670d8a7b7a3SRobert Watson {
1671d8a7b7a3SRobert Watson 
16726827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
16733de40469SRobert Watson 	SOCK_LOCK(so);
167478007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
16753de40469SRobert Watson 	SOCK_UNLOCK(so);
167630d239bcSRobert Watson 	COUNTER_INC(socket_check_connect);
1677250ee706SRobert Watson 
1678d8a7b7a3SRobert Watson 	return (0);
1679d8a7b7a3SRobert Watson }
1680d8a7b7a3SRobert Watson 
168130d239bcSRobert Watson COUNTER_DECL(socket_check_deliver);
1682d8a7b7a3SRobert Watson static int
test_socket_check_deliver(struct socket * so,struct label * solabel,struct mbuf * m,struct label * mlabel)16833f1a7a90SRobert Watson test_socket_check_deliver(struct socket *so, struct label *solabel,
168478007886SRobert Watson     struct mbuf *m, struct label *mlabel)
1685d8a7b7a3SRobert Watson {
1686d8a7b7a3SRobert Watson 
16873de40469SRobert Watson 	SOCK_LOCK(so);
168878007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
16893de40469SRobert Watson 	SOCK_UNLOCK(so);
169078007886SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
169130d239bcSRobert Watson 	COUNTER_INC(socket_check_deliver);
1692250ee706SRobert Watson 
1693d8a7b7a3SRobert Watson 	return (0);
1694d8a7b7a3SRobert Watson }
1695d8a7b7a3SRobert Watson 
169630d239bcSRobert Watson COUNTER_DECL(socket_check_listen);
1697d8a7b7a3SRobert Watson static int
test_socket_check_listen(struct ucred * cred,struct socket * so,struct label * solabel)16983f1a7a90SRobert Watson test_socket_check_listen(struct ucred *cred, struct socket *so,
169978007886SRobert Watson     struct label *solabel)
1700d8a7b7a3SRobert Watson {
1701d8a7b7a3SRobert Watson 
17026827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
17033de40469SRobert Watson 	SOCK_LOCK(so);
170478007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17053de40469SRobert Watson 	SOCK_UNLOCK(so);
170630d239bcSRobert Watson 	COUNTER_INC(socket_check_listen);
1707250ee706SRobert Watson 
1708d8a7b7a3SRobert Watson 	return (0);
1709d8a7b7a3SRobert Watson }
1710d8a7b7a3SRobert Watson 
171130d239bcSRobert Watson COUNTER_DECL(socket_check_poll);
1712d8a7b7a3SRobert Watson static int
test_socket_check_poll(struct ucred * cred,struct socket * so,struct label * solabel)17133f1a7a90SRobert Watson test_socket_check_poll(struct ucred *cred, struct socket *so,
171478007886SRobert Watson     struct label *solabel)
17157f53207bSRobert Watson {
17167f53207bSRobert Watson 
17176827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
17183de40469SRobert Watson 	SOCK_LOCK(so);
171978007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17203de40469SRobert Watson 	SOCK_UNLOCK(so);
172130d239bcSRobert Watson 	COUNTER_INC(socket_check_poll);
17227f53207bSRobert Watson 
17237f53207bSRobert Watson 	return (0);
17247f53207bSRobert Watson }
17257f53207bSRobert Watson 
172630d239bcSRobert Watson COUNTER_DECL(socket_check_receive);
17277f53207bSRobert Watson static int
test_socket_check_receive(struct ucred * cred,struct socket * so,struct label * solabel)17283f1a7a90SRobert Watson test_socket_check_receive(struct ucred *cred, struct socket *so,
172978007886SRobert Watson     struct label *solabel)
1730d8a7b7a3SRobert Watson {
1731d8a7b7a3SRobert Watson 
17326827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
17333de40469SRobert Watson 	SOCK_LOCK(so);
173478007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17353de40469SRobert Watson 	SOCK_UNLOCK(so);
173630d239bcSRobert Watson 	COUNTER_INC(socket_check_receive);
1737250ee706SRobert Watson 
1738d8a7b7a3SRobert Watson 	return (0);
1739d8a7b7a3SRobert Watson }
1740d8a7b7a3SRobert Watson 
174130d239bcSRobert Watson COUNTER_DECL(socket_check_relabel);
1742d8a7b7a3SRobert Watson static int
test_socket_check_relabel(struct ucred * cred,struct socket * so,struct label * solabel,struct label * newlabel)17433f1a7a90SRobert Watson test_socket_check_relabel(struct ucred *cred, struct socket *so,
174478007886SRobert Watson     struct label *solabel, struct label *newlabel)
1745d8a7b7a3SRobert Watson {
1746d8a7b7a3SRobert Watson 
17473de40469SRobert Watson 	SOCK_LOCK_ASSERT(so);
17483de40469SRobert Watson 
17496827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
175078007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17516827d029SRobert Watson 	LABEL_CHECK(newlabel, MAGIC_SOCKET);
175230d239bcSRobert Watson 	COUNTER_INC(socket_check_relabel);
1753250ee706SRobert Watson 
1754d8a7b7a3SRobert Watson 	return (0);
1755d8a7b7a3SRobert Watson }
1756d8a7b7a3SRobert Watson 
175730d239bcSRobert Watson COUNTER_DECL(socket_check_send);
1758d8a7b7a3SRobert Watson static int
test_socket_check_send(struct ucred * cred,struct socket * so,struct label * solabel)17593f1a7a90SRobert Watson test_socket_check_send(struct ucred *cred, struct socket *so,
176078007886SRobert Watson     struct label *solabel)
17617f53207bSRobert Watson {
17627f53207bSRobert Watson 
17636827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
17643de40469SRobert Watson 	SOCK_LOCK(so);
176578007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17663de40469SRobert Watson 	SOCK_UNLOCK(so);
176730d239bcSRobert Watson 	COUNTER_INC(socket_check_send);
17687f53207bSRobert Watson 
17697f53207bSRobert Watson 	return (0);
17707f53207bSRobert Watson }
17717f53207bSRobert Watson 
177230d239bcSRobert Watson COUNTER_DECL(socket_check_stat);
17737f53207bSRobert Watson static int
test_socket_check_stat(struct ucred * cred,struct socket * so,struct label * solabel)17743f1a7a90SRobert Watson test_socket_check_stat(struct ucred *cred, struct socket *so,
177578007886SRobert Watson     struct label *solabel)
17767f53207bSRobert Watson {
17777f53207bSRobert Watson 
17786827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
17793de40469SRobert Watson 	SOCK_LOCK(so);
178078007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17813de40469SRobert Watson 	SOCK_UNLOCK(so);
178230d239bcSRobert Watson 	COUNTER_INC(socket_check_stat);
17837f53207bSRobert Watson 
17847f53207bSRobert Watson 	return (0);
17857f53207bSRobert Watson }
17867f53207bSRobert Watson 
178730d239bcSRobert Watson COUNTER_DECL(socket_check_visible);
17887f53207bSRobert Watson static int
test_socket_check_visible(struct ucred * cred,struct socket * so,struct label * solabel)17893f1a7a90SRobert Watson test_socket_check_visible(struct ucred *cred, struct socket *so,
179078007886SRobert Watson     struct label *solabel)
17917f53207bSRobert Watson {
17927f53207bSRobert Watson 
17936827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
17943de40469SRobert Watson 	SOCK_LOCK(so);
179578007886SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
17963de40469SRobert Watson 	SOCK_UNLOCK(so);
179730d239bcSRobert Watson 	COUNTER_INC(socket_check_visible);
17987f53207bSRobert Watson 
17997f53207bSRobert Watson 	return (0);
18007f53207bSRobert Watson }
18017f53207bSRobert Watson 
1802eb320b0eSRobert Watson COUNTER_DECL(socket_copy_label);
1803eb320b0eSRobert Watson static void
test_socket_copy_label(struct label * src,struct label * dest)1804eb320b0eSRobert Watson test_socket_copy_label(struct label *src, struct label *dest)
1805eb320b0eSRobert Watson {
1806eb320b0eSRobert Watson 
1807eb320b0eSRobert Watson 	LABEL_CHECK(src, MAGIC_SOCKET);
1808eb320b0eSRobert Watson 	LABEL_CHECK(dest, MAGIC_SOCKET);
1809eb320b0eSRobert Watson 	COUNTER_INC(socket_copy_label);
1810eb320b0eSRobert Watson }
1811eb320b0eSRobert Watson 
1812eb320b0eSRobert Watson COUNTER_DECL(socket_create);
1813eb320b0eSRobert Watson static void
test_socket_create(struct ucred * cred,struct socket * so,struct label * solabel)1814f0336833SRobert Watson test_socket_create(struct ucred *cred, struct socket *so,
1815f0336833SRobert Watson     struct label *solabel)
1816eb320b0eSRobert Watson {
1817eb320b0eSRobert Watson 
1818eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1819f0336833SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1820eb320b0eSRobert Watson 	COUNTER_INC(socket_create);
1821eb320b0eSRobert Watson }
1822eb320b0eSRobert Watson 
1823eb320b0eSRobert Watson COUNTER_DECL(socket_create_mbuf);
1824eb320b0eSRobert Watson static void
test_socket_create_mbuf(struct socket * so,struct label * solabel,struct mbuf * m,struct label * mlabel)18253de40469SRobert Watson test_socket_create_mbuf(struct socket *so, struct label *solabel,
1826f0336833SRobert Watson     struct mbuf *m, struct label *mlabel)
1827eb320b0eSRobert Watson {
1828eb320b0eSRobert Watson 
18293de40469SRobert Watson 	SOCK_LOCK(so);
18303de40469SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
18313de40469SRobert Watson 	SOCK_UNLOCK(so);
1832f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1833eb320b0eSRobert Watson 	COUNTER_INC(socket_create_mbuf);
1834eb320b0eSRobert Watson }
1835eb320b0eSRobert Watson 
1836eb320b0eSRobert Watson COUNTER_DECL(socket_destroy_label);
1837eb320b0eSRobert Watson static void
test_socket_destroy_label(struct label * label)1838eb320b0eSRobert Watson test_socket_destroy_label(struct label *label)
1839eb320b0eSRobert Watson {
1840eb320b0eSRobert Watson 
1841eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SOCKET);
1842eb320b0eSRobert Watson 	COUNTER_INC(socket_destroy_label);
1843eb320b0eSRobert Watson }
1844eb320b0eSRobert Watson 
1845eb320b0eSRobert Watson COUNTER_DECL(socket_externalize_label);
1846eb320b0eSRobert Watson static int
test_socket_externalize_label(struct label * label,char * element_name,struct sbuf * sb,int * claimed)1847eb320b0eSRobert Watson test_socket_externalize_label(struct label *label, char *element_name,
1848eb320b0eSRobert Watson     struct sbuf *sb, int *claimed)
1849eb320b0eSRobert Watson {
1850eb320b0eSRobert Watson 
1851eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_SOCKET);
1852eb320b0eSRobert Watson 	COUNTER_INC(socket_externalize_label);
1853eb320b0eSRobert Watson 
1854eb320b0eSRobert Watson 	return (0);
1855eb320b0eSRobert Watson }
1856eb320b0eSRobert Watson 
1857eb320b0eSRobert Watson COUNTER_DECL(socket_init_label);
1858eb320b0eSRobert Watson static int
test_socket_init_label(struct label * label,int flag)1859eb320b0eSRobert Watson test_socket_init_label(struct label *label, int flag)
1860eb320b0eSRobert Watson {
1861eb320b0eSRobert Watson 
1862eb320b0eSRobert Watson 	if (flag & M_WAITOK)
1863eb320b0eSRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1864eb320b0eSRobert Watson 		    "test_socket_init_label() at %s:%d", __FILE__,
1865eb320b0eSRobert Watson 		    __LINE__);
1866eb320b0eSRobert Watson 
1867eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SOCKET);
1868eb320b0eSRobert Watson 	COUNTER_INC(socket_init_label);
1869eb320b0eSRobert Watson 	return (0);
1870eb320b0eSRobert Watson }
1871eb320b0eSRobert Watson 
18721876fb21SRobert Watson COUNTER_DECL(socket_internalize_label);
18731876fb21SRobert Watson static int
test_socket_internalize_label(struct label * label,char * element_name,char * element_data,int * claimed)18741876fb21SRobert Watson test_socket_internalize_label(struct label *label, char *element_name,
18751876fb21SRobert Watson     char *element_data, int *claimed)
18761876fb21SRobert Watson {
18771876fb21SRobert Watson 
18781876fb21SRobert Watson 	LABEL_CHECK(label, MAGIC_SOCKET);
18791876fb21SRobert Watson 	COUNTER_INC(socket_internalize_label);
18801876fb21SRobert Watson 
18811876fb21SRobert Watson 	return (0);
18821876fb21SRobert Watson }
18831876fb21SRobert Watson 
1884eb320b0eSRobert Watson COUNTER_DECL(socket_newconn);
1885eb320b0eSRobert Watson static void
test_socket_newconn(struct socket * oldso,struct label * oldsolabel,struct socket * newso,struct label * newsolabel)1886f0336833SRobert Watson test_socket_newconn(struct socket *oldso, struct label *oldsolabel,
1887f0336833SRobert Watson     struct socket *newso, struct label *newsolabel)
1888eb320b0eSRobert Watson {
1889eb320b0eSRobert Watson 
18903de40469SRobert Watson 	SOCK_LOCK(oldso);
1891f0336833SRobert Watson 	LABEL_CHECK(oldsolabel, MAGIC_SOCKET);
18923de40469SRobert Watson 	SOCK_UNLOCK(oldso);
18933de40469SRobert Watson 	SOCK_LOCK(newso);
1894f0336833SRobert Watson 	LABEL_CHECK(newsolabel, MAGIC_SOCKET);
18953de40469SRobert Watson 	SOCK_UNLOCK(newso);
1896eb320b0eSRobert Watson 	COUNTER_INC(socket_newconn);
1897eb320b0eSRobert Watson }
1898eb320b0eSRobert Watson 
1899eb320b0eSRobert Watson COUNTER_DECL(socket_relabel);
1900eb320b0eSRobert Watson static void
test_socket_relabel(struct ucred * cred,struct socket * so,struct label * solabel,struct label * newlabel)1901f0336833SRobert Watson test_socket_relabel(struct ucred *cred, struct socket *so,
1902f0336833SRobert Watson     struct label *solabel, struct label *newlabel)
1903eb320b0eSRobert Watson {
1904eb320b0eSRobert Watson 
19053de40469SRobert Watson 	SOCK_LOCK_ASSERT(so);
19063de40469SRobert Watson 
1907eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
1908f0336833SRobert Watson 	LABEL_CHECK(solabel, MAGIC_SOCKET);
1909eb320b0eSRobert Watson 	LABEL_CHECK(newlabel, MAGIC_SOCKET);
1910eb320b0eSRobert Watson 	COUNTER_INC(socket_relabel);
1911eb320b0eSRobert Watson }
1912eb320b0eSRobert Watson 
1913eb320b0eSRobert Watson COUNTER_DECL(socketpeer_destroy_label);
1914eb320b0eSRobert Watson static void
test_socketpeer_destroy_label(struct label * label)1915eb320b0eSRobert Watson test_socketpeer_destroy_label(struct label *label)
1916eb320b0eSRobert Watson {
1917eb320b0eSRobert Watson 
1918eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SOCKET);
1919eb320b0eSRobert Watson 	COUNTER_INC(socketpeer_destroy_label);
1920eb320b0eSRobert Watson }
1921eb320b0eSRobert Watson 
1922eb320b0eSRobert Watson COUNTER_DECL(socketpeer_externalize_label);
1923eb320b0eSRobert Watson static int
test_socketpeer_externalize_label(struct label * label,char * element_name,struct sbuf * sb,int * claimed)1924eb320b0eSRobert Watson test_socketpeer_externalize_label(struct label *label, char *element_name,
1925eb320b0eSRobert Watson     struct sbuf *sb, int *claimed)
1926eb320b0eSRobert Watson {
1927eb320b0eSRobert Watson 
1928eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_SOCKET);
1929eb320b0eSRobert Watson 	COUNTER_INC(socketpeer_externalize_label);
1930eb320b0eSRobert Watson 
1931eb320b0eSRobert Watson 	return (0);
1932eb320b0eSRobert Watson }
1933eb320b0eSRobert Watson 
1934eb320b0eSRobert Watson COUNTER_DECL(socketpeer_init_label);
1935eb320b0eSRobert Watson static int
test_socketpeer_init_label(struct label * label,int flag)1936eb320b0eSRobert Watson test_socketpeer_init_label(struct label *label, int flag)
1937eb320b0eSRobert Watson {
1938eb320b0eSRobert Watson 
1939eb320b0eSRobert Watson 	if (flag & M_WAITOK)
1940eb320b0eSRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
1941eb320b0eSRobert Watson 		    "test_socketpeer_init_label() at %s:%d", __FILE__,
1942eb320b0eSRobert Watson 		    __LINE__);
1943eb320b0eSRobert Watson 
1944eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SOCKET);
1945eb320b0eSRobert Watson 	COUNTER_INC(socketpeer_init_label);
1946eb320b0eSRobert Watson 	return (0);
1947eb320b0eSRobert Watson }
1948eb320b0eSRobert Watson 
1949eb320b0eSRobert Watson COUNTER_DECL(socketpeer_set_from_mbuf);
1950eb320b0eSRobert Watson static void
test_socketpeer_set_from_mbuf(struct mbuf * m,struct label * mlabel,struct socket * so,struct label * sopeerlabel)1951f0336833SRobert Watson test_socketpeer_set_from_mbuf(struct mbuf *m, struct label *mlabel,
19523de40469SRobert Watson     struct socket *so, struct label *sopeerlabel)
1953eb320b0eSRobert Watson {
1954eb320b0eSRobert Watson 
1955f0336833SRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
19563de40469SRobert Watson 	SOCK_LOCK(so);
19573de40469SRobert Watson 	LABEL_CHECK(sopeerlabel, MAGIC_SOCKET);
19583de40469SRobert Watson 	SOCK_UNLOCK(so);
1959eb320b0eSRobert Watson 	COUNTER_INC(socketpeer_set_from_mbuf);
1960eb320b0eSRobert Watson }
1961eb320b0eSRobert Watson 
1962eb320b0eSRobert Watson COUNTER_DECL(socketpeer_set_from_socket);
1963eb320b0eSRobert Watson static void
test_socketpeer_set_from_socket(struct socket * oldso,struct label * oldsolabel,struct socket * newso,struct label * newsopeerlabel)1964f0336833SRobert Watson test_socketpeer_set_from_socket(struct socket *oldso,
1965f0336833SRobert Watson     struct label *oldsolabel, struct socket *newso,
1966f0336833SRobert Watson     struct label *newsopeerlabel)
1967eb320b0eSRobert Watson {
1968eb320b0eSRobert Watson 
19693de40469SRobert Watson 	SOCK_LOCK(oldso);
1970f0336833SRobert Watson 	LABEL_CHECK(oldsolabel, MAGIC_SOCKET);
19713de40469SRobert Watson 	SOCK_UNLOCK(oldso);
19723de40469SRobert Watson 	SOCK_LOCK(newso);
1973f0336833SRobert Watson 	LABEL_CHECK(newsopeerlabel, MAGIC_SOCKET);
19743de40469SRobert Watson 	SOCK_UNLOCK(newso);
1975eb320b0eSRobert Watson 	COUNTER_INC(socketpeer_set_from_socket);
1976eb320b0eSRobert Watson }
1977eb320b0eSRobert Watson 
1978eb320b0eSRobert Watson COUNTER_DECL(syncache_create);
1979eb320b0eSRobert Watson static void
test_syncache_create(struct label * label,struct inpcb * inp)1980eb320b0eSRobert Watson test_syncache_create(struct label *label, struct inpcb *inp)
1981eb320b0eSRobert Watson {
1982eb320b0eSRobert Watson 
1983eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_SYNCACHE);
1984eb320b0eSRobert Watson 	COUNTER_INC(syncache_create);
1985eb320b0eSRobert Watson }
1986eb320b0eSRobert Watson 
1987eb320b0eSRobert Watson COUNTER_DECL(syncache_create_mbuf);
1988eb320b0eSRobert Watson static void
test_syncache_create_mbuf(struct label * sc_label,struct mbuf * m,struct label * mlabel)1989eb320b0eSRobert Watson test_syncache_create_mbuf(struct label *sc_label, struct mbuf *m,
1990eb320b0eSRobert Watson     struct label *mlabel)
1991eb320b0eSRobert Watson {
1992eb320b0eSRobert Watson 
1993eb320b0eSRobert Watson 	LABEL_CHECK(sc_label, MAGIC_SYNCACHE);
1994eb320b0eSRobert Watson 	LABEL_CHECK(mlabel, MAGIC_MBUF);
1995eb320b0eSRobert Watson 	COUNTER_INC(syncache_create_mbuf);
1996eb320b0eSRobert Watson }
1997eb320b0eSRobert Watson 
1998eb320b0eSRobert Watson COUNTER_DECL(syncache_destroy_label);
1999eb320b0eSRobert Watson static void
test_syncache_destroy_label(struct label * label)2000eb320b0eSRobert Watson test_syncache_destroy_label(struct label *label)
2001eb320b0eSRobert Watson {
2002eb320b0eSRobert Watson 
2003eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SYNCACHE);
2004eb320b0eSRobert Watson 	COUNTER_INC(syncache_destroy_label);
2005eb320b0eSRobert Watson }
2006eb320b0eSRobert Watson 
2007eb320b0eSRobert Watson COUNTER_DECL(syncache_init_label);
2008eb320b0eSRobert Watson static int
test_syncache_init_label(struct label * label,int flag)2009eb320b0eSRobert Watson test_syncache_init_label(struct label *label, int flag)
2010eb320b0eSRobert Watson {
2011eb320b0eSRobert Watson 
2012eb320b0eSRobert Watson 	if (flag & M_WAITOK)
2013eb320b0eSRobert Watson 		WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
2014eb320b0eSRobert Watson 		    "test_syncache_init_label() at %s:%d", __FILE__,
2015eb320b0eSRobert Watson 		    __LINE__);
2016eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SYNCACHE);
2017eb320b0eSRobert Watson 	COUNTER_INC(syncache_init_label);
2018eb320b0eSRobert Watson 	return (0);
2019eb320b0eSRobert Watson }
2020eb320b0eSRobert Watson 
202130d239bcSRobert Watson COUNTER_DECL(system_check_acct);
2022ca26e8baSRobert Watson static int
test_system_check_acct(struct ucred * cred,struct vnode * vp,struct label * vplabel)20233f1a7a90SRobert Watson test_system_check_acct(struct ucred *cred, struct vnode *vp,
202478007886SRobert Watson     struct label *vplabel)
2025ca26e8baSRobert Watson {
2026ca26e8baSRobert Watson 
20276827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
202878007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
202930d239bcSRobert Watson 	COUNTER_INC(system_check_acct);
203018717f69SRobert Watson 
203118717f69SRobert Watson 	return (0);
203218717f69SRobert Watson }
203318717f69SRobert Watson 
203430d239bcSRobert Watson COUNTER_DECL(system_check_audit);
203518717f69SRobert Watson static int
test_system_check_audit(struct ucred * cred,void * record,int length)20363f1a7a90SRobert Watson test_system_check_audit(struct ucred *cred, void *record, int length)
203718717f69SRobert Watson {
203818717f69SRobert Watson 
20396827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
204030d239bcSRobert Watson 	COUNTER_INC(system_check_audit);
204118717f69SRobert Watson 
204218717f69SRobert Watson 	return (0);
204318717f69SRobert Watson }
204418717f69SRobert Watson 
204530d239bcSRobert Watson COUNTER_DECL(system_check_auditctl);
204618717f69SRobert Watson static int
test_system_check_auditctl(struct ucred * cred,struct vnode * vp,struct label * vplabel)20473f1a7a90SRobert Watson test_system_check_auditctl(struct ucred *cred, struct vnode *vp,
204878007886SRobert Watson     struct label *vplabel)
204918717f69SRobert Watson {
205018717f69SRobert Watson 
20516827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
205278007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
205330d239bcSRobert Watson 	COUNTER_INC(system_check_auditctl);
205418717f69SRobert Watson 
205518717f69SRobert Watson 	return (0);
205618717f69SRobert Watson }
205718717f69SRobert Watson 
205830d239bcSRobert Watson COUNTER_DECL(system_check_auditon);
205918717f69SRobert Watson static int
test_system_check_auditon(struct ucred * cred,int cmd)20603f1a7a90SRobert Watson test_system_check_auditon(struct ucred *cred, int cmd)
206118717f69SRobert Watson {
206218717f69SRobert Watson 
20636827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
206430d239bcSRobert Watson 	COUNTER_INC(system_check_auditon);
2065250ee706SRobert Watson 
2066ca26e8baSRobert Watson 	return (0);
2067ca26e8baSRobert Watson }
2068ca26e8baSRobert Watson 
206930d239bcSRobert Watson COUNTER_DECL(system_check_reboot);
2070ca26e8baSRobert Watson static int
test_system_check_reboot(struct ucred * cred,int how)20713f1a7a90SRobert Watson test_system_check_reboot(struct ucred *cred, int how)
2072ca26e8baSRobert Watson {
2073ca26e8baSRobert Watson 
20746827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
207530d239bcSRobert Watson 	COUNTER_INC(system_check_reboot);
2076250ee706SRobert Watson 
2077ca26e8baSRobert Watson 	return (0);
2078ca26e8baSRobert Watson }
2079ca26e8baSRobert Watson 
208030d239bcSRobert Watson COUNTER_DECL(system_check_swapoff);
2081ca26e8baSRobert Watson static int
test_system_check_swapoff(struct ucred * cred,struct vnode * vp,struct label * vplabel)20823f1a7a90SRobert Watson test_system_check_swapoff(struct ucred *cred, struct vnode *vp,
208378007886SRobert Watson     struct label *vplabel)
2084ca26e8baSRobert Watson {
2085ca26e8baSRobert Watson 
20866827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
208778007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
208830d239bcSRobert Watson 	COUNTER_INC(system_check_swapoff);
2089250ee706SRobert Watson 
2090ca26e8baSRobert Watson 	return (0);
2091ca26e8baSRobert Watson }
2092ca26e8baSRobert Watson 
209330d239bcSRobert Watson COUNTER_DECL(system_check_swapon);
2094ca26e8baSRobert Watson static int
test_system_check_swapon(struct ucred * cred,struct vnode * vp,struct label * vplabel)20953f1a7a90SRobert Watson test_system_check_swapon(struct ucred *cred, struct vnode *vp,
209678007886SRobert Watson     struct label *vplabel)
2097ca26e8baSRobert Watson {
2098ca26e8baSRobert Watson 
20996827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
210078007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
210130d239bcSRobert Watson 	COUNTER_INC(system_check_swapon);
2102250ee706SRobert Watson 
2103ca26e8baSRobert Watson 	return (0);
2104ca26e8baSRobert Watson }
2105ca26e8baSRobert Watson 
210630d239bcSRobert Watson COUNTER_DECL(system_check_sysctl);
2107ca26e8baSRobert Watson static int
test_system_check_sysctl(struct ucred * cred,struct sysctl_oid * oidp,void * arg1,int arg2,struct sysctl_req * req)21083f1a7a90SRobert Watson test_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp,
210963dba32bSPawel Jakub Dawidek     void *arg1, int arg2, struct sysctl_req *req)
2110ca26e8baSRobert Watson {
2111ca26e8baSRobert Watson 
21126827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
211330d239bcSRobert Watson 	COUNTER_INC(system_check_sysctl);
2114250ee706SRobert Watson 
2115ca26e8baSRobert Watson 	return (0);
2116ca26e8baSRobert Watson }
2117ca26e8baSRobert Watson 
2118eb320b0eSRobert Watson COUNTER_DECL(sysvmsg_cleanup);
2119eb320b0eSRobert Watson static void
test_sysvmsg_cleanup(struct label * msglabel)2120eb320b0eSRobert Watson test_sysvmsg_cleanup(struct label *msglabel)
2121eb320b0eSRobert Watson {
2122eb320b0eSRobert Watson 
2123eb320b0eSRobert Watson 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2124eb320b0eSRobert Watson 	COUNTER_INC(sysvmsg_cleanup);
2125eb320b0eSRobert Watson }
2126eb320b0eSRobert Watson 
2127eb320b0eSRobert Watson COUNTER_DECL(sysvmsg_create);
2128eb320b0eSRobert Watson static void
test_sysvmsg_create(struct ucred * cred,struct msqid_kernel * msqkptr,struct label * msqlabel,struct msg * msgptr,struct label * msglabel)2129eb320b0eSRobert Watson test_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr,
2130eb320b0eSRobert Watson     struct label *msqlabel, struct msg *msgptr, struct label *msglabel)
2131eb320b0eSRobert Watson {
2132eb320b0eSRobert Watson 
2133eb320b0eSRobert Watson 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2134eb320b0eSRobert Watson 	LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ);
2135eb320b0eSRobert Watson 	COUNTER_INC(sysvmsg_create);
2136eb320b0eSRobert Watson }
2137eb320b0eSRobert Watson 
2138eb320b0eSRobert Watson COUNTER_DECL(sysvmsg_destroy_label);
2139eb320b0eSRobert Watson static void
test_sysvmsg_destroy_label(struct label * label)2140eb320b0eSRobert Watson test_sysvmsg_destroy_label(struct label *label)
2141eb320b0eSRobert Watson {
2142eb320b0eSRobert Watson 
2143eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SYSV_MSG);
2144eb320b0eSRobert Watson 	COUNTER_INC(sysvmsg_destroy_label);
2145eb320b0eSRobert Watson }
2146eb320b0eSRobert Watson 
2147eb320b0eSRobert Watson COUNTER_DECL(sysvmsg_init_label);
2148eb320b0eSRobert Watson static void
test_sysvmsg_init_label(struct label * label)2149eb320b0eSRobert Watson test_sysvmsg_init_label(struct label *label)
2150eb320b0eSRobert Watson {
2151eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SYSV_MSG);
2152eb320b0eSRobert Watson 	COUNTER_INC(sysvmsg_init_label);
2153eb320b0eSRobert Watson }
2154eb320b0eSRobert Watson 
2155eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msgmsq);
2156eb320b0eSRobert Watson static int
test_sysvmsq_check_msgmsq(struct ucred * cred,struct msg * msgptr,struct label * msglabel,struct msqid_kernel * msqkptr,struct label * msqklabel)2157eb320b0eSRobert Watson test_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr,
2158eb320b0eSRobert Watson     struct label *msglabel, struct msqid_kernel *msqkptr,
2159eb320b0eSRobert Watson     struct label *msqklabel)
2160eb320b0eSRobert Watson {
2161eb320b0eSRobert Watson 
2162eb320b0eSRobert Watson 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2163eb320b0eSRobert Watson 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2164eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2165eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msgmsq);
2166eb320b0eSRobert Watson 
2167eb320b0eSRobert Watson   	return (0);
2168eb320b0eSRobert Watson }
2169eb320b0eSRobert Watson 
2170eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msgrcv);
2171eb320b0eSRobert Watson static int
test_sysvmsq_check_msgrcv(struct ucred * cred,struct msg * msgptr,struct label * msglabel)2172eb320b0eSRobert Watson test_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr,
2173eb320b0eSRobert Watson     struct label *msglabel)
2174eb320b0eSRobert Watson {
2175eb320b0eSRobert Watson 
2176eb320b0eSRobert Watson 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2177eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2178eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msgrcv);
2179eb320b0eSRobert Watson 
2180eb320b0eSRobert Watson 	return (0);
2181eb320b0eSRobert Watson }
2182eb320b0eSRobert Watson 
2183eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msgrmid);
2184eb320b0eSRobert Watson static int
test_sysvmsq_check_msgrmid(struct ucred * cred,struct msg * msgptr,struct label * msglabel)2185eb320b0eSRobert Watson test_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr,
2186eb320b0eSRobert Watson     struct label *msglabel)
2187eb320b0eSRobert Watson {
2188eb320b0eSRobert Watson 
2189eb320b0eSRobert Watson 	LABEL_CHECK(msglabel, MAGIC_SYSV_MSG);
2190eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2191eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msgrmid);
2192eb320b0eSRobert Watson 
2193eb320b0eSRobert Watson 	return (0);
2194eb320b0eSRobert Watson }
2195eb320b0eSRobert Watson 
2196eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msqget);
2197eb320b0eSRobert Watson static int
test_sysvmsq_check_msqget(struct ucred * cred,struct msqid_kernel * msqkptr,struct label * msqklabel)2198eb320b0eSRobert Watson test_sysvmsq_check_msqget(struct ucred *cred,
2199eb320b0eSRobert Watson     struct msqid_kernel *msqkptr, struct label *msqklabel)
2200eb320b0eSRobert Watson {
2201eb320b0eSRobert Watson 
2202eb320b0eSRobert Watson 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2203eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2204eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msqget);
2205eb320b0eSRobert Watson 
2206eb320b0eSRobert Watson 	return (0);
2207eb320b0eSRobert Watson }
2208eb320b0eSRobert Watson 
2209eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msqsnd);
2210eb320b0eSRobert Watson static int
test_sysvmsq_check_msqsnd(struct ucred * cred,struct msqid_kernel * msqkptr,struct label * msqklabel)2211eb320b0eSRobert Watson test_sysvmsq_check_msqsnd(struct ucred *cred,
2212eb320b0eSRobert Watson     struct msqid_kernel *msqkptr, struct label *msqklabel)
2213eb320b0eSRobert Watson {
2214eb320b0eSRobert Watson 
2215eb320b0eSRobert Watson 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2216eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2217eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msqsnd);
2218eb320b0eSRobert Watson 
2219eb320b0eSRobert Watson 	return (0);
2220eb320b0eSRobert Watson }
2221eb320b0eSRobert Watson 
2222eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msqrcv);
2223eb320b0eSRobert Watson static int
test_sysvmsq_check_msqrcv(struct ucred * cred,struct msqid_kernel * msqkptr,struct label * msqklabel)2224eb320b0eSRobert Watson test_sysvmsq_check_msqrcv(struct ucred *cred,
2225eb320b0eSRobert Watson     struct msqid_kernel *msqkptr, struct label *msqklabel)
2226eb320b0eSRobert Watson {
2227eb320b0eSRobert Watson 
2228eb320b0eSRobert Watson 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2229eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2230eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msqrcv);
2231eb320b0eSRobert Watson 
2232eb320b0eSRobert Watson 	return (0);
2233eb320b0eSRobert Watson }
2234eb320b0eSRobert Watson 
2235eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_check_msqctl);
2236eb320b0eSRobert Watson static int
test_sysvmsq_check_msqctl(struct ucred * cred,struct msqid_kernel * msqkptr,struct label * msqklabel,int cmd)2237eb320b0eSRobert Watson test_sysvmsq_check_msqctl(struct ucred *cred,
2238eb320b0eSRobert Watson     struct msqid_kernel *msqkptr, struct label *msqklabel, int cmd)
2239eb320b0eSRobert Watson {
2240eb320b0eSRobert Watson 
2241eb320b0eSRobert Watson 	LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ);
2242eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2243eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_check_msqctl);
2244eb320b0eSRobert Watson 
2245eb320b0eSRobert Watson 	return (0);
2246eb320b0eSRobert Watson }
2247eb320b0eSRobert Watson 
2248eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_cleanup);
2249eb320b0eSRobert Watson static void
test_sysvmsq_cleanup(struct label * msqlabel)2250eb320b0eSRobert Watson test_sysvmsq_cleanup(struct label *msqlabel)
2251eb320b0eSRobert Watson {
2252eb320b0eSRobert Watson 
2253eb320b0eSRobert Watson 	LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ);
2254eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_cleanup);
2255eb320b0eSRobert Watson }
2256eb320b0eSRobert Watson 
2257eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_create);
2258eb320b0eSRobert Watson static void
test_sysvmsq_create(struct ucred * cred,struct msqid_kernel * msqkptr,struct label * msqlabel)2259eb320b0eSRobert Watson test_sysvmsq_create(struct ucred *cred,
2260eb320b0eSRobert Watson     struct msqid_kernel *msqkptr, struct label *msqlabel)
2261eb320b0eSRobert Watson {
2262eb320b0eSRobert Watson 
2263eb320b0eSRobert Watson 	LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ);
2264eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_create);
2265eb320b0eSRobert Watson }
2266eb320b0eSRobert Watson 
2267eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_destroy_label);
2268eb320b0eSRobert Watson static void
test_sysvmsq_destroy_label(struct label * label)2269eb320b0eSRobert Watson test_sysvmsq_destroy_label(struct label *label)
2270eb320b0eSRobert Watson {
2271eb320b0eSRobert Watson 
2272eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SYSV_MSQ);
2273eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_destroy_label);
2274eb320b0eSRobert Watson }
2275eb320b0eSRobert Watson 
2276eb320b0eSRobert Watson COUNTER_DECL(sysvmsq_init_label);
2277eb320b0eSRobert Watson static void
test_sysvmsq_init_label(struct label * label)2278eb320b0eSRobert Watson test_sysvmsq_init_label(struct label *label)
2279eb320b0eSRobert Watson {
2280eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SYSV_MSQ);
2281eb320b0eSRobert Watson 	COUNTER_INC(sysvmsq_init_label);
2282eb320b0eSRobert Watson }
2283eb320b0eSRobert Watson 
2284eb320b0eSRobert Watson COUNTER_DECL(sysvsem_check_semctl);
2285eb320b0eSRobert Watson static int
test_sysvsem_check_semctl(struct ucred * cred,struct semid_kernel * semakptr,struct label * semaklabel,int cmd)2286eb320b0eSRobert Watson test_sysvsem_check_semctl(struct ucred *cred,
2287eb320b0eSRobert Watson     struct semid_kernel *semakptr, struct label *semaklabel, int cmd)
2288eb320b0eSRobert Watson {
2289eb320b0eSRobert Watson 
2290eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2291eb320b0eSRobert Watson 	LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM);
2292eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_check_semctl);
2293eb320b0eSRobert Watson 
2294eb320b0eSRobert Watson   	return (0);
2295eb320b0eSRobert Watson }
2296eb320b0eSRobert Watson 
2297eb320b0eSRobert Watson COUNTER_DECL(sysvsem_check_semget);
2298eb320b0eSRobert Watson static int
test_sysvsem_check_semget(struct ucred * cred,struct semid_kernel * semakptr,struct label * semaklabel)2299eb320b0eSRobert Watson test_sysvsem_check_semget(struct ucred *cred,
2300eb320b0eSRobert Watson     struct semid_kernel *semakptr, struct label *semaklabel)
2301eb320b0eSRobert Watson {
2302eb320b0eSRobert Watson 
2303eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2304eb320b0eSRobert Watson 	LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM);
2305eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_check_semget);
2306eb320b0eSRobert Watson 
2307eb320b0eSRobert Watson 	return (0);
2308eb320b0eSRobert Watson }
2309eb320b0eSRobert Watson 
2310eb320b0eSRobert Watson COUNTER_DECL(sysvsem_check_semop);
2311eb320b0eSRobert Watson static int
test_sysvsem_check_semop(struct ucred * cred,struct semid_kernel * semakptr,struct label * semaklabel,size_t accesstype)2312eb320b0eSRobert Watson test_sysvsem_check_semop(struct ucred *cred,
2313eb320b0eSRobert Watson     struct semid_kernel *semakptr, struct label *semaklabel, size_t accesstype)
2314eb320b0eSRobert Watson {
2315eb320b0eSRobert Watson 
2316eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2317eb320b0eSRobert Watson 	LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM);
2318eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_check_semop);
2319eb320b0eSRobert Watson 
2320eb320b0eSRobert Watson 	return (0);
2321eb320b0eSRobert Watson }
2322eb320b0eSRobert Watson 
2323eb320b0eSRobert Watson COUNTER_DECL(sysvsem_cleanup);
2324eb320b0eSRobert Watson static void
test_sysvsem_cleanup(struct label * semalabel)2325eb320b0eSRobert Watson test_sysvsem_cleanup(struct label *semalabel)
2326eb320b0eSRobert Watson {
2327eb320b0eSRobert Watson 
2328eb320b0eSRobert Watson 	LABEL_CHECK(semalabel, MAGIC_SYSV_SEM);
2329eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_cleanup);
2330eb320b0eSRobert Watson }
2331eb320b0eSRobert Watson 
2332eb320b0eSRobert Watson COUNTER_DECL(sysvsem_create);
2333eb320b0eSRobert Watson static void
test_sysvsem_create(struct ucred * cred,struct semid_kernel * semakptr,struct label * semalabel)2334eb320b0eSRobert Watson test_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr,
2335eb320b0eSRobert Watson     struct label *semalabel)
2336eb320b0eSRobert Watson {
2337eb320b0eSRobert Watson 
2338eb320b0eSRobert Watson 	LABEL_CHECK(semalabel, MAGIC_SYSV_SEM);
2339eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_create);
2340eb320b0eSRobert Watson }
2341eb320b0eSRobert Watson 
2342eb320b0eSRobert Watson COUNTER_DECL(sysvsem_destroy_label);
2343eb320b0eSRobert Watson static void
test_sysvsem_destroy_label(struct label * label)2344eb320b0eSRobert Watson test_sysvsem_destroy_label(struct label *label)
2345eb320b0eSRobert Watson {
2346eb320b0eSRobert Watson 
2347eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SYSV_SEM);
2348eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_destroy_label);
2349eb320b0eSRobert Watson }
2350eb320b0eSRobert Watson 
2351eb320b0eSRobert Watson COUNTER_DECL(sysvsem_init_label);
2352eb320b0eSRobert Watson static void
test_sysvsem_init_label(struct label * label)2353eb320b0eSRobert Watson test_sysvsem_init_label(struct label *label)
2354eb320b0eSRobert Watson {
2355eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SYSV_SEM);
2356eb320b0eSRobert Watson 	COUNTER_INC(sysvsem_init_label);
2357eb320b0eSRobert Watson }
2358eb320b0eSRobert Watson 
2359eb320b0eSRobert Watson COUNTER_DECL(sysvshm_check_shmat);
2360eb320b0eSRobert Watson static int
test_sysvshm_check_shmat(struct ucred * cred,struct shmid_kernel * shmsegptr,struct label * shmseglabel,int shmflg)2361eb320b0eSRobert Watson test_sysvshm_check_shmat(struct ucred *cred,
2362eb320b0eSRobert Watson     struct shmid_kernel *shmsegptr, struct label *shmseglabel, int shmflg)
2363eb320b0eSRobert Watson {
2364eb320b0eSRobert Watson 
2365eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2366eb320b0eSRobert Watson 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2367eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_check_shmat);
2368eb320b0eSRobert Watson 
2369eb320b0eSRobert Watson   	return (0);
2370eb320b0eSRobert Watson }
2371eb320b0eSRobert Watson 
2372eb320b0eSRobert Watson COUNTER_DECL(sysvshm_check_shmctl);
2373eb320b0eSRobert Watson static int
test_sysvshm_check_shmctl(struct ucred * cred,struct shmid_kernel * shmsegptr,struct label * shmseglabel,int cmd)2374eb320b0eSRobert Watson test_sysvshm_check_shmctl(struct ucred *cred,
2375eb320b0eSRobert Watson     struct shmid_kernel *shmsegptr, struct label *shmseglabel, int cmd)
2376eb320b0eSRobert Watson {
2377eb320b0eSRobert Watson 
2378eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2379eb320b0eSRobert Watson 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2380eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_check_shmctl);
2381eb320b0eSRobert Watson 
2382eb320b0eSRobert Watson   	return (0);
2383eb320b0eSRobert Watson }
2384eb320b0eSRobert Watson 
2385eb320b0eSRobert Watson COUNTER_DECL(sysvshm_check_shmdt);
2386eb320b0eSRobert Watson static int
test_sysvshm_check_shmdt(struct ucred * cred,struct shmid_kernel * shmsegptr,struct label * shmseglabel)2387eb320b0eSRobert Watson test_sysvshm_check_shmdt(struct ucred *cred,
2388eb320b0eSRobert Watson     struct shmid_kernel *shmsegptr, struct label *shmseglabel)
2389eb320b0eSRobert Watson {
2390eb320b0eSRobert Watson 
2391eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2392eb320b0eSRobert Watson 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2393eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_check_shmdt);
2394eb320b0eSRobert Watson 
2395eb320b0eSRobert Watson 	return (0);
2396eb320b0eSRobert Watson }
2397eb320b0eSRobert Watson 
2398eb320b0eSRobert Watson COUNTER_DECL(sysvshm_check_shmget);
2399eb320b0eSRobert Watson static int
test_sysvshm_check_shmget(struct ucred * cred,struct shmid_kernel * shmsegptr,struct label * shmseglabel,int shmflg)2400eb320b0eSRobert Watson test_sysvshm_check_shmget(struct ucred *cred,
2401eb320b0eSRobert Watson     struct shmid_kernel *shmsegptr, struct label *shmseglabel, int shmflg)
2402eb320b0eSRobert Watson {
2403eb320b0eSRobert Watson 
2404eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2405eb320b0eSRobert Watson 	LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM);
2406eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_check_shmget);
2407eb320b0eSRobert Watson 
2408eb320b0eSRobert Watson 	return (0);
2409eb320b0eSRobert Watson }
2410eb320b0eSRobert Watson 
2411eb320b0eSRobert Watson COUNTER_DECL(sysvshm_cleanup);
2412eb320b0eSRobert Watson static void
test_sysvshm_cleanup(struct label * shmlabel)2413eb320b0eSRobert Watson test_sysvshm_cleanup(struct label *shmlabel)
2414eb320b0eSRobert Watson {
2415eb320b0eSRobert Watson 
2416eb320b0eSRobert Watson 	LABEL_CHECK(shmlabel, MAGIC_SYSV_SHM);
2417eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_cleanup);
2418eb320b0eSRobert Watson }
2419eb320b0eSRobert Watson 
2420eb320b0eSRobert Watson COUNTER_DECL(sysvshm_create);
2421eb320b0eSRobert Watson static void
test_sysvshm_create(struct ucred * cred,struct shmid_kernel * shmsegptr,struct label * shmlabel)2422eb320b0eSRobert Watson test_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr,
2423eb320b0eSRobert Watson     struct label *shmlabel)
2424eb320b0eSRobert Watson {
2425eb320b0eSRobert Watson 
2426eb320b0eSRobert Watson 	LABEL_CHECK(shmlabel, MAGIC_SYSV_SHM);
2427eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_create);
2428eb320b0eSRobert Watson }
2429eb320b0eSRobert Watson 
2430eb320b0eSRobert Watson COUNTER_DECL(sysvshm_destroy_label);
2431eb320b0eSRobert Watson static void
test_sysvshm_destroy_label(struct label * label)2432eb320b0eSRobert Watson test_sysvshm_destroy_label(struct label *label)
2433eb320b0eSRobert Watson {
2434eb320b0eSRobert Watson 
2435eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_SYSV_SHM);
2436eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_destroy_label);
2437eb320b0eSRobert Watson }
2438eb320b0eSRobert Watson 
2439eb320b0eSRobert Watson COUNTER_DECL(sysvshm_init_label);
2440eb320b0eSRobert Watson static void
test_sysvshm_init_label(struct label * label)2441eb320b0eSRobert Watson test_sysvshm_init_label(struct label *label)
2442eb320b0eSRobert Watson {
2443eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_SYSV_SHM);
2444eb320b0eSRobert Watson 	COUNTER_INC(sysvshm_init_label);
2445eb320b0eSRobert Watson }
2446eb320b0eSRobert Watson 
2447eb320b0eSRobert Watson COUNTER_DECL(thread_userret);
2448eb320b0eSRobert Watson static void
test_thread_userret(struct thread * td)2449eb320b0eSRobert Watson test_thread_userret(struct thread *td)
2450eb320b0eSRobert Watson {
2451eb320b0eSRobert Watson 
2452eb320b0eSRobert Watson 	COUNTER_INC(thread_userret);
2453eb320b0eSRobert Watson }
2454eb320b0eSRobert Watson 
2455eb320b0eSRobert Watson COUNTER_DECL(vnode_associate_extattr);
2456eb320b0eSRobert Watson static int
test_vnode_associate_extattr(struct mount * mp,struct label * mplabel,struct vnode * vp,struct label * vplabel)2457eb320b0eSRobert Watson test_vnode_associate_extattr(struct mount *mp, struct label *mplabel,
2458eb320b0eSRobert Watson     struct vnode *vp, struct label *vplabel)
2459eb320b0eSRobert Watson {
2460eb320b0eSRobert Watson 
2461eb320b0eSRobert Watson 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
2462eb320b0eSRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2463eb320b0eSRobert Watson 	COUNTER_INC(vnode_associate_extattr);
2464eb320b0eSRobert Watson 
2465eb320b0eSRobert Watson 	return (0);
2466eb320b0eSRobert Watson }
2467eb320b0eSRobert Watson 
2468eb320b0eSRobert Watson COUNTER_DECL(vnode_associate_singlelabel);
2469eb320b0eSRobert Watson static void
test_vnode_associate_singlelabel(struct mount * mp,struct label * mplabel,struct vnode * vp,struct label * vplabel)2470eb320b0eSRobert Watson test_vnode_associate_singlelabel(struct mount *mp, struct label *mplabel,
2471eb320b0eSRobert Watson     struct vnode *vp, struct label *vplabel)
2472eb320b0eSRobert Watson {
2473eb320b0eSRobert Watson 
2474eb320b0eSRobert Watson 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
2475eb320b0eSRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
2476eb320b0eSRobert Watson 	COUNTER_INC(vnode_associate_singlelabel);
2477eb320b0eSRobert Watson }
2478eb320b0eSRobert Watson 
247930d239bcSRobert Watson COUNTER_DECL(vnode_check_access);
2480ca26e8baSRobert Watson static int
test_vnode_check_access(struct ucred * cred,struct vnode * vp,struct label * vplabel,accmode_t accmode)24813f1a7a90SRobert Watson test_vnode_check_access(struct ucred *cred, struct vnode *vp,
248215bc6b2bSEdward Tomasz Napierala     struct label *vplabel, accmode_t accmode)
2483d8a7b7a3SRobert Watson {
2484d8a7b7a3SRobert Watson 
24856827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
248678007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
248730d239bcSRobert Watson 	COUNTER_INC(vnode_check_access);
2488250ee706SRobert Watson 
2489d8a7b7a3SRobert Watson 	return (0);
2490d8a7b7a3SRobert Watson }
2491d8a7b7a3SRobert Watson 
249230d239bcSRobert Watson COUNTER_DECL(vnode_check_chdir);
2493d8a7b7a3SRobert Watson static int
test_vnode_check_chdir(struct ucred * cred,struct vnode * dvp,struct label * dvplabel)24943f1a7a90SRobert Watson test_vnode_check_chdir(struct ucred *cred, struct vnode *dvp,
249578007886SRobert Watson     struct label *dvplabel)
2496d8a7b7a3SRobert Watson {
2497d8a7b7a3SRobert Watson 
24986827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
249978007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
250030d239bcSRobert Watson 	COUNTER_INC(vnode_check_chdir);
2501250ee706SRobert Watson 
2502d8a7b7a3SRobert Watson 	return (0);
2503d8a7b7a3SRobert Watson }
2504d8a7b7a3SRobert Watson 
250530d239bcSRobert Watson COUNTER_DECL(vnode_check_chroot);
2506d8a7b7a3SRobert Watson static int
test_vnode_check_chroot(struct ucred * cred,struct vnode * dvp,struct label * dvplabel)25073f1a7a90SRobert Watson test_vnode_check_chroot(struct ucred *cred, struct vnode *dvp,
250878007886SRobert Watson     struct label *dvplabel)
2509d8a7b7a3SRobert Watson {
2510d8a7b7a3SRobert Watson 
25116827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
251278007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
251330d239bcSRobert Watson 	COUNTER_INC(vnode_check_chroot);
2514250ee706SRobert Watson 
2515d8a7b7a3SRobert Watson 	return (0);
2516d8a7b7a3SRobert Watson }
2517d8a7b7a3SRobert Watson 
251830d239bcSRobert Watson COUNTER_DECL(vnode_check_create);
2519d8a7b7a3SRobert Watson static int
test_vnode_check_create(struct ucred * cred,struct vnode * dvp,struct label * dvplabel,struct componentname * cnp,struct vattr * vap)25203f1a7a90SRobert Watson test_vnode_check_create(struct ucred *cred, struct vnode *dvp,
252178007886SRobert Watson     struct label *dvplabel, struct componentname *cnp, struct vattr *vap)
2522d8a7b7a3SRobert Watson {
2523d8a7b7a3SRobert Watson 
25246827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
252578007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
252630d239bcSRobert Watson 	COUNTER_INC(vnode_check_create);
2527250ee706SRobert Watson 
2528d8a7b7a3SRobert Watson 	return (0);
2529d8a7b7a3SRobert Watson }
2530d8a7b7a3SRobert Watson 
253130d239bcSRobert Watson COUNTER_DECL(vnode_check_deleteacl);
2532d8a7b7a3SRobert Watson static int
test_vnode_check_deleteacl(struct ucred * cred,struct vnode * vp,struct label * vplabel,acl_type_t type)25333f1a7a90SRobert Watson test_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp,
253478007886SRobert Watson     struct label *vplabel, acl_type_t type)
2535d8a7b7a3SRobert Watson {
2536d8a7b7a3SRobert Watson 
25376827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
253878007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
253930d239bcSRobert Watson 	COUNTER_INC(vnode_check_deleteacl);
2540250ee706SRobert Watson 
2541250ee706SRobert Watson 	return (0);
2542250ee706SRobert Watson }
2543250ee706SRobert Watson 
254430d239bcSRobert Watson COUNTER_DECL(vnode_check_deleteextattr);
2545250ee706SRobert Watson static int
test_vnode_check_deleteextattr(struct ucred * cred,struct vnode * vp,struct label * vplabel,int attrnamespace,const char * name)25463f1a7a90SRobert Watson test_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp,
254778007886SRobert Watson     struct label *vplabel, int attrnamespace, const char *name)
2548250ee706SRobert Watson {
2549250ee706SRobert Watson 
25506827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
255178007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
255230d239bcSRobert Watson 	COUNTER_INC(vnode_check_deleteextattr);
2553250ee706SRobert Watson 
2554d8a7b7a3SRobert Watson 	return (0);
2555d8a7b7a3SRobert Watson }
2556d8a7b7a3SRobert Watson 
255730d239bcSRobert Watson COUNTER_DECL(vnode_check_exec);
2558d8a7b7a3SRobert Watson static int
test_vnode_check_exec(struct ucred * cred,struct vnode * vp,struct label * vplabel,struct image_params * imgp,struct label * execlabel)25593f1a7a90SRobert Watson test_vnode_check_exec(struct ucred *cred, struct vnode *vp,
256078007886SRobert Watson     struct label *vplabel, struct image_params *imgp,
2561ef5def59SRobert Watson     struct label *execlabel)
2562d8a7b7a3SRobert Watson {
2563d8a7b7a3SRobert Watson 
25646827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
256578007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
25666827d029SRobert Watson 	LABEL_CHECK(execlabel, MAGIC_CRED);
256730d239bcSRobert Watson 	COUNTER_INC(vnode_check_exec);
2568250ee706SRobert Watson 
2569d8a7b7a3SRobert Watson 	return (0);
2570d8a7b7a3SRobert Watson }
2571d8a7b7a3SRobert Watson 
257230d239bcSRobert Watson COUNTER_DECL(vnode_check_getacl);
2573d8a7b7a3SRobert Watson static int
test_vnode_check_getacl(struct ucred * cred,struct vnode * vp,struct label * vplabel,acl_type_t type)25743f1a7a90SRobert Watson test_vnode_check_getacl(struct ucred *cred, struct vnode *vp,
257578007886SRobert Watson     struct label *vplabel, acl_type_t type)
2576d8a7b7a3SRobert Watson {
2577d8a7b7a3SRobert Watson 
25786827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
257978007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
258030d239bcSRobert Watson 	COUNTER_INC(vnode_check_getacl);
2581250ee706SRobert Watson 
2582d8a7b7a3SRobert Watson 	return (0);
2583d8a7b7a3SRobert Watson }
2584d8a7b7a3SRobert Watson 
258530d239bcSRobert Watson COUNTER_DECL(vnode_check_getextattr);
2586d8a7b7a3SRobert Watson static int
test_vnode_check_getextattr(struct ucred * cred,struct vnode * vp,struct label * vplabel,int attrnamespace,const char * name)25873f1a7a90SRobert Watson test_vnode_check_getextattr(struct ucred *cred, struct vnode *vp,
2588fefd0ac8SRobert Watson     struct label *vplabel, int attrnamespace, const char *name)
2589d8a7b7a3SRobert Watson {
2590d8a7b7a3SRobert Watson 
25916827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
259278007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
259330d239bcSRobert Watson 	COUNTER_INC(vnode_check_getextattr);
2594250ee706SRobert Watson 
2595d8a7b7a3SRobert Watson 	return (0);
2596d8a7b7a3SRobert Watson }
2597d8a7b7a3SRobert Watson 
259830d239bcSRobert Watson COUNTER_DECL(vnode_check_link);
2599d8a7b7a3SRobert Watson static int
test_vnode_check_link(struct ucred * cred,struct vnode * dvp,struct label * dvplabel,struct vnode * vp,struct label * vplabel,struct componentname * cnp)26003f1a7a90SRobert Watson test_vnode_check_link(struct ucred *cred, struct vnode *dvp,
260178007886SRobert Watson     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2602c27b50f5SRobert Watson     struct componentname *cnp)
2603c27b50f5SRobert Watson {
2604c27b50f5SRobert Watson 
26056827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
260678007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
260778007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
260830d239bcSRobert Watson 	COUNTER_INC(vnode_check_link);
2609250ee706SRobert Watson 
2610250ee706SRobert Watson 	return (0);
2611250ee706SRobert Watson }
2612250ee706SRobert Watson 
261330d239bcSRobert Watson COUNTER_DECL(vnode_check_listextattr);
2614250ee706SRobert Watson static int
test_vnode_check_listextattr(struct ucred * cred,struct vnode * vp,struct label * vplabel,int attrnamespace)26153f1a7a90SRobert Watson test_vnode_check_listextattr(struct ucred *cred, struct vnode *vp,
261678007886SRobert Watson     struct label *vplabel, int attrnamespace)
2617250ee706SRobert Watson {
2618250ee706SRobert Watson 
26196827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
262078007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
262130d239bcSRobert Watson 	COUNTER_INC(vnode_check_listextattr);
2622250ee706SRobert Watson 
2623c27b50f5SRobert Watson 	return (0);
2624c27b50f5SRobert Watson }
2625c27b50f5SRobert Watson 
262630d239bcSRobert Watson COUNTER_DECL(vnode_check_lookup);
2627c27b50f5SRobert Watson static int
test_vnode_check_lookup(struct ucred * cred,struct vnode * dvp,struct label * dvplabel,struct componentname * cnp)26283f1a7a90SRobert Watson test_vnode_check_lookup(struct ucred *cred, struct vnode *dvp,
262978007886SRobert Watson     struct label *dvplabel, struct componentname *cnp)
2630d8a7b7a3SRobert Watson {
2631d8a7b7a3SRobert Watson 
26326827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
263378007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
263430d239bcSRobert Watson 	COUNTER_INC(vnode_check_lookup);
2635250ee706SRobert Watson 
2636d8a7b7a3SRobert Watson 	return (0);
2637d8a7b7a3SRobert Watson }
2638d8a7b7a3SRobert Watson 
263930d239bcSRobert Watson COUNTER_DECL(vnode_check_mmap);
2640d8a7b7a3SRobert Watson static int
test_vnode_check_mmap(struct ucred * cred,struct vnode * vp,struct label * vplabel,int prot,int flags)26413f1a7a90SRobert Watson test_vnode_check_mmap(struct ucred *cred, struct vnode *vp,
264278007886SRobert Watson     struct label *vplabel, int prot, int flags)
2643e183f80eSRobert Watson {
2644e183f80eSRobert Watson 
26456827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
264678007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
264730d239bcSRobert Watson 	COUNTER_INC(vnode_check_mmap);
2648250ee706SRobert Watson 
2649e183f80eSRobert Watson 	return (0);
2650e183f80eSRobert Watson }
2651e183f80eSRobert Watson 
265230d239bcSRobert Watson COUNTER_DECL(vnode_check_open);
2653e183f80eSRobert Watson static int
test_vnode_check_open(struct ucred * cred,struct vnode * vp,struct label * vplabel,accmode_t accmode)26543f1a7a90SRobert Watson test_vnode_check_open(struct ucred *cred, struct vnode *vp,
265515bc6b2bSEdward Tomasz Napierala     struct label *vplabel, accmode_t accmode)
2656d8a7b7a3SRobert Watson {
2657d8a7b7a3SRobert Watson 
26586827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
265978007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
266030d239bcSRobert Watson 	COUNTER_INC(vnode_check_open);
2661250ee706SRobert Watson 
2662d8a7b7a3SRobert Watson 	return (0);
2663d8a7b7a3SRobert Watson }
2664d8a7b7a3SRobert Watson 
266530d239bcSRobert Watson COUNTER_DECL(vnode_check_poll);
2666d8a7b7a3SRobert Watson static int
test_vnode_check_poll(struct ucred * active_cred,struct ucred * file_cred,struct vnode * vp,struct label * vplabel)26673f1a7a90SRobert Watson test_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred,
266878007886SRobert Watson     struct vnode *vp, struct label *vplabel)
26697f724f8bSRobert Watson {
26707f724f8bSRobert Watson 
26716827d029SRobert Watson 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
26726827d029SRobert Watson 	if (file_cred != NULL)
26736827d029SRobert Watson 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
267478007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
267530d239bcSRobert Watson 	COUNTER_INC(vnode_check_poll);
2676250ee706SRobert Watson 
26777f724f8bSRobert Watson 	return (0);
26787f724f8bSRobert Watson }
26797f724f8bSRobert Watson 
268030d239bcSRobert Watson COUNTER_DECL(vnode_check_read);
26817f724f8bSRobert Watson static int
test_vnode_check_read(struct ucred * active_cred,struct ucred * file_cred,struct vnode * vp,struct label * vplabel)26823f1a7a90SRobert Watson test_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred,
268378007886SRobert Watson     struct vnode *vp, struct label *vplabel)
26847f724f8bSRobert Watson {
26857f724f8bSRobert Watson 
26866827d029SRobert Watson 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
26876827d029SRobert Watson 	if (file_cred != NULL)
26886827d029SRobert Watson 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
268978007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
269030d239bcSRobert Watson 	COUNTER_INC(vnode_check_read);
2691250ee706SRobert Watson 
26927f724f8bSRobert Watson 	return (0);
26937f724f8bSRobert Watson }
26947f724f8bSRobert Watson 
269530d239bcSRobert Watson COUNTER_DECL(vnode_check_readdir);
26967f724f8bSRobert Watson static int
test_vnode_check_readdir(struct ucred * cred,struct vnode * dvp,struct label * dvplabel)26973f1a7a90SRobert Watson test_vnode_check_readdir(struct ucred *cred, struct vnode *dvp,
269878007886SRobert Watson     struct label *dvplabel)
2699d8a7b7a3SRobert Watson {
2700d8a7b7a3SRobert Watson 
27016827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
270278007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
270330d239bcSRobert Watson 	COUNTER_INC(vnode_check_readdir);
2704250ee706SRobert Watson 
2705d8a7b7a3SRobert Watson 	return (0);
2706d8a7b7a3SRobert Watson }
2707d8a7b7a3SRobert Watson 
270830d239bcSRobert Watson COUNTER_DECL(vnode_check_readlink);
2709d8a7b7a3SRobert Watson static int
test_vnode_check_readlink(struct ucred * cred,struct vnode * vp,struct label * vplabel)27103f1a7a90SRobert Watson test_vnode_check_readlink(struct ucred *cred, struct vnode *vp,
271178007886SRobert Watson     struct label *vplabel)
2712d8a7b7a3SRobert Watson {
2713d8a7b7a3SRobert Watson 
27146827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
271578007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
271630d239bcSRobert Watson 	COUNTER_INC(vnode_check_readlink);
2717250ee706SRobert Watson 
2718d8a7b7a3SRobert Watson 	return (0);
2719d8a7b7a3SRobert Watson }
2720d8a7b7a3SRobert Watson 
272130d239bcSRobert Watson COUNTER_DECL(vnode_check_relabel);
2722d8a7b7a3SRobert Watson static int
test_vnode_check_relabel(struct ucred * cred,struct vnode * vp,struct label * vplabel,struct label * newlabel)27233f1a7a90SRobert Watson test_vnode_check_relabel(struct ucred *cred, struct vnode *vp,
272478007886SRobert Watson     struct label *vplabel, struct label *newlabel)
2725d8a7b7a3SRobert Watson {
2726d8a7b7a3SRobert Watson 
27276827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
272878007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
27296827d029SRobert Watson 	LABEL_CHECK(newlabel, MAGIC_VNODE);
273030d239bcSRobert Watson 	COUNTER_INC(vnode_check_relabel);
2731250ee706SRobert Watson 
2732d8a7b7a3SRobert Watson 	return (0);
2733d8a7b7a3SRobert Watson }
2734d8a7b7a3SRobert Watson 
273530d239bcSRobert Watson COUNTER_DECL(vnode_check_rename_from);
2736d8a7b7a3SRobert Watson static int
test_vnode_check_rename_from(struct ucred * cred,struct vnode * dvp,struct label * dvplabel,struct vnode * vp,struct label * vplabel,struct componentname * cnp)27373f1a7a90SRobert Watson test_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp,
273878007886SRobert Watson     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
2739d8a7b7a3SRobert Watson     struct componentname *cnp)
2740d8a7b7a3SRobert Watson {
2741d8a7b7a3SRobert Watson 
27426827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
274378007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
274478007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
274530d239bcSRobert Watson 	COUNTER_INC(vnode_check_rename_from);
2746250ee706SRobert Watson 
2747d8a7b7a3SRobert Watson 	return (0);
2748d8a7b7a3SRobert Watson }
2749d8a7b7a3SRobert Watson 
275030d239bcSRobert Watson COUNTER_DECL(vnode_check_rename_to);
2751d8a7b7a3SRobert Watson static int
test_vnode_check_rename_to(struct ucred * cred,struct vnode * dvp,struct label * dvplabel,struct vnode * vp,struct label * vplabel,int samedir,struct componentname * cnp)27523f1a7a90SRobert Watson test_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp,
275378007886SRobert Watson     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
275478007886SRobert Watson     int samedir, struct componentname *cnp)
2755d8a7b7a3SRobert Watson {
2756d8a7b7a3SRobert Watson 
27576827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
275878007886SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
275978007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
276030d239bcSRobert Watson 	COUNTER_INC(vnode_check_rename_to);
2761250ee706SRobert Watson 
2762d8a7b7a3SRobert Watson 	return (0);
2763d8a7b7a3SRobert Watson }
2764d8a7b7a3SRobert Watson 
276530d239bcSRobert Watson COUNTER_DECL(vnode_check_revoke);
2766d8a7b7a3SRobert Watson static int
test_vnode_check_revoke(struct ucred * cred,struct vnode * vp,struct label * vplabel)27673f1a7a90SRobert Watson test_vnode_check_revoke(struct ucred *cred, struct vnode *vp,
276878007886SRobert Watson     struct label *vplabel)
2769d8a7b7a3SRobert Watson {
2770d8a7b7a3SRobert Watson 
27716827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
277278007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
277330d239bcSRobert Watson 	COUNTER_INC(vnode_check_revoke);
2774250ee706SRobert Watson 
2775d8a7b7a3SRobert Watson 	return (0);
2776d8a7b7a3SRobert Watson }
2777d8a7b7a3SRobert Watson 
277830d239bcSRobert Watson COUNTER_DECL(vnode_check_setacl);
2779d8a7b7a3SRobert Watson static int
test_vnode_check_setacl(struct ucred * cred,struct vnode * vp,struct label * vplabel,acl_type_t type,struct acl * acl)27803f1a7a90SRobert Watson test_vnode_check_setacl(struct ucred *cred, struct vnode *vp,
278178007886SRobert Watson     struct label *vplabel, acl_type_t type, struct acl *acl)
2782d8a7b7a3SRobert Watson {
2783d8a7b7a3SRobert Watson 
27846827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
278578007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
278630d239bcSRobert Watson 	COUNTER_INC(vnode_check_setacl);
2787250ee706SRobert Watson 
2788d8a7b7a3SRobert Watson 	return (0);
2789d8a7b7a3SRobert Watson }
2790d8a7b7a3SRobert Watson 
279130d239bcSRobert Watson COUNTER_DECL(vnode_check_setextattr);
2792d8a7b7a3SRobert Watson static int
test_vnode_check_setextattr(struct ucred * cred,struct vnode * vp,struct label * vplabel,int attrnamespace,const char * name)27933f1a7a90SRobert Watson test_vnode_check_setextattr(struct ucred *cred, struct vnode *vp,
2794fefd0ac8SRobert Watson     struct label *vplabel, int attrnamespace, const char *name)
2795d8a7b7a3SRobert Watson {
2796d8a7b7a3SRobert Watson 
27976827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
279878007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
279930d239bcSRobert Watson 	COUNTER_INC(vnode_check_setextattr);
2800250ee706SRobert Watson 
2801d8a7b7a3SRobert Watson 	return (0);
2802d8a7b7a3SRobert Watson }
2803d8a7b7a3SRobert Watson 
280430d239bcSRobert Watson COUNTER_DECL(vnode_check_setflags);
2805d8a7b7a3SRobert Watson static int
test_vnode_check_setflags(struct ucred * cred,struct vnode * vp,struct label * vplabel,u_long flags)28063f1a7a90SRobert Watson test_vnode_check_setflags(struct ucred *cred, struct vnode *vp,
280778007886SRobert Watson     struct label *vplabel, u_long flags)
2808d8a7b7a3SRobert Watson {
2809d8a7b7a3SRobert Watson 
28106827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
281178007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
281230d239bcSRobert Watson 	COUNTER_INC(vnode_check_setflags);
2813250ee706SRobert Watson 
2814d8a7b7a3SRobert Watson 	return (0);
2815d8a7b7a3SRobert Watson }
2816d8a7b7a3SRobert Watson 
281730d239bcSRobert Watson COUNTER_DECL(vnode_check_setmode);
2818d8a7b7a3SRobert Watson static int
test_vnode_check_setmode(struct ucred * cred,struct vnode * vp,struct label * vplabel,mode_t mode)28193f1a7a90SRobert Watson test_vnode_check_setmode(struct ucred *cred, struct vnode *vp,
282078007886SRobert Watson     struct label *vplabel, mode_t mode)
2821d8a7b7a3SRobert Watson {
2822d8a7b7a3SRobert Watson 
28236827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
282478007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
282530d239bcSRobert Watson 	COUNTER_INC(vnode_check_setmode);
2826250ee706SRobert Watson 
2827d8a7b7a3SRobert Watson 	return (0);
2828d8a7b7a3SRobert Watson }
2829d8a7b7a3SRobert Watson 
283030d239bcSRobert Watson COUNTER_DECL(vnode_check_setowner);
2831d8a7b7a3SRobert Watson static int
test_vnode_check_setowner(struct ucred * cred,struct vnode * vp,struct label * vplabel,uid_t uid,gid_t gid)28323f1a7a90SRobert Watson test_vnode_check_setowner(struct ucred *cred, struct vnode *vp,
283378007886SRobert Watson     struct label *vplabel, uid_t uid, gid_t gid)
2834d8a7b7a3SRobert Watson {
2835d8a7b7a3SRobert Watson 
28366827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
283778007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
283830d239bcSRobert Watson 	COUNTER_INC(vnode_check_setowner);
2839250ee706SRobert Watson 
2840d8a7b7a3SRobert Watson 	return (0);
2841d8a7b7a3SRobert Watson }
2842d8a7b7a3SRobert Watson 
284330d239bcSRobert Watson COUNTER_DECL(vnode_check_setutimes);
2844d8a7b7a3SRobert Watson static int
test_vnode_check_setutimes(struct ucred * cred,struct vnode * vp,struct label * vplabel,struct timespec atime,struct timespec mtime)28453f1a7a90SRobert Watson test_vnode_check_setutimes(struct ucred *cred, struct vnode *vp,
284678007886SRobert Watson     struct label *vplabel, struct timespec atime, struct timespec mtime)
2847d8a7b7a3SRobert Watson {
2848d8a7b7a3SRobert Watson 
28496827d029SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
285078007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
285130d239bcSRobert Watson 	COUNTER_INC(vnode_check_setutimes);
2852250ee706SRobert Watson 
2853d8a7b7a3SRobert Watson 	return (0);
2854d8a7b7a3SRobert Watson }
2855d8a7b7a3SRobert Watson 
285630d239bcSRobert Watson COUNTER_DECL(vnode_check_stat);
2857d8a7b7a3SRobert Watson static int
test_vnode_check_stat(struct ucred * active_cred,struct ucred * file_cred,struct vnode * vp,struct label * vplabel)28583f1a7a90SRobert Watson test_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred,
285978007886SRobert Watson     struct vnode *vp, struct label *vplabel)
2860d8a7b7a3SRobert Watson {
2861d8a7b7a3SRobert Watson 
28626827d029SRobert Watson 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
28636827d029SRobert Watson 	if (file_cred != NULL)
28646827d029SRobert Watson 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
286578007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
286630d239bcSRobert Watson 	COUNTER_INC(vnode_check_stat);
2867250ee706SRobert Watson 
2868d8a7b7a3SRobert Watson 	return (0);
2869d8a7b7a3SRobert Watson }
2870d8a7b7a3SRobert Watson 
287130d239bcSRobert Watson COUNTER_DECL(vnode_check_unlink);
287245e0f3d6SRobert Watson static int
test_vnode_check_unlink(struct ucred * cred,struct vnode * dvp,struct label * dvplabel,struct vnode * vp,struct label * vplabel,struct componentname * cnp)28733f1a7a90SRobert Watson test_vnode_check_unlink(struct ucred *cred, struct vnode *dvp,
287445e0f3d6SRobert Watson     struct label *dvplabel, struct vnode *vp, struct label *vplabel,
287545e0f3d6SRobert Watson     struct componentname *cnp)
287645e0f3d6SRobert Watson {
287745e0f3d6SRobert Watson 
287845e0f3d6SRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
287945e0f3d6SRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
288045e0f3d6SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
288130d239bcSRobert Watson 	COUNTER_INC(vnode_check_unlink);
288245e0f3d6SRobert Watson 
288345e0f3d6SRobert Watson 	return (0);
288445e0f3d6SRobert Watson }
288545e0f3d6SRobert Watson 
288630d239bcSRobert Watson COUNTER_DECL(vnode_check_write);
28877f724f8bSRobert Watson static int
test_vnode_check_write(struct ucred * active_cred,struct ucred * file_cred,struct vnode * vp,struct label * vplabel)28883f1a7a90SRobert Watson test_vnode_check_write(struct ucred *active_cred,
288978007886SRobert Watson     struct ucred *file_cred, struct vnode *vp, struct label *vplabel)
28907f724f8bSRobert Watson {
28917f724f8bSRobert Watson 
28926827d029SRobert Watson 	LABEL_CHECK(active_cred->cr_label, MAGIC_CRED);
28936827d029SRobert Watson 	if (file_cred != NULL)
28946827d029SRobert Watson 		LABEL_CHECK(file_cred->cr_label, MAGIC_CRED);
289578007886SRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
289630d239bcSRobert Watson 	COUNTER_INC(vnode_check_write);
2897250ee706SRobert Watson 
28987f724f8bSRobert Watson 	return (0);
28997f724f8bSRobert Watson }
29007f724f8bSRobert Watson 
2901eb320b0eSRobert Watson COUNTER_DECL(vnode_copy_label);
2902eb320b0eSRobert Watson static void
test_vnode_copy_label(struct label * src,struct label * dest)2903eb320b0eSRobert Watson test_vnode_copy_label(struct label *src, struct label *dest)
2904eb320b0eSRobert Watson {
2905eb320b0eSRobert Watson 
2906eb320b0eSRobert Watson 	LABEL_CHECK(src, MAGIC_VNODE);
2907eb320b0eSRobert Watson 	LABEL_CHECK(dest, MAGIC_VNODE);
2908eb320b0eSRobert Watson 	COUNTER_INC(vnode_copy_label);
2909eb320b0eSRobert Watson }
2910eb320b0eSRobert Watson 
2911eb320b0eSRobert Watson COUNTER_DECL(vnode_create_extattr);
2912eb320b0eSRobert Watson static int
test_vnode_create_extattr(struct ucred * cred,struct mount * mp,struct label * mplabel,struct vnode * dvp,struct label * dvplabel,struct vnode * vp,struct label * vplabel,struct componentname * cnp)2913eb320b0eSRobert Watson test_vnode_create_extattr(struct ucred *cred, struct mount *mp,
2914eb320b0eSRobert Watson     struct label *mplabel, struct vnode *dvp, struct label *dvplabel,
2915eb320b0eSRobert Watson     struct vnode *vp, struct label *vplabel, struct componentname *cnp)
2916eb320b0eSRobert Watson {
2917eb320b0eSRobert Watson 
2918eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
2919eb320b0eSRobert Watson 	LABEL_CHECK(mplabel, MAGIC_MOUNT);
2920eb320b0eSRobert Watson 	LABEL_CHECK(dvplabel, MAGIC_VNODE);
2921eb320b0eSRobert Watson 	COUNTER_INC(vnode_create_extattr);
2922eb320b0eSRobert Watson 
2923eb320b0eSRobert Watson 	return (0);
2924eb320b0eSRobert Watson }
2925eb320b0eSRobert Watson 
2926eb320b0eSRobert Watson COUNTER_DECL(vnode_destroy_label);
2927eb320b0eSRobert Watson static void
test_vnode_destroy_label(struct label * label)2928eb320b0eSRobert Watson test_vnode_destroy_label(struct label *label)
2929eb320b0eSRobert Watson {
2930eb320b0eSRobert Watson 
2931eb320b0eSRobert Watson 	LABEL_DESTROY(label, MAGIC_VNODE);
2932eb320b0eSRobert Watson 	COUNTER_INC(vnode_destroy_label);
2933eb320b0eSRobert Watson }
2934eb320b0eSRobert Watson 
2935eb320b0eSRobert Watson COUNTER_DECL(vnode_execve_transition);
2936eb320b0eSRobert Watson static void
test_vnode_execve_transition(struct ucred * old,struct ucred * new,struct vnode * vp,struct label * filelabel,struct label * interpvplabel,struct image_params * imgp,struct label * execlabel)2937eb320b0eSRobert Watson test_vnode_execve_transition(struct ucred *old, struct ucred *new,
2938eb320b0eSRobert Watson     struct vnode *vp, struct label *filelabel,
2939eb320b0eSRobert Watson     struct label *interpvplabel, struct image_params *imgp,
2940eb320b0eSRobert Watson     struct label *execlabel)
2941eb320b0eSRobert Watson {
2942eb320b0eSRobert Watson 
2943eb320b0eSRobert Watson 	LABEL_CHECK(old->cr_label, MAGIC_CRED);
2944eb320b0eSRobert Watson 	LABEL_CHECK(new->cr_label, MAGIC_CRED);
2945eb320b0eSRobert Watson 	LABEL_CHECK(filelabel, MAGIC_VNODE);
2946eb320b0eSRobert Watson 	LABEL_CHECK(interpvplabel, MAGIC_VNODE);
2947eb320b0eSRobert Watson 	LABEL_CHECK(execlabel, MAGIC_CRED);
2948eb320b0eSRobert Watson 	COUNTER_INC(vnode_execve_transition);
2949eb320b0eSRobert Watson }
2950eb320b0eSRobert Watson 
2951eb320b0eSRobert Watson COUNTER_DECL(vnode_execve_will_transition);
2952eb320b0eSRobert Watson static int
test_vnode_execve_will_transition(struct ucred * old,struct vnode * vp,struct label * filelabel,struct label * interpvplabel,struct image_params * imgp,struct label * execlabel)2953eb320b0eSRobert Watson test_vnode_execve_will_transition(struct ucred *old, struct vnode *vp,
2954eb320b0eSRobert Watson     struct label *filelabel, struct label *interpvplabel,
2955eb320b0eSRobert Watson     struct image_params *imgp, struct label *execlabel)
2956eb320b0eSRobert Watson {
2957eb320b0eSRobert Watson 
2958eb320b0eSRobert Watson 	LABEL_CHECK(old->cr_label, MAGIC_CRED);
2959eb320b0eSRobert Watson 	LABEL_CHECK(filelabel, MAGIC_VNODE);
2960eb320b0eSRobert Watson 	LABEL_CHECK(interpvplabel, MAGIC_VNODE);
2961eb320b0eSRobert Watson 	LABEL_CHECK(execlabel, MAGIC_CRED);
2962eb320b0eSRobert Watson 	COUNTER_INC(vnode_execve_will_transition);
2963eb320b0eSRobert Watson 
2964eb320b0eSRobert Watson 	return (0);
2965eb320b0eSRobert Watson }
2966eb320b0eSRobert Watson 
2967eb320b0eSRobert Watson COUNTER_DECL(vnode_externalize_label);
2968eb320b0eSRobert Watson static int
test_vnode_externalize_label(struct label * label,char * element_name,struct sbuf * sb,int * claimed)2969eb320b0eSRobert Watson test_vnode_externalize_label(struct label *label, char *element_name,
2970eb320b0eSRobert Watson     struct sbuf *sb, int *claimed)
2971eb320b0eSRobert Watson {
2972eb320b0eSRobert Watson 
2973eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_VNODE);
2974eb320b0eSRobert Watson 	COUNTER_INC(vnode_externalize_label);
2975eb320b0eSRobert Watson 
2976eb320b0eSRobert Watson 	return (0);
2977eb320b0eSRobert Watson }
2978eb320b0eSRobert Watson 
2979eb320b0eSRobert Watson COUNTER_DECL(vnode_init_label);
2980eb320b0eSRobert Watson static void
test_vnode_init_label(struct label * label)2981eb320b0eSRobert Watson test_vnode_init_label(struct label *label)
2982eb320b0eSRobert Watson {
2983eb320b0eSRobert Watson 
2984eb320b0eSRobert Watson 	LABEL_INIT(label, MAGIC_VNODE);
2985eb320b0eSRobert Watson 	COUNTER_INC(vnode_init_label);
2986eb320b0eSRobert Watson }
2987eb320b0eSRobert Watson 
29881876fb21SRobert Watson COUNTER_DECL(vnode_internalize_label);
29891876fb21SRobert Watson static int
test_vnode_internalize_label(struct label * label,char * element_name,char * element_data,int * claimed)29901876fb21SRobert Watson test_vnode_internalize_label(struct label *label, char *element_name,
29911876fb21SRobert Watson     char *element_data, int *claimed)
29921876fb21SRobert Watson {
29931876fb21SRobert Watson 
29941876fb21SRobert Watson 	LABEL_CHECK(label, MAGIC_VNODE);
29951876fb21SRobert Watson 	COUNTER_INC(vnode_internalize_label);
29961876fb21SRobert Watson 
29971876fb21SRobert Watson 	return (0);
29981876fb21SRobert Watson }
29991876fb21SRobert Watson 
3000eb320b0eSRobert Watson COUNTER_DECL(vnode_relabel);
3001eb320b0eSRobert Watson static void
test_vnode_relabel(struct ucred * cred,struct vnode * vp,struct label * vplabel,struct label * label)3002eb320b0eSRobert Watson test_vnode_relabel(struct ucred *cred, struct vnode *vp,
3003eb320b0eSRobert Watson     struct label *vplabel, struct label *label)
3004eb320b0eSRobert Watson {
3005eb320b0eSRobert Watson 
3006eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3007eb320b0eSRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
3008eb320b0eSRobert Watson 	LABEL_CHECK(label, MAGIC_VNODE);
3009eb320b0eSRobert Watson 	COUNTER_INC(vnode_relabel);
3010eb320b0eSRobert Watson }
3011eb320b0eSRobert Watson 
3012eb320b0eSRobert Watson COUNTER_DECL(vnode_setlabel_extattr);
3013eb320b0eSRobert Watson static int
test_vnode_setlabel_extattr(struct ucred * cred,struct vnode * vp,struct label * vplabel,struct label * intlabel)3014eb320b0eSRobert Watson test_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp,
3015eb320b0eSRobert Watson     struct label *vplabel, struct label *intlabel)
3016eb320b0eSRobert Watson {
3017eb320b0eSRobert Watson 
3018eb320b0eSRobert Watson 	LABEL_CHECK(cred->cr_label, MAGIC_CRED);
3019eb320b0eSRobert Watson 	LABEL_CHECK(vplabel, MAGIC_VNODE);
3020eb320b0eSRobert Watson 	LABEL_CHECK(intlabel, MAGIC_VNODE);
3021eb320b0eSRobert Watson 	COUNTER_INC(vnode_setlabel_extattr);
3022eb320b0eSRobert Watson 
3023eb320b0eSRobert Watson 	return (0);
3024eb320b0eSRobert Watson }
3025eb320b0eSRobert Watson 
30263f1a7a90SRobert Watson static struct mac_policy_ops test_ops =
3027d8a7b7a3SRobert Watson {
3028eb320b0eSRobert Watson 	.mpo_bpfdesc_check_receive = test_bpfdesc_check_receive,
3029eb320b0eSRobert Watson 	.mpo_bpfdesc_create = test_bpfdesc_create,
3030eb320b0eSRobert Watson 	.mpo_bpfdesc_create_mbuf = test_bpfdesc_create_mbuf,
30313f1a7a90SRobert Watson 	.mpo_bpfdesc_destroy_label = test_bpfdesc_destroy_label,
3032eb320b0eSRobert Watson 	.mpo_bpfdesc_init_label = test_bpfdesc_init_label,
3033eb320b0eSRobert Watson 
3034eb320b0eSRobert Watson 	.mpo_cred_check_relabel = test_cred_check_relabel,
30356f6174a7SRobert Watson 	.mpo_cred_check_setaudit = test_cred_check_setaudit,
30366f6174a7SRobert Watson 	.mpo_cred_check_setaudit_addr = test_cred_check_setaudit_addr,
30376f6174a7SRobert Watson 	.mpo_cred_check_setauid = test_cred_check_setauid,
30386f6174a7SRobert Watson 	.mpo_cred_check_seteuid = test_cred_check_seteuid,
30396f6174a7SRobert Watson 	.mpo_cred_check_setegid = test_cred_check_setegid,
30406f6174a7SRobert Watson 	.mpo_cred_check_setgid = test_cred_check_setgid,
30416f6174a7SRobert Watson 	.mpo_cred_check_setgroups = test_cred_check_setgroups,
30426f6174a7SRobert Watson 	.mpo_cred_check_setregid = test_cred_check_setregid,
30436f6174a7SRobert Watson 	.mpo_cred_check_setresgid = test_cred_check_setresgid,
30446f6174a7SRobert Watson 	.mpo_cred_check_setresuid = test_cred_check_setresuid,
30456f6174a7SRobert Watson 	.mpo_cred_check_setreuid = test_cred_check_setreuid,
30466f6174a7SRobert Watson 	.mpo_cred_check_setuid = test_cred_check_setuid,
3047eb320b0eSRobert Watson 	.mpo_cred_check_visible = test_cred_check_visible,
30483f1a7a90SRobert Watson 	.mpo_cred_copy_label = test_cred_copy_label,
3049212ab0cfSRobert Watson 	.mpo_cred_create_init = test_cred_create_init,
3050212ab0cfSRobert Watson 	.mpo_cred_create_swapper = test_cred_create_swapper,
3051eb320b0eSRobert Watson 	.mpo_cred_destroy_label = test_cred_destroy_label,
3052b0f4c777SRobert Watson 	.mpo_cred_externalize_label = test_cred_externalize_label,
3053eb320b0eSRobert Watson 	.mpo_cred_init_label = test_cred_init_label,
30541876fb21SRobert Watson 	.mpo_cred_internalize_label = test_cred_internalize_label,
3055eb320b0eSRobert Watson 	.mpo_cred_relabel = test_cred_relabel,
3056eb320b0eSRobert Watson 
3057*2449b9e5SMitchell Horne 	.mpo_ddb_command_exec = test_ddb_command_exec,
3058*2449b9e5SMitchell Horne 	.mpo_ddb_command_register = test_ddb_command_register,
3059*2449b9e5SMitchell Horne 
30603f1a7a90SRobert Watson 	.mpo_devfs_create_device = test_devfs_create_device,
30613f1a7a90SRobert Watson 	.mpo_devfs_create_directory = test_devfs_create_directory,
30623f1a7a90SRobert Watson 	.mpo_devfs_create_symlink = test_devfs_create_symlink,
3063eb320b0eSRobert Watson 	.mpo_devfs_destroy_label = test_devfs_destroy_label,
3064eb320b0eSRobert Watson 	.mpo_devfs_init_label = test_devfs_init_label,
30653f1a7a90SRobert Watson 	.mpo_devfs_update = test_devfs_update,
3066eb320b0eSRobert Watson 	.mpo_devfs_vnode_associate = test_devfs_vnode_associate,
3067eb320b0eSRobert Watson 
30683f1a7a90SRobert Watson 	.mpo_ifnet_check_relabel = test_ifnet_check_relabel,
30693f1a7a90SRobert Watson 	.mpo_ifnet_check_transmit = test_ifnet_check_transmit,
3070eb320b0eSRobert Watson 	.mpo_ifnet_copy_label = test_ifnet_copy_label,
3071eb320b0eSRobert Watson 	.mpo_ifnet_create = test_ifnet_create,
3072eb320b0eSRobert Watson 	.mpo_ifnet_create_mbuf = test_ifnet_create_mbuf,
3073eb320b0eSRobert Watson 	.mpo_ifnet_destroy_label = test_ifnet_destroy_label,
3074eb320b0eSRobert Watson 	.mpo_ifnet_externalize_label = test_ifnet_externalize_label,
3075eb320b0eSRobert Watson 	.mpo_ifnet_init_label = test_ifnet_init_label,
30761876fb21SRobert Watson 	.mpo_ifnet_internalize_label = test_ifnet_internalize_label,
3077eb320b0eSRobert Watson 	.mpo_ifnet_relabel = test_ifnet_relabel,
3078eb320b0eSRobert Watson 
3079eb320b0eSRobert Watson 	.mpo_syncache_destroy_label = test_syncache_destroy_label,
3080eb320b0eSRobert Watson 	.mpo_syncache_init_label = test_syncache_init_label,
3081eb320b0eSRobert Watson 
3082eb320b0eSRobert Watson 	.mpo_sysvmsg_destroy_label = test_sysvmsg_destroy_label,
3083eb320b0eSRobert Watson 	.mpo_sysvmsg_init_label = test_sysvmsg_init_label,
3084eb320b0eSRobert Watson 
3085eb320b0eSRobert Watson 	.mpo_sysvmsq_destroy_label = test_sysvmsq_destroy_label,
3086eb320b0eSRobert Watson 	.mpo_sysvmsq_init_label = test_sysvmsq_init_label,
3087eb320b0eSRobert Watson 
3088eb320b0eSRobert Watson 	.mpo_sysvsem_destroy_label = test_sysvsem_destroy_label,
3089eb320b0eSRobert Watson 	.mpo_sysvsem_init_label = test_sysvsem_init_label,
3090eb320b0eSRobert Watson 
3091eb320b0eSRobert Watson 	.mpo_sysvshm_destroy_label = test_sysvshm_destroy_label,
3092eb320b0eSRobert Watson 	.mpo_sysvshm_init_label = test_sysvshm_init_label,
3093eb320b0eSRobert Watson 
30943f1a7a90SRobert Watson 	.mpo_inpcb_check_deliver = test_inpcb_check_deliver,
30957fb179baSBjoern A. Zeeb 	.mpo_inpcb_check_visible = test_inpcb_check_visible,
3096eb320b0eSRobert Watson 	.mpo_inpcb_create = test_inpcb_create,
3097eb320b0eSRobert Watson 	.mpo_inpcb_create_mbuf = test_inpcb_create_mbuf,
3098eb320b0eSRobert Watson 	.mpo_inpcb_destroy_label = test_inpcb_destroy_label,
3099eb320b0eSRobert Watson 	.mpo_inpcb_init_label = test_inpcb_init_label,
3100eb320b0eSRobert Watson 	.mpo_inpcb_sosetlabel = test_inpcb_sosetlabel,
3101eb320b0eSRobert Watson 
3102048e1287SRobert Watson 	.mpo_ip6q_create = test_ip6q_create,
3103048e1287SRobert Watson 	.mpo_ip6q_destroy_label = test_ip6q_destroy_label,
3104048e1287SRobert Watson 	.mpo_ip6q_init_label = test_ip6q_init_label,
3105048e1287SRobert Watson 	.mpo_ip6q_match = test_ip6q_match,
3106048e1287SRobert Watson 	.mpo_ip6q_reassemble = test_ip6q_reassemble,
3107048e1287SRobert Watson 	.mpo_ip6q_update = test_ip6q_update,
3108048e1287SRobert Watson 
3109eb320b0eSRobert Watson 	.mpo_ipq_create = test_ipq_create,
3110eb320b0eSRobert Watson 	.mpo_ipq_destroy_label = test_ipq_destroy_label,
3111eb320b0eSRobert Watson 	.mpo_ipq_init_label = test_ipq_init_label,
3112eb320b0eSRobert Watson 	.mpo_ipq_match = test_ipq_match,
3113eb320b0eSRobert Watson 	.mpo_ipq_reassemble = test_ipq_reassemble,
3114eb320b0eSRobert Watson 	.mpo_ipq_update = test_ipq_update,
3115eb320b0eSRobert Watson 
3116*2449b9e5SMitchell Horne 	.mpo_kdb_check_backend = test_kdb_check_backend,
3117*2449b9e5SMitchell Horne 
31183f1a7a90SRobert Watson 	.mpo_kenv_check_dump = test_kenv_check_dump,
31193f1a7a90SRobert Watson 	.mpo_kenv_check_get = test_kenv_check_get,
31203f1a7a90SRobert Watson 	.mpo_kenv_check_set = test_kenv_check_set,
31213f1a7a90SRobert Watson 	.mpo_kenv_check_unset = test_kenv_check_unset,
3122eb320b0eSRobert Watson 
31233f1a7a90SRobert Watson 	.mpo_kld_check_load = test_kld_check_load,
31243f1a7a90SRobert Watson 	.mpo_kld_check_stat = test_kld_check_stat,
3125eb320b0eSRobert Watson 
3126eb320b0eSRobert Watson 	.mpo_mbuf_copy_label = test_mbuf_copy_label,
3127eb320b0eSRobert Watson 	.mpo_mbuf_destroy_label = test_mbuf_destroy_label,
3128eb320b0eSRobert Watson 	.mpo_mbuf_init_label = test_mbuf_init_label,
3129eb320b0eSRobert Watson 
31303f1a7a90SRobert Watson 	.mpo_mount_check_stat = test_mount_check_stat,
3131eb320b0eSRobert Watson 	.mpo_mount_create = test_mount_create,
3132eb320b0eSRobert Watson 	.mpo_mount_destroy_label = test_mount_destroy_label,
3133eb320b0eSRobert Watson 	.mpo_mount_init_label = test_mount_init_label,
3134eb320b0eSRobert Watson 
3135eb320b0eSRobert Watson 	.mpo_netinet_arp_send = test_netinet_arp_send,
3136eb320b0eSRobert Watson 	.mpo_netinet_fragment = test_netinet_fragment,
3137eb320b0eSRobert Watson 	.mpo_netinet_icmp_reply = test_netinet_icmp_reply,
3138eb320b0eSRobert Watson 	.mpo_netinet_icmp_replyinplace = test_netinet_icmp_replyinplace,
3139eb320b0eSRobert Watson 	.mpo_netinet_igmp_send = test_netinet_igmp_send,
3140eb320b0eSRobert Watson 	.mpo_netinet_tcp_reply = test_netinet_tcp_reply,
3141eb320b0eSRobert Watson 
3142eb320b0eSRobert Watson 	.mpo_netinet6_nd6_send = test_netinet6_nd6_send,
3143eb320b0eSRobert Watson 
31443f1a7a90SRobert Watson 	.mpo_pipe_check_ioctl = test_pipe_check_ioctl,
31453f1a7a90SRobert Watson 	.mpo_pipe_check_poll = test_pipe_check_poll,
31463f1a7a90SRobert Watson 	.mpo_pipe_check_read = test_pipe_check_read,
31473f1a7a90SRobert Watson 	.mpo_pipe_check_relabel = test_pipe_check_relabel,
31483f1a7a90SRobert Watson 	.mpo_pipe_check_stat = test_pipe_check_stat,
31493f1a7a90SRobert Watson 	.mpo_pipe_check_write = test_pipe_check_write,
3150eb320b0eSRobert Watson 	.mpo_pipe_copy_label = test_pipe_copy_label,
3151eb320b0eSRobert Watson 	.mpo_pipe_create = test_pipe_create,
3152eb320b0eSRobert Watson 	.mpo_pipe_destroy_label = test_pipe_destroy_label,
3153eb320b0eSRobert Watson 	.mpo_pipe_externalize_label = test_pipe_externalize_label,
3154eb320b0eSRobert Watson 	.mpo_pipe_init_label = test_pipe_init_label,
31551876fb21SRobert Watson 	.mpo_pipe_internalize_label = test_pipe_internalize_label,
3156eb320b0eSRobert Watson 	.mpo_pipe_relabel = test_pipe_relabel,
3157eb320b0eSRobert Watson 
3158438aeadfSRobert Watson 	.mpo_posixsem_check_getvalue = test_posixsem_check_getvalue,
3159438aeadfSRobert Watson 	.mpo_posixsem_check_open = test_posixsem_check_open,
3160438aeadfSRobert Watson 	.mpo_posixsem_check_post = test_posixsem_check_post,
31619c00bb91SKonstantin Belousov 	.mpo_posixsem_check_setmode = test_posixsem_check_setmode,
31629c00bb91SKonstantin Belousov 	.mpo_posixsem_check_setowner = test_posixsem_check_setowner,
31636bc1e9cdSJohn Baldwin 	.mpo_posixsem_check_stat = test_posixsem_check_stat,
3164438aeadfSRobert Watson 	.mpo_posixsem_check_unlink = test_posixsem_check_unlink,
3165438aeadfSRobert Watson 	.mpo_posixsem_check_wait = test_posixsem_check_wait,
3166eb320b0eSRobert Watson 	.mpo_posixsem_create = test_posixsem_create,
3167eb320b0eSRobert Watson 	.mpo_posixsem_destroy_label = test_posixsem_destroy_label,
3168eb320b0eSRobert Watson 	.mpo_posixsem_init_label = test_posixsem_init_label,
3169eb320b0eSRobert Watson 
31709b6dd12eSRobert Watson 	.mpo_posixshm_check_create = test_posixshm_check_create,
31718e38aeffSJohn Baldwin 	.mpo_posixshm_check_mmap = test_posixshm_check_mmap,
31728e38aeffSJohn Baldwin 	.mpo_posixshm_check_open = test_posixshm_check_open,
3173940cb0e2SKonstantin Belousov 	.mpo_posixshm_check_read = test_posixshm_check_read,
31749c00bb91SKonstantin Belousov 	.mpo_posixshm_check_setmode = test_posixshm_check_setmode,
31759c00bb91SKonstantin Belousov 	.mpo_posixshm_check_setowner = test_posixshm_check_setowner,
31768e38aeffSJohn Baldwin 	.mpo_posixshm_check_stat = test_posixshm_check_stat,
31778e38aeffSJohn Baldwin 	.mpo_posixshm_check_truncate = test_posixshm_check_truncate,
31788e38aeffSJohn Baldwin 	.mpo_posixshm_check_unlink = test_posixshm_check_unlink,
3179940cb0e2SKonstantin Belousov 	.mpo_posixshm_check_write = test_posixshm_check_write,
31808e38aeffSJohn Baldwin 	.mpo_posixshm_create = test_posixshm_create,
31818e38aeffSJohn Baldwin 	.mpo_posixshm_destroy_label = test_posixshm_destroy_label,
31828e38aeffSJohn Baldwin 	.mpo_posixshm_init_label = test_posixshm_init_label,
31838e38aeffSJohn Baldwin 
31843f1a7a90SRobert Watson 	.mpo_proc_check_debug = test_proc_check_debug,
31853f1a7a90SRobert Watson 	.mpo_proc_check_sched = test_proc_check_sched,
31863f1a7a90SRobert Watson 	.mpo_proc_check_signal = test_proc_check_signal,
31873f1a7a90SRobert Watson 	.mpo_proc_check_wait = test_proc_check_wait,
3188eb320b0eSRobert Watson 	.mpo_proc_destroy_label = test_proc_destroy_label,
3189eb320b0eSRobert Watson 	.mpo_proc_init_label = test_proc_init_label,
3190eb320b0eSRobert Watson 
31913f1a7a90SRobert Watson 	.mpo_socket_check_accept = test_socket_check_accept,
31923f1a7a90SRobert Watson 	.mpo_socket_check_bind = test_socket_check_bind,
31933f1a7a90SRobert Watson 	.mpo_socket_check_connect = test_socket_check_connect,
31943f1a7a90SRobert Watson 	.mpo_socket_check_deliver = test_socket_check_deliver,
31953f1a7a90SRobert Watson 	.mpo_socket_check_listen = test_socket_check_listen,
31963f1a7a90SRobert Watson 	.mpo_socket_check_poll = test_socket_check_poll,
31973f1a7a90SRobert Watson 	.mpo_socket_check_receive = test_socket_check_receive,
31983f1a7a90SRobert Watson 	.mpo_socket_check_relabel = test_socket_check_relabel,
31993f1a7a90SRobert Watson 	.mpo_socket_check_send = test_socket_check_send,
32003f1a7a90SRobert Watson 	.mpo_socket_check_stat = test_socket_check_stat,
32013f1a7a90SRobert Watson 	.mpo_socket_check_visible = test_socket_check_visible,
3202eb320b0eSRobert Watson 	.mpo_socket_copy_label = test_socket_copy_label,
3203eb320b0eSRobert Watson 	.mpo_socket_create = test_socket_create,
3204eb320b0eSRobert Watson 	.mpo_socket_create_mbuf = test_socket_create_mbuf,
3205eb320b0eSRobert Watson 	.mpo_socket_destroy_label = test_socket_destroy_label,
3206eb320b0eSRobert Watson 	.mpo_socket_externalize_label = test_socket_externalize_label,
3207eb320b0eSRobert Watson 	.mpo_socket_init_label = test_socket_init_label,
32081876fb21SRobert Watson 	.mpo_socket_internalize_label = test_socket_internalize_label,
3209eb320b0eSRobert Watson 	.mpo_socket_newconn = test_socket_newconn,
3210eb320b0eSRobert Watson 	.mpo_socket_relabel = test_socket_relabel,
3211eb320b0eSRobert Watson 
3212eb320b0eSRobert Watson 	.mpo_socketpeer_destroy_label = test_socketpeer_destroy_label,
3213eb320b0eSRobert Watson 	.mpo_socketpeer_externalize_label = test_socketpeer_externalize_label,
3214eb320b0eSRobert Watson 	.mpo_socketpeer_init_label = test_socketpeer_init_label,
3215eb320b0eSRobert Watson 	.mpo_socketpeer_set_from_mbuf = test_socketpeer_set_from_mbuf,
3216eb320b0eSRobert Watson 	.mpo_socketpeer_set_from_socket = test_socketpeer_set_from_socket,
3217eb320b0eSRobert Watson 
3218eb320b0eSRobert Watson 	.mpo_syncache_create = test_syncache_create,
3219eb320b0eSRobert Watson 	.mpo_syncache_create_mbuf = test_syncache_create_mbuf,
3220eb320b0eSRobert Watson 
32213f1a7a90SRobert Watson 	.mpo_system_check_acct = test_system_check_acct,
32223f1a7a90SRobert Watson 	.mpo_system_check_audit = test_system_check_audit,
32233f1a7a90SRobert Watson 	.mpo_system_check_auditctl = test_system_check_auditctl,
32243f1a7a90SRobert Watson 	.mpo_system_check_auditon = test_system_check_auditon,
32253f1a7a90SRobert Watson 	.mpo_system_check_reboot = test_system_check_reboot,
32263f1a7a90SRobert Watson 	.mpo_system_check_swapoff = test_system_check_swapoff,
32273f1a7a90SRobert Watson 	.mpo_system_check_swapon = test_system_check_swapon,
32283f1a7a90SRobert Watson 	.mpo_system_check_sysctl = test_system_check_sysctl,
3229eb320b0eSRobert Watson 
32303f1a7a90SRobert Watson 	.mpo_vnode_check_access = test_vnode_check_access,
3231eb320b0eSRobert Watson 	.mpo_sysvmsg_cleanup = test_sysvmsg_cleanup,
3232eb320b0eSRobert Watson 	.mpo_sysvmsg_create = test_sysvmsg_create,
3233eb320b0eSRobert Watson 
3234eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msgmsq = test_sysvmsq_check_msgmsq,
3235eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msgrcv = test_sysvmsq_check_msgrcv,
3236eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msgrmid = test_sysvmsq_check_msgrmid,
3237eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msqget = test_sysvmsq_check_msqget,
3238eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msqsnd = test_sysvmsq_check_msqsnd,
3239eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msqrcv = test_sysvmsq_check_msqrcv,
3240eb320b0eSRobert Watson 	.mpo_sysvmsq_check_msqctl = test_sysvmsq_check_msqctl,
3241eb320b0eSRobert Watson 	.mpo_sysvmsq_cleanup = test_sysvmsq_cleanup,
3242eb320b0eSRobert Watson 	.mpo_sysvmsq_create = test_sysvmsq_create,
3243eb320b0eSRobert Watson 
3244eb320b0eSRobert Watson 	.mpo_sysvsem_check_semctl = test_sysvsem_check_semctl,
3245eb320b0eSRobert Watson 	.mpo_sysvsem_check_semget = test_sysvsem_check_semget,
3246eb320b0eSRobert Watson 	.mpo_sysvsem_check_semop = test_sysvsem_check_semop,
3247eb320b0eSRobert Watson 	.mpo_sysvsem_cleanup = test_sysvsem_cleanup,
3248eb320b0eSRobert Watson 	.mpo_sysvsem_create = test_sysvsem_create,
3249eb320b0eSRobert Watson 
3250eb320b0eSRobert Watson 	.mpo_sysvshm_check_shmat = test_sysvshm_check_shmat,
3251eb320b0eSRobert Watson 	.mpo_sysvshm_check_shmctl = test_sysvshm_check_shmctl,
3252eb320b0eSRobert Watson 	.mpo_sysvshm_check_shmdt = test_sysvshm_check_shmdt,
3253eb320b0eSRobert Watson 	.mpo_sysvshm_check_shmget = test_sysvshm_check_shmget,
3254eb320b0eSRobert Watson 	.mpo_sysvshm_cleanup = test_sysvshm_cleanup,
3255eb320b0eSRobert Watson 	.mpo_sysvshm_create = test_sysvshm_create,
3256eb320b0eSRobert Watson 
3257eb320b0eSRobert Watson 	.mpo_thread_userret = test_thread_userret,
3258eb320b0eSRobert Watson 
3259eb320b0eSRobert Watson 	.mpo_vnode_associate_extattr = test_vnode_associate_extattr,
3260eb320b0eSRobert Watson 	.mpo_vnode_associate_singlelabel = test_vnode_associate_singlelabel,
32613f1a7a90SRobert Watson 	.mpo_vnode_check_chdir = test_vnode_check_chdir,
32623f1a7a90SRobert Watson 	.mpo_vnode_check_chroot = test_vnode_check_chroot,
32633f1a7a90SRobert Watson 	.mpo_vnode_check_create = test_vnode_check_create,
32643f1a7a90SRobert Watson 	.mpo_vnode_check_deleteacl = test_vnode_check_deleteacl,
32653f1a7a90SRobert Watson 	.mpo_vnode_check_deleteextattr = test_vnode_check_deleteextattr,
32663f1a7a90SRobert Watson 	.mpo_vnode_check_exec = test_vnode_check_exec,
32673f1a7a90SRobert Watson 	.mpo_vnode_check_getacl = test_vnode_check_getacl,
32683f1a7a90SRobert Watson 	.mpo_vnode_check_getextattr = test_vnode_check_getextattr,
32693f1a7a90SRobert Watson 	.mpo_vnode_check_link = test_vnode_check_link,
32703f1a7a90SRobert Watson 	.mpo_vnode_check_listextattr = test_vnode_check_listextattr,
32713f1a7a90SRobert Watson 	.mpo_vnode_check_lookup = test_vnode_check_lookup,
32723f1a7a90SRobert Watson 	.mpo_vnode_check_mmap = test_vnode_check_mmap,
32733f1a7a90SRobert Watson 	.mpo_vnode_check_open = test_vnode_check_open,
32743f1a7a90SRobert Watson 	.mpo_vnode_check_poll = test_vnode_check_poll,
32753f1a7a90SRobert Watson 	.mpo_vnode_check_read = test_vnode_check_read,
32763f1a7a90SRobert Watson 	.mpo_vnode_check_readdir = test_vnode_check_readdir,
32773f1a7a90SRobert Watson 	.mpo_vnode_check_readlink = test_vnode_check_readlink,
32783f1a7a90SRobert Watson 	.mpo_vnode_check_relabel = test_vnode_check_relabel,
32793f1a7a90SRobert Watson 	.mpo_vnode_check_rename_from = test_vnode_check_rename_from,
32803f1a7a90SRobert Watson 	.mpo_vnode_check_rename_to = test_vnode_check_rename_to,
32813f1a7a90SRobert Watson 	.mpo_vnode_check_revoke = test_vnode_check_revoke,
32823f1a7a90SRobert Watson 	.mpo_vnode_check_setacl = test_vnode_check_setacl,
32833f1a7a90SRobert Watson 	.mpo_vnode_check_setextattr = test_vnode_check_setextattr,
32843f1a7a90SRobert Watson 	.mpo_vnode_check_setflags = test_vnode_check_setflags,
32853f1a7a90SRobert Watson 	.mpo_vnode_check_setmode = test_vnode_check_setmode,
32863f1a7a90SRobert Watson 	.mpo_vnode_check_setowner = test_vnode_check_setowner,
32873f1a7a90SRobert Watson 	.mpo_vnode_check_setutimes = test_vnode_check_setutimes,
32883f1a7a90SRobert Watson 	.mpo_vnode_check_stat = test_vnode_check_stat,
32893f1a7a90SRobert Watson 	.mpo_vnode_check_unlink = test_vnode_check_unlink,
32903f1a7a90SRobert Watson 	.mpo_vnode_check_write = test_vnode_check_write,
3291eb320b0eSRobert Watson 	.mpo_vnode_copy_label = test_vnode_copy_label,
3292eb320b0eSRobert Watson 	.mpo_vnode_create_extattr = test_vnode_create_extattr,
3293eb320b0eSRobert Watson 	.mpo_vnode_destroy_label = test_vnode_destroy_label,
3294eb320b0eSRobert Watson 	.mpo_vnode_execve_transition = test_vnode_execve_transition,
3295eb320b0eSRobert Watson 	.mpo_vnode_execve_will_transition = test_vnode_execve_will_transition,
3296eb320b0eSRobert Watson 	.mpo_vnode_externalize_label = test_vnode_externalize_label,
3297eb320b0eSRobert Watson 	.mpo_vnode_init_label = test_vnode_init_label,
32981876fb21SRobert Watson 	.mpo_vnode_internalize_label = test_vnode_internalize_label,
3299eb320b0eSRobert Watson 	.mpo_vnode_relabel = test_vnode_relabel,
3300eb320b0eSRobert Watson 	.mpo_vnode_setlabel_extattr = test_vnode_setlabel_extattr,
3301d8a7b7a3SRobert Watson };
3302d8a7b7a3SRobert Watson 
33033f1a7a90SRobert Watson MAC_POLICY_SET(&test_ops, mac_test, "TrustedBSD MAC/Test",
33049162f64bSRobert Watson     MPC_LOADTIME_FLAG_UNLOADOK, &test_slot);
3305