1d8a7b7a3SRobert Watson /*- 20142affcSRobert Watson * Copyright (c) 1999-2002, 2007 Robert N. M. Watson 364094732SRobert Watson * Copyright (c) 2001-2005 McAfee, Inc. 430d239bcSRobert Watson * Copyright (c) 2006 SPARTA, Inc. 5d8a7b7a3SRobert Watson * All rights reserved. 6d8a7b7a3SRobert Watson * 7d8a7b7a3SRobert Watson * This software was developed by Robert Watson for the TrustedBSD Project. 8d8a7b7a3SRobert Watson * 964094732SRobert Watson * This software was developed for the FreeBSD Project in part by McAfee 1064094732SRobert Watson * Research, the Security Research Division of McAfee, Inc. under 1164094732SRobert Watson * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA 1264094732SRobert Watson * CHATS research program. 13d8a7b7a3SRobert Watson * 1430d239bcSRobert Watson * This software was enhanced by SPARTA ISSO under SPAWAR contract 1530d239bcSRobert Watson * N66001-04-C-6019 ("SEFOS"). 1630d239bcSRobert Watson * 17d8a7b7a3SRobert Watson * Redistribution and use in source and binary forms, with or without 18d8a7b7a3SRobert Watson * modification, are permitted provided that the following conditions 19d8a7b7a3SRobert Watson * are met: 20d8a7b7a3SRobert Watson * 1. Redistributions of source code must retain the above copyright 21d8a7b7a3SRobert Watson * notice, this list of conditions and the following disclaimer. 22d8a7b7a3SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 23d8a7b7a3SRobert Watson * notice, this list of conditions and the following disclaimer in the 24d8a7b7a3SRobert Watson * documentation and/or other materials provided with the distribution. 25d8a7b7a3SRobert Watson * 26d8a7b7a3SRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 27d8a7b7a3SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28d8a7b7a3SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29d8a7b7a3SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 30d8a7b7a3SRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31d8a7b7a3SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32d8a7b7a3SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33d8a7b7a3SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34d8a7b7a3SRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35d8a7b7a3SRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36d8a7b7a3SRobert Watson * SUCH DAMAGE. 37d8a7b7a3SRobert Watson * 38d8a7b7a3SRobert Watson * $FreeBSD$ 39d8a7b7a3SRobert Watson */ 40d8a7b7a3SRobert Watson 41d8a7b7a3SRobert Watson /* 42d8a7b7a3SRobert Watson * Developed by the TrustedBSD Project. 436827d029SRobert Watson * 446827d029SRobert Watson * MAC Test policy - tests MAC Framework labeling by assigning object class 456827d029SRobert Watson * magic numbers to each label and validates that each time an object label 466827d029SRobert Watson * is passed into the policy, it has a consistent object type, catching 476827d029SRobert Watson * incorrectly passed labels, labels passed after free, etc. 48d8a7b7a3SRobert Watson */ 49d8a7b7a3SRobert Watson 50d8a7b7a3SRobert Watson #include <sys/param.h> 51d8a7b7a3SRobert Watson #include <sys/acl.h> 5232240d08SMarcel Moolenaar #include <sys/kdb.h> 53d8a7b7a3SRobert Watson #include <sys/kernel.h> 546aeb05d7STom Rhodes #include <sys/ksem.h> 550712b254SRobert Watson #include <sys/malloc.h> 567405fcc3SRobert Watson #include <sys/module.h> 57d8a7b7a3SRobert Watson #include <sys/mount.h> 587405fcc3SRobert Watson #include <sys/msg.h> 59d8a7b7a3SRobert Watson #include <sys/proc.h> 60d8a7b7a3SRobert Watson #include <sys/vnode.h> 617405fcc3SRobert Watson #include <sys/sem.h> 627405fcc3SRobert Watson #include <sys/shm.h> 63d8a7b7a3SRobert Watson #include <sys/socket.h> 64d8a7b7a3SRobert Watson #include <sys/socketvar.h> 6536422989SPoul-Henning Kamp #include <sys/sx.h> 66d8a7b7a3SRobert Watson #include <sys/sysctl.h> 67d8a7b7a3SRobert Watson 68d8a7b7a3SRobert Watson #include <fs/devfs/devfs.h> 69d8a7b7a3SRobert Watson 70d8a7b7a3SRobert Watson #include <net/bpfdesc.h> 71d8a7b7a3SRobert Watson #include <net/if.h> 72d8a7b7a3SRobert Watson #include <net/if_types.h> 73d8a7b7a3SRobert Watson #include <net/if_var.h> 74d8a7b7a3SRobert Watson 750efd6615SRobert Watson #include <security/mac/mac_policy.h> 76d8a7b7a3SRobert Watson 77d8a7b7a3SRobert Watson SYSCTL_DECL(_security_mac); 78d8a7b7a3SRobert Watson 79d8a7b7a3SRobert Watson SYSCTL_NODE(_security_mac, OID_AUTO, test, CTLFLAG_RW, 0, 80d8a7b7a3SRobert Watson "TrustedBSD mac_test policy controls"); 81d8a7b7a3SRobert Watson 826827d029SRobert Watson #define MAGIC_BPF 0xfe1ad1b6 836827d029SRobert Watson #define MAGIC_DEVFS 0x9ee79c32 846827d029SRobert Watson #define MAGIC_IFNET 0xc218b120 856827d029SRobert Watson #define MAGIC_INPCB 0x4440f7bb 866827d029SRobert Watson #define MAGIC_IPQ 0x206188ef 876827d029SRobert Watson #define MAGIC_MBUF 0xbbefa5bb 886827d029SRobert Watson #define MAGIC_MOUNT 0xc7c46e47 896827d029SRobert Watson #define MAGIC_SOCKET 0x9199c6cd 90269ad130SRobert Watson #define MAGIC_SYSV_MSG 0x8bbba61e 91269ad130SRobert Watson #define MAGIC_SYSV_MSQ 0xea672391 92269ad130SRobert Watson #define MAGIC_SYSV_SEM 0x896e8a0b 93269ad130SRobert Watson #define MAGIC_SYSV_SHM 0x76119ab0 946827d029SRobert Watson #define MAGIC_PIPE 0xdc6c9919 95269ad130SRobert Watson #define MAGIC_POSIX_SEM 0x78ae980c 966827d029SRobert Watson #define MAGIC_PROC 0x3b4be98f 976827d029SRobert Watson #define MAGIC_CRED 0x9a5a4987 986827d029SRobert Watson #define MAGIC_VNODE 0x1a67a45c 996827d029SRobert Watson #define MAGIC_FREE 0x849ba1fd 100d8a7b7a3SRobert Watson 1010142affcSRobert Watson #define SLOT(x) mac_label_get((x), test_slot) 1020142affcSRobert Watson #define SLOT_SET(x, v) mac_label_set((x), test_slot, (v)) 103250ee706SRobert Watson 104d8a7b7a3SRobert Watson static int test_slot; 105d8a7b7a3SRobert Watson SYSCTL_INT(_security_mac_test, OID_AUTO, slot, CTLFLAG_RD, 106d8a7b7a3SRobert Watson &test_slot, 0, "Slot allocated by framework"); 107d8a7b7a3SRobert Watson 1086827d029SRobert Watson SYSCTL_NODE(_security_mac_test, OID_AUTO, counter, CTLFLAG_RW, 0, 1096827d029SRobert Watson "TrustedBSD mac_test counters controls"); 110d8a7b7a3SRobert Watson 1116827d029SRobert Watson #define COUNTER_DECL(variable) \ 1126827d029SRobert Watson static int counter_##variable; \ 1136827d029SRobert Watson SYSCTL_INT(_security_mac_test_counter, OID_AUTO, variable, \ 1146827d029SRobert Watson CTLFLAG_RD, &counter_##variable, 0, #variable) 115d8a7b7a3SRobert Watson 1166827d029SRobert Watson #define COUNTER_INC(variable) atomic_add_int(&counter_##variable, 1) 1176827d029SRobert Watson 118b2e3811cSRobert Watson #ifdef KDB 1196827d029SRobert Watson #define DEBUGGER(func, string) kdb_enter((string)) 120b2e3811cSRobert Watson #else 1216827d029SRobert Watson #define DEBUGGER(func, string) printf("mac_test: %s: %s\n", (func), (string)) 122b2e3811cSRobert Watson #endif 123b2e3811cSRobert Watson 1246827d029SRobert Watson #define LABEL_CHECK(label, magic) do { \ 1256827d029SRobert Watson if (label != NULL) { \ 1266827d029SRobert Watson KASSERT(SLOT(label) == magic || SLOT(label) == 0, \ 1276827d029SRobert Watson ("%s: bad %s label", __func__, #magic)); \ 1286827d029SRobert Watson } \ 1296827d029SRobert Watson } while (0) 1306827d029SRobert Watson 131269ad130SRobert Watson #define LABEL_DESTROY(label, magic) do { \ 1326827d029SRobert Watson if (SLOT(label) == magic || SLOT(label) == 0) { \ 1336827d029SRobert Watson SLOT_SET(label, MAGIC_FREE); \ 1346827d029SRobert Watson } else if (SLOT(label) == MAGIC_FREE) { \ 1356827d029SRobert Watson DEBUGGER("%s: dup destroy", __func__); \ 1366827d029SRobert Watson } else { \ 1376827d029SRobert Watson DEBUGGER("%s: corrupted label", __func__); \ 1386827d029SRobert Watson } \ 1396827d029SRobert Watson } while (0) 1406827d029SRobert Watson 141269ad130SRobert Watson #define LABEL_INIT(label, magic) do { \ 142269ad130SRobert Watson SLOT_SET(label, magic); \ 143269ad130SRobert Watson } while (0) 144269ad130SRobert Watson 1456827d029SRobert Watson #define LABEL_NOTFREE(label) do { \ 1466827d029SRobert Watson KASSERT(SLOT(label) != MAGIC_FREE, \ 1476827d029SRobert Watson ("%s: destroyed label", __func__)); \ 1486827d029SRobert Watson } while (0) 1496827d029SRobert Watson 150d8a7b7a3SRobert Watson /* 151d8a7b7a3SRobert Watson * Label operations. 152d8a7b7a3SRobert Watson */ 15330d239bcSRobert Watson COUNTER_DECL(bpfdesc_init_label); 154d8a7b7a3SRobert Watson static void 15530d239bcSRobert Watson mac_test_bpfdesc_init_label(struct label *label) 156d8a7b7a3SRobert Watson { 157d8a7b7a3SRobert Watson 158269ad130SRobert Watson LABEL_INIT(label, MAGIC_BPF); 15930d239bcSRobert Watson COUNTER_INC(bpfdesc_init_label); 160d8a7b7a3SRobert Watson } 161d8a7b7a3SRobert Watson 16230d239bcSRobert Watson COUNTER_DECL(cred_init_label); 163d8a7b7a3SRobert Watson static void 16430d239bcSRobert Watson mac_test_cred_init_label(struct label *label) 165d8a7b7a3SRobert Watson { 166d8a7b7a3SRobert Watson 167269ad130SRobert Watson LABEL_INIT(label, MAGIC_CRED); 16830d239bcSRobert Watson COUNTER_INC(cred_init_label); 169d8a7b7a3SRobert Watson } 170d8a7b7a3SRobert Watson 17130d239bcSRobert Watson COUNTER_DECL(devfs_init_label); 172d8a7b7a3SRobert Watson static void 17330d239bcSRobert Watson mac_test_devfs_init_label(struct label *label) 174d8a7b7a3SRobert Watson { 175d8a7b7a3SRobert Watson 176269ad130SRobert Watson LABEL_INIT(label, MAGIC_DEVFS); 17730d239bcSRobert Watson COUNTER_INC(devfs_init_label); 178d8a7b7a3SRobert Watson } 179d8a7b7a3SRobert Watson 18030d239bcSRobert Watson COUNTER_DECL(ifnet_init_label); 181d8a7b7a3SRobert Watson static void 18230d239bcSRobert Watson mac_test_ifnet_init_label(struct label *label) 183d8a7b7a3SRobert Watson { 184d8a7b7a3SRobert Watson 185269ad130SRobert Watson LABEL_INIT(label, MAGIC_IFNET); 18630d239bcSRobert Watson COUNTER_INC(ifnet_init_label); 187d8a7b7a3SRobert Watson } 188d8a7b7a3SRobert Watson 18930d239bcSRobert Watson COUNTER_DECL(inpcb_init_label); 1905e7ce478SRobert Watson static int 19130d239bcSRobert Watson mac_test_inpcb_init_label(struct label *label, int flag) 192a557af22SRobert Watson { 193a557af22SRobert Watson 194a557af22SRobert Watson if (flag & M_WAITOK) 195a557af22SRobert Watson WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 19630d239bcSRobert Watson "mac_test_inpcb_init_label() at %s:%d", __FILE__, 197a557af22SRobert Watson __LINE__); 198a557af22SRobert Watson 199269ad130SRobert Watson LABEL_INIT(label, MAGIC_INPCB); 20030d239bcSRobert Watson COUNTER_INC(inpcb_init_label); 201a557af22SRobert Watson return (0); 202a557af22SRobert Watson } 203a557af22SRobert Watson 20430d239bcSRobert Watson COUNTER_DECL(sysvmsg_init_label); 2057e400ed1SRobert Watson static void 20630d239bcSRobert Watson mac_test_sysvmsg_init_label(struct label *label) 2077e400ed1SRobert Watson { 208269ad130SRobert Watson LABEL_INIT(label, MAGIC_SYSV_MSG); 20930d239bcSRobert Watson COUNTER_INC(sysvmsg_init_label); 2107e400ed1SRobert Watson } 2117e400ed1SRobert Watson 21230d239bcSRobert Watson COUNTER_DECL(sysvmsq_init_label); 2137e400ed1SRobert Watson static void 21430d239bcSRobert Watson mac_test_sysvmsq_init_label(struct label *label) 2157e400ed1SRobert Watson { 216269ad130SRobert Watson LABEL_INIT(label, MAGIC_SYSV_MSQ); 21730d239bcSRobert Watson COUNTER_INC(sysvmsq_init_label); 2187e400ed1SRobert Watson } 2197e400ed1SRobert Watson 22030d239bcSRobert Watson COUNTER_DECL(sysvsem_init_label); 2217e400ed1SRobert Watson static void 22230d239bcSRobert Watson mac_test_sysvsem_init_label(struct label *label) 2237e400ed1SRobert Watson { 224269ad130SRobert Watson LABEL_INIT(label, MAGIC_SYSV_SEM); 22530d239bcSRobert Watson COUNTER_INC(sysvsem_init_label); 2267e400ed1SRobert Watson } 2277e400ed1SRobert Watson 22830d239bcSRobert Watson COUNTER_DECL(sysvshm_init_label); 2297e400ed1SRobert Watson static void 23030d239bcSRobert Watson mac_test_sysvshm_init_label(struct label *label) 2317e400ed1SRobert Watson { 232269ad130SRobert Watson LABEL_INIT(label, MAGIC_SYSV_SHM); 23330d239bcSRobert Watson COUNTER_INC(sysvshm_init_label); 2347e400ed1SRobert Watson } 2357e400ed1SRobert Watson 23630d239bcSRobert Watson COUNTER_DECL(ipq_init_label); 237a557af22SRobert Watson static int 23830d239bcSRobert Watson mac_test_ipq_init_label(struct label *label, int flag) 239d8a7b7a3SRobert Watson { 240d8a7b7a3SRobert Watson 2410712b254SRobert Watson if (flag & M_WAITOK) 2420712b254SRobert Watson WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 24330d239bcSRobert Watson "mac_test_ipq_init_label() at %s:%d", __FILE__, 2440712b254SRobert Watson __LINE__); 2450712b254SRobert Watson 246269ad130SRobert Watson LABEL_INIT(label, MAGIC_IPQ); 24730d239bcSRobert Watson COUNTER_INC(ipq_init_label); 2485e7ce478SRobert Watson return (0); 249d8a7b7a3SRobert Watson } 250d8a7b7a3SRobert Watson 25130d239bcSRobert Watson COUNTER_DECL(mbuf_init_label); 252d8a7b7a3SRobert Watson static int 25330d239bcSRobert Watson mac_test_mbuf_init_label(struct label *label, int flag) 254d8a7b7a3SRobert Watson { 255d8a7b7a3SRobert Watson 2560712b254SRobert Watson if (flag & M_WAITOK) 2570712b254SRobert Watson WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 25830d239bcSRobert Watson "mac_test_mbuf_init_label() at %s:%d", __FILE__, 2590712b254SRobert Watson __LINE__); 2600712b254SRobert Watson 261269ad130SRobert Watson LABEL_INIT(label, MAGIC_MBUF); 26230d239bcSRobert Watson COUNTER_INC(mbuf_init_label); 263d8a7b7a3SRobert Watson return (0); 264d8a7b7a3SRobert Watson } 265d8a7b7a3SRobert Watson 26630d239bcSRobert Watson COUNTER_DECL(mount_init_label); 267d8a7b7a3SRobert Watson static void 26830d239bcSRobert Watson mac_test_mount_init_label(struct label *label) 269d8a7b7a3SRobert Watson { 270d8a7b7a3SRobert Watson 271269ad130SRobert Watson LABEL_INIT(label, MAGIC_MOUNT); 27230d239bcSRobert Watson COUNTER_INC(mount_init_label); 273d8a7b7a3SRobert Watson } 274d8a7b7a3SRobert Watson 27530d239bcSRobert Watson COUNTER_DECL(socket_init_label); 27683985c26SRobert Watson static int 27730d239bcSRobert Watson mac_test_socket_init_label(struct label *label, int flag) 278d8a7b7a3SRobert Watson { 279d8a7b7a3SRobert Watson 2800712b254SRobert Watson if (flag & M_WAITOK) 2810712b254SRobert Watson WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 28230d239bcSRobert Watson "mac_test_socket_init_label() at %s:%d", __FILE__, 2830712b254SRobert Watson __LINE__); 2840712b254SRobert Watson 285269ad130SRobert Watson LABEL_INIT(label, MAGIC_SOCKET); 28630d239bcSRobert Watson COUNTER_INC(socket_init_label); 28783985c26SRobert Watson return (0); 288d8a7b7a3SRobert Watson } 289d8a7b7a3SRobert Watson 29030d239bcSRobert Watson COUNTER_DECL(socketpeer_init_label); 29183985c26SRobert Watson static int 29230d239bcSRobert Watson mac_test_socketpeer_init_label(struct label *label, int flag) 29396adb909SRobert Watson { 29496adb909SRobert Watson 2950712b254SRobert Watson if (flag & M_WAITOK) 2960712b254SRobert Watson WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, 29730d239bcSRobert Watson "mac_test_socketpeer_init_label() at %s:%d", __FILE__, 2980712b254SRobert Watson __LINE__); 2990712b254SRobert Watson 300269ad130SRobert Watson LABEL_INIT(label, MAGIC_SOCKET); 30130d239bcSRobert Watson COUNTER_INC(socketpeer_init_label); 30283985c26SRobert Watson return (0); 30396adb909SRobert Watson } 30496adb909SRobert Watson 30530d239bcSRobert Watson COUNTER_DECL(pipe_init_label); 30696adb909SRobert Watson static void 30730d239bcSRobert Watson mac_test_pipe_init_label(struct label *label) 308d8a7b7a3SRobert Watson { 309d8a7b7a3SRobert Watson 310269ad130SRobert Watson LABEL_INIT(label, MAGIC_PIPE); 31130d239bcSRobert Watson COUNTER_INC(pipe_init_label); 312d8a7b7a3SRobert Watson } 313d8a7b7a3SRobert Watson 31430d239bcSRobert Watson COUNTER_DECL(posixsem_init_label); 315d8a7b7a3SRobert Watson static void 31630d239bcSRobert Watson mac_test_posixsem_init_label(struct label *label) 31752648411SRobert Watson { 31852648411SRobert Watson 319269ad130SRobert Watson LABEL_INIT(label, MAGIC_POSIX_SEM); 32030d239bcSRobert Watson COUNTER_INC(posixsem_init_label); 32152648411SRobert Watson } 32252648411SRobert Watson 32330d239bcSRobert Watson COUNTER_DECL(proc_init_label); 32452648411SRobert Watson static void 32530d239bcSRobert Watson mac_test_proc_init_label(struct label *label) 326ca26e8baSRobert Watson { 327ca26e8baSRobert Watson 328269ad130SRobert Watson LABEL_INIT(label, MAGIC_PROC); 32930d239bcSRobert Watson COUNTER_INC(proc_init_label); 330ca26e8baSRobert Watson } 331ca26e8baSRobert Watson 33230d239bcSRobert Watson COUNTER_DECL(vnode_init_label); 333ca26e8baSRobert Watson static void 33430d239bcSRobert Watson mac_test_vnode_init_label(struct label *label) 335d8a7b7a3SRobert Watson { 336d8a7b7a3SRobert Watson 337269ad130SRobert Watson LABEL_INIT(label, MAGIC_VNODE); 33830d239bcSRobert Watson COUNTER_INC(vnode_init_label); 339d8a7b7a3SRobert Watson } 340d8a7b7a3SRobert Watson 34130d239bcSRobert Watson COUNTER_DECL(bpfdesc_destroy_label); 342d8a7b7a3SRobert Watson static void 34330d239bcSRobert Watson mac_test_bpfdesc_destroy_label(struct label *label) 344d8a7b7a3SRobert Watson { 345d8a7b7a3SRobert Watson 346269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_BPF); 34730d239bcSRobert Watson COUNTER_INC(bpfdesc_destroy_label); 348d8a7b7a3SRobert Watson } 349d8a7b7a3SRobert Watson 35030d239bcSRobert Watson COUNTER_DECL(cred_destroy_label); 351d8a7b7a3SRobert Watson static void 35230d239bcSRobert Watson mac_test_cred_destroy_label(struct label *label) 353d8a7b7a3SRobert Watson { 354d8a7b7a3SRobert Watson 355269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_CRED); 35630d239bcSRobert Watson COUNTER_INC(cred_destroy_label); 357d8a7b7a3SRobert Watson } 358d8a7b7a3SRobert Watson 35930d239bcSRobert Watson COUNTER_DECL(devfs_destroy_label); 360d8a7b7a3SRobert Watson static void 36130d239bcSRobert Watson mac_test_devfs_destroy_label(struct label *label) 362d8a7b7a3SRobert Watson { 363d8a7b7a3SRobert Watson 364269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_DEVFS); 36530d239bcSRobert Watson COUNTER_INC(devfs_destroy_label); 366d8a7b7a3SRobert Watson } 367d8a7b7a3SRobert Watson 36830d239bcSRobert Watson COUNTER_DECL(ifnet_destroy_label); 369d8a7b7a3SRobert Watson static void 37030d239bcSRobert Watson mac_test_ifnet_destroy_label(struct label *label) 371d8a7b7a3SRobert Watson { 372d8a7b7a3SRobert Watson 373269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_IFNET); 37430d239bcSRobert Watson COUNTER_INC(ifnet_destroy_label); 375d8a7b7a3SRobert Watson } 376d8a7b7a3SRobert Watson 37730d239bcSRobert Watson COUNTER_DECL(inpcb_destroy_label); 378d8a7b7a3SRobert Watson static void 37930d239bcSRobert Watson mac_test_inpcb_destroy_label(struct label *label) 380a557af22SRobert Watson { 381a557af22SRobert Watson 382269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_INPCB); 38330d239bcSRobert Watson COUNTER_INC(inpcb_destroy_label); 384a557af22SRobert Watson } 385a557af22SRobert Watson 38630d239bcSRobert Watson COUNTER_DECL(sysvmsg_destroy_label); 387a557af22SRobert Watson static void 38830d239bcSRobert Watson mac_test_sysvmsg_destroy_label(struct label *label) 3897e400ed1SRobert Watson { 3907e400ed1SRobert Watson 391269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_SYSV_MSG); 39230d239bcSRobert Watson COUNTER_INC(sysvmsg_destroy_label); 3937e400ed1SRobert Watson } 3947e400ed1SRobert Watson 39530d239bcSRobert Watson COUNTER_DECL(sysvmsq_destroy_label); 3967e400ed1SRobert Watson static void 39730d239bcSRobert Watson mac_test_sysvmsq_destroy_label(struct label *label) 3987e400ed1SRobert Watson { 3997e400ed1SRobert Watson 400269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_SYSV_MSQ); 40130d239bcSRobert Watson COUNTER_INC(sysvmsq_destroy_label); 4027e400ed1SRobert Watson } 4037e400ed1SRobert Watson 40430d239bcSRobert Watson COUNTER_DECL(sysvsem_destroy_label); 4057e400ed1SRobert Watson static void 40630d239bcSRobert Watson mac_test_sysvsem_destroy_label(struct label *label) 4077e400ed1SRobert Watson { 4087e400ed1SRobert Watson 409269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_SYSV_SEM); 41030d239bcSRobert Watson COUNTER_INC(sysvsem_destroy_label); 4117e400ed1SRobert Watson } 4127e400ed1SRobert Watson 41330d239bcSRobert Watson COUNTER_DECL(sysvshm_destroy_label); 4147e400ed1SRobert Watson static void 41530d239bcSRobert Watson mac_test_sysvshm_destroy_label(struct label *label) 4167e400ed1SRobert Watson { 4177e400ed1SRobert Watson 418269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_SYSV_SHM); 41930d239bcSRobert Watson COUNTER_INC(sysvshm_destroy_label); 4207e400ed1SRobert Watson } 4217e400ed1SRobert Watson 42230d239bcSRobert Watson COUNTER_DECL(ipq_destroy_label); 4237e400ed1SRobert Watson static void 42430d239bcSRobert Watson mac_test_ipq_destroy_label(struct label *label) 425d8a7b7a3SRobert Watson { 426d8a7b7a3SRobert Watson 427269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_IPQ); 42830d239bcSRobert Watson COUNTER_INC(ipq_destroy_label); 429d8a7b7a3SRobert Watson } 430d8a7b7a3SRobert Watson 43130d239bcSRobert Watson COUNTER_DECL(mbuf_destroy_label); 432d8a7b7a3SRobert Watson static void 43330d239bcSRobert Watson mac_test_mbuf_destroy_label(struct label *label) 434d8a7b7a3SRobert Watson { 435d8a7b7a3SRobert Watson 4360712b254SRobert Watson /* 4370712b254SRobert Watson * If we're loaded dynamically, there may be mbufs in flight that 4380712b254SRobert Watson * didn't have label storage allocated for them. Handle this 4390712b254SRobert Watson * gracefully. 4400712b254SRobert Watson */ 4410712b254SRobert Watson if (label == NULL) 4420712b254SRobert Watson return; 4430712b254SRobert Watson 444269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_MBUF); 44530d239bcSRobert Watson COUNTER_INC(mbuf_destroy_label); 446d8a7b7a3SRobert Watson } 447d8a7b7a3SRobert Watson 44830d239bcSRobert Watson COUNTER_DECL(mount_destroy_label); 449d8a7b7a3SRobert Watson static void 45030d239bcSRobert Watson mac_test_mount_destroy_label(struct label *label) 451d8a7b7a3SRobert Watson { 452d8a7b7a3SRobert Watson 453269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_MOUNT); 45430d239bcSRobert Watson COUNTER_INC(mount_destroy_label); 455d8a7b7a3SRobert Watson } 456d8a7b7a3SRobert Watson 45730d239bcSRobert Watson COUNTER_DECL(socket_destroy_label); 45896adb909SRobert Watson static void 45930d239bcSRobert Watson mac_test_socket_destroy_label(struct label *label) 46096adb909SRobert Watson { 46196adb909SRobert Watson 462269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_SOCKET); 46330d239bcSRobert Watson COUNTER_INC(socket_destroy_label); 464d8a7b7a3SRobert Watson } 46596adb909SRobert Watson 46630d239bcSRobert Watson COUNTER_DECL(socketpeer_destroy_label); 467d8a7b7a3SRobert Watson static void 46830d239bcSRobert Watson mac_test_socketpeer_destroy_label(struct label *label) 46996adb909SRobert Watson { 47096adb909SRobert Watson 471269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_SOCKET); 47230d239bcSRobert Watson COUNTER_INC(socketpeer_destroy_label); 47396adb909SRobert Watson } 47496adb909SRobert Watson 47530d239bcSRobert Watson COUNTER_DECL(pipe_destroy_label); 47696adb909SRobert Watson static void 47730d239bcSRobert Watson mac_test_pipe_destroy_label(struct label *label) 478d8a7b7a3SRobert Watson { 479d8a7b7a3SRobert Watson 480269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_PIPE); 48130d239bcSRobert Watson COUNTER_INC(pipe_destroy_label); 482d8a7b7a3SRobert Watson } 483d8a7b7a3SRobert Watson 48430d239bcSRobert Watson COUNTER_DECL(posixsem_destroy_label); 485d8a7b7a3SRobert Watson static void 48630d239bcSRobert Watson mac_test_posixsem_destroy_label(struct label *label) 48752648411SRobert Watson { 48852648411SRobert Watson 489269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_POSIX_SEM); 49030d239bcSRobert Watson COUNTER_INC(posixsem_destroy_label); 49152648411SRobert Watson } 49252648411SRobert Watson 49330d239bcSRobert Watson COUNTER_DECL(proc_destroy_label); 49452648411SRobert Watson static void 49530d239bcSRobert Watson mac_test_proc_destroy_label(struct label *label) 496ca26e8baSRobert Watson { 497ca26e8baSRobert Watson 498269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_PROC); 49930d239bcSRobert Watson COUNTER_INC(proc_destroy_label); 500ca26e8baSRobert Watson } 501ca26e8baSRobert Watson 50230d239bcSRobert Watson COUNTER_DECL(vnode_destroy_label); 503ca26e8baSRobert Watson static void 50430d239bcSRobert Watson mac_test_vnode_destroy_label(struct label *label) 505d8a7b7a3SRobert Watson { 506d8a7b7a3SRobert Watson 507269ad130SRobert Watson LABEL_DESTROY(label, MAGIC_VNODE); 50830d239bcSRobert Watson COUNTER_INC(vnode_destroy_label); 509d8a7b7a3SRobert Watson } 510d8a7b7a3SRobert Watson 51130d239bcSRobert Watson COUNTER_DECL(cred_copy_label); 5120196273bSRobert Watson static void 51330d239bcSRobert Watson mac_test_cred_copy_label(struct label *src, struct label *dest) 51456d9e932SRobert Watson { 51556d9e932SRobert Watson 5166827d029SRobert Watson LABEL_CHECK(src, MAGIC_CRED); 5176827d029SRobert Watson LABEL_CHECK(dest, MAGIC_CRED); 51830d239bcSRobert Watson COUNTER_INC(cred_copy_label); 51956d9e932SRobert Watson } 52056d9e932SRobert Watson 52130d239bcSRobert Watson COUNTER_DECL(ifnet_copy_label); 52256d9e932SRobert Watson static void 52330d239bcSRobert Watson mac_test_ifnet_copy_label(struct label *src, struct label *dest) 5242220907bSRobert Watson { 5252220907bSRobert Watson 5266827d029SRobert Watson LABEL_CHECK(src, MAGIC_IFNET); 5276827d029SRobert Watson LABEL_CHECK(dest, MAGIC_IFNET); 52830d239bcSRobert Watson COUNTER_INC(ifnet_copy_label); 5292220907bSRobert Watson } 5302220907bSRobert Watson 53130d239bcSRobert Watson COUNTER_DECL(mbuf_copy_label); 5322220907bSRobert Watson static void 53330d239bcSRobert Watson mac_test_mbuf_copy_label(struct label *src, struct label *dest) 5340196273bSRobert Watson { 5350196273bSRobert Watson 5366827d029SRobert Watson LABEL_CHECK(src, MAGIC_MBUF); 5376827d029SRobert Watson LABEL_CHECK(dest, MAGIC_MBUF); 53830d239bcSRobert Watson COUNTER_INC(mbuf_copy_label); 5390196273bSRobert Watson } 5400196273bSRobert Watson 54130d239bcSRobert Watson COUNTER_DECL(pipe_copy_label); 5420196273bSRobert Watson static void 54330d239bcSRobert Watson mac_test_pipe_copy_label(struct label *src, struct label *dest) 5440196273bSRobert Watson { 5450196273bSRobert Watson 5466827d029SRobert Watson LABEL_CHECK(src, MAGIC_PIPE); 5476827d029SRobert Watson LABEL_CHECK(dest, MAGIC_PIPE); 54830d239bcSRobert Watson COUNTER_INC(pipe_copy_label); 5490196273bSRobert Watson } 5500196273bSRobert Watson 55130d239bcSRobert Watson COUNTER_DECL(socket_copy_label); 5520196273bSRobert Watson static void 55330d239bcSRobert Watson mac_test_socket_copy_label(struct label *src, struct label *dest) 554b0323ea3SRobert Watson { 555b0323ea3SRobert Watson 5566827d029SRobert Watson LABEL_CHECK(src, MAGIC_SOCKET); 5576827d029SRobert Watson LABEL_CHECK(dest, MAGIC_SOCKET); 55830d239bcSRobert Watson COUNTER_INC(socket_copy_label); 559b0323ea3SRobert Watson } 560b0323ea3SRobert Watson 56130d239bcSRobert Watson COUNTER_DECL(vnode_copy_label); 562b0323ea3SRobert Watson static void 56330d239bcSRobert Watson mac_test_vnode_copy_label(struct label *src, struct label *dest) 5640196273bSRobert Watson { 5650196273bSRobert Watson 5666827d029SRobert Watson LABEL_CHECK(src, MAGIC_VNODE); 5676827d029SRobert Watson LABEL_CHECK(dest, MAGIC_VNODE); 56830d239bcSRobert Watson COUNTER_INC(vnode_copy_label); 5690196273bSRobert Watson } 5700196273bSRobert Watson 571269ad130SRobert Watson COUNTER_DECL(externalize_label); 572d8a7b7a3SRobert Watson static int 57324e8d0d0SRobert Watson mac_test_externalize_label(struct label *label, char *element_name, 574f51e5803SRobert Watson struct sbuf *sb, int *claimed) 575d8a7b7a3SRobert Watson { 576d8a7b7a3SRobert Watson 5776827d029SRobert Watson LABEL_NOTFREE(label); 578269ad130SRobert Watson COUNTER_INC(externalize_label); 579250ee706SRobert Watson 580d8a7b7a3SRobert Watson return (0); 581d8a7b7a3SRobert Watson } 582d8a7b7a3SRobert Watson 583269ad130SRobert Watson COUNTER_DECL(internalize_label); 584d8a7b7a3SRobert Watson static int 5851979061bSRobert Watson mac_test_internalize_label(struct label *label, char *element_name, 5861979061bSRobert Watson char *element_data, int *claimed) 587d8a7b7a3SRobert Watson { 588d8a7b7a3SRobert Watson 5896827d029SRobert Watson LABEL_NOTFREE(label); 590269ad130SRobert Watson COUNTER_INC(internalize_label); 591250ee706SRobert Watson 592d8a7b7a3SRobert Watson return (0); 593d8a7b7a3SRobert Watson } 594d8a7b7a3SRobert Watson 595d8a7b7a3SRobert Watson /* 596d8a7b7a3SRobert Watson * Labeling event operations: file system objects, and things that look 597d8a7b7a3SRobert Watson * a lot like file system objects. 598d8a7b7a3SRobert Watson */ 59930d239bcSRobert Watson COUNTER_DECL(devfs_vnode_associate); 600d8a7b7a3SRobert Watson static void 60130d239bcSRobert Watson mac_test_devfs_vnode_associate(struct mount *mp, struct label *mplabel, 602763bbd2fSRobert Watson struct devfs_dirent *de, struct label *delabel, struct vnode *vp, 60378007886SRobert Watson struct label *vplabel) 604763bbd2fSRobert Watson { 605763bbd2fSRobert Watson 60678007886SRobert Watson LABEL_CHECK(mplabel, MAGIC_MOUNT); 6076827d029SRobert Watson LABEL_CHECK(delabel, MAGIC_DEVFS); 60878007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 60930d239bcSRobert Watson COUNTER_INC(devfs_vnode_associate); 610763bbd2fSRobert Watson } 611763bbd2fSRobert Watson 61230d239bcSRobert Watson COUNTER_DECL(vnode_associate_extattr); 613763bbd2fSRobert Watson static int 61430d239bcSRobert Watson mac_test_vnode_associate_extattr(struct mount *mp, struct label *mplabel, 61578007886SRobert Watson struct vnode *vp, struct label *vplabel) 616763bbd2fSRobert Watson { 617763bbd2fSRobert Watson 61878007886SRobert Watson LABEL_CHECK(mplabel, MAGIC_MOUNT); 61978007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 62030d239bcSRobert Watson COUNTER_INC(vnode_associate_extattr); 621269ad130SRobert Watson 622763bbd2fSRobert Watson return (0); 623763bbd2fSRobert Watson } 624763bbd2fSRobert Watson 62530d239bcSRobert Watson COUNTER_DECL(vnode_associate_singlelabel); 626763bbd2fSRobert Watson static void 62730d239bcSRobert Watson mac_test_vnode_associate_singlelabel(struct mount *mp, struct label *mplabel, 62878007886SRobert Watson struct vnode *vp, struct label *vplabel) 629763bbd2fSRobert Watson { 630763bbd2fSRobert Watson 63178007886SRobert Watson LABEL_CHECK(mplabel, MAGIC_MOUNT); 63278007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 63330d239bcSRobert Watson COUNTER_INC(vnode_associate_singlelabel); 634763bbd2fSRobert Watson } 635763bbd2fSRobert Watson 63630d239bcSRobert Watson COUNTER_DECL(devfs_create_device); 637763bbd2fSRobert Watson static void 63830d239bcSRobert Watson mac_test_devfs_create_device(struct ucred *cred, struct mount *mp, 63978007886SRobert Watson struct cdev *dev, struct devfs_dirent *de, struct label *delabel) 640d8a7b7a3SRobert Watson { 641d8a7b7a3SRobert Watson 6426827d029SRobert Watson if (cred != NULL) 6436827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 64478007886SRobert Watson LABEL_CHECK(delabel, MAGIC_DEVFS); 64530d239bcSRobert Watson COUNTER_INC(devfs_create_device); 646d8a7b7a3SRobert Watson } 647d8a7b7a3SRobert Watson 64830d239bcSRobert Watson COUNTER_DECL(devfs_create_directory); 649d8a7b7a3SRobert Watson static void 65030d239bcSRobert Watson mac_test_devfs_create_directory(struct mount *mp, char *dirname, 65178007886SRobert Watson int dirnamelen, struct devfs_dirent *de, struct label *delabel) 652990b4b2dSRobert Watson { 653990b4b2dSRobert Watson 65478007886SRobert Watson LABEL_CHECK(delabel, MAGIC_DEVFS); 65530d239bcSRobert Watson COUNTER_INC(devfs_create_directory); 656990b4b2dSRobert Watson } 657990b4b2dSRobert Watson 65830d239bcSRobert Watson COUNTER_DECL(devfs_create_symlink); 659990b4b2dSRobert Watson static void 66030d239bcSRobert Watson mac_test_devfs_create_symlink(struct ucred *cred, struct mount *mp, 661990b4b2dSRobert Watson struct devfs_dirent *dd, struct label *ddlabel, struct devfs_dirent *de, 662990b4b2dSRobert Watson struct label *delabel) 663eea8ea31SRobert Watson { 664eea8ea31SRobert Watson 6656827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 6666827d029SRobert Watson LABEL_CHECK(ddlabel, MAGIC_DEVFS); 6676827d029SRobert Watson LABEL_CHECK(delabel, MAGIC_DEVFS); 66830d239bcSRobert Watson COUNTER_INC(devfs_create_symlink); 669eea8ea31SRobert Watson } 670eea8ea31SRobert Watson 67130d239bcSRobert Watson COUNTER_DECL(vnode_create_extattr); 672763bbd2fSRobert Watson static int 67330d239bcSRobert Watson mac_test_vnode_create_extattr(struct ucred *cred, struct mount *mp, 67478007886SRobert Watson struct label *mplabel, struct vnode *dvp, struct label *dvplabel, 67578007886SRobert Watson struct vnode *vp, struct label *vplabel, struct componentname *cnp) 676d8a7b7a3SRobert Watson { 677d8a7b7a3SRobert Watson 6786827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 67978007886SRobert Watson LABEL_CHECK(mplabel, MAGIC_MOUNT); 68078007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 68130d239bcSRobert Watson COUNTER_INC(vnode_create_extattr); 682250ee706SRobert Watson 683763bbd2fSRobert Watson return (0); 684d8a7b7a3SRobert Watson } 685d8a7b7a3SRobert Watson 68630d239bcSRobert Watson COUNTER_DECL(mount_create); 687d8a7b7a3SRobert Watson static void 68830d239bcSRobert Watson mac_test_mount_create(struct ucred *cred, struct mount *mp, 68978007886SRobert Watson struct label *mplabel) 690d8a7b7a3SRobert Watson { 691d8a7b7a3SRobert Watson 6926827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 69378007886SRobert Watson LABEL_CHECK(mplabel, MAGIC_MOUNT); 69430d239bcSRobert Watson COUNTER_INC(mount_create); 695d8a7b7a3SRobert Watson } 696d8a7b7a3SRobert Watson 69730d239bcSRobert Watson COUNTER_DECL(vnode_relabel); 698d8a7b7a3SRobert Watson static void 69930d239bcSRobert Watson mac_test_vnode_relabel(struct ucred *cred, struct vnode *vp, 70078007886SRobert Watson struct label *vplabel, struct label *label) 701d8a7b7a3SRobert Watson { 702d8a7b7a3SRobert Watson 7036827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 70478007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 7056827d029SRobert Watson LABEL_CHECK(label, MAGIC_VNODE); 70630d239bcSRobert Watson COUNTER_INC(vnode_relabel); 707d8a7b7a3SRobert Watson } 708d8a7b7a3SRobert Watson 70930d239bcSRobert Watson COUNTER_DECL(vnode_setlabel_extattr); 710d8a7b7a3SRobert Watson static int 71130d239bcSRobert Watson mac_test_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp, 71278007886SRobert Watson struct label *vplabel, struct label *intlabel) 713d8a7b7a3SRobert Watson { 714d8a7b7a3SRobert Watson 7156827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 71678007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 7176827d029SRobert Watson LABEL_CHECK(intlabel, MAGIC_VNODE); 71830d239bcSRobert Watson COUNTER_INC(vnode_setlabel_extattr); 719269ad130SRobert Watson 720d8a7b7a3SRobert Watson return (0); 721d8a7b7a3SRobert Watson } 722d8a7b7a3SRobert Watson 72330d239bcSRobert Watson COUNTER_DECL(devfs_update); 724d8a7b7a3SRobert Watson static void 72530d239bcSRobert Watson mac_test_devfs_update(struct mount *mp, struct devfs_dirent *devfs_dirent, 72630575990SRobert Watson struct label *direntlabel, struct vnode *vp, struct label *vplabel) 727d8a7b7a3SRobert Watson { 728d8a7b7a3SRobert Watson 7296827d029SRobert Watson LABEL_CHECK(direntlabel, MAGIC_DEVFS); 73078007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 73130d239bcSRobert Watson COUNTER_INC(devfs_update); 732d8a7b7a3SRobert Watson } 733d8a7b7a3SRobert Watson 734d8a7b7a3SRobert Watson /* 735d8a7b7a3SRobert Watson * Labeling event operations: IPC object. 736d8a7b7a3SRobert Watson */ 73730d239bcSRobert Watson COUNTER_DECL(socket_create_mbuf); 738d8a7b7a3SRobert Watson static void 73930d239bcSRobert Watson mac_test_socket_create_mbuf(struct socket *so, struct label *socketlabel, 740d8a7b7a3SRobert Watson struct mbuf *m, struct label *mbuflabel) 741d8a7b7a3SRobert Watson { 742d8a7b7a3SRobert Watson 7436827d029SRobert Watson LABEL_CHECK(socketlabel, MAGIC_SOCKET); 7446827d029SRobert Watson LABEL_CHECK(mbuflabel, MAGIC_MBUF); 74530d239bcSRobert Watson COUNTER_INC(socket_create_mbuf); 746d8a7b7a3SRobert Watson } 747d8a7b7a3SRobert Watson 74830d239bcSRobert Watson COUNTER_DECL(socket_create); 749d8a7b7a3SRobert Watson static void 75030d239bcSRobert Watson mac_test_socket_create(struct ucred *cred, struct socket *socket, 751d8a7b7a3SRobert Watson struct label *socketlabel) 752d8a7b7a3SRobert Watson { 753d8a7b7a3SRobert Watson 7546827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 7556827d029SRobert Watson LABEL_CHECK(socketlabel, MAGIC_SOCKET); 75630d239bcSRobert Watson COUNTER_INC(socket_create); 757d8a7b7a3SRobert Watson } 758d8a7b7a3SRobert Watson 75930d239bcSRobert Watson COUNTER_DECL(pipe_create); 760d8a7b7a3SRobert Watson static void 76130d239bcSRobert Watson mac_test_pipe_create(struct ucred *cred, struct pipepair *pp, 762d8a7b7a3SRobert Watson struct label *pipelabel) 763d8a7b7a3SRobert Watson { 764d8a7b7a3SRobert Watson 7656827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 7666827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 76730d239bcSRobert Watson COUNTER_INC(pipe_create); 768d8a7b7a3SRobert Watson } 769d8a7b7a3SRobert Watson 77030d239bcSRobert Watson COUNTER_DECL(posixsem_create); 771d8a7b7a3SRobert Watson static void 77230d239bcSRobert Watson mac_test_posixsem_create(struct ucred *cred, struct ksem *ks, 773fe09513eSRobert Watson struct label *kslabel) 77452648411SRobert Watson { 77552648411SRobert Watson 7766827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 777fe09513eSRobert Watson LABEL_CHECK(kslabel, MAGIC_POSIX_SEM); 77830d239bcSRobert Watson COUNTER_INC(posixsem_create); 77952648411SRobert Watson } 78052648411SRobert Watson 78130d239bcSRobert Watson COUNTER_DECL(socket_newconn); 78252648411SRobert Watson static void 78330d239bcSRobert Watson mac_test_socket_newconn(struct socket *oldsocket, 784d8a7b7a3SRobert Watson struct label *oldsocketlabel, struct socket *newsocket, 785d8a7b7a3SRobert Watson struct label *newsocketlabel) 786d8a7b7a3SRobert Watson { 787d8a7b7a3SRobert Watson 7886827d029SRobert Watson LABEL_CHECK(oldsocketlabel, MAGIC_SOCKET); 7896827d029SRobert Watson LABEL_CHECK(newsocketlabel, MAGIC_SOCKET); 79030d239bcSRobert Watson COUNTER_INC(socket_newconn); 791d8a7b7a3SRobert Watson } 792d8a7b7a3SRobert Watson 79330d239bcSRobert Watson COUNTER_DECL(socket_relabel); 794d8a7b7a3SRobert Watson static void 79530d239bcSRobert Watson mac_test_socket_relabel(struct ucred *cred, struct socket *socket, 796d8a7b7a3SRobert Watson struct label *socketlabel, struct label *newlabel) 797d8a7b7a3SRobert Watson { 798d8a7b7a3SRobert Watson 7996827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 8006827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_SOCKET); 80130d239bcSRobert Watson COUNTER_INC(socket_relabel); 802d8a7b7a3SRobert Watson } 803d8a7b7a3SRobert Watson 80430d239bcSRobert Watson COUNTER_DECL(pipe_relabel); 805d8a7b7a3SRobert Watson static void 80630d239bcSRobert Watson mac_test_pipe_relabel(struct ucred *cred, struct pipepair *pp, 807d8a7b7a3SRobert Watson struct label *pipelabel, struct label *newlabel) 808d8a7b7a3SRobert Watson { 809d8a7b7a3SRobert Watson 8106827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 8116827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 8126827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_PIPE); 81330d239bcSRobert Watson COUNTER_INC(pipe_relabel); 814d8a7b7a3SRobert Watson } 815d8a7b7a3SRobert Watson 81630d239bcSRobert Watson COUNTER_DECL(socketpeer_set_from_mbuf); 817d8a7b7a3SRobert Watson static void 81830d239bcSRobert Watson mac_test_socketpeer_set_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, 819d8a7b7a3SRobert Watson struct socket *socket, struct label *socketpeerlabel) 820d8a7b7a3SRobert Watson { 821d8a7b7a3SRobert Watson 8226827d029SRobert Watson LABEL_CHECK(mbuflabel, MAGIC_MBUF); 8236827d029SRobert Watson LABEL_CHECK(socketpeerlabel, MAGIC_SOCKET); 82430d239bcSRobert Watson COUNTER_INC(socketpeer_set_from_mbuf); 825d8a7b7a3SRobert Watson } 826d8a7b7a3SRobert Watson 827d8a7b7a3SRobert Watson /* 828d8a7b7a3SRobert Watson * Labeling event operations: network objects. 829d8a7b7a3SRobert Watson */ 83030d239bcSRobert Watson COUNTER_DECL(socketpeer_set_from_socket); 831d8a7b7a3SRobert Watson static void 83230d239bcSRobert Watson mac_test_socketpeer_set_from_socket(struct socket *oldsocket, 833d8a7b7a3SRobert Watson struct label *oldsocketlabel, struct socket *newsocket, 834d8a7b7a3SRobert Watson struct label *newsocketpeerlabel) 835d8a7b7a3SRobert Watson { 836d8a7b7a3SRobert Watson 8376827d029SRobert Watson LABEL_CHECK(oldsocketlabel, MAGIC_SOCKET); 8386827d029SRobert Watson LABEL_CHECK(newsocketpeerlabel, MAGIC_SOCKET); 83930d239bcSRobert Watson COUNTER_INC(socketpeer_set_from_socket); 840d8a7b7a3SRobert Watson } 841d8a7b7a3SRobert Watson 84230d239bcSRobert Watson COUNTER_DECL(bpfdesc_create); 843d8a7b7a3SRobert Watson static void 84430d239bcSRobert Watson mac_test_bpfdesc_create(struct ucred *cred, struct bpf_d *bpf_d, 845d8a7b7a3SRobert Watson struct label *bpflabel) 846d8a7b7a3SRobert Watson { 847d8a7b7a3SRobert Watson 8486827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 8496827d029SRobert Watson LABEL_CHECK(bpflabel, MAGIC_BPF); 85030d239bcSRobert Watson COUNTER_INC(bpfdesc_create); 851d8a7b7a3SRobert Watson } 852d8a7b7a3SRobert Watson 85330d239bcSRobert Watson COUNTER_DECL(ipq_reassemble); 854d8a7b7a3SRobert Watson static void 85530d239bcSRobert Watson mac_test_ipq_reassemble(struct ipq *ipq, struct label *ipqlabel, 856d8a7b7a3SRobert Watson struct mbuf *datagram, struct label *datagramlabel) 857d8a7b7a3SRobert Watson { 858d8a7b7a3SRobert Watson 8596827d029SRobert Watson LABEL_CHECK(ipqlabel, MAGIC_IPQ); 8606827d029SRobert Watson LABEL_CHECK(datagramlabel, MAGIC_MBUF); 86130d239bcSRobert Watson COUNTER_INC(ipq_reassemble); 862d8a7b7a3SRobert Watson } 863d8a7b7a3SRobert Watson 86430d239bcSRobert Watson COUNTER_DECL(netinet_fragment); 865d8a7b7a3SRobert Watson static void 86630d239bcSRobert Watson mac_test_netinet_fragment(struct mbuf *datagram, struct label *datagramlabel, 867d8a7b7a3SRobert Watson struct mbuf *fragment, struct label *fragmentlabel) 868d8a7b7a3SRobert Watson { 869d8a7b7a3SRobert Watson 8706827d029SRobert Watson LABEL_CHECK(datagramlabel, MAGIC_MBUF); 8716827d029SRobert Watson LABEL_CHECK(fragmentlabel, MAGIC_MBUF); 87230d239bcSRobert Watson COUNTER_INC(netinet_fragment); 873d8a7b7a3SRobert Watson } 874d8a7b7a3SRobert Watson 87530d239bcSRobert Watson COUNTER_DECL(ifnet_create); 876d8a7b7a3SRobert Watson static void 87730d239bcSRobert Watson mac_test_ifnet_create(struct ifnet *ifnet, struct label *ifnetlabel) 878d8a7b7a3SRobert Watson { 879d8a7b7a3SRobert Watson 8806827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 88130d239bcSRobert Watson COUNTER_INC(ifnet_create); 882d8a7b7a3SRobert Watson } 883d8a7b7a3SRobert Watson 88430d239bcSRobert Watson COUNTER_DECL(inpcb_create); 885d8a7b7a3SRobert Watson static void 88630d239bcSRobert Watson mac_test_inpcb_create(struct socket *so, struct label *solabel, 887a557af22SRobert Watson struct inpcb *inp, struct label *inplabel) 888a557af22SRobert Watson { 889a557af22SRobert Watson 8906827d029SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 8916827d029SRobert Watson LABEL_CHECK(inplabel, MAGIC_INPCB); 89230d239bcSRobert Watson COUNTER_INC(inpcb_create); 893a557af22SRobert Watson } 894a557af22SRobert Watson 89530d239bcSRobert Watson COUNTER_DECL(sysvmsg_create); 896a557af22SRobert Watson static void 89730d239bcSRobert Watson mac_test_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr, 8987e400ed1SRobert Watson struct label *msqlabel, struct msg *msgptr, struct label *msglabel) 8997e400ed1SRobert Watson { 9007e400ed1SRobert Watson 901269ad130SRobert Watson LABEL_CHECK(msglabel, MAGIC_SYSV_MSG); 902269ad130SRobert Watson LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ); 90330d239bcSRobert Watson COUNTER_INC(sysvmsg_create); 9047e400ed1SRobert Watson } 9057e400ed1SRobert Watson 90630d239bcSRobert Watson COUNTER_DECL(sysvmsq_create); 9077e400ed1SRobert Watson static void 90830d239bcSRobert Watson mac_test_sysvmsq_create(struct ucred *cred, 9097e400ed1SRobert Watson struct msqid_kernel *msqkptr, struct label *msqlabel) 9107e400ed1SRobert Watson { 9117e400ed1SRobert Watson 912269ad130SRobert Watson LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ); 91330d239bcSRobert Watson COUNTER_INC(sysvmsq_create); 9147e400ed1SRobert Watson } 9157e400ed1SRobert Watson 91630d239bcSRobert Watson COUNTER_DECL(sysvsem_create); 9177e400ed1SRobert Watson static void 91830d239bcSRobert Watson mac_test_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr, 9197e400ed1SRobert Watson struct label *semalabel) 9207e400ed1SRobert Watson { 9217e400ed1SRobert Watson 922269ad130SRobert Watson LABEL_CHECK(semalabel, MAGIC_SYSV_SEM); 92330d239bcSRobert Watson COUNTER_INC(sysvsem_create); 9247e400ed1SRobert Watson } 9257e400ed1SRobert Watson 92630d239bcSRobert Watson COUNTER_DECL(sysvshm_create); 9277e400ed1SRobert Watson static void 92830d239bcSRobert Watson mac_test_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr, 9297e400ed1SRobert Watson struct label *shmlabel) 9307e400ed1SRobert Watson { 9317e400ed1SRobert Watson 932269ad130SRobert Watson LABEL_CHECK(shmlabel, MAGIC_SYSV_SHM); 93330d239bcSRobert Watson COUNTER_INC(sysvshm_create); 9347e400ed1SRobert Watson } 9357e400ed1SRobert Watson 93630d239bcSRobert Watson COUNTER_DECL(ipq_create); 9377e400ed1SRobert Watson static void 93830d239bcSRobert Watson mac_test_ipq_create(struct mbuf *fragment, struct label *fragmentlabel, 939d8a7b7a3SRobert Watson struct ipq *ipq, struct label *ipqlabel) 940d8a7b7a3SRobert Watson { 941d8a7b7a3SRobert Watson 9426827d029SRobert Watson LABEL_CHECK(fragmentlabel, MAGIC_MBUF); 9436827d029SRobert Watson LABEL_CHECK(ipqlabel, MAGIC_IPQ); 94430d239bcSRobert Watson COUNTER_INC(ipq_create); 945d8a7b7a3SRobert Watson } 946d8a7b7a3SRobert Watson 94730d239bcSRobert Watson COUNTER_DECL(inpcb_create_mbuf); 948d8a7b7a3SRobert Watson static void 94930d239bcSRobert Watson mac_test_inpcb_create_mbuf(struct inpcb *inp, struct label *inplabel, 9502d92ec98SRobert Watson struct mbuf *m, struct label *mlabel) 9512d92ec98SRobert Watson { 9522d92ec98SRobert Watson 9536827d029SRobert Watson LABEL_CHECK(inplabel, MAGIC_INPCB); 9546827d029SRobert Watson LABEL_CHECK(mlabel, MAGIC_MBUF); 95530d239bcSRobert Watson COUNTER_INC(inpcb_create_mbuf); 9562d92ec98SRobert Watson } 9572d92ec98SRobert Watson 958269ad130SRobert Watson COUNTER_DECL(create_mbuf_linklayer); 9592d92ec98SRobert Watson static void 960d8a7b7a3SRobert Watson mac_test_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, 961d8a7b7a3SRobert Watson struct mbuf *mbuf, struct label *mbuflabel) 962d8a7b7a3SRobert Watson { 963d8a7b7a3SRobert Watson 9646827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 9656827d029SRobert Watson LABEL_CHECK(mbuflabel, MAGIC_MBUF); 966269ad130SRobert Watson COUNTER_INC(create_mbuf_linklayer); 967d8a7b7a3SRobert Watson } 968d8a7b7a3SRobert Watson 96930d239bcSRobert Watson COUNTER_DECL(bpfdesc_create_mbuf); 970d8a7b7a3SRobert Watson static void 97130d239bcSRobert Watson mac_test_bpfdesc_create_mbuf(struct bpf_d *bpf_d, struct label *bpflabel, 972d8a7b7a3SRobert Watson struct mbuf *mbuf, struct label *mbuflabel) 973d8a7b7a3SRobert Watson { 974d8a7b7a3SRobert Watson 9756827d029SRobert Watson LABEL_CHECK(bpflabel, MAGIC_BPF); 9766827d029SRobert Watson LABEL_CHECK(mbuflabel, MAGIC_MBUF); 97730d239bcSRobert Watson COUNTER_INC(bpfdesc_create_mbuf); 978d8a7b7a3SRobert Watson } 979d8a7b7a3SRobert Watson 98030d239bcSRobert Watson COUNTER_DECL(ifnet_create_mbuf); 981d8a7b7a3SRobert Watson static void 98230d239bcSRobert Watson mac_test_ifnet_create_mbuf(struct ifnet *ifnet, struct label *ifnetlabel, 983d8a7b7a3SRobert Watson struct mbuf *m, struct label *mbuflabel) 984d8a7b7a3SRobert Watson { 985d8a7b7a3SRobert Watson 9866827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 9876827d029SRobert Watson LABEL_CHECK(mbuflabel, MAGIC_MBUF); 98830d239bcSRobert Watson COUNTER_INC(ifnet_create_mbuf); 989d8a7b7a3SRobert Watson } 990d8a7b7a3SRobert Watson 99130d239bcSRobert Watson COUNTER_DECL(mbuf_create_multicast_encap); 992d8a7b7a3SRobert Watson static void 99330d239bcSRobert Watson mac_test_mbuf_create_multicast_encap(struct mbuf *oldmbuf, 994d8a7b7a3SRobert Watson struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, 995d8a7b7a3SRobert Watson struct mbuf *newmbuf, struct label *newmbuflabel) 996d8a7b7a3SRobert Watson { 997d8a7b7a3SRobert Watson 9986827d029SRobert Watson LABEL_CHECK(oldmbuflabel, MAGIC_MBUF); 9996827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 10006827d029SRobert Watson LABEL_CHECK(newmbuflabel, MAGIC_MBUF); 100130d239bcSRobert Watson COUNTER_INC(mbuf_create_multicast_encap); 1002d8a7b7a3SRobert Watson } 1003d8a7b7a3SRobert Watson 100430d239bcSRobert Watson COUNTER_DECL(mbuf_create_netlayer); 1005d8a7b7a3SRobert Watson static void 100630d239bcSRobert Watson mac_test_mbuf_create_netlayer(struct mbuf *oldmbuf, 1007d8a7b7a3SRobert Watson struct label *oldmbuflabel, struct mbuf *newmbuf, 1008d8a7b7a3SRobert Watson struct label *newmbuflabel) 1009d8a7b7a3SRobert Watson { 1010d8a7b7a3SRobert Watson 10116827d029SRobert Watson LABEL_CHECK(oldmbuflabel, MAGIC_MBUF); 10126827d029SRobert Watson LABEL_CHECK(newmbuflabel, MAGIC_MBUF); 101330d239bcSRobert Watson COUNTER_INC(mbuf_create_netlayer); 1014d8a7b7a3SRobert Watson } 1015d8a7b7a3SRobert Watson 101630d239bcSRobert Watson COUNTER_DECL(ipq_match); 1017d8a7b7a3SRobert Watson static int 101830d239bcSRobert Watson mac_test_ipq_match(struct mbuf *fragment, struct label *fragmentlabel, 1019d8a7b7a3SRobert Watson struct ipq *ipq, struct label *ipqlabel) 1020d8a7b7a3SRobert Watson { 1021d8a7b7a3SRobert Watson 10226827d029SRobert Watson LABEL_CHECK(fragmentlabel, MAGIC_MBUF); 10236827d029SRobert Watson LABEL_CHECK(ipqlabel, MAGIC_IPQ); 102430d239bcSRobert Watson COUNTER_INC(ipq_match); 1025250ee706SRobert Watson 1026d8a7b7a3SRobert Watson return (1); 1027d8a7b7a3SRobert Watson } 1028d8a7b7a3SRobert Watson 102930d239bcSRobert Watson COUNTER_DECL(netinet_icmp_reply); 1030d8a7b7a3SRobert Watson static void 103130d239bcSRobert Watson mac_test_netinet_icmp_reply(struct mbuf *m, struct label *mlabel) 1032250ee706SRobert Watson { 1033250ee706SRobert Watson 10346827d029SRobert Watson LABEL_CHECK(mlabel, MAGIC_MBUF); 103530d239bcSRobert Watson COUNTER_INC(netinet_icmp_reply); 1036250ee706SRobert Watson } 1037250ee706SRobert Watson 103830d239bcSRobert Watson COUNTER_DECL(netinet_tcp_reply); 1039250ee706SRobert Watson static void 104030d239bcSRobert Watson mac_test_netinet_tcp_reply(struct mbuf *m, struct label *mlabel) 1041250ee706SRobert Watson { 1042250ee706SRobert Watson 10436827d029SRobert Watson LABEL_CHECK(mlabel, MAGIC_MBUF); 104430d239bcSRobert Watson COUNTER_INC(netinet_tcp_reply); 1045250ee706SRobert Watson } 1046250ee706SRobert Watson 104730d239bcSRobert Watson COUNTER_DECL(ifnet_relabel); 1048250ee706SRobert Watson static void 104930d239bcSRobert Watson mac_test_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, 1050d8a7b7a3SRobert Watson struct label *ifnetlabel, struct label *newlabel) 1051d8a7b7a3SRobert Watson { 1052d8a7b7a3SRobert Watson 10536827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 10546827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 10556827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_IFNET); 105630d239bcSRobert Watson COUNTER_INC(ifnet_relabel); 1057d8a7b7a3SRobert Watson } 1058d8a7b7a3SRobert Watson 105930d239bcSRobert Watson COUNTER_DECL(ipq_update); 1060d8a7b7a3SRobert Watson static void 106130d239bcSRobert Watson mac_test_ipq_update(struct mbuf *fragment, struct label *fragmentlabel, 1062d8a7b7a3SRobert Watson struct ipq *ipq, struct label *ipqlabel) 1063d8a7b7a3SRobert Watson { 1064d8a7b7a3SRobert Watson 10656827d029SRobert Watson LABEL_CHECK(fragmentlabel, MAGIC_MBUF); 10666827d029SRobert Watson LABEL_CHECK(ipqlabel, MAGIC_IPQ); 106730d239bcSRobert Watson COUNTER_INC(ipq_update); 1068d8a7b7a3SRobert Watson } 1069d8a7b7a3SRobert Watson 1070269ad130SRobert Watson COUNTER_DECL(inpcb_sosetlabel); 1071a557af22SRobert Watson static void 1072a557af22SRobert Watson mac_test_inpcb_sosetlabel(struct socket *so, struct label *solabel, 1073a557af22SRobert Watson struct inpcb *inp, struct label *inplabel) 1074a557af22SRobert Watson { 1075a557af22SRobert Watson 10766827d029SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 10776827d029SRobert Watson LABEL_CHECK(inplabel, MAGIC_INPCB); 1078269ad130SRobert Watson COUNTER_INC(inpcb_sosetlabel); 1079a557af22SRobert Watson } 1080a557af22SRobert Watson 1081d8a7b7a3SRobert Watson /* 1082d8a7b7a3SRobert Watson * Labeling event operations: processes. 1083d8a7b7a3SRobert Watson */ 108430d239bcSRobert Watson COUNTER_DECL(vnode_execve_transition); 1085d8a7b7a3SRobert Watson static void 108630d239bcSRobert Watson mac_test_vnode_execve_transition(struct ucred *old, struct ucred *new, 1087939b97cbSRobert Watson struct vnode *vp, struct label *filelabel, 108878007886SRobert Watson struct label *interpvplabel, struct image_params *imgp, 1089ef5def59SRobert Watson struct label *execlabel) 1090d8a7b7a3SRobert Watson { 1091d8a7b7a3SRobert Watson 10926827d029SRobert Watson LABEL_CHECK(old->cr_label, MAGIC_CRED); 10936827d029SRobert Watson LABEL_CHECK(new->cr_label, MAGIC_CRED); 10946827d029SRobert Watson LABEL_CHECK(filelabel, MAGIC_VNODE); 109578007886SRobert Watson LABEL_CHECK(interpvplabel, MAGIC_VNODE); 10966827d029SRobert Watson LABEL_CHECK(execlabel, MAGIC_CRED); 109730d239bcSRobert Watson COUNTER_INC(vnode_execve_transition); 1098d8a7b7a3SRobert Watson } 1099d8a7b7a3SRobert Watson 110030d239bcSRobert Watson COUNTER_DECL(vnode_execve_will_transition); 1101d8a7b7a3SRobert Watson static int 110230d239bcSRobert Watson mac_test_vnode_execve_will_transition(struct ucred *old, struct vnode *vp, 110378007886SRobert Watson struct label *filelabel, struct label *interpvplabel, 1104ef5def59SRobert Watson struct image_params *imgp, struct label *execlabel) 1105d8a7b7a3SRobert Watson { 1106d8a7b7a3SRobert Watson 11076827d029SRobert Watson LABEL_CHECK(old->cr_label, MAGIC_CRED); 11086827d029SRobert Watson LABEL_CHECK(filelabel, MAGIC_VNODE); 110978007886SRobert Watson LABEL_CHECK(interpvplabel, MAGIC_VNODE); 11106827d029SRobert Watson LABEL_CHECK(execlabel, MAGIC_CRED); 111130d239bcSRobert Watson COUNTER_INC(vnode_execve_will_transition); 1112250ee706SRobert Watson 1113d8a7b7a3SRobert Watson return (0); 1114d8a7b7a3SRobert Watson } 1115d8a7b7a3SRobert Watson 111630d239bcSRobert Watson COUNTER_DECL(proc_create_swapper); 1117d8a7b7a3SRobert Watson static void 111830d239bcSRobert Watson mac_test_proc_create_swapper(struct ucred *cred) 1119d8a7b7a3SRobert Watson { 1120d8a7b7a3SRobert Watson 11216827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 112230d239bcSRobert Watson COUNTER_INC(proc_create_swapper); 1123d8a7b7a3SRobert Watson } 1124d8a7b7a3SRobert Watson 112530d239bcSRobert Watson COUNTER_DECL(proc_create_init); 1126d8a7b7a3SRobert Watson static void 112730d239bcSRobert Watson mac_test_proc_create_init(struct ucred *cred) 1128d8a7b7a3SRobert Watson { 1129d8a7b7a3SRobert Watson 11306827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 113130d239bcSRobert Watson COUNTER_INC(proc_create_init); 1132d8a7b7a3SRobert Watson } 1133d8a7b7a3SRobert Watson 113430d239bcSRobert Watson COUNTER_DECL(cred_relabel); 1135d8a7b7a3SRobert Watson static void 113630d239bcSRobert Watson mac_test_cred_relabel(struct ucred *cred, struct label *newlabel) 1137d8a7b7a3SRobert Watson { 1138d8a7b7a3SRobert Watson 11396827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 11406827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_CRED); 114130d239bcSRobert Watson COUNTER_INC(cred_relabel); 1142d8a7b7a3SRobert Watson } 1143d8a7b7a3SRobert Watson 1144269ad130SRobert Watson COUNTER_DECL(thread_userret); 1145ca26e8baSRobert Watson static void 1146ca26e8baSRobert Watson mac_test_thread_userret(struct thread *td) 1147ca26e8baSRobert Watson { 1148ca26e8baSRobert Watson 1149269ad130SRobert Watson COUNTER_INC(thread_userret); 1150ca26e8baSRobert Watson } 1151ca26e8baSRobert Watson 1152d8a7b7a3SRobert Watson /* 11537e400ed1SRobert Watson * Label cleanup/flush operations 11547e400ed1SRobert Watson */ 115530d239bcSRobert Watson COUNTER_DECL(sysvmsg_cleanup); 11567e400ed1SRobert Watson static void 115730d239bcSRobert Watson mac_test_sysvmsg_cleanup(struct label *msglabel) 11587e400ed1SRobert Watson { 11597e400ed1SRobert Watson 1160269ad130SRobert Watson LABEL_CHECK(msglabel, MAGIC_SYSV_MSG); 116130d239bcSRobert Watson COUNTER_INC(sysvmsg_cleanup); 11627e400ed1SRobert Watson } 11637e400ed1SRobert Watson 116430d239bcSRobert Watson COUNTER_DECL(sysvmsq_cleanup); 11657e400ed1SRobert Watson static void 116630d239bcSRobert Watson mac_test_sysvmsq_cleanup(struct label *msqlabel) 11677e400ed1SRobert Watson { 11687e400ed1SRobert Watson 1169269ad130SRobert Watson LABEL_CHECK(msqlabel, MAGIC_SYSV_MSQ); 117030d239bcSRobert Watson COUNTER_INC(sysvmsq_cleanup); 11717e400ed1SRobert Watson } 11727e400ed1SRobert Watson 117330d239bcSRobert Watson COUNTER_DECL(sysvsem_cleanup); 11747e400ed1SRobert Watson static void 117530d239bcSRobert Watson mac_test_sysvsem_cleanup(struct label *semalabel) 11767e400ed1SRobert Watson { 11777e400ed1SRobert Watson 1178269ad130SRobert Watson LABEL_CHECK(semalabel, MAGIC_SYSV_SEM); 117930d239bcSRobert Watson COUNTER_INC(sysvsem_cleanup); 11807e400ed1SRobert Watson } 11817e400ed1SRobert Watson 118230d239bcSRobert Watson COUNTER_DECL(sysvshm_cleanup); 11837e400ed1SRobert Watson static void 118430d239bcSRobert Watson mac_test_sysvshm_cleanup(struct label *shmlabel) 11857e400ed1SRobert Watson { 11867e400ed1SRobert Watson 1187269ad130SRobert Watson LABEL_CHECK(shmlabel, MAGIC_SYSV_SHM); 118830d239bcSRobert Watson COUNTER_INC(sysvshm_cleanup); 11897e400ed1SRobert Watson } 11907e400ed1SRobert Watson 11917e400ed1SRobert Watson /* 1192d8a7b7a3SRobert Watson * Access control checks. 1193d8a7b7a3SRobert Watson */ 119430d239bcSRobert Watson COUNTER_DECL(bpfdesc_check_receive); 1195d8a7b7a3SRobert Watson static int 119630d239bcSRobert Watson mac_test_bpfdesc_check_receive(struct bpf_d *bpf_d, struct label *bpflabel, 1197d8a7b7a3SRobert Watson struct ifnet *ifnet, struct label *ifnetlabel) 1198d8a7b7a3SRobert Watson { 1199d8a7b7a3SRobert Watson 12006827d029SRobert Watson LABEL_CHECK(bpflabel, MAGIC_BPF); 12016827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 120230d239bcSRobert Watson COUNTER_INC(bpfdesc_check_receive); 1203250ee706SRobert Watson 1204d8a7b7a3SRobert Watson return (0); 1205d8a7b7a3SRobert Watson } 1206d8a7b7a3SRobert Watson 120730d239bcSRobert Watson COUNTER_DECL(cred_check_relabel); 1208d8a7b7a3SRobert Watson static int 120930d239bcSRobert Watson mac_test_cred_check_relabel(struct ucred *cred, struct label *newlabel) 1210d8a7b7a3SRobert Watson { 1211d8a7b7a3SRobert Watson 12126827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 12136827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_CRED); 121430d239bcSRobert Watson COUNTER_INC(cred_check_relabel); 1215250ee706SRobert Watson 1216d8a7b7a3SRobert Watson return (0); 1217d8a7b7a3SRobert Watson } 1218d8a7b7a3SRobert Watson 121930d239bcSRobert Watson COUNTER_DECL(cred_check_visible); 1220d8a7b7a3SRobert Watson static int 122130d239bcSRobert Watson mac_test_cred_check_visible(struct ucred *u1, struct ucred *u2) 1222d8a7b7a3SRobert Watson { 1223d8a7b7a3SRobert Watson 12246827d029SRobert Watson LABEL_CHECK(u1->cr_label, MAGIC_CRED); 12256827d029SRobert Watson LABEL_CHECK(u2->cr_label, MAGIC_CRED); 122630d239bcSRobert Watson COUNTER_INC(cred_check_visible); 1227250ee706SRobert Watson 1228d8a7b7a3SRobert Watson return (0); 1229d8a7b7a3SRobert Watson } 1230d8a7b7a3SRobert Watson 123130d239bcSRobert Watson COUNTER_DECL(ifnet_check_relabel); 1232d8a7b7a3SRobert Watson static int 123330d239bcSRobert Watson mac_test_ifnet_check_relabel(struct ucred *cred, struct ifnet *ifnet, 1234d8a7b7a3SRobert Watson struct label *ifnetlabel, struct label *newlabel) 1235d8a7b7a3SRobert Watson { 1236d8a7b7a3SRobert Watson 12376827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 12386827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 12396827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_IFNET); 124030d239bcSRobert Watson COUNTER_INC(ifnet_check_relabel); 1241269ad130SRobert Watson 1242d8a7b7a3SRobert Watson return (0); 1243d8a7b7a3SRobert Watson } 1244d8a7b7a3SRobert Watson 124530d239bcSRobert Watson COUNTER_DECL(ifnet_check_transmit); 1246d8a7b7a3SRobert Watson static int 124730d239bcSRobert Watson mac_test_ifnet_check_transmit(struct ifnet *ifnet, struct label *ifnetlabel, 1248d8a7b7a3SRobert Watson struct mbuf *m, struct label *mbuflabel) 1249d8a7b7a3SRobert Watson { 1250d8a7b7a3SRobert Watson 12516827d029SRobert Watson LABEL_CHECK(ifnetlabel, MAGIC_IFNET); 12526827d029SRobert Watson LABEL_CHECK(mbuflabel, MAGIC_MBUF); 125330d239bcSRobert Watson COUNTER_INC(ifnet_check_transmit); 1254250ee706SRobert Watson 1255d8a7b7a3SRobert Watson return (0); 1256d8a7b7a3SRobert Watson } 1257d8a7b7a3SRobert Watson 125830d239bcSRobert Watson COUNTER_DECL(inpcb_check_deliver); 1259d8a7b7a3SRobert Watson static int 126030d239bcSRobert Watson mac_test_inpcb_check_deliver(struct inpcb *inp, struct label *inplabel, 1261a557af22SRobert Watson struct mbuf *m, struct label *mlabel) 1262a557af22SRobert Watson { 1263a557af22SRobert Watson 12646827d029SRobert Watson LABEL_CHECK(inplabel, MAGIC_INPCB); 12656827d029SRobert Watson LABEL_CHECK(mlabel, MAGIC_MBUF); 126630d239bcSRobert Watson COUNTER_INC(inpcb_check_deliver); 1267a557af22SRobert Watson 1268a557af22SRobert Watson return (0); 1269a557af22SRobert Watson } 1270a557af22SRobert Watson 127130d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msgmsq); 1272a557af22SRobert Watson static int 127330d239bcSRobert Watson mac_test_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr, 12747e400ed1SRobert Watson struct label *msglabel, struct msqid_kernel *msqkptr, 12757e400ed1SRobert Watson struct label *msqklabel) 12767e400ed1SRobert Watson { 12777e400ed1SRobert Watson 1278269ad130SRobert Watson LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ); 1279269ad130SRobert Watson LABEL_CHECK(msglabel, MAGIC_SYSV_MSG); 12806827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 128130d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msgmsq); 12827e400ed1SRobert Watson 12837e400ed1SRobert Watson return (0); 12847e400ed1SRobert Watson } 12857e400ed1SRobert Watson 128630d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msgrcv); 12877e400ed1SRobert Watson static int 128830d239bcSRobert Watson mac_test_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr, 12897e400ed1SRobert Watson struct label *msglabel) 12907e400ed1SRobert Watson { 12917e400ed1SRobert Watson 1292269ad130SRobert Watson LABEL_CHECK(msglabel, MAGIC_SYSV_MSG); 12936827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 129430d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msgrcv); 12957e400ed1SRobert Watson 12967e400ed1SRobert Watson return (0); 12977e400ed1SRobert Watson } 12987e400ed1SRobert Watson 129930d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msgrmid); 13007e400ed1SRobert Watson static int 130130d239bcSRobert Watson mac_test_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr, 13027e400ed1SRobert Watson struct label *msglabel) 13037e400ed1SRobert Watson { 13047e400ed1SRobert Watson 1305269ad130SRobert Watson LABEL_CHECK(msglabel, MAGIC_SYSV_MSG); 13066827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 130730d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msgrmid); 13087e400ed1SRobert Watson 13097e400ed1SRobert Watson return (0); 13107e400ed1SRobert Watson } 13117e400ed1SRobert Watson 131230d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msqget); 13137e400ed1SRobert Watson static int 131430d239bcSRobert Watson mac_test_sysvmsq_check_msqget(struct ucred *cred, 131530d239bcSRobert Watson struct msqid_kernel *msqkptr, struct label *msqklabel) 13167e400ed1SRobert Watson { 13177e400ed1SRobert Watson 1318269ad130SRobert Watson LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ); 13196827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 132030d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msqget); 13217e400ed1SRobert Watson 13227e400ed1SRobert Watson return (0); 13237e400ed1SRobert Watson } 13247e400ed1SRobert Watson 132530d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msqsnd); 13267e400ed1SRobert Watson static int 132730d239bcSRobert Watson mac_test_sysvmsq_check_msqsnd(struct ucred *cred, 132830d239bcSRobert Watson struct msqid_kernel *msqkptr, struct label *msqklabel) 13297e400ed1SRobert Watson { 13307e400ed1SRobert Watson 1331269ad130SRobert Watson LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ); 13326827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 133330d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msqsnd); 13347e400ed1SRobert Watson 13357e400ed1SRobert Watson return (0); 13367e400ed1SRobert Watson } 13377e400ed1SRobert Watson 133830d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msqrcv); 13397e400ed1SRobert Watson static int 134030d239bcSRobert Watson mac_test_sysvmsq_check_msqrcv(struct ucred *cred, 134130d239bcSRobert Watson struct msqid_kernel *msqkptr, struct label *msqklabel) 13427e400ed1SRobert Watson { 13437e400ed1SRobert Watson 1344269ad130SRobert Watson LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ); 13456827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 134630d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msqrcv); 13477e400ed1SRobert Watson 13487e400ed1SRobert Watson return (0); 13497e400ed1SRobert Watson } 13507e400ed1SRobert Watson 135130d239bcSRobert Watson COUNTER_DECL(sysvmsq_check_msqctl); 13527e400ed1SRobert Watson static int 135330d239bcSRobert Watson mac_test_sysvmsq_check_msqctl(struct ucred *cred, 135430d239bcSRobert Watson struct msqid_kernel *msqkptr, struct label *msqklabel, int cmd) 13557e400ed1SRobert Watson { 13567e400ed1SRobert Watson 1357269ad130SRobert Watson LABEL_CHECK(msqklabel, MAGIC_SYSV_MSQ); 13586827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 135930d239bcSRobert Watson COUNTER_INC(sysvmsq_check_msqctl); 13607e400ed1SRobert Watson 13617e400ed1SRobert Watson return (0); 13627e400ed1SRobert Watson } 13637e400ed1SRobert Watson 136430d239bcSRobert Watson COUNTER_DECL(sysvsem_check_semctl); 13657e400ed1SRobert Watson static int 136630d239bcSRobert Watson mac_test_sysvsem_check_semctl(struct ucred *cred, 136730d239bcSRobert Watson struct semid_kernel *semakptr, struct label *semaklabel, int cmd) 13687e400ed1SRobert Watson { 13697e400ed1SRobert Watson 13706827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1371269ad130SRobert Watson LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM); 137230d239bcSRobert Watson COUNTER_INC(sysvsem_check_semctl); 13737e400ed1SRobert Watson 13747e400ed1SRobert Watson return (0); 13757e400ed1SRobert Watson } 13767e400ed1SRobert Watson 137730d239bcSRobert Watson COUNTER_DECL(sysvsem_check_semget); 13787e400ed1SRobert Watson static int 137930d239bcSRobert Watson mac_test_sysvsem_check_semget(struct ucred *cred, 138030d239bcSRobert Watson struct semid_kernel *semakptr, struct label *semaklabel) 13817e400ed1SRobert Watson { 13827e400ed1SRobert Watson 13836827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1384269ad130SRobert Watson LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM); 138530d239bcSRobert Watson COUNTER_INC(sysvsem_check_semget); 13867e400ed1SRobert Watson 13877e400ed1SRobert Watson return (0); 13887e400ed1SRobert Watson } 13897e400ed1SRobert Watson 139030d239bcSRobert Watson COUNTER_DECL(sysvsem_check_semop); 13917e400ed1SRobert Watson static int 139230d239bcSRobert Watson mac_test_sysvsem_check_semop(struct ucred *cred, 139330d239bcSRobert Watson struct semid_kernel *semakptr, struct label *semaklabel, size_t accesstype) 13947e400ed1SRobert Watson { 13957e400ed1SRobert Watson 13966827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1397269ad130SRobert Watson LABEL_CHECK(semaklabel, MAGIC_SYSV_SEM); 139830d239bcSRobert Watson COUNTER_INC(sysvsem_check_semop); 13997e400ed1SRobert Watson 14007e400ed1SRobert Watson return (0); 14017e400ed1SRobert Watson } 14027e400ed1SRobert Watson 140330d239bcSRobert Watson COUNTER_DECL(sysvshm_check_shmat); 14047e400ed1SRobert Watson static int 140530d239bcSRobert Watson mac_test_sysvshm_check_shmat(struct ucred *cred, 140630d239bcSRobert Watson struct shmid_kernel *shmsegptr, struct label *shmseglabel, int shmflg) 14077e400ed1SRobert Watson { 14087e400ed1SRobert Watson 14096827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1410269ad130SRobert Watson LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM); 141130d239bcSRobert Watson COUNTER_INC(sysvshm_check_shmat); 14127e400ed1SRobert Watson 14137e400ed1SRobert Watson return (0); 14147e400ed1SRobert Watson } 14157e400ed1SRobert Watson 141630d239bcSRobert Watson COUNTER_DECL(sysvshm_check_shmctl); 14177e400ed1SRobert Watson static int 141830d239bcSRobert Watson mac_test_sysvshm_check_shmctl(struct ucred *cred, 141930d239bcSRobert Watson struct shmid_kernel *shmsegptr, struct label *shmseglabel, int cmd) 14207e400ed1SRobert Watson { 14217e400ed1SRobert Watson 14226827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1423269ad130SRobert Watson LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM); 142430d239bcSRobert Watson COUNTER_INC(sysvshm_check_shmctl); 14257e400ed1SRobert Watson 14267e400ed1SRobert Watson return (0); 14277e400ed1SRobert Watson } 14287e400ed1SRobert Watson 142930d239bcSRobert Watson COUNTER_DECL(sysvshm_check_shmdt); 14307e400ed1SRobert Watson static int 143130d239bcSRobert Watson mac_test_sysvshm_check_shmdt(struct ucred *cred, 143230d239bcSRobert Watson struct shmid_kernel *shmsegptr, struct label *shmseglabel) 14337e400ed1SRobert Watson { 14347e400ed1SRobert Watson 14356827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1436269ad130SRobert Watson LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM); 143730d239bcSRobert Watson COUNTER_INC(sysvshm_check_shmdt); 14387e400ed1SRobert Watson 14397e400ed1SRobert Watson return (0); 14407e400ed1SRobert Watson } 14417e400ed1SRobert Watson 144230d239bcSRobert Watson COUNTER_DECL(sysvshm_check_shmget); 14437e400ed1SRobert Watson static int 144430d239bcSRobert Watson mac_test_sysvshm_check_shmget(struct ucred *cred, 144530d239bcSRobert Watson struct shmid_kernel *shmsegptr, struct label *shmseglabel, int shmflg) 14467e400ed1SRobert Watson { 14477e400ed1SRobert Watson 14486827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1449269ad130SRobert Watson LABEL_CHECK(shmseglabel, MAGIC_SYSV_SHM); 145030d239bcSRobert Watson COUNTER_INC(sysvshm_check_shmget); 14517e400ed1SRobert Watson 14527e400ed1SRobert Watson return (0); 14537e400ed1SRobert Watson } 14547e400ed1SRobert Watson 145530d239bcSRobert Watson COUNTER_DECL(kenv_check_dump); 14567e400ed1SRobert Watson static int 145730d239bcSRobert Watson mac_test_kenv_check_dump(struct ucred *cred) 1458ca26e8baSRobert Watson { 1459ca26e8baSRobert Watson 14606827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 146130d239bcSRobert Watson COUNTER_INC(kenv_check_dump); 1462250ee706SRobert Watson 1463ca26e8baSRobert Watson return (0); 1464ca26e8baSRobert Watson } 1465ca26e8baSRobert Watson 146630d239bcSRobert Watson COUNTER_DECL(kenv_check_get); 1467ca26e8baSRobert Watson static int 146830d239bcSRobert Watson mac_test_kenv_check_get(struct ucred *cred, char *name) 1469ca26e8baSRobert Watson { 1470ca26e8baSRobert Watson 14716827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 147230d239bcSRobert Watson COUNTER_INC(kenv_check_get); 1473250ee706SRobert Watson 1474ca26e8baSRobert Watson return (0); 1475ca26e8baSRobert Watson } 1476ca26e8baSRobert Watson 147730d239bcSRobert Watson COUNTER_DECL(kenv_check_set); 1478ca26e8baSRobert Watson static int 147930d239bcSRobert Watson mac_test_kenv_check_set(struct ucred *cred, char *name, char *value) 1480ca26e8baSRobert Watson { 1481ca26e8baSRobert Watson 14826827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 148330d239bcSRobert Watson COUNTER_INC(kenv_check_set); 1484250ee706SRobert Watson 1485ca26e8baSRobert Watson return (0); 1486ca26e8baSRobert Watson } 1487ca26e8baSRobert Watson 148830d239bcSRobert Watson COUNTER_DECL(kenv_check_unset); 1489ca26e8baSRobert Watson static int 149030d239bcSRobert Watson mac_test_kenv_check_unset(struct ucred *cred, char *name) 1491ca26e8baSRobert Watson { 1492ca26e8baSRobert Watson 14936827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 149430d239bcSRobert Watson COUNTER_INC(kenv_check_unset); 1495250ee706SRobert Watson 1496ca26e8baSRobert Watson return (0); 1497ca26e8baSRobert Watson } 1498ca26e8baSRobert Watson 149930d239bcSRobert Watson COUNTER_DECL(kld_check_load); 1500ca26e8baSRobert Watson static int 150130d239bcSRobert Watson mac_test_kld_check_load(struct ucred *cred, struct vnode *vp, 1502ca26e8baSRobert Watson struct label *label) 1503ca26e8baSRobert Watson { 1504ca26e8baSRobert Watson 15056827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 15066827d029SRobert Watson LABEL_CHECK(label, MAGIC_VNODE); 150730d239bcSRobert Watson COUNTER_INC(kld_check_load); 1508250ee706SRobert Watson 1509ca26e8baSRobert Watson return (0); 1510ca26e8baSRobert Watson } 1511ca26e8baSRobert Watson 151230d239bcSRobert Watson COUNTER_DECL(kld_check_stat); 1513ca26e8baSRobert Watson static int 151430d239bcSRobert Watson mac_test_kld_check_stat(struct ucred *cred) 1515ca26e8baSRobert Watson { 1516ca26e8baSRobert Watson 15176827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 151830d239bcSRobert Watson COUNTER_INC(kld_check_stat); 1519250ee706SRobert Watson 1520ca26e8baSRobert Watson return (0); 1521ca26e8baSRobert Watson } 1522ca26e8baSRobert Watson 152330d239bcSRobert Watson COUNTER_DECL(mount_check_stat); 1524ca26e8baSRobert Watson static int 152530d239bcSRobert Watson mac_test_mount_check_stat(struct ucred *cred, struct mount *mp, 152678007886SRobert Watson struct label *mplabel) 1527d8a7b7a3SRobert Watson { 1528d8a7b7a3SRobert Watson 15296827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 153078007886SRobert Watson LABEL_CHECK(mplabel, MAGIC_MOUNT); 153130d239bcSRobert Watson COUNTER_INC(mount_check_stat); 1532250ee706SRobert Watson 1533d8a7b7a3SRobert Watson return (0); 1534d8a7b7a3SRobert Watson } 1535d8a7b7a3SRobert Watson 153630d239bcSRobert Watson COUNTER_DECL(pipe_check_ioctl); 1537d8a7b7a3SRobert Watson static int 153830d239bcSRobert Watson mac_test_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp, 1539d8a7b7a3SRobert Watson struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) 1540d8a7b7a3SRobert Watson { 1541d8a7b7a3SRobert Watson 15426827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 15436827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 154430d239bcSRobert Watson COUNTER_INC(pipe_check_ioctl); 1545250ee706SRobert Watson 1546d8a7b7a3SRobert Watson return (0); 1547d8a7b7a3SRobert Watson } 1548d8a7b7a3SRobert Watson 154930d239bcSRobert Watson COUNTER_DECL(pipe_check_poll); 1550d8a7b7a3SRobert Watson static int 155130d239bcSRobert Watson mac_test_pipe_check_poll(struct ucred *cred, struct pipepair *pp, 1552c024c3eeSRobert Watson struct label *pipelabel) 1553c024c3eeSRobert Watson { 1554c024c3eeSRobert Watson 15556827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 15566827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 155730d239bcSRobert Watson COUNTER_INC(pipe_check_poll); 1558250ee706SRobert Watson 1559c024c3eeSRobert Watson return (0); 1560c024c3eeSRobert Watson } 1561c024c3eeSRobert Watson 156230d239bcSRobert Watson COUNTER_DECL(pipe_check_read); 1563c024c3eeSRobert Watson static int 156430d239bcSRobert Watson mac_test_pipe_check_read(struct ucred *cred, struct pipepair *pp, 1565c024c3eeSRobert Watson struct label *pipelabel) 1566d8a7b7a3SRobert Watson { 1567d8a7b7a3SRobert Watson 15686827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 15696827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 157030d239bcSRobert Watson COUNTER_INC(pipe_check_read); 1571250ee706SRobert Watson 1572d8a7b7a3SRobert Watson return (0); 1573d8a7b7a3SRobert Watson } 1574d8a7b7a3SRobert Watson 157530d239bcSRobert Watson COUNTER_DECL(pipe_check_relabel); 1576d8a7b7a3SRobert Watson static int 157730d239bcSRobert Watson mac_test_pipe_check_relabel(struct ucred *cred, struct pipepair *pp, 1578d8a7b7a3SRobert Watson struct label *pipelabel, struct label *newlabel) 1579d8a7b7a3SRobert Watson { 1580d8a7b7a3SRobert Watson 15816827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 15826827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 15836827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_PIPE); 158430d239bcSRobert Watson COUNTER_INC(pipe_check_relabel); 1585250ee706SRobert Watson 1586d8a7b7a3SRobert Watson return (0); 1587d8a7b7a3SRobert Watson } 1588d8a7b7a3SRobert Watson 158930d239bcSRobert Watson COUNTER_DECL(pipe_check_stat); 1590d8a7b7a3SRobert Watson static int 159130d239bcSRobert Watson mac_test_pipe_check_stat(struct ucred *cred, struct pipepair *pp, 1592c024c3eeSRobert Watson struct label *pipelabel) 1593c024c3eeSRobert Watson { 1594c024c3eeSRobert Watson 15956827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 15966827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 159730d239bcSRobert Watson COUNTER_INC(pipe_check_stat); 1598250ee706SRobert Watson 1599c024c3eeSRobert Watson return (0); 1600c024c3eeSRobert Watson } 1601c024c3eeSRobert Watson 160230d239bcSRobert Watson COUNTER_DECL(pipe_check_write); 1603c024c3eeSRobert Watson static int 160430d239bcSRobert Watson mac_test_pipe_check_write(struct ucred *cred, struct pipepair *pp, 1605c024c3eeSRobert Watson struct label *pipelabel) 1606c024c3eeSRobert Watson { 1607c024c3eeSRobert Watson 16086827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 16096827d029SRobert Watson LABEL_CHECK(pipelabel, MAGIC_PIPE); 161030d239bcSRobert Watson COUNTER_INC(pipe_check_write); 1611250ee706SRobert Watson 1612c024c3eeSRobert Watson return (0); 1613c024c3eeSRobert Watson } 1614c024c3eeSRobert Watson 161530d239bcSRobert Watson COUNTER_DECL(posixsem_check); 1616c024c3eeSRobert Watson static int 161730d239bcSRobert Watson mac_test_posixsem_check(struct ucred *cred, struct ksem *ks, 1618fe09513eSRobert Watson struct label *kslabel) 161952648411SRobert Watson { 162052648411SRobert Watson 16216827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 1622fe09513eSRobert Watson LABEL_CHECK(kslabel, MAGIC_POSIX_SEM); 162330d239bcSRobert Watson COUNTER_INC(posixsem_check); 162452648411SRobert Watson 162552648411SRobert Watson return (0); 162652648411SRobert Watson } 162752648411SRobert Watson 162830d239bcSRobert Watson COUNTER_DECL(proc_check_debug); 162952648411SRobert Watson static int 163030d239bcSRobert Watson mac_test_proc_check_debug(struct ucred *cred, struct proc *p) 1631d8a7b7a3SRobert Watson { 1632d8a7b7a3SRobert Watson 16336827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 163478007886SRobert Watson LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED); 163530d239bcSRobert Watson COUNTER_INC(proc_check_debug); 1636250ee706SRobert Watson 1637d8a7b7a3SRobert Watson return (0); 1638d8a7b7a3SRobert Watson } 1639d8a7b7a3SRobert Watson 164030d239bcSRobert Watson COUNTER_DECL(proc_check_sched); 1641d8a7b7a3SRobert Watson static int 164230d239bcSRobert Watson mac_test_proc_check_sched(struct ucred *cred, struct proc *p) 1643d8a7b7a3SRobert Watson { 1644d8a7b7a3SRobert Watson 16456827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 164678007886SRobert Watson LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED); 164730d239bcSRobert Watson COUNTER_INC(proc_check_sched); 1648250ee706SRobert Watson 1649d8a7b7a3SRobert Watson return (0); 1650d8a7b7a3SRobert Watson } 1651d8a7b7a3SRobert Watson 165230d239bcSRobert Watson COUNTER_DECL(proc_check_signal); 1653d8a7b7a3SRobert Watson static int 165430d239bcSRobert Watson mac_test_proc_check_signal(struct ucred *cred, struct proc *p, int signum) 1655d8a7b7a3SRobert Watson { 1656d8a7b7a3SRobert Watson 16576827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 165878007886SRobert Watson LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED); 165930d239bcSRobert Watson COUNTER_INC(proc_check_signal); 1660250ee706SRobert Watson 1661d8a7b7a3SRobert Watson return (0); 1662d8a7b7a3SRobert Watson } 1663d8a7b7a3SRobert Watson 166430d239bcSRobert Watson COUNTER_DECL(proc_check_setaudit); 1665d8a7b7a3SRobert Watson static int 166630d239bcSRobert Watson mac_test_proc_check_setaudit(struct ucred *cred, struct auditinfo *ai) 166718717f69SRobert Watson { 166818717f69SRobert Watson 16696827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 167030d239bcSRobert Watson COUNTER_INC(proc_check_setaudit); 167118717f69SRobert Watson 167218717f69SRobert Watson return (0); 167318717f69SRobert Watson } 167418717f69SRobert Watson 167530d239bcSRobert Watson COUNTER_DECL(proc_check_setaudit_addr); 1676f1e8bf6dSRobert Watson static int 167730d239bcSRobert Watson mac_test_proc_check_setaudit_addr(struct ucred *cred, 1678f1e8bf6dSRobert Watson struct auditinfo_addr *aia) 1679f1e8bf6dSRobert Watson { 1680f1e8bf6dSRobert Watson 1681f1e8bf6dSRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 168230d239bcSRobert Watson COUNTER_INC(proc_check_setaudit_addr); 1683f1e8bf6dSRobert Watson 1684f1e8bf6dSRobert Watson return (0); 1685f1e8bf6dSRobert Watson } 1686f1e8bf6dSRobert Watson 168730d239bcSRobert Watson COUNTER_DECL(proc_check_setauid); 168818717f69SRobert Watson static int 168930d239bcSRobert Watson mac_test_proc_check_setauid(struct ucred *cred, uid_t auid) 169018717f69SRobert Watson { 169118717f69SRobert Watson 16926827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 169330d239bcSRobert Watson COUNTER_INC(proc_check_setauid); 169418717f69SRobert Watson 169518717f69SRobert Watson return (0); 169618717f69SRobert Watson } 169718717f69SRobert Watson 169830d239bcSRobert Watson COUNTER_DECL(proc_check_setuid); 169918717f69SRobert Watson static int 170030d239bcSRobert Watson mac_test_proc_check_setuid(struct ucred *cred, uid_t uid) 1701030a28b3SRobert Watson { 1702030a28b3SRobert Watson 17036827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 170430d239bcSRobert Watson COUNTER_INC(proc_check_setuid); 1705030a28b3SRobert Watson 1706030a28b3SRobert Watson return (0); 1707030a28b3SRobert Watson } 1708030a28b3SRobert Watson 170930d239bcSRobert Watson COUNTER_DECL(proc_check_euid); 1710030a28b3SRobert Watson static int 171130d239bcSRobert Watson mac_test_proc_check_seteuid(struct ucred *cred, uid_t euid) 1712030a28b3SRobert Watson { 1713030a28b3SRobert Watson 17146827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 171530d239bcSRobert Watson COUNTER_INC(proc_check_euid); 1716030a28b3SRobert Watson 1717030a28b3SRobert Watson return (0); 1718030a28b3SRobert Watson } 1719030a28b3SRobert Watson 172030d239bcSRobert Watson COUNTER_DECL(proc_check_setgid); 1721030a28b3SRobert Watson static int 172230d239bcSRobert Watson mac_test_proc_check_setgid(struct ucred *cred, gid_t gid) 1723030a28b3SRobert Watson { 1724030a28b3SRobert Watson 17256827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 172630d239bcSRobert Watson COUNTER_INC(proc_check_setgid); 1727030a28b3SRobert Watson 1728030a28b3SRobert Watson return (0); 1729030a28b3SRobert Watson } 1730030a28b3SRobert Watson 173130d239bcSRobert Watson COUNTER_DECL(proc_check_setegid); 1732030a28b3SRobert Watson static int 173330d239bcSRobert Watson mac_test_proc_check_setegid(struct ucred *cred, gid_t egid) 1734030a28b3SRobert Watson { 1735030a28b3SRobert Watson 17366827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 173730d239bcSRobert Watson COUNTER_INC(proc_check_setegid); 1738030a28b3SRobert Watson 1739030a28b3SRobert Watson return (0); 1740030a28b3SRobert Watson } 1741030a28b3SRobert Watson 174230d239bcSRobert Watson COUNTER_DECL(proc_check_setgroups); 1743030a28b3SRobert Watson static int 174430d239bcSRobert Watson mac_test_proc_check_setgroups(struct ucred *cred, int ngroups, 1745030a28b3SRobert Watson gid_t *gidset) 1746030a28b3SRobert Watson { 1747030a28b3SRobert Watson 17486827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 174930d239bcSRobert Watson COUNTER_INC(proc_check_setgroups); 1750030a28b3SRobert Watson 1751030a28b3SRobert Watson return (0); 1752030a28b3SRobert Watson } 1753030a28b3SRobert Watson 175430d239bcSRobert Watson COUNTER_DECL(proc_check_setreuid); 1755030a28b3SRobert Watson static int 175630d239bcSRobert Watson mac_test_proc_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid) 1757030a28b3SRobert Watson { 1758030a28b3SRobert Watson 17596827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 176030d239bcSRobert Watson COUNTER_INC(proc_check_setreuid); 1761030a28b3SRobert Watson 1762030a28b3SRobert Watson return (0); 1763030a28b3SRobert Watson } 1764030a28b3SRobert Watson 176530d239bcSRobert Watson COUNTER_DECL(proc_check_setregid); 1766030a28b3SRobert Watson static int 176730d239bcSRobert Watson mac_test_proc_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid) 1768030a28b3SRobert Watson { 1769030a28b3SRobert Watson 17706827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 177130d239bcSRobert Watson COUNTER_INC(proc_check_setregid); 1772030a28b3SRobert Watson 1773030a28b3SRobert Watson return (0); 1774030a28b3SRobert Watson } 1775030a28b3SRobert Watson 177630d239bcSRobert Watson COUNTER_DECL(proc_check_setresuid); 1777030a28b3SRobert Watson static int 177830d239bcSRobert Watson mac_test_proc_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid, 1779030a28b3SRobert Watson uid_t suid) 1780030a28b3SRobert Watson { 1781030a28b3SRobert Watson 17826827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 178330d239bcSRobert Watson COUNTER_INC(proc_check_setresuid); 1784030a28b3SRobert Watson 1785030a28b3SRobert Watson return (0); 1786030a28b3SRobert Watson } 1787030a28b3SRobert Watson 178830d239bcSRobert Watson COUNTER_DECL(proc_check_setresgid); 1789030a28b3SRobert Watson static int 179030d239bcSRobert Watson mac_test_proc_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid, 1791030a28b3SRobert Watson gid_t sgid) 1792030a28b3SRobert Watson { 1793030a28b3SRobert Watson 17946827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 179530d239bcSRobert Watson COUNTER_INC(proc_check_setresgid); 1796030a28b3SRobert Watson 1797030a28b3SRobert Watson return (0); 1798030a28b3SRobert Watson } 1799030a28b3SRobert Watson 180030d239bcSRobert Watson COUNTER_DECL(proc_check_wait); 1801030a28b3SRobert Watson static int 180230d239bcSRobert Watson mac_test_proc_check_wait(struct ucred *cred, struct proc *p) 1803babe9a2bSRobert Watson { 1804babe9a2bSRobert Watson 18056827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 180678007886SRobert Watson LABEL_CHECK(p->p_ucred->cr_label, MAGIC_CRED); 180730d239bcSRobert Watson COUNTER_INC(proc_check_wait); 1808babe9a2bSRobert Watson 1809babe9a2bSRobert Watson return (0); 1810babe9a2bSRobert Watson } 1811babe9a2bSRobert Watson 181230d239bcSRobert Watson COUNTER_DECL(socket_check_accept); 1813babe9a2bSRobert Watson static int 181430d239bcSRobert Watson mac_test_socket_check_accept(struct ucred *cred, struct socket *so, 181578007886SRobert Watson struct label *solabel) 18167f53207bSRobert Watson { 18177f53207bSRobert Watson 18186827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 181978007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 182030d239bcSRobert Watson COUNTER_INC(socket_check_accept); 18217f53207bSRobert Watson 18227f53207bSRobert Watson return (0); 18237f53207bSRobert Watson } 18247f53207bSRobert Watson 182530d239bcSRobert Watson COUNTER_DECL(socket_check_bind); 18267f53207bSRobert Watson static int 182730d239bcSRobert Watson mac_test_socket_check_bind(struct ucred *cred, struct socket *so, 182878007886SRobert Watson struct label *solabel, struct sockaddr *sa) 1829d8a7b7a3SRobert Watson { 1830d8a7b7a3SRobert Watson 18316827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 183278007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 183330d239bcSRobert Watson COUNTER_INC(socket_check_bind); 1834250ee706SRobert Watson 1835d8a7b7a3SRobert Watson return (0); 1836d8a7b7a3SRobert Watson } 1837d8a7b7a3SRobert Watson 183830d239bcSRobert Watson COUNTER_DECL(socket_check_connect); 1839d8a7b7a3SRobert Watson static int 184030d239bcSRobert Watson mac_test_socket_check_connect(struct ucred *cred, struct socket *so, 184178007886SRobert Watson struct label *solabel, struct sockaddr *sa) 1842d8a7b7a3SRobert Watson { 1843d8a7b7a3SRobert Watson 18446827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 184578007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 184630d239bcSRobert Watson COUNTER_INC(socket_check_connect); 1847250ee706SRobert Watson 1848d8a7b7a3SRobert Watson return (0); 1849d8a7b7a3SRobert Watson } 1850d8a7b7a3SRobert Watson 185130d239bcSRobert Watson COUNTER_DECL(socket_check_deliver); 1852d8a7b7a3SRobert Watson static int 185330d239bcSRobert Watson mac_test_socket_check_deliver(struct socket *so, struct label *solabel, 185478007886SRobert Watson struct mbuf *m, struct label *mlabel) 1855d8a7b7a3SRobert Watson { 1856d8a7b7a3SRobert Watson 185778007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 185878007886SRobert Watson LABEL_CHECK(mlabel, MAGIC_MBUF); 185930d239bcSRobert Watson COUNTER_INC(socket_check_deliver); 1860250ee706SRobert Watson 1861d8a7b7a3SRobert Watson return (0); 1862d8a7b7a3SRobert Watson } 1863d8a7b7a3SRobert Watson 186430d239bcSRobert Watson COUNTER_DECL(socket_check_listen); 1865d8a7b7a3SRobert Watson static int 186630d239bcSRobert Watson mac_test_socket_check_listen(struct ucred *cred, struct socket *so, 186778007886SRobert Watson struct label *solabel) 1868d8a7b7a3SRobert Watson { 1869d8a7b7a3SRobert Watson 18706827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 187178007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 187230d239bcSRobert Watson COUNTER_INC(socket_check_listen); 1873250ee706SRobert Watson 1874d8a7b7a3SRobert Watson return (0); 1875d8a7b7a3SRobert Watson } 1876d8a7b7a3SRobert Watson 187730d239bcSRobert Watson COUNTER_DECL(socket_check_poll); 1878d8a7b7a3SRobert Watson static int 187930d239bcSRobert Watson mac_test_socket_check_poll(struct ucred *cred, struct socket *so, 188078007886SRobert Watson struct label *solabel) 18817f53207bSRobert Watson { 18827f53207bSRobert Watson 18836827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 188478007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 188530d239bcSRobert Watson COUNTER_INC(socket_check_poll); 18867f53207bSRobert Watson 18877f53207bSRobert Watson return (0); 18887f53207bSRobert Watson } 18897f53207bSRobert Watson 189030d239bcSRobert Watson COUNTER_DECL(socket_check_receive); 18917f53207bSRobert Watson static int 189230d239bcSRobert Watson mac_test_socket_check_receive(struct ucred *cred, struct socket *so, 189378007886SRobert Watson struct label *solabel) 1894d8a7b7a3SRobert Watson { 1895d8a7b7a3SRobert Watson 18966827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 189778007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 189830d239bcSRobert Watson COUNTER_INC(socket_check_receive); 1899250ee706SRobert Watson 1900d8a7b7a3SRobert Watson return (0); 1901d8a7b7a3SRobert Watson } 1902d8a7b7a3SRobert Watson 190330d239bcSRobert Watson COUNTER_DECL(socket_check_relabel); 1904d8a7b7a3SRobert Watson static int 190530d239bcSRobert Watson mac_test_socket_check_relabel(struct ucred *cred, struct socket *so, 190678007886SRobert Watson struct label *solabel, struct label *newlabel) 1907d8a7b7a3SRobert Watson { 1908d8a7b7a3SRobert Watson 19096827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 191078007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 19116827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_SOCKET); 191230d239bcSRobert Watson COUNTER_INC(socket_check_relabel); 1913250ee706SRobert Watson 1914d8a7b7a3SRobert Watson return (0); 1915d8a7b7a3SRobert Watson } 1916d8a7b7a3SRobert Watson 191730d239bcSRobert Watson COUNTER_DECL(socket_check_send); 1918d8a7b7a3SRobert Watson static int 191930d239bcSRobert Watson mac_test_socket_check_send(struct ucred *cred, struct socket *so, 192078007886SRobert Watson struct label *solabel) 19217f53207bSRobert Watson { 19227f53207bSRobert Watson 19236827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 192478007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 192530d239bcSRobert Watson COUNTER_INC(socket_check_send); 19267f53207bSRobert Watson 19277f53207bSRobert Watson return (0); 19287f53207bSRobert Watson } 19297f53207bSRobert Watson 193030d239bcSRobert Watson COUNTER_DECL(socket_check_stat); 19317f53207bSRobert Watson static int 193230d239bcSRobert Watson mac_test_socket_check_stat(struct ucred *cred, struct socket *so, 193378007886SRobert Watson struct label *solabel) 19347f53207bSRobert Watson { 19357f53207bSRobert Watson 19366827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 193778007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 193830d239bcSRobert Watson COUNTER_INC(socket_check_stat); 19397f53207bSRobert Watson 19407f53207bSRobert Watson return (0); 19417f53207bSRobert Watson } 19427f53207bSRobert Watson 194330d239bcSRobert Watson COUNTER_DECL(socket_check_visible); 19447f53207bSRobert Watson static int 194530d239bcSRobert Watson mac_test_socket_check_visible(struct ucred *cred, struct socket *so, 194678007886SRobert Watson struct label *solabel) 19477f53207bSRobert Watson { 19487f53207bSRobert Watson 19496827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 195078007886SRobert Watson LABEL_CHECK(solabel, MAGIC_SOCKET); 195130d239bcSRobert Watson COUNTER_INC(socket_check_visible); 19527f53207bSRobert Watson 19537f53207bSRobert Watson return (0); 19547f53207bSRobert Watson } 19557f53207bSRobert Watson 195630d239bcSRobert Watson COUNTER_DECL(system_check_acct); 1957ca26e8baSRobert Watson static int 195830d239bcSRobert Watson mac_test_system_check_acct(struct ucred *cred, struct vnode *vp, 195978007886SRobert Watson struct label *vplabel) 1960ca26e8baSRobert Watson { 1961ca26e8baSRobert Watson 19626827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 196378007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 196430d239bcSRobert Watson COUNTER_INC(system_check_acct); 196518717f69SRobert Watson 196618717f69SRobert Watson return (0); 196718717f69SRobert Watson } 196818717f69SRobert Watson 196930d239bcSRobert Watson COUNTER_DECL(system_check_audit); 197018717f69SRobert Watson static int 197130d239bcSRobert Watson mac_test_system_check_audit(struct ucred *cred, void *record, int length) 197218717f69SRobert Watson { 197318717f69SRobert Watson 19746827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 197530d239bcSRobert Watson COUNTER_INC(system_check_audit); 197618717f69SRobert Watson 197718717f69SRobert Watson return (0); 197818717f69SRobert Watson } 197918717f69SRobert Watson 198030d239bcSRobert Watson COUNTER_DECL(system_check_auditctl); 198118717f69SRobert Watson static int 198230d239bcSRobert Watson mac_test_system_check_auditctl(struct ucred *cred, struct vnode *vp, 198378007886SRobert Watson struct label *vplabel) 198418717f69SRobert Watson { 198518717f69SRobert Watson 19866827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 198778007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 198830d239bcSRobert Watson COUNTER_INC(system_check_auditctl); 198918717f69SRobert Watson 199018717f69SRobert Watson return (0); 199118717f69SRobert Watson } 199218717f69SRobert Watson 199330d239bcSRobert Watson COUNTER_DECL(system_check_auditon); 199418717f69SRobert Watson static int 199530d239bcSRobert Watson mac_test_system_check_auditon(struct ucred *cred, int cmd) 199618717f69SRobert Watson { 199718717f69SRobert Watson 19986827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 199930d239bcSRobert Watson COUNTER_INC(system_check_auditon); 2000250ee706SRobert Watson 2001ca26e8baSRobert Watson return (0); 2002ca26e8baSRobert Watson } 2003ca26e8baSRobert Watson 200430d239bcSRobert Watson COUNTER_DECL(system_check_reboot); 2005ca26e8baSRobert Watson static int 200630d239bcSRobert Watson mac_test_system_check_reboot(struct ucred *cred, int how) 2007ca26e8baSRobert Watson { 2008ca26e8baSRobert Watson 20096827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 201030d239bcSRobert Watson COUNTER_INC(system_check_reboot); 2011250ee706SRobert Watson 2012ca26e8baSRobert Watson return (0); 2013ca26e8baSRobert Watson } 2014ca26e8baSRobert Watson 201530d239bcSRobert Watson COUNTER_DECL(system_check_swapoff); 2016ca26e8baSRobert Watson static int 201730d239bcSRobert Watson mac_test_system_check_swapoff(struct ucred *cred, struct vnode *vp, 201878007886SRobert Watson struct label *vplabel) 2019ca26e8baSRobert Watson { 2020ca26e8baSRobert Watson 20216827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 202278007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 202330d239bcSRobert Watson COUNTER_INC(system_check_swapoff); 2024250ee706SRobert Watson 2025ca26e8baSRobert Watson return (0); 2026ca26e8baSRobert Watson } 2027ca26e8baSRobert Watson 202830d239bcSRobert Watson COUNTER_DECL(system_check_swapon); 2029ca26e8baSRobert Watson static int 203030d239bcSRobert Watson mac_test_system_check_swapon(struct ucred *cred, struct vnode *vp, 203178007886SRobert Watson struct label *vplabel) 2032ca26e8baSRobert Watson { 2033ca26e8baSRobert Watson 20346827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 203578007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 203630d239bcSRobert Watson COUNTER_INC(system_check_swapon); 2037250ee706SRobert Watson 2038ca26e8baSRobert Watson return (0); 2039ca26e8baSRobert Watson } 2040ca26e8baSRobert Watson 204130d239bcSRobert Watson COUNTER_DECL(system_check_sysctl); 2042ca26e8baSRobert Watson static int 204330d239bcSRobert Watson mac_test_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, 204463dba32bSPawel Jakub Dawidek void *arg1, int arg2, struct sysctl_req *req) 2045ca26e8baSRobert Watson { 2046ca26e8baSRobert Watson 20476827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 204830d239bcSRobert Watson COUNTER_INC(system_check_sysctl); 2049250ee706SRobert Watson 2050ca26e8baSRobert Watson return (0); 2051ca26e8baSRobert Watson } 2052ca26e8baSRobert Watson 205330d239bcSRobert Watson COUNTER_DECL(vnode_check_access); 2054ca26e8baSRobert Watson static int 205530d239bcSRobert Watson mac_test_vnode_check_access(struct ucred *cred, struct vnode *vp, 205678007886SRobert Watson struct label *vplabel, int acc_mode) 2057d8a7b7a3SRobert Watson { 2058d8a7b7a3SRobert Watson 20596827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 206078007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 206130d239bcSRobert Watson COUNTER_INC(vnode_check_access); 2062250ee706SRobert Watson 2063d8a7b7a3SRobert Watson return (0); 2064d8a7b7a3SRobert Watson } 2065d8a7b7a3SRobert Watson 206630d239bcSRobert Watson COUNTER_DECL(vnode_check_chdir); 2067d8a7b7a3SRobert Watson static int 206830d239bcSRobert Watson mac_test_vnode_check_chdir(struct ucred *cred, struct vnode *dvp, 206978007886SRobert Watson struct label *dvplabel) 2070d8a7b7a3SRobert Watson { 2071d8a7b7a3SRobert Watson 20726827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 207378007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 207430d239bcSRobert Watson COUNTER_INC(vnode_check_chdir); 2075250ee706SRobert Watson 2076d8a7b7a3SRobert Watson return (0); 2077d8a7b7a3SRobert Watson } 2078d8a7b7a3SRobert Watson 207930d239bcSRobert Watson COUNTER_DECL(vnode_check_chroot); 2080d8a7b7a3SRobert Watson static int 208130d239bcSRobert Watson mac_test_vnode_check_chroot(struct ucred *cred, struct vnode *dvp, 208278007886SRobert Watson struct label *dvplabel) 2083d8a7b7a3SRobert Watson { 2084d8a7b7a3SRobert Watson 20856827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 208678007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 208730d239bcSRobert Watson COUNTER_INC(vnode_check_chroot); 2088250ee706SRobert Watson 2089d8a7b7a3SRobert Watson return (0); 2090d8a7b7a3SRobert Watson } 2091d8a7b7a3SRobert Watson 209230d239bcSRobert Watson COUNTER_DECL(vnode_check_create); 2093d8a7b7a3SRobert Watson static int 209430d239bcSRobert Watson mac_test_vnode_check_create(struct ucred *cred, struct vnode *dvp, 209578007886SRobert Watson struct label *dvplabel, struct componentname *cnp, struct vattr *vap) 2096d8a7b7a3SRobert Watson { 2097d8a7b7a3SRobert Watson 20986827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 209978007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 210030d239bcSRobert Watson COUNTER_INC(vnode_check_create); 2101250ee706SRobert Watson 2102d8a7b7a3SRobert Watson return (0); 2103d8a7b7a3SRobert Watson } 2104d8a7b7a3SRobert Watson 210530d239bcSRobert Watson COUNTER_DECL(vnode_check_deleteacl); 2106d8a7b7a3SRobert Watson static int 210730d239bcSRobert Watson mac_test_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, 210878007886SRobert Watson struct label *vplabel, acl_type_t type) 2109d8a7b7a3SRobert Watson { 2110d8a7b7a3SRobert Watson 21116827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 211278007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 211330d239bcSRobert Watson COUNTER_INC(vnode_check_deleteacl); 2114250ee706SRobert Watson 2115250ee706SRobert Watson return (0); 2116250ee706SRobert Watson } 2117250ee706SRobert Watson 211830d239bcSRobert Watson COUNTER_DECL(vnode_check_deleteextattr); 2119250ee706SRobert Watson static int 212030d239bcSRobert Watson mac_test_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp, 212178007886SRobert Watson struct label *vplabel, int attrnamespace, const char *name) 2122250ee706SRobert Watson { 2123250ee706SRobert Watson 21246827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 212578007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 212630d239bcSRobert Watson COUNTER_INC(vnode_check_deleteextattr); 2127250ee706SRobert Watson 2128d8a7b7a3SRobert Watson return (0); 2129d8a7b7a3SRobert Watson } 2130d8a7b7a3SRobert Watson 213130d239bcSRobert Watson COUNTER_DECL(vnode_check_exec); 2132d8a7b7a3SRobert Watson static int 213330d239bcSRobert Watson mac_test_vnode_check_exec(struct ucred *cred, struct vnode *vp, 213478007886SRobert Watson struct label *vplabel, struct image_params *imgp, 2135ef5def59SRobert Watson struct label *execlabel) 2136d8a7b7a3SRobert Watson { 2137d8a7b7a3SRobert Watson 21386827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 213978007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 21406827d029SRobert Watson LABEL_CHECK(execlabel, MAGIC_CRED); 214130d239bcSRobert Watson COUNTER_INC(vnode_check_exec); 2142250ee706SRobert Watson 2143d8a7b7a3SRobert Watson return (0); 2144d8a7b7a3SRobert Watson } 2145d8a7b7a3SRobert Watson 214630d239bcSRobert Watson COUNTER_DECL(vnode_check_getacl); 2147d8a7b7a3SRobert Watson static int 214830d239bcSRobert Watson mac_test_vnode_check_getacl(struct ucred *cred, struct vnode *vp, 214978007886SRobert Watson struct label *vplabel, acl_type_t type) 2150d8a7b7a3SRobert Watson { 2151d8a7b7a3SRobert Watson 21526827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 215378007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 215430d239bcSRobert Watson COUNTER_INC(vnode_check_getacl); 2155250ee706SRobert Watson 2156d8a7b7a3SRobert Watson return (0); 2157d8a7b7a3SRobert Watson } 2158d8a7b7a3SRobert Watson 215930d239bcSRobert Watson COUNTER_DECL(vnode_check_getextattr); 2160d8a7b7a3SRobert Watson static int 216130d239bcSRobert Watson mac_test_vnode_check_getextattr(struct ucred *cred, struct vnode *vp, 216278007886SRobert Watson struct label *vplabel, int attrnamespace, const char *name, 216378007886SRobert Watson struct uio *uio) 2164d8a7b7a3SRobert Watson { 2165d8a7b7a3SRobert Watson 21666827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 216778007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 216830d239bcSRobert Watson COUNTER_INC(vnode_check_getextattr); 2169250ee706SRobert Watson 2170d8a7b7a3SRobert Watson return (0); 2171d8a7b7a3SRobert Watson } 2172d8a7b7a3SRobert Watson 217330d239bcSRobert Watson COUNTER_DECL(vnode_check_link); 2174d8a7b7a3SRobert Watson static int 217530d239bcSRobert Watson mac_test_vnode_check_link(struct ucred *cred, struct vnode *dvp, 217678007886SRobert Watson struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2177c27b50f5SRobert Watson struct componentname *cnp) 2178c27b50f5SRobert Watson { 2179c27b50f5SRobert Watson 21806827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 218178007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 218278007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 218330d239bcSRobert Watson COUNTER_INC(vnode_check_link); 2184250ee706SRobert Watson 2185250ee706SRobert Watson return (0); 2186250ee706SRobert Watson } 2187250ee706SRobert Watson 218830d239bcSRobert Watson COUNTER_DECL(vnode_check_listextattr); 2189250ee706SRobert Watson static int 219030d239bcSRobert Watson mac_test_vnode_check_listextattr(struct ucred *cred, struct vnode *vp, 219178007886SRobert Watson struct label *vplabel, int attrnamespace) 2192250ee706SRobert Watson { 2193250ee706SRobert Watson 21946827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 219578007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 219630d239bcSRobert Watson COUNTER_INC(vnode_check_listextattr); 2197250ee706SRobert Watson 2198c27b50f5SRobert Watson return (0); 2199c27b50f5SRobert Watson } 2200c27b50f5SRobert Watson 220130d239bcSRobert Watson COUNTER_DECL(vnode_check_lookup); 2202c27b50f5SRobert Watson static int 220330d239bcSRobert Watson mac_test_vnode_check_lookup(struct ucred *cred, struct vnode *dvp, 220478007886SRobert Watson struct label *dvplabel, struct componentname *cnp) 2205d8a7b7a3SRobert Watson { 2206d8a7b7a3SRobert Watson 22076827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 220878007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 220930d239bcSRobert Watson COUNTER_INC(vnode_check_lookup); 2210250ee706SRobert Watson 2211d8a7b7a3SRobert Watson return (0); 2212d8a7b7a3SRobert Watson } 2213d8a7b7a3SRobert Watson 221430d239bcSRobert Watson COUNTER_DECL(vnode_check_mmap); 2215d8a7b7a3SRobert Watson static int 221630d239bcSRobert Watson mac_test_vnode_check_mmap(struct ucred *cred, struct vnode *vp, 221778007886SRobert Watson struct label *vplabel, int prot, int flags) 2218e183f80eSRobert Watson { 2219e183f80eSRobert Watson 22206827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 222178007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 222230d239bcSRobert Watson COUNTER_INC(vnode_check_mmap); 2223250ee706SRobert Watson 2224e183f80eSRobert Watson return (0); 2225e183f80eSRobert Watson } 2226e183f80eSRobert Watson 222730d239bcSRobert Watson COUNTER_DECL(vnode_check_open); 2228e183f80eSRobert Watson static int 222930d239bcSRobert Watson mac_test_vnode_check_open(struct ucred *cred, struct vnode *vp, 223078007886SRobert Watson struct label *vplabel, int acc_mode) 2231d8a7b7a3SRobert Watson { 2232d8a7b7a3SRobert Watson 22336827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 223478007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 223530d239bcSRobert Watson COUNTER_INC(vnode_check_open); 2236250ee706SRobert Watson 2237d8a7b7a3SRobert Watson return (0); 2238d8a7b7a3SRobert Watson } 2239d8a7b7a3SRobert Watson 224030d239bcSRobert Watson COUNTER_DECL(vnode_check_poll); 2241d8a7b7a3SRobert Watson static int 224230d239bcSRobert Watson mac_test_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred, 224378007886SRobert Watson struct vnode *vp, struct label *vplabel) 22447f724f8bSRobert Watson { 22457f724f8bSRobert Watson 22466827d029SRobert Watson LABEL_CHECK(active_cred->cr_label, MAGIC_CRED); 22476827d029SRobert Watson if (file_cred != NULL) 22486827d029SRobert Watson LABEL_CHECK(file_cred->cr_label, MAGIC_CRED); 224978007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 225030d239bcSRobert Watson COUNTER_INC(vnode_check_poll); 2251250ee706SRobert Watson 22527f724f8bSRobert Watson return (0); 22537f724f8bSRobert Watson } 22547f724f8bSRobert Watson 225530d239bcSRobert Watson COUNTER_DECL(vnode_check_read); 22567f724f8bSRobert Watson static int 225730d239bcSRobert Watson mac_test_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred, 225878007886SRobert Watson struct vnode *vp, struct label *vplabel) 22597f724f8bSRobert Watson { 22607f724f8bSRobert Watson 22616827d029SRobert Watson LABEL_CHECK(active_cred->cr_label, MAGIC_CRED); 22626827d029SRobert Watson if (file_cred != NULL) 22636827d029SRobert Watson LABEL_CHECK(file_cred->cr_label, MAGIC_CRED); 226478007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 226530d239bcSRobert Watson COUNTER_INC(vnode_check_read); 2266250ee706SRobert Watson 22677f724f8bSRobert Watson return (0); 22687f724f8bSRobert Watson } 22697f724f8bSRobert Watson 227030d239bcSRobert Watson COUNTER_DECL(vnode_check_readdir); 22717f724f8bSRobert Watson static int 227230d239bcSRobert Watson mac_test_vnode_check_readdir(struct ucred *cred, struct vnode *dvp, 227378007886SRobert Watson struct label *dvplabel) 2274d8a7b7a3SRobert Watson { 2275d8a7b7a3SRobert Watson 22766827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 227778007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 227830d239bcSRobert Watson COUNTER_INC(vnode_check_readdir); 2279250ee706SRobert Watson 2280d8a7b7a3SRobert Watson return (0); 2281d8a7b7a3SRobert Watson } 2282d8a7b7a3SRobert Watson 228330d239bcSRobert Watson COUNTER_DECL(vnode_check_readlink); 2284d8a7b7a3SRobert Watson static int 228530d239bcSRobert Watson mac_test_vnode_check_readlink(struct ucred *cred, struct vnode *vp, 228678007886SRobert Watson struct label *vplabel) 2287d8a7b7a3SRobert Watson { 2288d8a7b7a3SRobert Watson 22896827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 229078007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 229130d239bcSRobert Watson COUNTER_INC(vnode_check_readlink); 2292250ee706SRobert Watson 2293d8a7b7a3SRobert Watson return (0); 2294d8a7b7a3SRobert Watson } 2295d8a7b7a3SRobert Watson 229630d239bcSRobert Watson COUNTER_DECL(vnode_check_relabel); 2297d8a7b7a3SRobert Watson static int 229830d239bcSRobert Watson mac_test_vnode_check_relabel(struct ucred *cred, struct vnode *vp, 229978007886SRobert Watson struct label *vplabel, struct label *newlabel) 2300d8a7b7a3SRobert Watson { 2301d8a7b7a3SRobert Watson 23026827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 230378007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 23046827d029SRobert Watson LABEL_CHECK(newlabel, MAGIC_VNODE); 230530d239bcSRobert Watson COUNTER_INC(vnode_check_relabel); 2306250ee706SRobert Watson 2307d8a7b7a3SRobert Watson return (0); 2308d8a7b7a3SRobert Watson } 2309d8a7b7a3SRobert Watson 231030d239bcSRobert Watson COUNTER_DECL(vnode_check_rename_from); 2311d8a7b7a3SRobert Watson static int 231230d239bcSRobert Watson mac_test_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, 231378007886SRobert Watson struct label *dvplabel, struct vnode *vp, struct label *vplabel, 2314d8a7b7a3SRobert Watson struct componentname *cnp) 2315d8a7b7a3SRobert Watson { 2316d8a7b7a3SRobert Watson 23176827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 231878007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 231978007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 232030d239bcSRobert Watson COUNTER_INC(vnode_check_rename_from); 2321250ee706SRobert Watson 2322d8a7b7a3SRobert Watson return (0); 2323d8a7b7a3SRobert Watson } 2324d8a7b7a3SRobert Watson 232530d239bcSRobert Watson COUNTER_DECL(vnode_check_rename_to); 2326d8a7b7a3SRobert Watson static int 232730d239bcSRobert Watson mac_test_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, 232878007886SRobert Watson struct label *dvplabel, struct vnode *vp, struct label *vplabel, 232978007886SRobert Watson int samedir, struct componentname *cnp) 2330d8a7b7a3SRobert Watson { 2331d8a7b7a3SRobert Watson 23326827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 233378007886SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 233478007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 233530d239bcSRobert Watson COUNTER_INC(vnode_check_rename_to); 2336250ee706SRobert Watson 2337d8a7b7a3SRobert Watson return (0); 2338d8a7b7a3SRobert Watson } 2339d8a7b7a3SRobert Watson 234030d239bcSRobert Watson COUNTER_DECL(vnode_check_revoke); 2341d8a7b7a3SRobert Watson static int 234230d239bcSRobert Watson mac_test_vnode_check_revoke(struct ucred *cred, struct vnode *vp, 234378007886SRobert Watson struct label *vplabel) 2344d8a7b7a3SRobert Watson { 2345d8a7b7a3SRobert Watson 23466827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 234778007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 234830d239bcSRobert Watson COUNTER_INC(vnode_check_revoke); 2349250ee706SRobert Watson 2350d8a7b7a3SRobert Watson return (0); 2351d8a7b7a3SRobert Watson } 2352d8a7b7a3SRobert Watson 235330d239bcSRobert Watson COUNTER_DECL(vnode_check_setacl); 2354d8a7b7a3SRobert Watson static int 235530d239bcSRobert Watson mac_test_vnode_check_setacl(struct ucred *cred, struct vnode *vp, 235678007886SRobert Watson struct label *vplabel, acl_type_t type, struct acl *acl) 2357d8a7b7a3SRobert Watson { 2358d8a7b7a3SRobert Watson 23596827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 236078007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 236130d239bcSRobert Watson COUNTER_INC(vnode_check_setacl); 2362250ee706SRobert Watson 2363d8a7b7a3SRobert Watson return (0); 2364d8a7b7a3SRobert Watson } 2365d8a7b7a3SRobert Watson 236630d239bcSRobert Watson COUNTER_DECL(vnode_check_setextattr); 2367d8a7b7a3SRobert Watson static int 236830d239bcSRobert Watson mac_test_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, 236978007886SRobert Watson struct label *vplabel, int attrnamespace, const char *name, 237078007886SRobert Watson struct uio *uio) 2371d8a7b7a3SRobert Watson { 2372d8a7b7a3SRobert Watson 23736827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 237478007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 237530d239bcSRobert Watson COUNTER_INC(vnode_check_setextattr); 2376250ee706SRobert Watson 2377d8a7b7a3SRobert Watson return (0); 2378d8a7b7a3SRobert Watson } 2379d8a7b7a3SRobert Watson 238030d239bcSRobert Watson COUNTER_DECL(vnode_check_setflags); 2381d8a7b7a3SRobert Watson static int 238230d239bcSRobert Watson mac_test_vnode_check_setflags(struct ucred *cred, struct vnode *vp, 238378007886SRobert Watson struct label *vplabel, u_long flags) 2384d8a7b7a3SRobert Watson { 2385d8a7b7a3SRobert Watson 23866827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 238778007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 238830d239bcSRobert Watson COUNTER_INC(vnode_check_setflags); 2389250ee706SRobert Watson 2390d8a7b7a3SRobert Watson return (0); 2391d8a7b7a3SRobert Watson } 2392d8a7b7a3SRobert Watson 239330d239bcSRobert Watson COUNTER_DECL(vnode_check_setmode); 2394d8a7b7a3SRobert Watson static int 239530d239bcSRobert Watson mac_test_vnode_check_setmode(struct ucred *cred, struct vnode *vp, 239678007886SRobert Watson struct label *vplabel, mode_t mode) 2397d8a7b7a3SRobert Watson { 2398d8a7b7a3SRobert Watson 23996827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 240078007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 240130d239bcSRobert Watson COUNTER_INC(vnode_check_setmode); 2402250ee706SRobert Watson 2403d8a7b7a3SRobert Watson return (0); 2404d8a7b7a3SRobert Watson } 2405d8a7b7a3SRobert Watson 240630d239bcSRobert Watson COUNTER_DECL(vnode_check_setowner); 2407d8a7b7a3SRobert Watson static int 240830d239bcSRobert Watson mac_test_vnode_check_setowner(struct ucred *cred, struct vnode *vp, 240978007886SRobert Watson struct label *vplabel, uid_t uid, gid_t gid) 2410d8a7b7a3SRobert Watson { 2411d8a7b7a3SRobert Watson 24126827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 241378007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 241430d239bcSRobert Watson COUNTER_INC(vnode_check_setowner); 2415250ee706SRobert Watson 2416d8a7b7a3SRobert Watson return (0); 2417d8a7b7a3SRobert Watson } 2418d8a7b7a3SRobert Watson 241930d239bcSRobert Watson COUNTER_DECL(vnode_check_setutimes); 2420d8a7b7a3SRobert Watson static int 242130d239bcSRobert Watson mac_test_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, 242278007886SRobert Watson struct label *vplabel, struct timespec atime, struct timespec mtime) 2423d8a7b7a3SRobert Watson { 2424d8a7b7a3SRobert Watson 24256827d029SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 242678007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 242730d239bcSRobert Watson COUNTER_INC(vnode_check_setutimes); 2428250ee706SRobert Watson 2429d8a7b7a3SRobert Watson return (0); 2430d8a7b7a3SRobert Watson } 2431d8a7b7a3SRobert Watson 243230d239bcSRobert Watson COUNTER_DECL(vnode_check_stat); 2433d8a7b7a3SRobert Watson static int 243430d239bcSRobert Watson mac_test_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred, 243578007886SRobert Watson struct vnode *vp, struct label *vplabel) 2436d8a7b7a3SRobert Watson { 2437d8a7b7a3SRobert Watson 24386827d029SRobert Watson LABEL_CHECK(active_cred->cr_label, MAGIC_CRED); 24396827d029SRobert Watson if (file_cred != NULL) 24406827d029SRobert Watson LABEL_CHECK(file_cred->cr_label, MAGIC_CRED); 244178007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 244230d239bcSRobert Watson COUNTER_INC(vnode_check_stat); 2443250ee706SRobert Watson 2444d8a7b7a3SRobert Watson return (0); 2445d8a7b7a3SRobert Watson } 2446d8a7b7a3SRobert Watson 244730d239bcSRobert Watson COUNTER_DECL(vnode_check_unlink); 244845e0f3d6SRobert Watson static int 244930d239bcSRobert Watson mac_test_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, 245045e0f3d6SRobert Watson struct label *dvplabel, struct vnode *vp, struct label *vplabel, 245145e0f3d6SRobert Watson struct componentname *cnp) 245245e0f3d6SRobert Watson { 245345e0f3d6SRobert Watson 245445e0f3d6SRobert Watson LABEL_CHECK(cred->cr_label, MAGIC_CRED); 245545e0f3d6SRobert Watson LABEL_CHECK(dvplabel, MAGIC_VNODE); 245645e0f3d6SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 245730d239bcSRobert Watson COUNTER_INC(vnode_check_unlink); 245845e0f3d6SRobert Watson 245945e0f3d6SRobert Watson return (0); 246045e0f3d6SRobert Watson } 246145e0f3d6SRobert Watson 246230d239bcSRobert Watson COUNTER_DECL(vnode_check_write); 24637f724f8bSRobert Watson static int 246430d239bcSRobert Watson mac_test_vnode_check_write(struct ucred *active_cred, 246578007886SRobert Watson struct ucred *file_cred, struct vnode *vp, struct label *vplabel) 24667f724f8bSRobert Watson { 24677f724f8bSRobert Watson 24686827d029SRobert Watson LABEL_CHECK(active_cred->cr_label, MAGIC_CRED); 24696827d029SRobert Watson if (file_cred != NULL) 24706827d029SRobert Watson LABEL_CHECK(file_cred->cr_label, MAGIC_CRED); 247178007886SRobert Watson LABEL_CHECK(vplabel, MAGIC_VNODE); 247230d239bcSRobert Watson COUNTER_INC(vnode_check_write); 2473250ee706SRobert Watson 24747f724f8bSRobert Watson return (0); 24757f724f8bSRobert Watson } 24767f724f8bSRobert Watson 24775c8dd342SRobert Watson static struct mac_policy_ops mac_test_ops = 2478d8a7b7a3SRobert Watson { 247930d239bcSRobert Watson .mpo_bpfdesc_init_label = mac_test_bpfdesc_init_label, 248030d239bcSRobert Watson .mpo_cred_init_label = mac_test_cred_init_label, 248130d239bcSRobert Watson .mpo_devfs_init_label = mac_test_devfs_init_label, 248230d239bcSRobert Watson .mpo_ifnet_init_label = mac_test_ifnet_init_label, 248330d239bcSRobert Watson .mpo_sysvmsg_init_label = mac_test_sysvmsg_init_label, 248430d239bcSRobert Watson .mpo_sysvmsq_init_label = mac_test_sysvmsq_init_label, 248530d239bcSRobert Watson .mpo_sysvsem_init_label = mac_test_sysvsem_init_label, 248630d239bcSRobert Watson .mpo_sysvshm_init_label = mac_test_sysvshm_init_label, 248730d239bcSRobert Watson .mpo_inpcb_init_label = mac_test_inpcb_init_label, 248830d239bcSRobert Watson .mpo_ipq_init_label = mac_test_ipq_init_label, 248930d239bcSRobert Watson .mpo_mbuf_init_label = mac_test_mbuf_init_label, 249030d239bcSRobert Watson .mpo_mount_init_label = mac_test_mount_init_label, 249130d239bcSRobert Watson .mpo_pipe_init_label = mac_test_pipe_init_label, 249230d239bcSRobert Watson .mpo_posixsem_init_label = mac_test_posixsem_init_label, 249330d239bcSRobert Watson .mpo_proc_init_label = mac_test_proc_init_label, 249430d239bcSRobert Watson .mpo_socket_init_label = mac_test_socket_init_label, 249530d239bcSRobert Watson .mpo_socketpeer_init_label = mac_test_socketpeer_init_label, 249630d239bcSRobert Watson .mpo_vnode_init_label = mac_test_vnode_init_label, 249730d239bcSRobert Watson .mpo_bpfdesc_destroy_label = mac_test_bpfdesc_destroy_label, 249830d239bcSRobert Watson .mpo_cred_destroy_label = mac_test_cred_destroy_label, 249930d239bcSRobert Watson .mpo_devfs_destroy_label = mac_test_devfs_destroy_label, 250030d239bcSRobert Watson .mpo_ifnet_destroy_label = mac_test_ifnet_destroy_label, 250130d239bcSRobert Watson .mpo_sysvmsg_destroy_label = mac_test_sysvmsg_destroy_label, 250230d239bcSRobert Watson .mpo_sysvmsq_destroy_label = 250330d239bcSRobert Watson mac_test_sysvmsq_destroy_label, 250430d239bcSRobert Watson .mpo_sysvsem_destroy_label = mac_test_sysvsem_destroy_label, 250530d239bcSRobert Watson .mpo_sysvshm_destroy_label = mac_test_sysvshm_destroy_label, 250630d239bcSRobert Watson .mpo_inpcb_destroy_label = mac_test_inpcb_destroy_label, 250730d239bcSRobert Watson .mpo_ipq_destroy_label = mac_test_ipq_destroy_label, 250830d239bcSRobert Watson .mpo_mbuf_destroy_label = mac_test_mbuf_destroy_label, 250930d239bcSRobert Watson .mpo_mount_destroy_label = mac_test_mount_destroy_label, 251030d239bcSRobert Watson .mpo_pipe_destroy_label = mac_test_pipe_destroy_label, 251130d239bcSRobert Watson .mpo_posixsem_destroy_label = mac_test_posixsem_destroy_label, 251230d239bcSRobert Watson .mpo_proc_destroy_label = mac_test_proc_destroy_label, 251330d239bcSRobert Watson .mpo_socket_destroy_label = mac_test_socket_destroy_label, 251430d239bcSRobert Watson .mpo_socketpeer_destroy_label = mac_test_socketpeer_destroy_label, 251530d239bcSRobert Watson .mpo_vnode_destroy_label = mac_test_vnode_destroy_label, 251630d239bcSRobert Watson .mpo_cred_copy_label = mac_test_cred_copy_label, 251730d239bcSRobert Watson .mpo_ifnet_copy_label = mac_test_ifnet_copy_label, 251830d239bcSRobert Watson .mpo_mbuf_copy_label = mac_test_mbuf_copy_label, 251930d239bcSRobert Watson .mpo_pipe_copy_label = mac_test_pipe_copy_label, 252030d239bcSRobert Watson .mpo_socket_copy_label = mac_test_socket_copy_label, 252130d239bcSRobert Watson .mpo_vnode_copy_label = mac_test_vnode_copy_label, 252230d239bcSRobert Watson .mpo_cred_externalize_label = mac_test_externalize_label, 252330d239bcSRobert Watson .mpo_ifnet_externalize_label = mac_test_externalize_label, 252430d239bcSRobert Watson .mpo_pipe_externalize_label = mac_test_externalize_label, 252530d239bcSRobert Watson .mpo_socket_externalize_label = mac_test_externalize_label, 252630d239bcSRobert Watson .mpo_socketpeer_externalize_label = mac_test_externalize_label, 252730d239bcSRobert Watson .mpo_vnode_externalize_label = mac_test_externalize_label, 252830d239bcSRobert Watson .mpo_cred_internalize_label = mac_test_internalize_label, 252930d239bcSRobert Watson .mpo_ifnet_internalize_label = mac_test_internalize_label, 253030d239bcSRobert Watson .mpo_pipe_internalize_label = mac_test_internalize_label, 253130d239bcSRobert Watson .mpo_socket_internalize_label = mac_test_internalize_label, 253230d239bcSRobert Watson .mpo_vnode_internalize_label = mac_test_internalize_label, 253330d239bcSRobert Watson .mpo_devfs_vnode_associate = mac_test_devfs_vnode_associate, 253430d239bcSRobert Watson .mpo_vnode_associate_extattr = mac_test_vnode_associate_extattr, 253530d239bcSRobert Watson .mpo_vnode_associate_singlelabel = mac_test_vnode_associate_singlelabel, 253630d239bcSRobert Watson .mpo_devfs_create_device = mac_test_devfs_create_device, 253730d239bcSRobert Watson .mpo_devfs_create_directory = mac_test_devfs_create_directory, 253830d239bcSRobert Watson .mpo_devfs_create_symlink = mac_test_devfs_create_symlink, 253930d239bcSRobert Watson .mpo_vnode_create_extattr = mac_test_vnode_create_extattr, 254030d239bcSRobert Watson .mpo_mount_create = mac_test_mount_create, 254130d239bcSRobert Watson .mpo_vnode_relabel = mac_test_vnode_relabel, 254230d239bcSRobert Watson .mpo_vnode_setlabel_extattr = mac_test_vnode_setlabel_extattr, 254330d239bcSRobert Watson .mpo_devfs_update = mac_test_devfs_update, 254430d239bcSRobert Watson .mpo_socket_create_mbuf = mac_test_socket_create_mbuf, 254530d239bcSRobert Watson .mpo_pipe_create = mac_test_pipe_create, 254630d239bcSRobert Watson .mpo_posixsem_create = mac_test_posixsem_create, 254730d239bcSRobert Watson .mpo_socket_create = mac_test_socket_create, 254830d239bcSRobert Watson .mpo_socket_newconn = mac_test_socket_newconn, 254930d239bcSRobert Watson .mpo_pipe_relabel = mac_test_pipe_relabel, 255030d239bcSRobert Watson .mpo_socket_relabel = mac_test_socket_relabel, 255130d239bcSRobert Watson .mpo_socketpeer_set_from_mbuf = mac_test_socketpeer_set_from_mbuf, 255230d239bcSRobert Watson .mpo_socketpeer_set_from_socket = mac_test_socketpeer_set_from_socket, 255330d239bcSRobert Watson .mpo_bpfdesc_create = mac_test_bpfdesc_create, 255430d239bcSRobert Watson .mpo_ifnet_create = mac_test_ifnet_create, 255530d239bcSRobert Watson .mpo_inpcb_create = mac_test_inpcb_create, 255630d239bcSRobert Watson .mpo_sysvmsg_create = mac_test_sysvmsg_create, 255730d239bcSRobert Watson .mpo_sysvmsq_create = mac_test_sysvmsq_create, 255830d239bcSRobert Watson .mpo_sysvsem_create = mac_test_sysvsem_create, 255930d239bcSRobert Watson .mpo_sysvshm_create = mac_test_sysvshm_create, 256030d239bcSRobert Watson .mpo_ipq_reassemble = mac_test_ipq_reassemble, 256130d239bcSRobert Watson .mpo_netinet_fragment = mac_test_netinet_fragment, 256230d239bcSRobert Watson .mpo_ipq_create = mac_test_ipq_create, 256330d239bcSRobert Watson .mpo_inpcb_create_mbuf = mac_test_inpcb_create_mbuf, 25645c8dd342SRobert Watson .mpo_create_mbuf_linklayer = mac_test_create_mbuf_linklayer, 256530d239bcSRobert Watson .mpo_bpfdesc_create_mbuf = mac_test_bpfdesc_create_mbuf, 256630d239bcSRobert Watson .mpo_ifnet_create_mbuf = mac_test_ifnet_create_mbuf, 256730d239bcSRobert Watson .mpo_mbuf_create_multicast_encap = mac_test_mbuf_create_multicast_encap, 256830d239bcSRobert Watson .mpo_mbuf_create_netlayer = mac_test_mbuf_create_netlayer, 256930d239bcSRobert Watson .mpo_ipq_match = mac_test_ipq_match, 257030d239bcSRobert Watson .mpo_netinet_icmp_reply = mac_test_netinet_icmp_reply, 257130d239bcSRobert Watson .mpo_netinet_tcp_reply = mac_test_netinet_tcp_reply, 257230d239bcSRobert Watson .mpo_ifnet_relabel = mac_test_ifnet_relabel, 257330d239bcSRobert Watson .mpo_ipq_update = mac_test_ipq_update, 2574a557af22SRobert Watson .mpo_inpcb_sosetlabel = mac_test_inpcb_sosetlabel, 257530d239bcSRobert Watson .mpo_vnode_execve_transition = mac_test_vnode_execve_transition, 257630d239bcSRobert Watson .mpo_vnode_execve_will_transition = 257730d239bcSRobert Watson mac_test_vnode_execve_will_transition, 257830d239bcSRobert Watson .mpo_proc_create_swapper = mac_test_proc_create_swapper, 257930d239bcSRobert Watson .mpo_proc_create_init = mac_test_proc_create_init, 258030d239bcSRobert Watson .mpo_cred_relabel = mac_test_cred_relabel, 2581ca26e8baSRobert Watson .mpo_thread_userret = mac_test_thread_userret, 258230d239bcSRobert Watson .mpo_sysvmsg_cleanup = mac_test_sysvmsg_cleanup, 258330d239bcSRobert Watson .mpo_sysvmsq_cleanup = mac_test_sysvmsq_cleanup, 258430d239bcSRobert Watson .mpo_sysvsem_cleanup = mac_test_sysvsem_cleanup, 258530d239bcSRobert Watson .mpo_sysvshm_cleanup = mac_test_sysvshm_cleanup, 258630d239bcSRobert Watson .mpo_bpfdesc_check_receive = mac_test_bpfdesc_check_receive, 258730d239bcSRobert Watson .mpo_cred_check_relabel = mac_test_cred_check_relabel, 258830d239bcSRobert Watson .mpo_cred_check_visible = mac_test_cred_check_visible, 258930d239bcSRobert Watson .mpo_ifnet_check_relabel = mac_test_ifnet_check_relabel, 259030d239bcSRobert Watson .mpo_ifnet_check_transmit = mac_test_ifnet_check_transmit, 259130d239bcSRobert Watson .mpo_inpcb_check_deliver = mac_test_inpcb_check_deliver, 259230d239bcSRobert Watson .mpo_sysvmsq_check_msgmsq = mac_test_sysvmsq_check_msgmsq, 259330d239bcSRobert Watson .mpo_sysvmsq_check_msgrcv = mac_test_sysvmsq_check_msgrcv, 259430d239bcSRobert Watson .mpo_sysvmsq_check_msgrmid = mac_test_sysvmsq_check_msgrmid, 259530d239bcSRobert Watson .mpo_sysvmsq_check_msqget = mac_test_sysvmsq_check_msqget, 259630d239bcSRobert Watson .mpo_sysvmsq_check_msqsnd = mac_test_sysvmsq_check_msqsnd, 259730d239bcSRobert Watson .mpo_sysvmsq_check_msqrcv = mac_test_sysvmsq_check_msqrcv, 259830d239bcSRobert Watson .mpo_sysvmsq_check_msqctl = mac_test_sysvmsq_check_msqctl, 259930d239bcSRobert Watson .mpo_sysvsem_check_semctl = mac_test_sysvsem_check_semctl, 260030d239bcSRobert Watson .mpo_sysvsem_check_semget = mac_test_sysvsem_check_semget, 260130d239bcSRobert Watson .mpo_sysvsem_check_semop = mac_test_sysvsem_check_semop, 260230d239bcSRobert Watson .mpo_sysvshm_check_shmat = mac_test_sysvshm_check_shmat, 260330d239bcSRobert Watson .mpo_sysvshm_check_shmctl = mac_test_sysvshm_check_shmctl, 260430d239bcSRobert Watson .mpo_sysvshm_check_shmdt = mac_test_sysvshm_check_shmdt, 260530d239bcSRobert Watson .mpo_sysvshm_check_shmget = mac_test_sysvshm_check_shmget, 260630d239bcSRobert Watson .mpo_kenv_check_dump = mac_test_kenv_check_dump, 260730d239bcSRobert Watson .mpo_kenv_check_get = mac_test_kenv_check_get, 260830d239bcSRobert Watson .mpo_kenv_check_set = mac_test_kenv_check_set, 260930d239bcSRobert Watson .mpo_kenv_check_unset = mac_test_kenv_check_unset, 261030d239bcSRobert Watson .mpo_kld_check_load = mac_test_kld_check_load, 261130d239bcSRobert Watson .mpo_kld_check_stat = mac_test_kld_check_stat, 261230d239bcSRobert Watson .mpo_mount_check_stat = mac_test_mount_check_stat, 261330d239bcSRobert Watson .mpo_pipe_check_ioctl = mac_test_pipe_check_ioctl, 261430d239bcSRobert Watson .mpo_pipe_check_poll = mac_test_pipe_check_poll, 261530d239bcSRobert Watson .mpo_pipe_check_read = mac_test_pipe_check_read, 261630d239bcSRobert Watson .mpo_pipe_check_relabel = mac_test_pipe_check_relabel, 261730d239bcSRobert Watson .mpo_pipe_check_stat = mac_test_pipe_check_stat, 261830d239bcSRobert Watson .mpo_pipe_check_write = mac_test_pipe_check_write, 261930d239bcSRobert Watson .mpo_posixsem_check_destroy = mac_test_posixsem_check, 262030d239bcSRobert Watson .mpo_posixsem_check_getvalue = mac_test_posixsem_check, 262130d239bcSRobert Watson .mpo_posixsem_check_open = mac_test_posixsem_check, 262230d239bcSRobert Watson .mpo_posixsem_check_post = mac_test_posixsem_check, 262330d239bcSRobert Watson .mpo_posixsem_check_unlink = mac_test_posixsem_check, 262430d239bcSRobert Watson .mpo_posixsem_check_wait = mac_test_posixsem_check, 262530d239bcSRobert Watson .mpo_proc_check_debug = mac_test_proc_check_debug, 262630d239bcSRobert Watson .mpo_proc_check_sched = mac_test_proc_check_sched, 262730d239bcSRobert Watson .mpo_proc_check_setaudit = mac_test_proc_check_setaudit, 262830d239bcSRobert Watson .mpo_proc_check_setaudit_addr = mac_test_proc_check_setaudit_addr, 262930d239bcSRobert Watson .mpo_proc_check_setauid = mac_test_proc_check_setauid, 263030d239bcSRobert Watson .mpo_proc_check_setuid = mac_test_proc_check_setuid, 263130d239bcSRobert Watson .mpo_proc_check_seteuid = mac_test_proc_check_seteuid, 263230d239bcSRobert Watson .mpo_proc_check_setgid = mac_test_proc_check_setgid, 263330d239bcSRobert Watson .mpo_proc_check_setegid = mac_test_proc_check_setegid, 263430d239bcSRobert Watson .mpo_proc_check_setgroups = mac_test_proc_check_setgroups, 263530d239bcSRobert Watson .mpo_proc_check_setreuid = mac_test_proc_check_setreuid, 263630d239bcSRobert Watson .mpo_proc_check_setregid = mac_test_proc_check_setregid, 263730d239bcSRobert Watson .mpo_proc_check_setresuid = mac_test_proc_check_setresuid, 263830d239bcSRobert Watson .mpo_proc_check_setresgid = mac_test_proc_check_setresgid, 263930d239bcSRobert Watson .mpo_proc_check_signal = mac_test_proc_check_signal, 264030d239bcSRobert Watson .mpo_proc_check_wait = mac_test_proc_check_wait, 264130d239bcSRobert Watson .mpo_socket_check_accept = mac_test_socket_check_accept, 264230d239bcSRobert Watson .mpo_socket_check_bind = mac_test_socket_check_bind, 264330d239bcSRobert Watson .mpo_socket_check_connect = mac_test_socket_check_connect, 264430d239bcSRobert Watson .mpo_socket_check_deliver = mac_test_socket_check_deliver, 264530d239bcSRobert Watson .mpo_socket_check_listen = mac_test_socket_check_listen, 264630d239bcSRobert Watson .mpo_socket_check_poll = mac_test_socket_check_poll, 264730d239bcSRobert Watson .mpo_socket_check_receive = mac_test_socket_check_receive, 264830d239bcSRobert Watson .mpo_socket_check_relabel = mac_test_socket_check_relabel, 264930d239bcSRobert Watson .mpo_socket_check_send = mac_test_socket_check_send, 265030d239bcSRobert Watson .mpo_socket_check_stat = mac_test_socket_check_stat, 265130d239bcSRobert Watson .mpo_socket_check_visible = mac_test_socket_check_visible, 265230d239bcSRobert Watson .mpo_system_check_acct = mac_test_system_check_acct, 265330d239bcSRobert Watson .mpo_system_check_audit = mac_test_system_check_audit, 265430d239bcSRobert Watson .mpo_system_check_auditctl = mac_test_system_check_auditctl, 265530d239bcSRobert Watson .mpo_system_check_auditon = mac_test_system_check_auditon, 265630d239bcSRobert Watson .mpo_system_check_reboot = mac_test_system_check_reboot, 265730d239bcSRobert Watson .mpo_system_check_swapoff = mac_test_system_check_swapoff, 265830d239bcSRobert Watson .mpo_system_check_swapon = mac_test_system_check_swapon, 265930d239bcSRobert Watson .mpo_system_check_sysctl = mac_test_system_check_sysctl, 266030d239bcSRobert Watson .mpo_vnode_check_access = mac_test_vnode_check_access, 266130d239bcSRobert Watson .mpo_vnode_check_chdir = mac_test_vnode_check_chdir, 266230d239bcSRobert Watson .mpo_vnode_check_chroot = mac_test_vnode_check_chroot, 266330d239bcSRobert Watson .mpo_vnode_check_create = mac_test_vnode_check_create, 266430d239bcSRobert Watson .mpo_vnode_check_deleteacl = mac_test_vnode_check_deleteacl, 266530d239bcSRobert Watson .mpo_vnode_check_deleteextattr = mac_test_vnode_check_deleteextattr, 266630d239bcSRobert Watson .mpo_vnode_check_exec = mac_test_vnode_check_exec, 266730d239bcSRobert Watson .mpo_vnode_check_getacl = mac_test_vnode_check_getacl, 266830d239bcSRobert Watson .mpo_vnode_check_getextattr = mac_test_vnode_check_getextattr, 266930d239bcSRobert Watson .mpo_vnode_check_link = mac_test_vnode_check_link, 267030d239bcSRobert Watson .mpo_vnode_check_listextattr = mac_test_vnode_check_listextattr, 267130d239bcSRobert Watson .mpo_vnode_check_lookup = mac_test_vnode_check_lookup, 267230d239bcSRobert Watson .mpo_vnode_check_mmap = mac_test_vnode_check_mmap, 267330d239bcSRobert Watson .mpo_vnode_check_open = mac_test_vnode_check_open, 267430d239bcSRobert Watson .mpo_vnode_check_poll = mac_test_vnode_check_poll, 267530d239bcSRobert Watson .mpo_vnode_check_read = mac_test_vnode_check_read, 267630d239bcSRobert Watson .mpo_vnode_check_readdir = mac_test_vnode_check_readdir, 267730d239bcSRobert Watson .mpo_vnode_check_readlink = mac_test_vnode_check_readlink, 267830d239bcSRobert Watson .mpo_vnode_check_relabel = mac_test_vnode_check_relabel, 267930d239bcSRobert Watson .mpo_vnode_check_rename_from = mac_test_vnode_check_rename_from, 268030d239bcSRobert Watson .mpo_vnode_check_rename_to = mac_test_vnode_check_rename_to, 268130d239bcSRobert Watson .mpo_vnode_check_revoke = mac_test_vnode_check_revoke, 268230d239bcSRobert Watson .mpo_vnode_check_setacl = mac_test_vnode_check_setacl, 268330d239bcSRobert Watson .mpo_vnode_check_setextattr = mac_test_vnode_check_setextattr, 268430d239bcSRobert Watson .mpo_vnode_check_setflags = mac_test_vnode_check_setflags, 268530d239bcSRobert Watson .mpo_vnode_check_setmode = mac_test_vnode_check_setmode, 268630d239bcSRobert Watson .mpo_vnode_check_setowner = mac_test_vnode_check_setowner, 268730d239bcSRobert Watson .mpo_vnode_check_setutimes = mac_test_vnode_check_setutimes, 268830d239bcSRobert Watson .mpo_vnode_check_stat = mac_test_vnode_check_stat, 268930d239bcSRobert Watson .mpo_vnode_check_unlink = mac_test_vnode_check_unlink, 269030d239bcSRobert Watson .mpo_vnode_check_write = mac_test_vnode_check_write, 2691d8a7b7a3SRobert Watson }; 2692d8a7b7a3SRobert Watson 269378183ac2SRobert Watson MAC_POLICY_SET(&mac_test_ops, mac_test, "TrustedBSD MAC/Test", 26949a1b0237SRobert Watson MPC_LOADTIME_FLAG_UNLOADOK | MPC_LOADTIME_FLAG_LABELMBUFS, &test_slot); 2695