Index: head/sys/security/mac/mac_atalk.c =================================================================== --- head/sys/security/mac/mac_atalk.c (revision 191730) +++ head/sys/security/mac/mac_atalk.c (revision 191731) @@ -1,70 +1,70 @@ /*- * Copyright (c) 2007-2009 Robert N. M. Watson * All rights reserved. * * This software was developed by Robert Watson for the TrustedBSD Project. * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include void mac_netatalk_aarp_send(struct ifnet *ifp, struct mbuf *m) { struct label *mlabel; mlabel = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); - MAC_PERFORM_NOSLEEP(netatalk_aarp_send, ifp, ifp->if_label, m, + MAC_POLICY_PERFORM_NOSLEEP(netatalk_aarp_send, ifp, ifp->if_label, m, mlabel); MAC_IFNET_UNLOCK(ifp); } Index: head/sys/security/mac/mac_audit.c =================================================================== --- head/sys/security/mac/mac_audit.c (revision 191730) +++ head/sys/security/mac/mac_audit.c (revision 191731) @@ -1,145 +1,145 @@ /*- * Copyright (c) 1999-2002, 2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include #include #include #include #include #include #include #include #include #include MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit, "struct ucred *", "struct auditinfo *"); int mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai) { int error; - MAC_CHECK_NOSLEEP(cred_check_setaudit, cred, ai); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit, cred, ai); MAC_CHECK_PROBE2(cred_check_setaudit, error, cred, ai); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit_addr, "struct ucred *", "struct auditinfo_addr *"); int mac_cred_check_setaudit_addr(struct ucred *cred, struct auditinfo_addr *aia) { int error; - MAC_CHECK_NOSLEEP(cred_check_setaudit_addr, cred, aia); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit_addr, cred, aia); MAC_CHECK_PROBE2(cred_check_setaudit_addr, error, cred, aia); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_setauid, "struct ucred *", "uid_t"); int mac_cred_check_setauid(struct ucred *cred, uid_t auid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setauid, cred, auid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setauid, cred, auid); MAC_CHECK_PROBE2(cred_check_setauid, error, cred, auid); return (error); } MAC_CHECK_PROBE_DEFINE3(system_check_audit, "struct ucred *", "void *", "int"); int mac_system_check_audit(struct ucred *cred, void *record, int length) { int error; - MAC_CHECK_NOSLEEP(system_check_audit, cred, record, length); + MAC_POLICY_CHECK_NOSLEEP(system_check_audit, cred, record, length); MAC_CHECK_PROBE3(system_check_audit, error, cred, record, length); return (error); } MAC_CHECK_PROBE_DEFINE2(system_check_auditctl, "struct ucred *", "struct vnode *"); int mac_system_check_auditctl(struct ucred *cred, struct vnode *vp) { int error; struct label *vl; ASSERT_VOP_LOCKED(vp, "mac_system_check_auditctl"); vl = (vp != NULL) ? vp->v_label : NULL; - MAC_CHECK(system_check_auditctl, cred, vp, vl); + MAC_POLICY_CHECK(system_check_auditctl, cred, vp, vl); MAC_CHECK_PROBE2(system_check_auditctl, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE2(system_check_auditon, "struct ucred *", "int"); int mac_system_check_auditon(struct ucred *cred, int cmd) { int error; - MAC_CHECK_NOSLEEP(system_check_auditon, cred, cmd); + MAC_POLICY_CHECK_NOSLEEP(system_check_auditon, cred, cmd); MAC_CHECK_PROBE2(system_check_auditon, error, cred, cmd); return (error); } Index: head/sys/security/mac/mac_cred.c =================================================================== --- head/sys/security/mac/mac_cred.c (revision 191730) +++ head/sys/security/mac/mac_cred.c (revision 191731) @@ -1,352 +1,353 @@ /*- * Copyright (c) 1999-2002, 2008-2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2003 Networks Associates Technology, Inc. * Copyright (c) 2005 Samy Al Bahra * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct label * mac_cred_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(cred_init_label, label); + MAC_POLICY_PERFORM(cred_init_label, label); return (label); } void mac_cred_init(struct ucred *cred) { if (mac_labeled & MPC_OBJECT_CRED) cred->cr_label = mac_cred_label_alloc(); else cred->cr_label = NULL; } void mac_cred_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(cred_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(cred_destroy_label, label); mac_labelzone_free(label); } void mac_cred_destroy(struct ucred *cred) { if (cred->cr_label != NULL) { mac_cred_label_free(cred->cr_label); cred->cr_label = NULL; } } /* * When a thread becomes an NFS server daemon, its credential may need to be * updated to reflect this so that policies can recognize when file system * operations originate from the network. * * At some point, it would be desirable if the credential used for each NFS * RPC could be set based on the RPC context (i.e., source system, etc) to * provide more fine-grained access control. */ void mac_cred_associate_nfsd(struct ucred *cred) { - MAC_PERFORM_NOSLEEP(cred_associate_nfsd, cred); + MAC_POLICY_PERFORM_NOSLEEP(cred_associate_nfsd, cred); } /* * Initialize MAC label for the first kernel process, from which other kernel * processes and threads are spawned. */ void mac_cred_create_swapper(struct ucred *cred) { - MAC_PERFORM_NOSLEEP(cred_create_swapper, cred); + MAC_POLICY_PERFORM_NOSLEEP(cred_create_swapper, cred); } /* * Initialize MAC label for the first userland process, from which other * userland processes and threads are spawned. */ void mac_cred_create_init(struct ucred *cred) { - MAC_PERFORM_NOSLEEP(cred_create_init, cred); + MAC_POLICY_PERFORM_NOSLEEP(cred_create_init, cred); } int mac_cred_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen) { int error; - MAC_EXTERNALIZE(cred, label, elements, outbuf, outbuflen); + MAC_POLICY_EXTERNALIZE(cred, label, elements, outbuf, outbuflen); return (error); } int mac_cred_internalize_label(struct label *label, char *string) { int error; - MAC_INTERNALIZE(cred, label, string); + MAC_POLICY_INTERNALIZE(cred, label, string); return (error); } /* * When a new process is created, its label must be initialized. Generally, * this involves inheritence from the parent process, modulo possible deltas. * This function allows that processing to take place. */ void mac_cred_copy(struct ucred *src, struct ucred *dest) { - MAC_PERFORM_NOSLEEP(cred_copy_label, src->cr_label, dest->cr_label); + MAC_POLICY_PERFORM_NOSLEEP(cred_copy_label, src->cr_label, + dest->cr_label); } /* * When the subject's label changes, it may require revocation of privilege * to mapped objects. This can't be done on-the-fly later with a unified * buffer cache. */ void mac_cred_relabel(struct ucred *cred, struct label *newlabel) { - MAC_PERFORM_NOSLEEP(cred_relabel, cred, newlabel); + MAC_POLICY_PERFORM_NOSLEEP(cred_relabel, cred, newlabel); } MAC_CHECK_PROBE_DEFINE2(cred_check_relabel, "struct ucred *", "struct label *"); int mac_cred_check_relabel(struct ucred *cred, struct label *newlabel) { int error; - MAC_CHECK_NOSLEEP(cred_check_relabel, cred, newlabel); + MAC_POLICY_CHECK_NOSLEEP(cred_check_relabel, cred, newlabel); MAC_CHECK_PROBE2(cred_check_relabel, error, cred, newlabel); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_setuid, "struct ucred *", "uid_t"); int mac_cred_check_setuid(struct ucred *cred, uid_t uid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setuid, cred, uid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setuid, cred, uid); MAC_CHECK_PROBE2(cred_check_setuid, error, cred, uid); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_seteuid, "struct ucred *", "uid_t"); int mac_cred_check_seteuid(struct ucred *cred, uid_t euid) { int error; - MAC_CHECK_NOSLEEP(cred_check_seteuid, cred, euid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_seteuid, cred, euid); MAC_CHECK_PROBE2(cred_check_seteuid, error, cred, euid); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_setgid, "struct ucred *", "gid_t"); int mac_cred_check_setgid(struct ucred *cred, gid_t gid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setgid, cred, gid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setgid, cred, gid); MAC_CHECK_PROBE2(cred_check_setgid, error, cred, gid); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_setegid, "struct ucred *", "gid_t"); int mac_cred_check_setegid(struct ucred *cred, gid_t egid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setegid, cred, egid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setegid, cred, egid); MAC_CHECK_PROBE2(cred_check_setegid, error, cred, egid); return (error); } MAC_CHECK_PROBE_DEFINE3(cred_check_setgroups, "struct ucred *", "int", "gid_t *"); int mac_cred_check_setgroups(struct ucred *cred, int ngroups, gid_t *gidset) { int error; - MAC_CHECK_NOSLEEP(cred_check_setgroups, cred, ngroups, gidset); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setgroups, cred, ngroups, gidset); MAC_CHECK_PROBE3(cred_check_setgroups, error, cred, ngroups, gidset); return (error); } MAC_CHECK_PROBE_DEFINE3(cred_check_setreuid, "struct ucred *", "uid_t", "uid_t"); int mac_cred_check_setreuid(struct ucred *cred, uid_t ruid, uid_t euid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setreuid, cred, ruid, euid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setreuid, cred, ruid, euid); MAC_CHECK_PROBE3(cred_check_setreuid, error, cred, ruid, euid); return (error); } MAC_CHECK_PROBE_DEFINE3(cred_check_setregid, "struct ucred *", "gid_t", "gid_t"); int mac_cred_check_setregid(struct ucred *cred, gid_t rgid, gid_t egid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setregid, cred, rgid, egid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setregid, cred, rgid, egid); MAC_CHECK_PROBE3(cred_check_setregid, error, cred, rgid, egid); return (error); } MAC_CHECK_PROBE_DEFINE4(cred_check_setresuid, "struct ucred *", "uid_t", "uid_t", "uid_t"); int mac_cred_check_setresuid(struct ucred *cred, uid_t ruid, uid_t euid, uid_t suid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setresuid, cred, ruid, euid, suid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setresuid, cred, ruid, euid, suid); MAC_CHECK_PROBE4(cred_check_setresuid, error, cred, ruid, euid, suid); return (error); } MAC_CHECK_PROBE_DEFINE4(cred_check_setresgid, "struct ucred *", "gid_t", "gid_t", "gid_t"); int mac_cred_check_setresgid(struct ucred *cred, gid_t rgid, gid_t egid, gid_t sgid) { int error; - MAC_CHECK_NOSLEEP(cred_check_setresgid, cred, rgid, egid, sgid); + MAC_POLICY_CHECK_NOSLEEP(cred_check_setresgid, cred, rgid, egid, sgid); MAC_CHECK_PROBE4(cred_check_setresgid, error, cred, rgid, egid, sgid); return (error); } MAC_CHECK_PROBE_DEFINE2(cred_check_visible, "struct ucred *", "struct ucred *"); int mac_cred_check_visible(struct ucred *cr1, struct ucred *cr2) { int error; - MAC_CHECK_NOSLEEP(cred_check_visible, cr1, cr2); + MAC_POLICY_CHECK_NOSLEEP(cred_check_visible, cr1, cr2); MAC_CHECK_PROBE2(cred_check_visible, error, cr1, cr2); return (error); } Index: head/sys/security/mac/mac_inet.c =================================================================== --- head/sys/security/mac/mac_inet.c (revision 191730) +++ head/sys/security/mac/mac_inet.c (revision 191731) @@ -1,455 +1,462 @@ /*- * Copyright (c) 1999-2002, 2007, 2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_inpcb_label_alloc(int flag) { struct label *label; int error; label = mac_labelzone_alloc(flag); if (label == NULL) return (NULL); if (flag & M_WAITOK) - MAC_CHECK(inpcb_init_label, label, flag); + MAC_POLICY_CHECK(inpcb_init_label, label, flag); else - MAC_CHECK_NOSLEEP(inpcb_init_label, label, flag); + MAC_POLICY_CHECK_NOSLEEP(inpcb_init_label, label, flag); if (error) { - MAC_PERFORM_NOSLEEP(inpcb_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(inpcb_destroy_label, label); mac_labelzone_free(label); return (NULL); } return (label); } int mac_inpcb_init(struct inpcb *inp, int flag) { if (mac_labeled & MPC_OBJECT_INPCB) { inp->inp_label = mac_inpcb_label_alloc(flag); if (inp->inp_label == NULL) return (ENOMEM); } else inp->inp_label = NULL; return (0); } static struct label * mac_ipq_label_alloc(int flag) { struct label *label; int error; label = mac_labelzone_alloc(flag); if (label == NULL) return (NULL); if (flag & M_WAITOK) - MAC_CHECK(ipq_init_label, label, flag); + MAC_POLICY_CHECK(ipq_init_label, label, flag); else - MAC_CHECK_NOSLEEP(ipq_init_label, label, flag); + MAC_POLICY_CHECK_NOSLEEP(ipq_init_label, label, flag); if (error) { - MAC_PERFORM_NOSLEEP(ipq_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(ipq_destroy_label, label); mac_labelzone_free(label); return (NULL); } return (label); } int mac_ipq_init(struct ipq *q, int flag) { if (mac_labeled & MPC_OBJECT_IPQ) { q->ipq_label = mac_ipq_label_alloc(flag); if (q->ipq_label == NULL) return (ENOMEM); } else q->ipq_label = NULL; return (0); } static void mac_inpcb_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(inpcb_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(inpcb_destroy_label, label); mac_labelzone_free(label); } void mac_inpcb_destroy(struct inpcb *inp) { if (inp->inp_label != NULL) { mac_inpcb_label_free(inp->inp_label); inp->inp_label = NULL; } } static void mac_ipq_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(ipq_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(ipq_destroy_label, label); mac_labelzone_free(label); } void mac_ipq_destroy(struct ipq *q) { if (q->ipq_label != NULL) { mac_ipq_label_free(q->ipq_label); q->ipq_label = NULL; } } void mac_inpcb_create(struct socket *so, struct inpcb *inp) { - MAC_PERFORM_NOSLEEP(inpcb_create, so, so->so_label, inp, + MAC_POLICY_PERFORM_NOSLEEP(inpcb_create, so, so->so_label, inp, inp->inp_label); } void mac_ipq_reassemble(struct ipq *q, struct mbuf *m) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(ipq_reassemble, q, q->ipq_label, m, label); + MAC_POLICY_PERFORM_NOSLEEP(ipq_reassemble, q, q->ipq_label, m, + label); } void mac_netinet_fragment(struct mbuf *m, struct mbuf *frag) { struct label *mlabel, *fraglabel; mlabel = mac_mbuf_to_label(m); fraglabel = mac_mbuf_to_label(frag); - MAC_PERFORM_NOSLEEP(netinet_fragment, m, mlabel, frag, fraglabel); + MAC_POLICY_PERFORM_NOSLEEP(netinet_fragment, m, mlabel, frag, + fraglabel); } void mac_ipq_create(struct mbuf *m, struct ipq *q) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(ipq_create, m, label, q, q->ipq_label); + MAC_POLICY_PERFORM_NOSLEEP(ipq_create, m, label, q, q->ipq_label); } void mac_inpcb_create_mbuf(struct inpcb *inp, struct mbuf *m) { struct label *mlabel; INP_LOCK_ASSERT(inp); mlabel = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(inpcb_create_mbuf, inp, inp->inp_label, m, + MAC_POLICY_PERFORM_NOSLEEP(inpcb_create_mbuf, inp, inp->inp_label, m, mlabel); } int mac_ipq_match(struct mbuf *m, struct ipq *q) { struct label *label; int result; label = mac_mbuf_to_label(m); result = 1; - MAC_BOOLEAN_NOSLEEP(ipq_match, &&, m, label, q, q->ipq_label); + MAC_POLICY_BOOLEAN_NOSLEEP(ipq_match, &&, m, label, q, q->ipq_label); return (result); } void mac_netinet_arp_send(struct ifnet *ifp, struct mbuf *m) { struct label *mlabel; mlabel = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); - MAC_PERFORM_NOSLEEP(netinet_arp_send, ifp, ifp->if_label, m, mlabel); + MAC_POLICY_PERFORM_NOSLEEP(netinet_arp_send, ifp, ifp->if_label, m, + mlabel); MAC_IFNET_UNLOCK(ifp); } void mac_netinet_icmp_reply(struct mbuf *mrecv, struct mbuf *msend) { struct label *mrecvlabel, *msendlabel; mrecvlabel = mac_mbuf_to_label(mrecv); msendlabel = mac_mbuf_to_label(msend); - MAC_PERFORM_NOSLEEP(netinet_icmp_reply, mrecv, mrecvlabel, msend, - msendlabel); + MAC_POLICY_PERFORM_NOSLEEP(netinet_icmp_reply, mrecv, mrecvlabel, + msend, msendlabel); } void mac_netinet_icmp_replyinplace(struct mbuf *m) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(netinet_icmp_replyinplace, m, label); + MAC_POLICY_PERFORM_NOSLEEP(netinet_icmp_replyinplace, m, label); } void mac_netinet_igmp_send(struct ifnet *ifp, struct mbuf *m) { struct label *mlabel; mlabel = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); - MAC_PERFORM_NOSLEEP(netinet_igmp_send, ifp, ifp->if_label, m, + MAC_POLICY_PERFORM_NOSLEEP(netinet_igmp_send, ifp, ifp->if_label, m, mlabel); MAC_IFNET_UNLOCK(ifp); } void mac_netinet_tcp_reply(struct mbuf *m) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(netinet_tcp_reply, m, label); + MAC_POLICY_PERFORM_NOSLEEP(netinet_tcp_reply, m, label); } void mac_ipq_update(struct mbuf *m, struct ipq *q) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(ipq_update, m, label, q, q->ipq_label); + MAC_POLICY_PERFORM_NOSLEEP(ipq_update, m, label, q, q->ipq_label); } MAC_CHECK_PROBE_DEFINE2(inpcb_check_deliver, "struct inpcb *", "struct mbuf *"); int mac_inpcb_check_deliver(struct inpcb *inp, struct mbuf *m) { struct label *label; int error; M_ASSERTPKTHDR(m); label = mac_mbuf_to_label(m); - MAC_CHECK_NOSLEEP(inpcb_check_deliver, inp, inp->inp_label, m, + MAC_POLICY_CHECK_NOSLEEP(inpcb_check_deliver, inp, inp->inp_label, m, label); MAC_CHECK_PROBE2(inpcb_check_deliver, error, inp, m); return (error); } MAC_CHECK_PROBE_DEFINE2(inpcb_check_visible, "struct ucred *", "struct inpcb *"); int mac_inpcb_check_visible(struct ucred *cred, struct inpcb *inp) { int error; INP_LOCK_ASSERT(inp); - MAC_CHECK_NOSLEEP(inpcb_check_visible, cred, inp, inp->inp_label); + MAC_POLICY_CHECK_NOSLEEP(inpcb_check_visible, cred, inp, + inp->inp_label); MAC_CHECK_PROBE2(inpcb_check_visible, error, cred, inp); return (error); } void mac_inpcb_sosetlabel(struct socket *so, struct inpcb *inp) { INP_WLOCK_ASSERT(inp); SOCK_LOCK_ASSERT(so); - MAC_PERFORM_NOSLEEP(inpcb_sosetlabel, so, so->so_label, inp, + MAC_POLICY_PERFORM_NOSLEEP(inpcb_sosetlabel, so, so->so_label, inp, inp->inp_label); } void mac_netinet_firewall_reply(struct mbuf *mrecv, struct mbuf *msend) { struct label *mrecvlabel, *msendlabel; M_ASSERTPKTHDR(mrecv); M_ASSERTPKTHDR(msend); mrecvlabel = mac_mbuf_to_label(mrecv); msendlabel = mac_mbuf_to_label(msend); - MAC_PERFORM_NOSLEEP(netinet_firewall_reply, mrecv, mrecvlabel, msend, - msendlabel); + MAC_POLICY_PERFORM_NOSLEEP(netinet_firewall_reply, mrecv, mrecvlabel, + msend, msendlabel); } void mac_netinet_firewall_send(struct mbuf *m) { struct label *label; M_ASSERTPKTHDR(m); label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(netinet_firewall_send, m, label); + MAC_POLICY_PERFORM_NOSLEEP(netinet_firewall_send, m, label); } /* * These functions really should be referencing the syncache structure * instead of the label. However, due to some of the complexities associated * with exposing this syncache structure we operate directly on it's label * pointer. This should be OK since we aren't making any access control * decisions within this code directly, we are merely allocating and copying * label storage so we can properly initialize mbuf labels for any packets * the syncache code might create. */ void mac_syncache_destroy(struct label **label) { if (*label != NULL) { - MAC_PERFORM_NOSLEEP(syncache_destroy_label, *label); + MAC_POLICY_PERFORM_NOSLEEP(syncache_destroy_label, *label); mac_labelzone_free(*label); *label = NULL; } } int mac_syncache_init(struct label **label) { int error; if (mac_labeled & MPC_OBJECT_SYNCACHE) { *label = mac_labelzone_alloc(M_NOWAIT); if (*label == NULL) return (ENOMEM); /* * Since we are holding the inpcb locks the policy can not * allocate policy specific label storage using M_WAITOK. So * we need to do a MAC_CHECK instead of the typical * MAC_PERFORM so we can propagate allocation failures back * to the syncache code. */ - MAC_CHECK_NOSLEEP(syncache_init_label, *label, M_NOWAIT); + MAC_POLICY_CHECK_NOSLEEP(syncache_init_label, *label, + M_NOWAIT); if (error) { - MAC_PERFORM_NOSLEEP(syncache_destroy_label, *label); + MAC_POLICY_PERFORM_NOSLEEP(syncache_destroy_label, + *label); mac_labelzone_free(*label); } return (error); } else *label = NULL; return (0); } void mac_syncache_create(struct label *label, struct inpcb *inp) { INP_WLOCK_ASSERT(inp); - MAC_PERFORM_NOSLEEP(syncache_create, label, inp); + MAC_POLICY_PERFORM_NOSLEEP(syncache_create, label, inp); } void mac_syncache_create_mbuf(struct label *sc_label, struct mbuf *m) { struct label *mlabel; M_ASSERTPKTHDR(m); mlabel = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(syncache_create_mbuf, sc_label, m, mlabel); + MAC_POLICY_PERFORM_NOSLEEP(syncache_create_mbuf, sc_label, m, + mlabel); } Index: head/sys/security/mac/mac_inet6.c =================================================================== --- head/sys/security/mac/mac_inet6.c (revision 191730) +++ head/sys/security/mac/mac_inet6.c (revision 191731) @@ -1,169 +1,173 @@ /*- * Copyright (c) 2007-2009 Robert N. M. Watson * All rights reserved. * * This software was developed by Robert Watson for the TrustedBSD Project. * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_ip6q_label_alloc(int flag) { struct label *label; int error; label = mac_labelzone_alloc(flag); if (label == NULL) return (NULL); if (flag & M_WAITOK) - MAC_CHECK(ip6q_init_label, label, flag); + MAC_POLICY_CHECK(ip6q_init_label, label, flag); else - MAC_CHECK_NOSLEEP(ip6q_init_label, label, flag); + MAC_POLICY_CHECK_NOSLEEP(ip6q_init_label, label, flag); if (error) { - MAC_PERFORM_NOSLEEP(ip6q_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(ip6q_destroy_label, label); mac_labelzone_free(label); return (NULL); } return (label); } int mac_ip6q_init(struct ip6q *q6, int flag) { if (mac_labeled & MPC_OBJECT_IP6Q) { q6->ip6q_label = mac_ip6q_label_alloc(flag); if (q6->ip6q_label == NULL) return (ENOMEM); } else q6->ip6q_label = NULL; return (0); } static void mac_ip6q_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(ip6q_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(ip6q_destroy_label, label); mac_labelzone_free(label); } void mac_ip6q_destroy(struct ip6q *q6) { if (q6->ip6q_label != NULL) { mac_ip6q_label_free(q6->ip6q_label); q6->ip6q_label = NULL; } } void mac_ip6q_reassemble(struct ip6q *q6, struct mbuf *m) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(ip6q_reassemble, q6, q6->ip6q_label, m, label); + MAC_POLICY_PERFORM_NOSLEEP(ip6q_reassemble, q6, q6->ip6q_label, m, + label); } void mac_ip6q_create(struct mbuf *m, struct ip6q *q6) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(ip6q_create, m, label, q6, q6->ip6q_label); + MAC_POLICY_PERFORM_NOSLEEP(ip6q_create, m, label, q6, + q6->ip6q_label); } int mac_ip6q_match(struct mbuf *m, struct ip6q *q6) { struct label *label; int result; label = mac_mbuf_to_label(m); result = 1; - MAC_BOOLEAN_NOSLEEP(ip6q_match, &&, m, label, q6, q6->ip6q_label); + MAC_POLICY_BOOLEAN_NOSLEEP(ip6q_match, &&, m, label, q6, + q6->ip6q_label); return (result); } void mac_ip6q_update(struct mbuf *m, struct ip6q *q6) { struct label *label; label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(ip6q_update, m, label, q6, q6->ip6q_label); + MAC_POLICY_PERFORM_NOSLEEP(ip6q_update, m, label, q6, + q6->ip6q_label); } void mac_netinet6_nd6_send(struct ifnet *ifp, struct mbuf *m) { struct label *mlabel; mlabel = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(netinet6_nd6_send, ifp, ifp->if_label, m, + MAC_POLICY_PERFORM_NOSLEEP(netinet6_nd6_send, ifp, ifp->if_label, m, mlabel); } Index: head/sys/security/mac/mac_internal.h =================================================================== --- head/sys/security/mac/mac_internal.h (revision 191730) +++ head/sys/security/mac/mac_internal.h (revision 191731) @@ -1,504 +1,504 @@ /*- * Copyright (c) 1999-2002, 2006, 2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 nCircle Network Security, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2009 Apple, Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was developed by Robert N. M. Watson for the TrustedBSD * Project under contract to nCircle Network Security, Inc. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #ifndef _SECURITY_MAC_MAC_INTERNAL_H_ #define _SECURITY_MAC_MAC_INTERNAL_H_ #ifndef _KERNEL #error "no user-serviceable parts inside" #endif /* * MAC Framework sysctl namespace. */ #ifdef SYSCTL_DECL SYSCTL_DECL(_security_mac); #endif /* SYSCTL_DECL */ /* * MAC Framework SDT DTrace probe namespace, macros for declaring entry * point probes, macros for invoking them. */ #ifdef SDT_PROVIDER_DECLARE SDT_PROVIDER_DECLARE(mac); /* MAC Framework-level events. */ SDT_PROVIDER_DECLARE(mac_framework); /* Entry points to MAC. */ #define MAC_CHECK_PROBE_DEFINE4(name, arg0, arg1, arg2, arg3) \ SDT_PROBE_DEFINE5(mac_framework, kernel, name, mac_check_err, \ "int", arg0, arg1, arg2, arg3); \ SDT_PROBE_DEFINE5(mac_framework, kernel, name, mac_check_ok, \ "int", arg0, arg1, arg2, arg3); #define MAC_CHECK_PROBE_DEFINE3(name, arg0, arg1, arg2) \ SDT_PROBE_DEFINE4(mac_framework, kernel, name, mac_check_err, \ "int", arg0, arg1, arg2); \ SDT_PROBE_DEFINE4(mac_framework, kernel, name, mac_check_ok, \ "int", arg0, arg1, arg2); #define MAC_CHECK_PROBE_DEFINE2(name, arg0, arg1) \ SDT_PROBE_DEFINE3(mac_framework, kernel, name, mac_check_err, \ "int", arg0, arg1); \ SDT_PROBE_DEFINE3(mac_framework, kernel, name, mac_check_ok, \ "int", arg0, arg1); #define MAC_CHECK_PROBE_DEFINE1(name, arg0) \ SDT_PROBE_DEFINE2(mac_framework, kernel, name, mac_check_err, \ "int", arg0); \ SDT_PROBE_DEFINE2(mac_framework, kernel, name, mac_check_ok, \ "int", arg0); #define MAC_CHECK_PROBE4(name, error, arg0, arg1, arg2, arg3) do { \ if (error) { \ SDT_PROBE(mac_framework, kernel, name, mac_check_err, \ error, arg0, arg1, arg2, arg3); \ } else { \ SDT_PROBE(mac_framework, kernel, name, mac_check_ok, \ 0, arg0, arg1, arg2, arg3); \ } \ } while (0) #define MAC_CHECK_PROBE3(name, error, arg0, arg1, arg2) \ MAC_CHECK_PROBE4(name, error, arg0, arg1, arg2, 0) #define MAC_CHECK_PROBE2(name, error, arg0, arg1) \ MAC_CHECK_PROBE3(name, error, arg0, arg1, 0) #define MAC_CHECK_PROBE1(name, error, arg0) \ MAC_CHECK_PROBE2(name, error, arg0, 0) #endif #define MAC_GRANT_PROBE_DEFINE2(name, arg0, arg1) \ SDT_PROBE_DEFINE3(mac_framework, kernel, name, mac_grant_err, \ "int", arg0, arg1); \ SDT_PROBE_DEFINE3(mac_framework, kernel, name, mac_grant_ok, \ "INT", arg0, arg1); #define MAC_GRANT_PROBE2(name, error, arg0, arg1) do { \ if (error) { \ SDT_PROBE(mac_framework, kernel, name, mac_grant_err, \ error, arg0, arg1, 0, 0); \ } else { \ SDT_PROBE(mac_framework, kernel, name, mac_grant_ok, \ error, arg0, arg1, 0, 0); \ } \ } while (0) /* * MAC Framework global types and typedefs. */ LIST_HEAD(mac_policy_list_head, mac_policy_conf); #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_MACTEMP); #endif /* * MAC labels -- in-kernel storage format. * * In general, struct label pointers are embedded in kernel data structures * representing objects that may be labeled (and protected). Struct label is * opaque to both kernel services that invoke the MAC Framework and MAC * policy modules. In particular, we do not wish to encode the layout of the * label structure into any ABIs. Historically, the slot array contained * unions of {long, void} but now contains uintptr_t. */ #define MAC_MAX_SLOTS 4 #define MAC_FLAG_INITIALIZED 0x0000001 /* Is initialized for use. */ struct label { int l_flags; intptr_t l_perpolicy[MAC_MAX_SLOTS]; }; /* * Flags for mac_labeled, a bitmask of object types need across the union of * all policies currently registered with the MAC Framework, used to key * whether or not labels are allocated and constructors for the type are * invoked. */ #define MPC_OBJECT_CRED 0x0000000000000001 #define MPC_OBJECT_PROC 0x0000000000000002 #define MPC_OBJECT_VNODE 0x0000000000000004 #define MPC_OBJECT_INPCB 0x0000000000000008 #define MPC_OBJECT_SOCKET 0x0000000000000010 #define MPC_OBJECT_DEVFS 0x0000000000000020 #define MPC_OBJECT_MBUF 0x0000000000000040 #define MPC_OBJECT_IPQ 0x0000000000000080 #define MPC_OBJECT_IFNET 0x0000000000000100 #define MPC_OBJECT_BPFDESC 0x0000000000000200 #define MPC_OBJECT_PIPE 0x0000000000000400 #define MPC_OBJECT_MOUNT 0x0000000000000800 #define MPC_OBJECT_POSIXSEM 0x0000000000001000 #define MPC_OBJECT_POSIXSHM 0x0000000000002000 #define MPC_OBJECT_SYSVMSG 0x0000000000004000 #define MPC_OBJECT_SYSVMSQ 0x0000000000008000 #define MPC_OBJECT_SYSVSEM 0x0000000000010000 #define MPC_OBJECT_SYSVSHM 0x0000000000020000 #define MPC_OBJECT_SYNCACHE 0x0000000000040000 #define MPC_OBJECT_IP6Q 0x0000000000080000 /* * MAC Framework global variables. */ extern struct mac_policy_list_head mac_policy_list; extern struct mac_policy_list_head mac_static_policy_list; extern uint64_t mac_labeled; extern struct mtx mac_ifnet_mtx; /* * MAC Framework infrastructure functions. */ int mac_error_select(int error1, int error2); void mac_policy_slock_nosleep(void); void mac_policy_slock_sleep(void); void mac_policy_sunlock_nosleep(void); void mac_policy_sunlock_sleep(void); struct label *mac_labelzone_alloc(int flags); void mac_labelzone_free(struct label *label); void mac_labelzone_init(void); void mac_init_label(struct label *label); void mac_destroy_label(struct label *label); int mac_check_structmac_consistent(struct mac *mac); int mac_allocate_slot(void); #define MAC_IFNET_LOCK(ifp) mtx_lock(&mac_ifnet_mtx) #define MAC_IFNET_UNLOCK(ifp) mtx_unlock(&mac_ifnet_mtx) /* * MAC Framework per-object type functions. It's not yet clear how the * namespaces, etc, should work for these, so for now, sort by object type. */ struct label *mac_cred_label_alloc(void); void mac_cred_label_free(struct label *label); struct label *mac_pipe_label_alloc(void); void mac_pipe_label_free(struct label *label); struct label *mac_socket_label_alloc(int flag); void mac_socket_label_free(struct label *label); struct label *mac_vnode_label_alloc(void); void mac_vnode_label_free(struct label *label); int mac_cred_check_relabel(struct ucred *cred, struct label *newlabel); int mac_cred_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen); int mac_cred_internalize_label(struct label *label, char *string); void mac_cred_relabel(struct ucred *cred, struct label *newlabel); struct label *mac_mbuf_to_label(struct mbuf *m); void mac_pipe_copy_label(struct label *src, struct label *dest); int mac_pipe_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen); int mac_pipe_internalize_label(struct label *label, char *string); int mac_socket_label_set(struct ucred *cred, struct socket *so, struct label *label); void mac_socket_copy_label(struct label *src, struct label *dest); int mac_socket_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen); int mac_socket_internalize_label(struct label *label, char *string); int mac_vnode_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen); int mac_vnode_internalize_label(struct label *label, char *string); void mac_vnode_check_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot); int vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred); /* * MAC Framework composition macros invoke all registered MAC policies for a * specific entry point. They come in two forms: one which permits policies * to sleep/block, and another that does not. * - * MAC_CHECK performs the designated check by walking the policy module list - * and checking with each as to how it feels about the request. Note that it - * returns its value via 'error' in the scope of the caller. + * MAC_POLICY_CHECK performs the designated check by walking the policy + * module list and checking with each as to how it feels about the request. + * Note that it returns its value via 'error' in the scope of the caller. */ -#define MAC_CHECK(check, args...) do { \ +#define MAC_POLICY_CHECK(check, args...) do { \ struct mac_policy_conf *mpc; \ \ error = 0; \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## check != NULL) \ error = mac_error_select( \ mpc->mpc_ops->mpo_ ## check (args), \ error); \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_sleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## check != NULL) \ error = mac_error_select( \ mpc->mpc_ops->mpo_ ## check (args), \ error); \ } \ mac_policy_sunlock_sleep(); \ } \ } while (0) -#define MAC_CHECK_NOSLEEP(check, args...) do { \ +#define MAC_POLICY_CHECK_NOSLEEP(check, args...) do { \ struct mac_policy_conf *mpc; \ \ error = 0; \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## check != NULL) \ error = mac_error_select( \ mpc->mpc_ops->mpo_ ## check (args), \ error); \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_nosleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## check != NULL) \ error = mac_error_select( \ mpc->mpc_ops->mpo_ ## check (args), \ error); \ } \ mac_policy_sunlock_nosleep(); \ } \ } while (0) /* - * MAC_GRANT performs the designated check by walking the policy module list - * and checking with each as to how it feels about the request. Unlike - * MAC_CHECK, it grants if any policies return '0', and otherwise returns - * EPERM. Note that it returns its value via 'error' in the scope of the - * caller. + * MAC_POLICY_GRANT performs the designated check by walking the policy + * module list and checking with each as to how it feels about the request. + * Unlike MAC_POLICY_CHECK, it grants if any policies return '0', and + * otherwise returns EPERM. Note that it returns its value via 'error' in + * the scope of the caller. */ -#define MAC_GRANT_NOSLEEP(check, args...) do { \ +#define MAC_POLICY_GRANT_NOSLEEP(check, args...) do { \ struct mac_policy_conf *mpc; \ \ error = EPERM; \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## check != NULL) { \ if (mpc->mpc_ops->mpo_ ## check(args) == 0) \ error = 0; \ } \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_nosleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## check != NULL) { \ if (mpc->mpc_ops->mpo_ ## check (args) \ == 0) \ error = 0; \ } \ } \ mac_policy_sunlock_nosleep(); \ } \ } while (0) /* - * MAC_BOOLEAN performs the designated boolean composition by walking the - * module list, invoking each instance of the operation, and combining the - * results using the passed C operator. Note that it returns its value via - * 'result' in the scope of the caller, which should be initialized by the - * caller in a meaningful way to get a meaningful result. + * MAC_POLICY_BOOLEAN performs the designated boolean composition by walking + * the module list, invoking each instance of the operation, and combining + * the results using the passed C operator. Note that it returns its value + * via 'result' in the scope of the caller, which should be initialized by + * the caller in a meaningful way to get a meaningful result. */ -#define MAC_BOOLEAN(operation, composition, args...) do { \ +#define MAC_POLICY_BOOLEAN(operation, composition, args...) do { \ struct mac_policy_conf *mpc; \ \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ result = result composition \ mpc->mpc_ops->mpo_ ## operation (args); \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_sleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ result = result composition \ mpc->mpc_ops->mpo_ ## operation \ (args); \ } \ mac_policy_sunlock_sleep(); \ } \ } while (0) -#define MAC_BOOLEAN_NOSLEEP(operation, composition, args...) do { \ +#define MAC_POLICY_BOOLEAN_NOSLEEP(operation, composition, args...) do {\ struct mac_policy_conf *mpc; \ \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ result = result composition \ mpc->mpc_ops->mpo_ ## operation (args); \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_nosleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ result = result composition \ mpc->mpc_ops->mpo_ ## operation \ (args); \ } \ mac_policy_sunlock_nosleep(); \ } \ } while (0) /* - * MAC_EXTERNALIZE queries each policy to see if it can generate an + * MAC_POLICY_EXTERNALIZE queries each policy to see if it can generate an * externalized version of a label element by name. Policies declare whether * they have matched a particular element name, parsed from the string by - * MAC_EXTERNALIZE, and an error is returned if any element is matched by no - * policy. + * MAC_POLICY_EXTERNALIZE, and an error is returned if any element is matched + * by no policy. */ -#define MAC_EXTERNALIZE(type, label, elementlist, outbuf, \ +#define MAC_POLICY_EXTERNALIZE(type, label, elementlist, outbuf, \ outbuflen) do { \ int claimed, first, ignorenotfound, savedlen; \ char *element_name, *element_temp; \ struct sbuf sb; \ \ error = 0; \ first = 1; \ sbuf_new(&sb, outbuf, outbuflen, SBUF_FIXEDLEN); \ element_temp = elementlist; \ while ((element_name = strsep(&element_temp, ",")) != NULL) { \ if (element_name[0] == '?') { \ element_name++; \ ignorenotfound = 1; \ } else \ ignorenotfound = 0; \ savedlen = sbuf_len(&sb); \ if (first) \ error = sbuf_printf(&sb, "%s/", element_name); \ else \ error = sbuf_printf(&sb, ",%s/", element_name); \ if (error == -1) { \ error = EINVAL; /* XXX: E2BIG? */ \ break; \ } \ claimed = 0; \ - MAC_CHECK(type ## _externalize_label, label, \ + MAC_POLICY_CHECK(type ## _externalize_label, label, \ element_name, &sb, &claimed); \ if (error) \ break; \ if (claimed == 0 && ignorenotfound) { \ /* Revert last label name. */ \ sbuf_setpos(&sb, savedlen); \ } else if (claimed != 1) { \ error = EINVAL; /* XXX: ENOLABEL? */ \ break; \ } else { \ first = 0; \ } \ } \ sbuf_finish(&sb); \ } while (0) /* - * MAC_INTERNALIZE presents parsed element names and data to each policy to - * see if any is willing to claim it and internalize the label data. If no - * policies match, an error is returned. + * MAC_POLICY_INTERNALIZE presents parsed element names and data to each + * policy to see if any is willing to claim it and internalize the label + * data. If no policies match, an error is returned. */ -#define MAC_INTERNALIZE(type, label, instring) do { \ +#define MAC_POLICY_INTERNALIZE(type, label, instring) do { \ char *element, *element_name, *element_data; \ int claimed; \ \ error = 0; \ element = instring; \ while ((element_name = strsep(&element, ",")) != NULL) { \ element_data = element_name; \ element_name = strsep(&element_data, "/"); \ if (element_data == NULL) { \ error = EINVAL; \ break; \ } \ claimed = 0; \ - MAC_CHECK(type ## _internalize_label, label, \ + MAC_POLICY_CHECK(type ## _internalize_label, label, \ element_name, element_data, &claimed); \ if (error) \ break; \ if (claimed != 1) { \ /* XXXMAC: Another error here? */ \ error = EINVAL; \ break; \ } \ } \ } while (0) /* - * MAC_PERFORM performs the designated operation by walking the policy module - * list and invoking that operation for each policy. + * MAC_POLICY_PERFORM performs the designated operation by walking the policy + * module list and invoking that operation for each policy. */ -#define MAC_PERFORM(operation, args...) do { \ +#define MAC_POLICY_PERFORM(operation, args...) do { \ struct mac_policy_conf *mpc; \ \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ mpc->mpc_ops->mpo_ ## operation (args); \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_sleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ mpc->mpc_ops->mpo_ ## operation (args); \ } \ mac_policy_sunlock_sleep(); \ } \ } while (0) -#define MAC_PERFORM_NOSLEEP(operation, args...) do { \ +#define MAC_POLICY_PERFORM_NOSLEEP(operation, args...) do { \ struct mac_policy_conf *mpc; \ \ LIST_FOREACH(mpc, &mac_static_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ mpc->mpc_ops->mpo_ ## operation (args); \ } \ if (!LIST_EMPTY(&mac_policy_list)) { \ mac_policy_slock_nosleep(); \ LIST_FOREACH(mpc, &mac_policy_list, mpc_list) { \ if (mpc->mpc_ops->mpo_ ## operation != NULL) \ mpc->mpc_ops->mpo_ ## operation (args); \ } \ mac_policy_sunlock_nosleep(); \ } \ } while (0) #endif /* !_SECURITY_MAC_MAC_INTERNAL_H_ */ Index: head/sys/security/mac/mac_net.c =================================================================== --- head/sys/security/mac/mac_net.c (revision 191730) +++ head/sys/security/mac/mac_net.c (revision 191731) @@ -1,480 +1,482 @@ /*- * Copyright (c) 1999-2002, 2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * XXXRW: struct ifnet locking is incomplete in the network code, so we use * our own global mutex for struct ifnet. Non-ideal, but should help in the * SMP environment. */ struct mtx mac_ifnet_mtx; MTX_SYSINIT(mac_ifnet_mtx, &mac_ifnet_mtx, "mac_ifnet", MTX_DEF); /* * Retrieve the label associated with an mbuf by searching for the tag. * Depending on the value of mac_labelmbufs, it's possible that a label will * not be present, in which case NULL is returned. Policies must handle the * possibility of an mbuf not having label storage if they do not enforce * early loading. */ struct label * mac_mbuf_to_label(struct mbuf *m) { struct m_tag *tag; struct label *label; if (m == NULL) return (NULL); tag = m_tag_find(m, PACKET_TAG_MACLABEL, NULL); if (tag == NULL) return (NULL); label = (struct label *)(tag+1); return (label); } static struct label * mac_bpfdesc_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(bpfdesc_init_label, label); + MAC_POLICY_PERFORM(bpfdesc_init_label, label); return (label); } void mac_bpfdesc_init(struct bpf_d *d) { if (mac_labeled & MPC_OBJECT_BPFDESC) d->bd_label = mac_bpfdesc_label_alloc(); else d->bd_label = NULL; } static struct label * mac_ifnet_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(ifnet_init_label, label); + MAC_POLICY_PERFORM(ifnet_init_label, label); return (label); } void mac_ifnet_init(struct ifnet *ifp) { if (mac_labeled & MPC_OBJECT_IFNET) ifp->if_label = mac_ifnet_label_alloc(); else ifp->if_label = NULL; } int mac_mbuf_tag_init(struct m_tag *tag, int flag) { struct label *label; int error; label = (struct label *) (tag + 1); mac_init_label(label); if (flag & M_WAITOK) - MAC_CHECK(mbuf_init_label, label, flag); + MAC_POLICY_CHECK(mbuf_init_label, label, flag); else - MAC_CHECK_NOSLEEP(mbuf_init_label, label, flag); + MAC_POLICY_CHECK_NOSLEEP(mbuf_init_label, label, flag); if (error) { - MAC_PERFORM_NOSLEEP(mbuf_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(mbuf_destroy_label, label); mac_destroy_label(label); } return (error); } int mac_mbuf_init(struct mbuf *m, int flag) { struct m_tag *tag; int error; M_ASSERTPKTHDR(m); if (mac_labeled & MPC_OBJECT_MBUF) { tag = m_tag_get(PACKET_TAG_MACLABEL, sizeof(struct label), flag); if (tag == NULL) return (ENOMEM); error = mac_mbuf_tag_init(tag, flag); if (error) { m_tag_free(tag); return (error); } m_tag_prepend(m, tag); } return (0); } static void mac_bpfdesc_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(bpfdesc_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(bpfdesc_destroy_label, label); mac_labelzone_free(label); } void mac_bpfdesc_destroy(struct bpf_d *d) { if (d->bd_label != NULL) { mac_bpfdesc_label_free(d->bd_label); d->bd_label = NULL; } } static void mac_ifnet_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(ifnet_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(ifnet_destroy_label, label); mac_labelzone_free(label); } void mac_ifnet_destroy(struct ifnet *ifp) { if (ifp->if_label != NULL) { mac_ifnet_label_free(ifp->if_label); ifp->if_label = NULL; } } void mac_mbuf_tag_destroy(struct m_tag *tag) { struct label *label; label = (struct label *)(tag+1); - MAC_PERFORM_NOSLEEP(mbuf_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(mbuf_destroy_label, label); mac_destroy_label(label); } /* * mac_mbuf_tag_copy is called when an mbuf header is duplicated, in which * case the labels must also be duplicated. */ void mac_mbuf_tag_copy(struct m_tag *src, struct m_tag *dest) { struct label *src_label, *dest_label; src_label = (struct label *)(src+1); dest_label = (struct label *)(dest+1); /* * mac_mbuf_tag_init() is called on the target tag in m_tag_copy(), * so we don't need to call it here. */ - MAC_PERFORM_NOSLEEP(mbuf_copy_label, src_label, dest_label); + MAC_POLICY_PERFORM_NOSLEEP(mbuf_copy_label, src_label, dest_label); } void mac_mbuf_copy(struct mbuf *m_from, struct mbuf *m_to) { struct label *src_label, *dest_label; src_label = mac_mbuf_to_label(m_from); dest_label = mac_mbuf_to_label(m_to); - MAC_PERFORM_NOSLEEP(mbuf_copy_label, src_label, dest_label); + MAC_POLICY_PERFORM_NOSLEEP(mbuf_copy_label, src_label, dest_label); } static void mac_ifnet_copy_label(struct label *src, struct label *dest) { - MAC_PERFORM_NOSLEEP(ifnet_copy_label, src, dest); + MAC_POLICY_PERFORM_NOSLEEP(ifnet_copy_label, src, dest); } static int mac_ifnet_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen) { int error; - MAC_EXTERNALIZE(ifnet, label, elements, outbuf, outbuflen); + MAC_POLICY_EXTERNALIZE(ifnet, label, elements, outbuf, outbuflen); return (error); } static int mac_ifnet_internalize_label(struct label *label, char *string) { int error; - MAC_INTERNALIZE(ifnet, label, string); + MAC_POLICY_INTERNALIZE(ifnet, label, string); return (error); } void mac_ifnet_create(struct ifnet *ifp) { MAC_IFNET_LOCK(ifp); - MAC_PERFORM_NOSLEEP(ifnet_create, ifp, ifp->if_label); + MAC_POLICY_PERFORM_NOSLEEP(ifnet_create, ifp, ifp->if_label); MAC_IFNET_UNLOCK(ifp); } void mac_bpfdesc_create(struct ucred *cred, struct bpf_d *d) { - MAC_PERFORM_NOSLEEP(bpfdesc_create, cred, d, d->bd_label); + MAC_POLICY_PERFORM_NOSLEEP(bpfdesc_create, cred, d, d->bd_label); } void mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m) { struct label *label; BPFD_LOCK_ASSERT(d); label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(bpfdesc_create_mbuf, d, d->bd_label, m, label); + MAC_POLICY_PERFORM_NOSLEEP(bpfdesc_create_mbuf, d, d->bd_label, m, + label); } void mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m) { struct label *label; label = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); - MAC_PERFORM_NOSLEEP(ifnet_create_mbuf, ifp, ifp->if_label, m, label); + MAC_POLICY_PERFORM_NOSLEEP(ifnet_create_mbuf, ifp, ifp->if_label, m, + label); MAC_IFNET_UNLOCK(ifp); } MAC_CHECK_PROBE_DEFINE2(bpfdesc_check_receive, "struct bpf_d *", "struct ifnet *"); int mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp) { int error; BPFD_LOCK_ASSERT(d); MAC_IFNET_LOCK(ifp); - MAC_CHECK_NOSLEEP(bpfdesc_check_receive, d, d->bd_label, ifp, + MAC_POLICY_CHECK_NOSLEEP(bpfdesc_check_receive, d, d->bd_label, ifp, ifp->if_label); MAC_CHECK_PROBE2(bpfdesc_check_receive, error, d, ifp); MAC_IFNET_UNLOCK(ifp); return (error); } MAC_CHECK_PROBE_DEFINE2(ifnet_check_transmit, "struct ifnet *", "struct mbuf *"); int mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m) { struct label *label; int error; M_ASSERTPKTHDR(m); label = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); - MAC_CHECK_NOSLEEP(ifnet_check_transmit, ifp, ifp->if_label, m, + MAC_POLICY_CHECK_NOSLEEP(ifnet_check_transmit, ifp, ifp->if_label, m, label); MAC_CHECK_PROBE2(ifnet_check_transmit, error, ifp, m); MAC_IFNET_UNLOCK(ifp); return (error); } int mac_ifnet_ioctl_get(struct ucred *cred, struct ifreq *ifr, struct ifnet *ifp) { char *elements, *buffer; struct label *intlabel; struct mac mac; int error; if (!(mac_labeled & MPC_OBJECT_IFNET)) return (EINVAL); error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac)); if (error) return (error); error = mac_check_structmac_consistent(&mac); if (error) return (error); elements = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK); error = copyinstr(mac.m_string, elements, mac.m_buflen, NULL); if (error) { free(elements, M_MACTEMP); return (error); } buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO); intlabel = mac_ifnet_label_alloc(); MAC_IFNET_LOCK(ifp); mac_ifnet_copy_label(ifp->if_label, intlabel); MAC_IFNET_UNLOCK(ifp); error = mac_ifnet_externalize_label(intlabel, elements, buffer, mac.m_buflen); mac_ifnet_label_free(intlabel); if (error == 0) error = copyout(buffer, mac.m_string, strlen(buffer)+1); free(buffer, M_MACTEMP); free(elements, M_MACTEMP); return (error); } int mac_ifnet_ioctl_set(struct ucred *cred, struct ifreq *ifr, struct ifnet *ifp) { struct label *intlabel; struct mac mac; char *buffer; int error; if (!(mac_labeled & MPC_OBJECT_IFNET)) return (EINVAL); error = copyin(ifr->ifr_ifru.ifru_data, &mac, sizeof(mac)); if (error) return (error); error = mac_check_structmac_consistent(&mac); if (error) return (error); buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK); error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL); if (error) { free(buffer, M_MACTEMP); return (error); } intlabel = mac_ifnet_label_alloc(); error = mac_ifnet_internalize_label(intlabel, buffer); free(buffer, M_MACTEMP); if (error) { mac_ifnet_label_free(intlabel); return (error); } /* * XXX: Note that this is a redundant privilege check, since policies * impose this check themselves if required by the policy * Eventually, this should go away. */ error = priv_check_cred(cred, PRIV_NET_SETIFMAC, 0); if (error) { mac_ifnet_label_free(intlabel); return (error); } MAC_IFNET_LOCK(ifp); - MAC_CHECK_NOSLEEP(ifnet_check_relabel, cred, ifp, ifp->if_label, - intlabel); + MAC_POLICY_CHECK_NOSLEEP(ifnet_check_relabel, cred, ifp, + ifp->if_label, intlabel); if (error) { MAC_IFNET_UNLOCK(ifp); mac_ifnet_label_free(intlabel); return (error); } - MAC_PERFORM_NOSLEEP(ifnet_relabel, cred, ifp, ifp->if_label, + MAC_POLICY_PERFORM_NOSLEEP(ifnet_relabel, cred, ifp, ifp->if_label, intlabel); MAC_IFNET_UNLOCK(ifp); mac_ifnet_label_free(intlabel); return (0); } Index: head/sys/security/mac/mac_pipe.c =================================================================== --- head/sys/security/mac/mac_pipe.c (revision 191730) +++ head/sys/security/mac/mac_pipe.c (revision 191731) @@ -1,259 +1,260 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include struct label * mac_pipe_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(pipe_init_label, label); + MAC_POLICY_PERFORM(pipe_init_label, label); return (label); } void mac_pipe_init(struct pipepair *pp) { if (mac_labeled & MPC_OBJECT_PIPE) pp->pp_label = mac_pipe_label_alloc(); else pp->pp_label = NULL; } void mac_pipe_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(pipe_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(pipe_destroy_label, label); mac_labelzone_free(label); } void mac_pipe_destroy(struct pipepair *pp) { if (pp->pp_label != NULL) { mac_pipe_label_free(pp->pp_label); pp->pp_label = NULL; } } void mac_pipe_copy_label(struct label *src, struct label *dest) { - MAC_PERFORM_NOSLEEP(pipe_copy_label, src, dest); + MAC_POLICY_PERFORM_NOSLEEP(pipe_copy_label, src, dest); } int mac_pipe_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen) { int error; - MAC_EXTERNALIZE(pipe, label, elements, outbuf, outbuflen); + MAC_POLICY_EXTERNALIZE(pipe, label, elements, outbuf, outbuflen); return (error); } int mac_pipe_internalize_label(struct label *label, char *string) { int error; - MAC_INTERNALIZE(pipe, label, string); + MAC_POLICY_INTERNALIZE(pipe, label, string); return (error); } void mac_pipe_create(struct ucred *cred, struct pipepair *pp) { - MAC_PERFORM_NOSLEEP(pipe_create, cred, pp, pp->pp_label); + MAC_POLICY_PERFORM_NOSLEEP(pipe_create, cred, pp, pp->pp_label); } static void mac_pipe_relabel(struct ucred *cred, struct pipepair *pp, struct label *newlabel) { - MAC_PERFORM_NOSLEEP(pipe_relabel, cred, pp, pp->pp_label, newlabel); + MAC_POLICY_PERFORM_NOSLEEP(pipe_relabel, cred, pp, pp->pp_label, + newlabel); } MAC_CHECK_PROBE_DEFINE4(pipe_check_ioctl, "struct ucred *", "struct pipepair *", "unsigned long", "void *"); int mac_pipe_check_ioctl(struct ucred *cred, struct pipepair *pp, unsigned long cmd, void *data) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); - MAC_CHECK_NOSLEEP(pipe_check_ioctl, cred, pp, pp->pp_label, cmd, - data); + MAC_POLICY_CHECK_NOSLEEP(pipe_check_ioctl, cred, pp, pp->pp_label, + cmd, data); MAC_CHECK_PROBE4(pipe_check_ioctl, error, cred, pp, cmd, data); return (error); } MAC_CHECK_PROBE_DEFINE2(pipe_check_poll, "struct ucred *", "struct pipepair *"); int mac_pipe_check_poll(struct ucred *cred, struct pipepair *pp) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); - MAC_CHECK_NOSLEEP(pipe_check_poll, cred, pp, pp->pp_label); + MAC_POLICY_CHECK_NOSLEEP(pipe_check_poll, cred, pp, pp->pp_label); MAC_CHECK_PROBE2(pipe_check_poll, error, cred, pp); return (error); } MAC_CHECK_PROBE_DEFINE2(pipe_check_read, "struct ucred *", "struct pipepair *"); int mac_pipe_check_read(struct ucred *cred, struct pipepair *pp) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); - MAC_CHECK_NOSLEEP(pipe_check_read, cred, pp, pp->pp_label); + MAC_POLICY_CHECK_NOSLEEP(pipe_check_read, cred, pp, pp->pp_label); MAC_CHECK_PROBE2(pipe_check_read, error, cred, pp); return (error); } MAC_CHECK_PROBE_DEFINE3(pipe_check_relabel, "struct ucred *", "struct pipepair *", "struct label *"); static int mac_pipe_check_relabel(struct ucred *cred, struct pipepair *pp, struct label *newlabel) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); - MAC_CHECK_NOSLEEP(pipe_check_relabel, cred, pp, pp->pp_label, + MAC_POLICY_CHECK_NOSLEEP(pipe_check_relabel, cred, pp, pp->pp_label, newlabel); MAC_CHECK_PROBE3(pipe_check_relabel, error, cred, pp, newlabel); return (error); } MAC_CHECK_PROBE_DEFINE2(pipe_check_stat, "struct ucred *", "struct pipepair *"); int mac_pipe_check_stat(struct ucred *cred, struct pipepair *pp) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); - MAC_CHECK_NOSLEEP(pipe_check_stat, cred, pp, pp->pp_label); + MAC_POLICY_CHECK_NOSLEEP(pipe_check_stat, cred, pp, pp->pp_label); MAC_CHECK_PROBE2(pipe_check_stat, error, cred, pp); return (error); } MAC_CHECK_PROBE_DEFINE2(pipe_check_write, "struct ucred *", "struct pipepair *"); int mac_pipe_check_write(struct ucred *cred, struct pipepair *pp) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); - MAC_CHECK_NOSLEEP(pipe_check_write, cred, pp, pp->pp_label); + MAC_POLICY_CHECK_NOSLEEP(pipe_check_write, cred, pp, pp->pp_label); MAC_CHECK_PROBE2(pipe_check_write, error, cred, pp); return (error); } int mac_pipe_label_set(struct ucred *cred, struct pipepair *pp, struct label *label) { int error; mtx_assert(&pp->pp_mtx, MA_OWNED); error = mac_pipe_check_relabel(cred, pp, label); if (error) return (error); mac_pipe_relabel(cred, pp, label); return (0); } Index: head/sys/security/mac/mac_posix_sem.c =================================================================== --- head/sys/security/mac/mac_posix_sem.c (revision 191730) +++ head/sys/security/mac/mac_posix_sem.c (revision 191731) @@ -1,198 +1,200 @@ /*- * Copyright (c) 2003-2006 SPARTA, Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include "opt_posix.h" #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_posixsem_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(posixsem_init_label, label); + MAC_POLICY_PERFORM(posixsem_init_label, label); return (label); } void mac_posixsem_init(struct ksem *ks) { if (mac_labeled & MPC_OBJECT_POSIXSEM) ks->ks_label = mac_posixsem_label_alloc(); else ks->ks_label = NULL; } static void mac_posixsem_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(posixsem_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(posixsem_destroy_label, label); mac_labelzone_free(label); } void mac_posixsem_destroy(struct ksem *ks) { if (ks->ks_label != NULL) { mac_posixsem_label_free(ks->ks_label); ks->ks_label = NULL; } } void mac_posixsem_create(struct ucred *cred, struct ksem *ks) { - MAC_PERFORM_NOSLEEP(posixsem_create, cred, ks, ks->ks_label); + MAC_POLICY_PERFORM_NOSLEEP(posixsem_create, cred, ks, ks->ks_label); } MAC_CHECK_PROBE_DEFINE2(posixsem_check_open, "struct ucred *", "struct ksem *"); int mac_posixsem_check_open(struct ucred *cred, struct ksem *ks) { int error; - MAC_CHECK_NOSLEEP(posixsem_check_open, cred, ks, ks->ks_label); + MAC_POLICY_CHECK_NOSLEEP(posixsem_check_open, cred, ks, + ks->ks_label); MAC_CHECK_PROBE2(posixsem_check_open, error, cred, ks); return (error); } MAC_CHECK_PROBE_DEFINE3(posixsem_check_getvalue, "struct ucred *", "struct ucred *", "struct ksem *"); int mac_posixsem_check_getvalue(struct ucred *active_cred, struct ucred *file_cred, struct ksem *ks) { int error; - MAC_CHECK_NOSLEEP(posixsem_check_getvalue, active_cred, file_cred, - ks, ks->ks_label); + MAC_POLICY_CHECK_NOSLEEP(posixsem_check_getvalue, active_cred, + file_cred, ks, ks->ks_label); MAC_CHECK_PROBE3(posixsem_check_getvalue, error, active_cred, file_cred, ks); return (error); } MAC_CHECK_PROBE_DEFINE3(posixsem_check_post, "struct ucred *", "struct ucred *", "struct ksem *"); int mac_posixsem_check_post(struct ucred *active_cred, struct ucred *file_cred, struct ksem *ks) { int error; - MAC_CHECK_NOSLEEP(posixsem_check_post, active_cred, file_cred, ks, - ks->ks_label); + MAC_POLICY_CHECK_NOSLEEP(posixsem_check_post, active_cred, file_cred, + ks, ks->ks_label); MAC_CHECK_PROBE3(posixsem_check_post, error, active_cred, file_cred, ks); return (error); } MAC_CHECK_PROBE_DEFINE3(posixsem_check_stat, "struct ucred *", "struct ucred *", "struct ksem *"); int mac_posixsem_check_stat(struct ucred *active_cred, struct ucred *file_cred, struct ksem *ks) { int error; - MAC_CHECK_NOSLEEP(posixsem_check_stat, active_cred, file_cred, ks, - ks->ks_label); + MAC_POLICY_CHECK_NOSLEEP(posixsem_check_stat, active_cred, file_cred, + ks, ks->ks_label); MAC_CHECK_PROBE3(posixsem_check_stat, error, active_cred, file_cred, ks); return (error); } MAC_CHECK_PROBE_DEFINE2(posixsem_check_unlink, "struct ucred *", "struct ksem *"); int mac_posixsem_check_unlink(struct ucred *cred, struct ksem *ks) { int error; - MAC_CHECK_NOSLEEP(posixsem_check_unlink, cred, ks, ks->ks_label); + MAC_POLICY_CHECK_NOSLEEP(posixsem_check_unlink, cred, ks, + ks->ks_label); MAC_CHECK_PROBE2(posixsem_check_unlink, error, cred, ks); return (error); } MAC_CHECK_PROBE_DEFINE3(posixsem_check_wait, "struct ucred *", "struct ucred *", "struct ksem *"); int mac_posixsem_check_wait(struct ucred *active_cred, struct ucred *file_cred, struct ksem *ks) { int error; - MAC_CHECK_NOSLEEP(posixsem_check_wait, active_cred, file_cred, ks, - ks->ks_label); + MAC_POLICY_CHECK_NOSLEEP(posixsem_check_wait, active_cred, file_cred, + ks, ks->ks_label); MAC_CHECK_PROBE3(posixsem_check_wait, error, active_cred, file_cred, ks); return (error); } Index: head/sys/security/mac/mac_posix_shm.c =================================================================== --- head/sys/security/mac/mac_posix_shm.c (revision 191730) +++ head/sys/security/mac/mac_posix_shm.c (revision 191731) @@ -1,181 +1,183 @@ /*- * Copyright (c) 2003-2006 SPARTA, Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_posixshm_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(posixshm_init_label, label); + MAC_POLICY_PERFORM(posixshm_init_label, label); return (label); } void mac_posixshm_init(struct shmfd *shmfd) { if (mac_labeled & MPC_OBJECT_POSIXSHM) shmfd->shm_label = mac_posixshm_label_alloc(); else shmfd->shm_label = NULL; } static void mac_posixshm_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(posixshm_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(posixshm_destroy_label, label); mac_labelzone_free(label); } void mac_posixshm_destroy(struct shmfd *shmfd) { if (shmfd->shm_label != NULL) { mac_posixshm_label_free(shmfd->shm_label); shmfd->shm_label = NULL; } } void mac_posixshm_create(struct ucred *cred, struct shmfd *shmfd) { - MAC_PERFORM_NOSLEEP(posixshm_create, cred, shmfd, shmfd->shm_label); + MAC_POLICY_PERFORM_NOSLEEP(posixshm_create, cred, shmfd, + shmfd->shm_label); } MAC_CHECK_PROBE_DEFINE4(posixshm_check_mmap, "struct ucred *", "struct shmfd *", "int", "int"); int mac_posixshm_check_mmap(struct ucred *cred, struct shmfd *shmfd, int prot, int flags) { int error; - MAC_CHECK_NOSLEEP(posixshm_check_mmap, cred, shmfd, shmfd->shm_label, - prot, flags); + MAC_POLICY_CHECK_NOSLEEP(posixshm_check_mmap, cred, shmfd, + shmfd->shm_label, prot, flags); MAC_CHECK_PROBE4(posixshm_check_mmap, error, cred, shmfd, prot, flags); return (error); } MAC_CHECK_PROBE_DEFINE2(posixshm_check_open, "struct ucred *", "struct shmfd *"); int mac_posixshm_check_open(struct ucred *cred, struct shmfd *shmfd) { int error; - MAC_CHECK_NOSLEEP(posixshm_check_open, cred, shmfd, shmfd->shm_label); + MAC_POLICY_CHECK_NOSLEEP(posixshm_check_open, cred, shmfd, + shmfd->shm_label); MAC_CHECK_PROBE2(posixshm_check_open, error, cred, shmfd); return (error); } MAC_CHECK_PROBE_DEFINE3(posixshm_check_stat, "struct ucred *", "struct ucred *", "struct shmfd *"); int mac_posixshm_check_stat(struct ucred *active_cred, struct ucred *file_cred, struct shmfd *shmfd) { int error; - MAC_CHECK_NOSLEEP(posixshm_check_stat, active_cred, file_cred, shmfd, - shmfd->shm_label); + MAC_POLICY_CHECK_NOSLEEP(posixshm_check_stat, active_cred, file_cred, + shmfd, shmfd->shm_label); MAC_CHECK_PROBE3(posixshm_check_stat, error, active_cred, file_cred, shmfd); return (error); } MAC_CHECK_PROBE_DEFINE3(posixshm_check_truncate, "struct ucred *", "struct ucred *", "struct shmfd *"); int mac_posixshm_check_truncate(struct ucred *active_cred, struct ucred *file_cred, struct shmfd *shmfd) { int error; - MAC_CHECK_NOSLEEP(posixshm_check_truncate, active_cred, file_cred, - shmfd, shmfd->shm_label); + MAC_POLICY_CHECK_NOSLEEP(posixshm_check_truncate, active_cred, + file_cred, shmfd, shmfd->shm_label); MAC_CHECK_PROBE3(posixshm_check_truncate, error, active_cred, file_cred, shmfd); return (error); } MAC_CHECK_PROBE_DEFINE2(posixshm_check_unlink, "struct ucred *", "struct shmfd *"); int mac_posixshm_check_unlink(struct ucred *cred, struct shmfd *shmfd) { int error; - MAC_CHECK_NOSLEEP(posixshm_check_unlink, cred, shmfd, + MAC_POLICY_CHECK_NOSLEEP(posixshm_check_unlink, cred, shmfd, shmfd->shm_label); MAC_CHECK_PROBE2(posixshm_check_unlink, error, cred, shmfd); return (error); } Index: head/sys/security/mac/mac_priv.c =================================================================== --- head/sys/security/mac/mac_priv.c (revision 191730) +++ head/sys/security/mac/mac_priv.c (revision 191731) @@ -1,96 +1,96 @@ /*- * Copyright (c) 2006 nCircle Network Security, Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed by Robert N. M. Watson for the TrustedBSD * Project under contract to nCircle Network Security, Inc. * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR, NCIRCLE NETWORK SECURITY, * INC., OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * MAC checks for system privileges. */ #include "sys/cdefs.h" __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include /* * The MAC Framework interacts with kernel privilege checks in two ways: it * may restrict the granting of privilege to a subject, and it may grant * additional privileges to the subject. Policies may implement none, one, * or both of these entry points. Restriction of privilege by any policy * always overrides granting of privilege by any policy or other privilege * mechanism. See kern_priv.c:priv_check_cred() for details of the * composition. */ MAC_CHECK_PROBE_DEFINE2(priv_check, "struct ucred *", "int"); /* * Restrict access to a privilege for a credential. Return failure if any * policy denies access. */ int mac_priv_check(struct ucred *cred, int priv) { int error; - MAC_CHECK_NOSLEEP(priv_check, cred, priv); + MAC_POLICY_CHECK_NOSLEEP(priv_check, cred, priv); MAC_CHECK_PROBE2(priv_check, error, cred, priv); return (error); } MAC_GRANT_PROBE_DEFINE2(priv_grant, "struct ucred *", "int"); /* * Grant access to a privilege for a credential. Return success if any * policy grants access. */ int mac_priv_grant(struct ucred *cred, int priv) { int error; - MAC_GRANT_NOSLEEP(priv_grant, cred, priv); + MAC_POLICY_GRANT_NOSLEEP(priv_grant, cred, priv); MAC_GRANT_PROBE2(priv_grant, error, cred, priv); return (error); } Index: head/sys/security/mac/mac_process.c =================================================================== --- head/sys/security/mac/mac_process.c (revision 191730) +++ head/sys/security/mac/mac_process.c (revision 191731) @@ -1,439 +1,439 @@ /*- * Copyright (c) 1999-2002, 2008-2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2003 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int mac_mmap_revocation = 1; SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation, CTLFLAG_RW, &mac_mmap_revocation, 0, "Revoke mmap access to files on subject " "relabel"); static int mac_mmap_revocation_via_cow = 0; SYSCTL_INT(_security_mac, OID_AUTO, mmap_revocation_via_cow, CTLFLAG_RW, &mac_mmap_revocation_via_cow, 0, "Revoke mmap access to files via " "copy-on-write semantics, or by removing all write access"); static void mac_proc_vm_revoke_recurse(struct thread *td, struct ucred *cred, struct vm_map *map); static struct label * mac_proc_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(proc_init_label, label); + MAC_POLICY_PERFORM(proc_init_label, label); return (label); } void mac_proc_init(struct proc *p) { if (mac_labeled & MPC_OBJECT_PROC) p->p_label = mac_proc_label_alloc(); else p->p_label = NULL; } static void mac_proc_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(proc_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(proc_destroy_label, label); mac_labelzone_free(label); } void mac_proc_destroy(struct proc *p) { if (p->p_label != NULL) { mac_proc_label_free(p->p_label); p->p_label = NULL; } } void mac_thread_userret(struct thread *td) { - MAC_PERFORM(thread_userret, td); + MAC_POLICY_PERFORM(thread_userret, td); } int mac_execve_enter(struct image_params *imgp, struct mac *mac_p) { struct label *label; struct mac mac; char *buffer; int error; if (mac_p == NULL) return (0); if (!(mac_labeled & MPC_OBJECT_CRED)) return (EINVAL); error = copyin(mac_p, &mac, sizeof(mac)); if (error) return (error); error = mac_check_structmac_consistent(&mac); if (error) return (error); buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK); error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL); if (error) { free(buffer, M_MACTEMP); return (error); } label = mac_cred_label_alloc(); error = mac_cred_internalize_label(label, buffer); free(buffer, M_MACTEMP); if (error) { mac_cred_label_free(label); return (error); } imgp->execlabel = label; return (0); } void mac_execve_exit(struct image_params *imgp) { if (imgp->execlabel != NULL) { mac_cred_label_free(imgp->execlabel); imgp->execlabel = NULL; } } void mac_execve_interpreter_enter(struct vnode *interpvp, struct label **interpvplabel) { if (mac_labeled & MPC_OBJECT_VNODE) { *interpvplabel = mac_vnode_label_alloc(); mac_vnode_copy_label(interpvp->v_label, *interpvplabel); } else *interpvplabel = NULL; } void mac_execve_interpreter_exit(struct label *interpvplabel) { if (interpvplabel != NULL) mac_vnode_label_free(interpvplabel); } /* * When relabeling a process, call out to the policies for the maximum * permission allowed for each object type we know about in its memory space, * and revoke access (in the least surprising ways we know) when necessary. * The process lock is not held here. */ void mac_proc_vm_revoke(struct thread *td) { struct ucred *cred; PROC_LOCK(td->td_proc); cred = crhold(td->td_proc->p_ucred); PROC_UNLOCK(td->td_proc); /* XXX freeze all other threads */ mac_proc_vm_revoke_recurse(td, cred, &td->td_proc->p_vmspace->vm_map); /* XXX allow other threads to continue */ crfree(cred); } static __inline const char * prot2str(vm_prot_t prot) { switch (prot & VM_PROT_ALL) { case VM_PROT_READ: return ("r--"); case VM_PROT_READ | VM_PROT_WRITE: return ("rw-"); case VM_PROT_READ | VM_PROT_EXECUTE: return ("r-x"); case VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE: return ("rwx"); case VM_PROT_WRITE: return ("-w-"); case VM_PROT_EXECUTE: return ("--x"); case VM_PROT_WRITE | VM_PROT_EXECUTE: return ("-wx"); default: return ("---"); } } static void mac_proc_vm_revoke_recurse(struct thread *td, struct ucred *cred, struct vm_map *map) { vm_map_entry_t vme; int vfslocked, result; vm_prot_t revokeperms; vm_object_t backing_object, object; vm_ooffset_t offset; struct vnode *vp; struct mount *mp; if (!mac_mmap_revocation) return; vm_map_lock(map); for (vme = map->header.next; vme != &map->header; vme = vme->next) { if (vme->eflags & MAP_ENTRY_IS_SUB_MAP) { mac_proc_vm_revoke_recurse(td, cred, vme->object.sub_map); continue; } /* * Skip over entries that obviously are not shared. */ if (vme->eflags & (MAP_ENTRY_COW | MAP_ENTRY_NOSYNC) || !vme->max_protection) continue; /* * Drill down to the deepest backing object. */ offset = vme->offset; object = vme->object.vm_object; if (object == NULL) continue; VM_OBJECT_LOCK(object); while ((backing_object = object->backing_object) != NULL) { VM_OBJECT_LOCK(backing_object); offset += object->backing_object_offset; VM_OBJECT_UNLOCK(object); object = backing_object; } VM_OBJECT_UNLOCK(object); /* * At the moment, vm_maps and objects aren't considered by * the MAC system, so only things with backing by a normal * object (read: vnodes) are checked. */ if (object->type != OBJT_VNODE) continue; vp = (struct vnode *)object->handle; vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); result = vme->max_protection; mac_vnode_check_mmap_downgrade(cred, vp, &result); VOP_UNLOCK(vp, 0); /* * Find out what maximum protection we may be allowing now * but a policy needs to get removed. */ revokeperms = vme->max_protection & ~result; if (!revokeperms) { VFS_UNLOCK_GIANT(vfslocked); continue; } printf("pid %ld: revoking %s perms from %#lx:%ld " "(max %s/cur %s)\n", (long)td->td_proc->p_pid, prot2str(revokeperms), (u_long)vme->start, (long)(vme->end - vme->start), prot2str(vme->max_protection), prot2str(vme->protection)); /* * This is the really simple case: if a map has more * max_protection than is allowed, but it's not being * actually used (that is, the current protection is still * allowed), we can just wipe it out and do nothing more. */ if ((vme->protection & revokeperms) == 0) { vme->max_protection -= revokeperms; } else { if (revokeperms & VM_PROT_WRITE) { /* * In the more complicated case, flush out all * pending changes to the object then turn it * copy-on-write. */ vm_object_reference(object); (void) vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); VM_OBJECT_LOCK(object); vm_object_page_clean(object, OFF_TO_IDX(offset), OFF_TO_IDX(offset + vme->end - vme->start + PAGE_MASK), OBJPC_SYNC); VM_OBJECT_UNLOCK(object); VOP_UNLOCK(vp, 0); vn_finished_write(mp); vm_object_deallocate(object); /* * Why bother if there's no read permissions * anymore? For the rest, we need to leave * the write permissions on for COW, or * remove them entirely if configured to. */ if (!mac_mmap_revocation_via_cow) { vme->max_protection &= ~VM_PROT_WRITE; vme->protection &= ~VM_PROT_WRITE; } if ((revokeperms & VM_PROT_READ) == 0) vme->eflags |= MAP_ENTRY_COW | MAP_ENTRY_NEEDS_COPY; } if (revokeperms & VM_PROT_EXECUTE) { vme->max_protection &= ~VM_PROT_EXECUTE; vme->protection &= ~VM_PROT_EXECUTE; } if (revokeperms & VM_PROT_READ) { vme->max_protection = 0; vme->protection = 0; } pmap_protect(map->pmap, vme->start, vme->end, vme->protection & ~revokeperms); vm_map_simplify_entry(map, vme); } VFS_UNLOCK_GIANT(vfslocked); } vm_map_unlock(map); } MAC_CHECK_PROBE_DEFINE2(proc_check_debug, "struct ucred *", "struct proc *"); int mac_proc_check_debug(struct ucred *cred, struct proc *p) { int error; PROC_LOCK_ASSERT(p, MA_OWNED); - MAC_CHECK_NOSLEEP(proc_check_debug, cred, p); + MAC_POLICY_CHECK_NOSLEEP(proc_check_debug, cred, p); MAC_CHECK_PROBE2(proc_check_debug, error, cred, p); return (error); } MAC_CHECK_PROBE_DEFINE2(proc_check_sched, "struct ucred *", "struct proc *"); int mac_proc_check_sched(struct ucred *cred, struct proc *p) { int error; PROC_LOCK_ASSERT(p, MA_OWNED); - MAC_CHECK_NOSLEEP(proc_check_sched, cred, p); + MAC_POLICY_CHECK_NOSLEEP(proc_check_sched, cred, p); MAC_CHECK_PROBE2(proc_check_sched, error, cred, p); return (error); } MAC_CHECK_PROBE_DEFINE3(proc_check_signal, "struct ucred *", "struct proc *", "int"); int mac_proc_check_signal(struct ucred *cred, struct proc *p, int signum) { int error; PROC_LOCK_ASSERT(p, MA_OWNED); - MAC_CHECK_NOSLEEP(proc_check_signal, cred, p, signum); + MAC_POLICY_CHECK_NOSLEEP(proc_check_signal, cred, p, signum); MAC_CHECK_PROBE3(proc_check_signal, error, cred, p, signum); return (error); } MAC_CHECK_PROBE_DEFINE2(proc_check_wait, "struct ucred *", "struct proc *"); int mac_proc_check_wait(struct ucred *cred, struct proc *p) { int error; PROC_LOCK_ASSERT(p, MA_OWNED); - MAC_CHECK_NOSLEEP(proc_check_wait, cred, p); + MAC_POLICY_CHECK_NOSLEEP(proc_check_wait, cred, p); MAC_CHECK_PROBE2(proc_check_wait, error, cred, p); return (error); } Index: head/sys/security/mac/mac_socket.c =================================================================== --- head/sys/security/mac/mac_socket.c (revision 191730) +++ head/sys/security/mac/mac_socket.c (revision 191731) @@ -1,633 +1,643 @@ /*- * Copyright (c) 1999-2002, 2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2005 Networks Associates Technology, Inc. * Copyright (c) 2005-2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by McAfee * Research, the Technology Research Division of Network Associates, Inc. * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the * DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * Currently, sockets hold two labels: the label of the socket itself, and a * peer label, which may be used by policies to hold a copy of the label of * any remote endpoint. * * Possibly, this peer label should be maintained at the protocol layer * (inpcb, unpcb, etc), as this would allow protocol-aware code to maintain * the label consistently. For example, it might be copied live from a * remote socket for UNIX domain sockets rather than keeping a local copy on * this endpoint, but be cached and updated based on packets received for * TCP/IP. */ struct label * mac_socket_label_alloc(int flag) { struct label *label; int error; label = mac_labelzone_alloc(flag); if (label == NULL) return (NULL); if (flag & M_WAITOK) - MAC_CHECK(socket_init_label, label, flag); + MAC_POLICY_CHECK(socket_init_label, label, flag); else - MAC_CHECK_NOSLEEP(socket_init_label, label, flag); + MAC_POLICY_CHECK_NOSLEEP(socket_init_label, label, flag); if (error) { - MAC_PERFORM_NOSLEEP(socket_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(socket_destroy_label, label); mac_labelzone_free(label); return (NULL); } return (label); } static struct label * mac_socketpeer_label_alloc(int flag) { struct label *label; int error; label = mac_labelzone_alloc(flag); if (label == NULL) return (NULL); if (flag & M_WAITOK) - MAC_CHECK(socketpeer_init_label, label, flag); + MAC_POLICY_CHECK(socketpeer_init_label, label, flag); else - MAC_CHECK_NOSLEEP(socketpeer_init_label, label, flag); + MAC_POLICY_CHECK_NOSLEEP(socketpeer_init_label, label, flag); if (error) { - MAC_PERFORM_NOSLEEP(socketpeer_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(socketpeer_destroy_label, label); mac_labelzone_free(label); return (NULL); } return (label); } int mac_socket_init(struct socket *so, int flag) { if (mac_labeled & MPC_OBJECT_SOCKET) { so->so_label = mac_socket_label_alloc(flag); if (so->so_label == NULL) return (ENOMEM); so->so_peerlabel = mac_socketpeer_label_alloc(flag); if (so->so_peerlabel == NULL) { mac_socket_label_free(so->so_label); so->so_label = NULL; return (ENOMEM); } } else { so->so_label = NULL; so->so_peerlabel = NULL; } return (0); } void mac_socket_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(socket_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(socket_destroy_label, label); mac_labelzone_free(label); } static void mac_socketpeer_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(socketpeer_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(socketpeer_destroy_label, label); mac_labelzone_free(label); } void mac_socket_destroy(struct socket *so) { if (so->so_label != NULL) { mac_socket_label_free(so->so_label); so->so_label = NULL; mac_socketpeer_label_free(so->so_peerlabel); so->so_peerlabel = NULL; } } void mac_socket_copy_label(struct label *src, struct label *dest) { - MAC_PERFORM_NOSLEEP(socket_copy_label, src, dest); + MAC_POLICY_PERFORM_NOSLEEP(socket_copy_label, src, dest); } int mac_socket_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen) { int error; - MAC_EXTERNALIZE(socket, label, elements, outbuf, outbuflen); + MAC_POLICY_EXTERNALIZE(socket, label, elements, outbuf, outbuflen); return (error); } static int mac_socketpeer_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen) { int error; - MAC_EXTERNALIZE(socketpeer, label, elements, outbuf, outbuflen); + MAC_POLICY_EXTERNALIZE(socketpeer, label, elements, outbuf, + outbuflen); return (error); } int mac_socket_internalize_label(struct label *label, char *string) { int error; - MAC_INTERNALIZE(socket, label, string); + MAC_POLICY_INTERNALIZE(socket, label, string); return (error); } void mac_socket_create(struct ucred *cred, struct socket *so) { - MAC_PERFORM_NOSLEEP(socket_create, cred, so, so->so_label); + MAC_POLICY_PERFORM_NOSLEEP(socket_create, cred, so, so->so_label); } void mac_socket_newconn(struct socket *oldso, struct socket *newso) { SOCK_LOCK_ASSERT(oldso); - MAC_PERFORM_NOSLEEP(socket_newconn, oldso, oldso->so_label, newso, - newso->so_label); + MAC_POLICY_PERFORM_NOSLEEP(socket_newconn, oldso, oldso->so_label, + newso, newso->so_label); } static void mac_socket_relabel(struct ucred *cred, struct socket *so, struct label *newlabel) { SOCK_LOCK_ASSERT(so); - MAC_PERFORM_NOSLEEP(socket_relabel, cred, so, so->so_label, + MAC_POLICY_PERFORM_NOSLEEP(socket_relabel, cred, so, so->so_label, newlabel); } void mac_socketpeer_set_from_mbuf(struct mbuf *m, struct socket *so) { struct label *label; SOCK_LOCK_ASSERT(so); label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(socketpeer_set_from_mbuf, m, label, so, + MAC_POLICY_PERFORM_NOSLEEP(socketpeer_set_from_mbuf, m, label, so, so->so_peerlabel); } void mac_socketpeer_set_from_socket(struct socket *oldso, struct socket *newso) { /* * XXXRW: only hold the socket lock on one at a time, as one socket * is the original, and one is the new. However, it's called in both * directions, so we can't assert the lock here currently. */ - MAC_PERFORM_NOSLEEP(socketpeer_set_from_socket, oldso, + MAC_POLICY_PERFORM_NOSLEEP(socketpeer_set_from_socket, oldso, oldso->so_label, newso, newso->so_peerlabel); } void mac_socket_create_mbuf(struct socket *so, struct mbuf *m) { struct label *label; SOCK_LOCK_ASSERT(so); label = mac_mbuf_to_label(m); - MAC_PERFORM_NOSLEEP(socket_create_mbuf, so, so->so_label, m, label); + MAC_POLICY_PERFORM_NOSLEEP(socket_create_mbuf, so, so->so_label, m, + label); } MAC_CHECK_PROBE_DEFINE2(socket_check_accept, "struct ucred *", "struct socket *"); int mac_socket_check_accept(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_accept, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_accept, cred, so, + so->so_label); MAC_CHECK_PROBE2(socket_check_accept, error, cred, so); return (error); } MAC_CHECK_PROBE_DEFINE3(socket_check_bind, "struct ucred *", "struct socket *", "struct sockaddr *"); int mac_socket_check_bind(struct ucred *cred, struct socket *so, struct sockaddr *sa) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_bind, cred, so, so->so_label, sa); + MAC_POLICY_CHECK_NOSLEEP(socket_check_bind, cred, so, so->so_label, + sa); MAC_CHECK_PROBE3(socket_check_bind, error, cred, so, sa); return (error); } MAC_CHECK_PROBE_DEFINE3(socket_check_connect, "struct ucred *", "struct socket *", "struct sockaddr *"); int mac_socket_check_connect(struct ucred *cred, struct socket *so, struct sockaddr *sa) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_connect, cred, so, so->so_label, sa); + MAC_POLICY_CHECK_NOSLEEP(socket_check_connect, cred, so, + so->so_label, sa); MAC_CHECK_PROBE3(socket_check_connect, error, cred, so, sa); return (error); } MAC_CHECK_PROBE_DEFINE4(socket_check_create, "struct ucred *", "int", "int", "int"); int mac_socket_check_create(struct ucred *cred, int domain, int type, int proto) { int error; - MAC_CHECK_NOSLEEP(socket_check_create, cred, domain, type, proto); + MAC_POLICY_CHECK_NOSLEEP(socket_check_create, cred, domain, type, + proto); MAC_CHECK_PROBE4(socket_check_create, error, cred, domain, type, proto); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_deliver, "struct socket *", "struct mbuf *"); int mac_socket_check_deliver(struct socket *so, struct mbuf *m) { struct label *label; int error; SOCK_LOCK_ASSERT(so); label = mac_mbuf_to_label(m); - MAC_CHECK_NOSLEEP(socket_check_deliver, so, so->so_label, m, label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_deliver, so, so->so_label, m, + label); MAC_CHECK_PROBE2(socket_check_deliver, error, so, m); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_listen, "struct ucred *", "struct socket *"); int mac_socket_check_listen(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_listen, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_listen, cred, so, + so->so_label); MAC_CHECK_PROBE2(socket_check_listen, error, cred, so); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_poll, "struct ucred *", "struct socket *"); int mac_socket_check_poll(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_poll, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_poll, cred, so, so->so_label); MAC_CHECK_PROBE2(socket_check_poll, error, cred, so); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_receive, "struct ucred *", "struct socket *"); int mac_socket_check_receive(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_receive, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_receive, cred, so, + so->so_label); MAC_CHECK_PROBE2(socket_check_receive, error, cred, so); return (error); } MAC_CHECK_PROBE_DEFINE3(socket_check_relabel, "struct ucred *", "struct socket *", "struct label *"); static int mac_socket_check_relabel(struct ucred *cred, struct socket *so, struct label *newlabel) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_relabel, cred, so, so->so_label, - newlabel); + MAC_POLICY_CHECK_NOSLEEP(socket_check_relabel, cred, so, + so->so_label, newlabel); MAC_CHECK_PROBE3(socket_check_relabel, error, cred, so, newlabel); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_send, "struct ucred *", "struct socket *"); int mac_socket_check_send(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_send, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_send, cred, so, so->so_label); MAC_CHECK_PROBE2(socket_check_send, error, cred, so); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_stat, "struct ucred *", "struct socket *"); int mac_socket_check_stat(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_stat, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_stat, cred, so, so->so_label); MAC_CHECK_PROBE2(socket_check_stat, error, cred, so); return (error); } MAC_CHECK_PROBE_DEFINE2(socket_check_visible, "struct ucred *", "struct socket *"); int mac_socket_check_visible(struct ucred *cred, struct socket *so) { int error; SOCK_LOCK_ASSERT(so); - MAC_CHECK_NOSLEEP(socket_check_visible, cred, so, so->so_label); + MAC_POLICY_CHECK_NOSLEEP(socket_check_visible, cred, so, + so->so_label); MAC_CHECK_PROBE2(socket_check_visible, error, cred, so); return (error); } int mac_socket_label_set(struct ucred *cred, struct socket *so, struct label *label) { int error; /* * We acquire the socket lock when we perform the test and set, but * have to release it as the pcb code needs to acquire the pcb lock, * which will precede the socket lock in the lock order. However, * this is fine, as any race will simply result in the inpcb being * refreshed twice, but still consistently, as the inpcb code will * acquire the socket lock before refreshing, holding both locks. */ SOCK_LOCK(so); error = mac_socket_check_relabel(cred, so, label); if (error) { SOCK_UNLOCK(so); return (error); } mac_socket_relabel(cred, so, label); SOCK_UNLOCK(so); /* * If the protocol has expressed interest in socket layer changes, * such as if it needs to propagate changes to a cached pcb label * from the socket, notify it of the label change while holding the * socket lock. */ if (so->so_proto->pr_usrreqs->pru_sosetlabel != NULL) (so->so_proto->pr_usrreqs->pru_sosetlabel)(so); return (0); } int mac_setsockopt_label(struct ucred *cred, struct socket *so, struct mac *mac) { struct label *intlabel; char *buffer; int error; if (!(mac_labeled & MPC_OBJECT_SOCKET)) return (EINVAL); error = mac_check_structmac_consistent(mac); if (error) return (error); buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK); error = copyinstr(mac->m_string, buffer, mac->m_buflen, NULL); if (error) { free(buffer, M_MACTEMP); return (error); } intlabel = mac_socket_label_alloc(M_WAITOK); error = mac_socket_internalize_label(intlabel, buffer); free(buffer, M_MACTEMP); if (error) goto out; error = mac_socket_label_set(cred, so, intlabel); out: mac_socket_label_free(intlabel); return (error); } int mac_getsockopt_label(struct ucred *cred, struct socket *so, struct mac *mac) { char *buffer, *elements; struct label *intlabel; int error; if (!(mac_labeled & MPC_OBJECT_SOCKET)) return (EINVAL); error = mac_check_structmac_consistent(mac); if (error) return (error); elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK); error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL); if (error) { free(elements, M_MACTEMP); return (error); } buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO); intlabel = mac_socket_label_alloc(M_WAITOK); SOCK_LOCK(so); mac_socket_copy_label(so->so_label, intlabel); SOCK_UNLOCK(so); error = mac_socket_externalize_label(intlabel, elements, buffer, mac->m_buflen); mac_socket_label_free(intlabel); if (error == 0) error = copyout(buffer, mac->m_string, strlen(buffer)+1); free(buffer, M_MACTEMP); free(elements, M_MACTEMP); return (error); } int mac_getsockopt_peerlabel(struct ucred *cred, struct socket *so, struct mac *mac) { char *elements, *buffer; struct label *intlabel; int error; if (!(mac_labeled & MPC_OBJECT_SOCKET)) return (EINVAL); error = mac_check_structmac_consistent(mac); if (error) return (error); elements = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK); error = copyinstr(mac->m_string, elements, mac->m_buflen, NULL); if (error) { free(elements, M_MACTEMP); return (error); } buffer = malloc(mac->m_buflen, M_MACTEMP, M_WAITOK | M_ZERO); intlabel = mac_socket_label_alloc(M_WAITOK); SOCK_LOCK(so); mac_socket_copy_label(so->so_peerlabel, intlabel); SOCK_UNLOCK(so); error = mac_socketpeer_externalize_label(intlabel, elements, buffer, mac->m_buflen); mac_socket_label_free(intlabel); if (error == 0) error = copyout(buffer, mac->m_string, strlen(buffer)+1); free(buffer, M_MACTEMP); free(elements, M_MACTEMP); return (error); } Index: head/sys/security/mac/mac_system.c =================================================================== --- head/sys/security/mac/mac_system.c (revision 191730) +++ head/sys/security/mac/mac_system.c (revision 191731) @@ -1,236 +1,237 @@ /*- * Copyright (c) 2002-2003 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2007, 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * Portions of this software were developed by Robert Watson for the * TrustedBSD Project. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * MAC Framework entry points relating to overall operation of system, * including global services such as the kernel environment and loadable * modules. * * System checks often align with existing privilege checks, but provide * additional security context that may be relevant to policies, such as the * specific object being operated on. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include MAC_CHECK_PROBE_DEFINE1(kenv_check_dump, "struct ucred *"); int mac_kenv_check_dump(struct ucred *cred) { int error; - MAC_CHECK_NOSLEEP(kenv_check_dump, cred); + MAC_POLICY_CHECK_NOSLEEP(kenv_check_dump, cred); MAC_CHECK_PROBE1(kenv_check_dump, error, cred); return (error); } MAC_CHECK_PROBE_DEFINE2(kenv_check_get, "struct ucred *", "char *"); int mac_kenv_check_get(struct ucred *cred, char *name) { int error; - MAC_CHECK_NOSLEEP(kenv_check_get, cred, name); + MAC_POLICY_CHECK_NOSLEEP(kenv_check_get, cred, name); MAC_CHECK_PROBE2(kenv_check_get, error, cred, name); return (error); } MAC_CHECK_PROBE_DEFINE3(kenv_check_set, "struct ucred *", "char *", "char *"); int mac_kenv_check_set(struct ucred *cred, char *name, char *value) { int error; - MAC_CHECK_NOSLEEP(kenv_check_set, cred, name, value); + MAC_POLICY_CHECK_NOSLEEP(kenv_check_set, cred, name, value); MAC_CHECK_PROBE3(kenv_check_set, error, cred, name, value); return (error); } MAC_CHECK_PROBE_DEFINE2(kenv_check_unset, "struct ucred *", "char *"); int mac_kenv_check_unset(struct ucred *cred, char *name) { int error; - MAC_CHECK_NOSLEEP(kenv_check_unset, cred, name); + MAC_POLICY_CHECK_NOSLEEP(kenv_check_unset, cred, name); MAC_CHECK_PROBE2(kenv_check_unset, error, cred, name); return (error); } MAC_CHECK_PROBE_DEFINE2(kld_check_load, "struct ucred *", "struct vnode *"); int mac_kld_check_load(struct ucred *cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_kld_check_load"); - MAC_CHECK(kld_check_load, cred, vp, vp->v_label); + MAC_POLICY_CHECK(kld_check_load, cred, vp, vp->v_label); MAC_CHECK_PROBE2(kld_check_load, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE1(kld_check_stat, "struct ucred *"); int mac_kld_check_stat(struct ucred *cred) { int error; - MAC_CHECK_NOSLEEP(kld_check_stat, cred); + MAC_POLICY_CHECK_NOSLEEP(kld_check_stat, cred); MAC_CHECK_PROBE1(kld_check_stat, error, cred); return (error); } MAC_CHECK_PROBE_DEFINE2(system_check_acct, "struct ucred *", "struct vnode *"); int mac_system_check_acct(struct ucred *cred, struct vnode *vp) { int error; if (vp != NULL) { ASSERT_VOP_LOCKED(vp, "mac_system_check_acct"); } - MAC_CHECK(system_check_acct, cred, vp, + MAC_POLICY_CHECK(system_check_acct, cred, vp, vp != NULL ? vp->v_label : NULL); MAC_CHECK_PROBE2(system_check_acct, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE2(system_check_reboot, "struct ucred *", "int"); int mac_system_check_reboot(struct ucred *cred, int howto) { int error; - MAC_CHECK_NOSLEEP(system_check_reboot, cred, howto); + MAC_POLICY_CHECK_NOSLEEP(system_check_reboot, cred, howto); MAC_CHECK_PROBE2(system_check_reboot, error, cred, howto); return (error); } MAC_CHECK_PROBE_DEFINE2(system_check_swapon, "struct ucred *", "struct vnode *"); int mac_system_check_swapon(struct ucred *cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_system_check_swapon"); - MAC_CHECK(system_check_swapon, cred, vp, vp->v_label); + MAC_POLICY_CHECK(system_check_swapon, cred, vp, vp->v_label); MAC_CHECK_PROBE2(system_check_swapon, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE2(system_check_swapoff, "struct ucred *", "struct vnode *"); int mac_system_check_swapoff(struct ucred *cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_system_check_swapoff"); - MAC_CHECK(system_check_swapoff, cred, vp, vp->v_label); + MAC_POLICY_CHECK(system_check_swapoff, cred, vp, vp->v_label); MAC_CHECK_PROBE2(system_check_swapoff, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE3(system_check_sysctl, "struct ucred *", "struct sysctl_oid *", "struct sysctl_req *"); int mac_system_check_sysctl(struct ucred *cred, struct sysctl_oid *oidp, void *arg1, int arg2, struct sysctl_req *req) { int error; /* * XXXMAC: We would very much like to assert the SYSCTL_LOCK here, * but since it's not exported from kern_sysctl.c, we can't. */ - MAC_CHECK_NOSLEEP(system_check_sysctl, cred, oidp, arg1, arg2, req); + MAC_POLICY_CHECK_NOSLEEP(system_check_sysctl, cred, oidp, arg1, arg2, + req); MAC_CHECK_PROBE3(system_check_sysctl, error, cred, oidp, req); return (error); } Index: head/sys/security/mac/mac_sysv_msg.c =================================================================== --- head/sys/security/mac/mac_sysv_msg.c (revision 191730) +++ head/sys/security/mac/mac_sysv_msg.c (revision 191731) @@ -1,276 +1,278 @@ /*- * Copyright (c) 2003-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_sysv_msgmsg_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(sysvmsg_init_label, label); + MAC_POLICY_PERFORM(sysvmsg_init_label, label); return (label); } void mac_sysvmsg_init(struct msg *msgptr) { if (mac_labeled & MPC_OBJECT_SYSVMSG) msgptr->label = mac_sysv_msgmsg_label_alloc(); else msgptr->label = NULL; } static struct label * mac_sysv_msgqueue_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(sysvmsq_init_label, label); + MAC_POLICY_PERFORM(sysvmsq_init_label, label); return (label); } void mac_sysvmsq_init(struct msqid_kernel *msqkptr) { if (mac_labeled & MPC_OBJECT_SYSVMSQ) msqkptr->label = mac_sysv_msgqueue_label_alloc(); else msqkptr->label = NULL; } static void mac_sysv_msgmsg_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(sysvmsg_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(sysvmsg_destroy_label, label); mac_labelzone_free(label); } void mac_sysvmsg_destroy(struct msg *msgptr) { if (msgptr->label != NULL) { mac_sysv_msgmsg_label_free(msgptr->label); msgptr->label = NULL; } } static void mac_sysv_msgqueue_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(sysvmsq_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(sysvmsq_destroy_label, label); mac_labelzone_free(label); } void mac_sysvmsq_destroy(struct msqid_kernel *msqkptr) { if (msqkptr->label != NULL) { mac_sysv_msgqueue_label_free(msqkptr->label); msqkptr->label = NULL; } } void mac_sysvmsg_create(struct ucred *cred, struct msqid_kernel *msqkptr, struct msg *msgptr) { - MAC_PERFORM_NOSLEEP(sysvmsg_create, cred, msqkptr, msqkptr->label, - msgptr, msgptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvmsg_create, cred, msqkptr, + msqkptr->label, msgptr, msgptr->label); } void mac_sysvmsq_create(struct ucred *cred, struct msqid_kernel *msqkptr) { - MAC_PERFORM_NOSLEEP(sysvmsq_create, cred, msqkptr, msqkptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvmsq_create, cred, msqkptr, + msqkptr->label); } void mac_sysvmsg_cleanup(struct msg *msgptr) { - MAC_PERFORM_NOSLEEP(sysvmsg_cleanup, msgptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvmsg_cleanup, msgptr->label); } void mac_sysvmsq_cleanup(struct msqid_kernel *msqkptr) { - MAC_PERFORM_NOSLEEP(sysvmsq_cleanup, msqkptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvmsq_cleanup, msqkptr->label); } MAC_CHECK_PROBE_DEFINE3(sysvmsq_check_msgmsq, "struct ucred *", "struct msg *", "struct msqid_kernel *"); int mac_sysvmsq_check_msgmsq(struct ucred *cred, struct msg *msgptr, struct msqid_kernel *msqkptr) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msgmsq, cred, msgptr, msgptr->label, - msqkptr, msqkptr->label); + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msgmsq, cred, msgptr, + msgptr->label, msqkptr, msqkptr->label); MAC_CHECK_PROBE3(sysvmsq_check_msgmsq, error, cred, msgptr, msqkptr); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msgrcv, "struct ucred *", "struct msg *"); int mac_sysvmsq_check_msgrcv(struct ucred *cred, struct msg *msgptr) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msgrcv, cred, msgptr, msgptr->label); + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msgrcv, cred, msgptr, + msgptr->label); MAC_CHECK_PROBE2(sysvmsq_check_msgrcv, error, cred, msgptr); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msgrmid, "struct ucred *", "struct msg *"); int mac_sysvmsq_check_msgrmid(struct ucred *cred, struct msg *msgptr) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msgrmid, cred, msgptr, + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msgrmid, cred, msgptr, msgptr->label); MAC_CHECK_PROBE2(sysvmsq_check_msgrmid, error, cred, msgptr); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msqget, "struct ucred *", "struct msqid_kernel *"); int mac_sysvmsq_check_msqget(struct ucred *cred, struct msqid_kernel *msqkptr) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msqget, cred, msqkptr, + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqget, cred, msqkptr, msqkptr->label); MAC_CHECK_PROBE2(sysvmsq_check_msqget, error, cred, msqkptr); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msqsnd, "struct ucred *", "struct msqid_kernel *"); int mac_sysvmsq_check_msqsnd(struct ucred *cred, struct msqid_kernel *msqkptr) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msqsnd, cred, msqkptr, + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqsnd, cred, msqkptr, msqkptr->label); MAC_CHECK_PROBE2(sysvmsq_check_msqsnd, error, cred, msqkptr); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvmsq_check_msqrcv, "struct ucred *", "struct msqid_kernel *"); int mac_sysvmsq_check_msqrcv(struct ucred *cred, struct msqid_kernel *msqkptr) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msqrcv, cred, msqkptr, + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqrcv, cred, msqkptr, msqkptr->label); MAC_CHECK_PROBE2(sysvmsq_check_msqrcv, error, cred, msqkptr); return (error); } MAC_CHECK_PROBE_DEFINE3(sysvmsq_check_msqctl, "struct ucred *", "struct msqid_kernel *", "int"); int mac_sysvmsq_check_msqctl(struct ucred *cred, struct msqid_kernel *msqkptr, int cmd) { int error; - MAC_CHECK_NOSLEEP(sysvmsq_check_msqctl, cred, msqkptr, + MAC_POLICY_CHECK_NOSLEEP(sysvmsq_check_msqctl, cred, msqkptr, msqkptr->label, cmd); MAC_CHECK_PROBE3(sysvmsq_check_msqctl, error, cred, msqkptr, cmd); return (error); } Index: head/sys/security/mac/mac_sysv_sem.c =================================================================== --- head/sys/security/mac/mac_sysv_sem.c (revision 191730) +++ head/sys/security/mac/mac_sysv_sem.c (revision 191731) @@ -1,162 +1,163 @@ /*- * Copyright (c) 2003-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_sysv_sem_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(sysvsem_init_label, label); + MAC_POLICY_PERFORM(sysvsem_init_label, label); return (label); } void mac_sysvsem_init(struct semid_kernel *semakptr) { if (mac_labeled & MPC_OBJECT_SYSVSEM) semakptr->label = mac_sysv_sem_label_alloc(); else semakptr->label = NULL; } static void mac_sysv_sem_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(sysvsem_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(sysvsem_destroy_label, label); mac_labelzone_free(label); } void mac_sysvsem_destroy(struct semid_kernel *semakptr) { if (semakptr->label != NULL) { mac_sysv_sem_label_free(semakptr->label); semakptr->label = NULL; } } void mac_sysvsem_create(struct ucred *cred, struct semid_kernel *semakptr) { - MAC_PERFORM_NOSLEEP(sysvsem_create, cred, semakptr, semakptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvsem_create, cred, semakptr, + semakptr->label); } void mac_sysvsem_cleanup(struct semid_kernel *semakptr) { - MAC_PERFORM_NOSLEEP(sysvsem_cleanup, semakptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvsem_cleanup, semakptr->label); } MAC_CHECK_PROBE_DEFINE3(sysvsem_check_semctl, "struct ucred *", "struct semid_kernel *", "int"); int mac_sysvsem_check_semctl(struct ucred *cred, struct semid_kernel *semakptr, int cmd) { int error; - MAC_CHECK_NOSLEEP(sysvsem_check_semctl, cred, semakptr, + MAC_POLICY_CHECK_NOSLEEP(sysvsem_check_semctl, cred, semakptr, semakptr->label, cmd); MAC_CHECK_PROBE3(sysvsem_check_semctl, error, cred, semakptr, cmd); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvsem_check_semget, "struct ucred *", "struct semid_kernel *"); int mac_sysvsem_check_semget(struct ucred *cred, struct semid_kernel *semakptr) { int error; - MAC_CHECK_NOSLEEP(sysvsem_check_semget, cred, semakptr, + MAC_POLICY_CHECK_NOSLEEP(sysvsem_check_semget, cred, semakptr, semakptr->label); return (error); } MAC_CHECK_PROBE_DEFINE3(sysvsem_check_semop, "struct ucred *", "struct semid_kernel *", "size_t"); int mac_sysvsem_check_semop(struct ucred *cred, struct semid_kernel *semakptr, size_t accesstype) { int error; - MAC_CHECK_NOSLEEP(sysvsem_check_semop, cred, semakptr, + MAC_POLICY_CHECK_NOSLEEP(sysvsem_check_semop, cred, semakptr, semakptr->label, accesstype); MAC_CHECK_PROBE3(sysvsem_check_semop, error, cred, semakptr, accesstype); return (error); } Index: head/sys/security/mac/mac_sysv_shm.c =================================================================== --- head/sys/security/mac/mac_sysv_shm.c (revision 191730) +++ head/sys/security/mac/mac_sysv_shm.c (revision 191731) @@ -1,181 +1,181 @@ /*- * Copyright (c) 2003-2004 Networks Associates Technology, Inc. * Copyright (c) 2006 SPARTA, Inc. * Copyright (c) 2009 Robert N. M. Watson * All rights reserved. * * This software was developed for the FreeBSD Project in part by Network * Associates Laboratories, the Security Research Division of Network * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), * as part of the DARPA CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct label * mac_sysv_shm_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(sysvshm_init_label, label); + MAC_POLICY_PERFORM(sysvshm_init_label, label); return (label); } void mac_sysvshm_init(struct shmid_kernel *shmsegptr) { if (mac_labeled & MPC_OBJECT_SYSVSHM) shmsegptr->label = mac_sysv_shm_label_alloc(); else shmsegptr->label = NULL; } static void mac_sysv_shm_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(sysvshm_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(sysvshm_destroy_label, label); mac_labelzone_free(label); } void mac_sysvshm_destroy(struct shmid_kernel *shmsegptr) { if (shmsegptr->label != NULL) { mac_sysv_shm_label_free(shmsegptr->label); shmsegptr->label = NULL; } } void mac_sysvshm_create(struct ucred *cred, struct shmid_kernel *shmsegptr) { - MAC_PERFORM_NOSLEEP(sysvshm_create, cred, shmsegptr, + MAC_POLICY_PERFORM_NOSLEEP(sysvshm_create, cred, shmsegptr, shmsegptr->label); } void mac_sysvshm_cleanup(struct shmid_kernel *shmsegptr) { - MAC_PERFORM_NOSLEEP(sysvshm_cleanup, shmsegptr->label); + MAC_POLICY_PERFORM_NOSLEEP(sysvshm_cleanup, shmsegptr->label); } MAC_CHECK_PROBE_DEFINE3(sysvshm_check_shmat, "struct ucred *", "struct shmid_kernel *", "int"); int mac_sysvshm_check_shmat(struct ucred *cred, struct shmid_kernel *shmsegptr, int shmflg) { int error; - MAC_CHECK_NOSLEEP(sysvshm_check_shmat, cred, shmsegptr, + MAC_POLICY_CHECK_NOSLEEP(sysvshm_check_shmat, cred, shmsegptr, shmsegptr->label, shmflg); MAC_CHECK_PROBE3(sysvshm_check_shmat, error, cred, shmsegptr, shmflg); return (error); } MAC_CHECK_PROBE_DEFINE3(sysvshm_check_shmctl, "struct ucred *", "struct shmid_kernel *", "int"); int mac_sysvshm_check_shmctl(struct ucred *cred, struct shmid_kernel *shmsegptr, int cmd) { int error; - MAC_CHECK_NOSLEEP(sysvshm_check_shmctl, cred, shmsegptr, + MAC_POLICY_CHECK_NOSLEEP(sysvshm_check_shmctl, cred, shmsegptr, shmsegptr->label, cmd); MAC_CHECK_PROBE3(sysvshm_check_shmctl, error, cred, shmsegptr, cmd); return (error); } MAC_CHECK_PROBE_DEFINE2(sysvshm_check_shmdt, "struct ucred *", "struct shmid *"); int mac_sysvshm_check_shmdt(struct ucred *cred, struct shmid_kernel *shmsegptr) { int error; - MAC_CHECK_NOSLEEP(sysvshm_check_shmdt, cred, shmsegptr, + MAC_POLICY_CHECK_NOSLEEP(sysvshm_check_shmdt, cred, shmsegptr, shmsegptr->label); MAC_CHECK_PROBE2(sysvshm_check_shmdt, error, cred, shmsegptr); return (error); } MAC_CHECK_PROBE_DEFINE3(sysvshm_check_shmget, "struct ucred *", "struct shmid_kernel *", "int"); int mac_sysvshm_check_shmget(struct ucred *cred, struct shmid_kernel *shmsegptr, int shmflg) { int error; - MAC_CHECK_NOSLEEP(sysvshm_check_shmget, cred, shmsegptr, + MAC_POLICY_CHECK_NOSLEEP(sysvshm_check_shmget, cred, shmsegptr, shmsegptr->label, shmflg); MAC_CHECK_PROBE3(sysvshm_check_shmget, error, cred, shmsegptr, shmflg); return (error); } Index: head/sys/security/mac/mac_vfs.c =================================================================== --- head/sys/security/mac/mac_vfs.c (revision 191730) +++ head/sys/security/mac/mac_vfs.c (revision 191731) @@ -1,1067 +1,1069 @@ /*- * Copyright (c) 1999-2002, 2009 Robert N. M. Watson * Copyright (c) 2001 Ilmar S. Habibulin * Copyright (c) 2001-2005 McAfee, Inc. * Copyright (c) 2005-2006 SPARTA, Inc. * Copyright (c) 2008 Apple Inc. * All rights reserved. * * This software was developed by Robert Watson and Ilmar Habibulin for the * TrustedBSD Project. * * This software was developed for the FreeBSD Project in part by McAfee * Research, the Security Research Division of McAfee, Inc. under * DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA * CHATS research program. * * This software was enhanced by SPARTA ISSO under SPAWAR contract * N66001-04-C-6019 ("SEFOS"). * * This software was developed at the University of Cambridge Computer * Laboratory with support from a grant from Google, Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "opt_kdtrace.h" #include "opt_mac.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* * Warn about EA transactions only the first time they happen. No locking on * this variable. */ static int ea_warn_once = 0; static int mac_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp, struct label *intlabel); static struct label * mac_devfs_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(devfs_init_label, label); + MAC_POLICY_PERFORM(devfs_init_label, label); return (label); } void mac_devfs_init(struct devfs_dirent *de) { if (mac_labeled & MPC_OBJECT_DEVFS) de->de_label = mac_devfs_label_alloc(); else de->de_label = NULL; } static struct label * mac_mount_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(mount_init_label, label); + MAC_POLICY_PERFORM(mount_init_label, label); return (label); } void mac_mount_init(struct mount *mp) { if (mac_labeled & MPC_OBJECT_MOUNT) mp->mnt_label = mac_mount_label_alloc(); else mp->mnt_label = NULL; } struct label * mac_vnode_label_alloc(void) { struct label *label; label = mac_labelzone_alloc(M_WAITOK); - MAC_PERFORM(vnode_init_label, label); + MAC_POLICY_PERFORM(vnode_init_label, label); return (label); } void mac_vnode_init(struct vnode *vp) { if (mac_labeled & MPC_OBJECT_VNODE) vp->v_label = mac_vnode_label_alloc(); else vp->v_label = NULL; } static void mac_devfs_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(devfs_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(devfs_destroy_label, label); mac_labelzone_free(label); } void mac_devfs_destroy(struct devfs_dirent *de) { if (de->de_label != NULL) { mac_devfs_label_free(de->de_label); de->de_label = NULL; } } static void mac_mount_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(mount_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(mount_destroy_label, label); mac_labelzone_free(label); } void mac_mount_destroy(struct mount *mp) { if (mp->mnt_label != NULL) { mac_mount_label_free(mp->mnt_label); mp->mnt_label = NULL; } } void mac_vnode_label_free(struct label *label) { - MAC_PERFORM_NOSLEEP(vnode_destroy_label, label); + MAC_POLICY_PERFORM_NOSLEEP(vnode_destroy_label, label); mac_labelzone_free(label); } void mac_vnode_destroy(struct vnode *vp) { if (vp->v_label != NULL) { mac_vnode_label_free(vp->v_label); vp->v_label = NULL; } } void mac_vnode_copy_label(struct label *src, struct label *dest) { - MAC_PERFORM_NOSLEEP(vnode_copy_label, src, dest); + MAC_POLICY_PERFORM_NOSLEEP(vnode_copy_label, src, dest); } int mac_vnode_externalize_label(struct label *label, char *elements, char *outbuf, size_t outbuflen) { int error; - MAC_EXTERNALIZE(vnode, label, elements, outbuf, outbuflen); + MAC_POLICY_EXTERNALIZE(vnode, label, elements, outbuf, outbuflen); return (error); } int mac_vnode_internalize_label(struct label *label, char *string) { int error; - MAC_INTERNALIZE(vnode, label, string); + MAC_POLICY_INTERNALIZE(vnode, label, string); return (error); } void mac_devfs_update(struct mount *mp, struct devfs_dirent *de, struct vnode *vp) { - MAC_PERFORM_NOSLEEP(devfs_update, mp, de, de->de_label, vp, + MAC_POLICY_PERFORM_NOSLEEP(devfs_update, mp, de, de->de_label, vp, vp->v_label); } void mac_devfs_vnode_associate(struct mount *mp, struct devfs_dirent *de, struct vnode *vp) { - MAC_PERFORM_NOSLEEP(devfs_vnode_associate, mp, mp->mnt_label, de, - de->de_label, vp, vp->v_label); + MAC_POLICY_PERFORM_NOSLEEP(devfs_vnode_associate, mp, mp->mnt_label, + de, de->de_label, vp, vp->v_label); } int mac_vnode_associate_extattr(struct mount *mp, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_associate_extattr"); - MAC_CHECK(vnode_associate_extattr, mp, mp->mnt_label, vp, + MAC_POLICY_CHECK(vnode_associate_extattr, mp, mp->mnt_label, vp, vp->v_label); return (error); } void mac_vnode_associate_singlelabel(struct mount *mp, struct vnode *vp) { - MAC_PERFORM_NOSLEEP(vnode_associate_singlelabel, mp, mp->mnt_label, - vp, vp->v_label); + MAC_POLICY_PERFORM_NOSLEEP(vnode_associate_singlelabel, mp, + mp->mnt_label, vp, vp->v_label); } /* * Functions implementing extended-attribute backed labels for file systems * that support it. * * Where possible, we use EA transactions to make writes to multiple * attributes across difference policies mutually atomic. We allow work to * continue on file systems not supporting EA transactions, but generate a * printf warning. */ int mac_vnode_create_extattr(struct ucred *cred, struct mount *mp, struct vnode *dvp, struct vnode *vp, struct componentname *cnp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_create_extattr"); ASSERT_VOP_LOCKED(vp, "mac_vnode_create_extattr"); error = VOP_OPENEXTATTR(vp, cred, curthread); if (error == EOPNOTSUPP) { if (ea_warn_once == 0) { printf("Warning: transactions not supported " "in EA write.\n"); ea_warn_once = 1; } } else if (error) return (error); - MAC_CHECK(vnode_create_extattr, cred, mp, mp->mnt_label, dvp, + MAC_POLICY_CHECK(vnode_create_extattr, cred, mp, mp->mnt_label, dvp, dvp->v_label, vp, vp->v_label, cnp); if (error) { VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread); return (error); } error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread); if (error == EOPNOTSUPP) error = 0; return (error); } static int mac_vnode_setlabel_extattr(struct ucred *cred, struct vnode *vp, struct label *intlabel) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_setlabel_extattr"); error = VOP_OPENEXTATTR(vp, cred, curthread); if (error == EOPNOTSUPP) { if (ea_warn_once == 0) { printf("Warning: transactions not supported " "in EA write.\n"); ea_warn_once = 1; } } else if (error) return (error); - MAC_CHECK(vnode_setlabel_extattr, cred, vp, vp->v_label, intlabel); + MAC_POLICY_CHECK(vnode_setlabel_extattr, cred, vp, vp->v_label, + intlabel); if (error) { VOP_CLOSEEXTATTR(vp, 0, NOCRED, curthread); return (error); } error = VOP_CLOSEEXTATTR(vp, 1, NOCRED, curthread); if (error == EOPNOTSUPP) error = 0; return (error); } void mac_vnode_execve_transition(struct ucred *old, struct ucred *new, struct vnode *vp, struct label *interpvplabel, struct image_params *imgp) { ASSERT_VOP_LOCKED(vp, "mac_vnode_execve_transition"); - MAC_PERFORM(vnode_execve_transition, old, new, vp, vp->v_label, - interpvplabel, imgp, imgp->execlabel); + MAC_POLICY_PERFORM(vnode_execve_transition, old, new, vp, + vp->v_label, interpvplabel, imgp, imgp->execlabel); } int mac_vnode_execve_will_transition(struct ucred *old, struct vnode *vp, struct label *interpvplabel, struct image_params *imgp) { int result; ASSERT_VOP_LOCKED(vp, "mac_vnode_execve_will_transition"); result = 0; /* No sleeping since the process lock will be held by the caller. */ - MAC_BOOLEAN_NOSLEEP(vnode_execve_will_transition, ||, old, vp, + MAC_POLICY_BOOLEAN_NOSLEEP(vnode_execve_will_transition, ||, old, vp, vp->v_label, interpvplabel, imgp, imgp->execlabel); return (result); } MAC_CHECK_PROBE_DEFINE3(vnode_check_access, "struct ucred *", "struct vnode *", "accmode_t"); int mac_vnode_check_access(struct ucred *cred, struct vnode *vp, accmode_t accmode) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_access"); - MAC_CHECK(vnode_check_access, cred, vp, vp->v_label, accmode); + MAC_POLICY_CHECK(vnode_check_access, cred, vp, vp->v_label, accmode); MAC_CHECK_PROBE3(vnode_check_access, error, cred, vp, accmode); return (error); } MAC_CHECK_PROBE_DEFINE2(vnode_check_chdir, "struct ucred *", "struct vnode *"); int mac_vnode_check_chdir(struct ucred *cred, struct vnode *dvp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_chdir"); - MAC_CHECK(vnode_check_chdir, cred, dvp, dvp->v_label); + MAC_POLICY_CHECK(vnode_check_chdir, cred, dvp, dvp->v_label); MAC_CHECK_PROBE2(vnode_check_chdir, error, cred, dvp); return (error); } MAC_CHECK_PROBE_DEFINE2(vnode_check_chroot, "struct ucred *", "struct vnode *"); int mac_vnode_check_chroot(struct ucred *cred, struct vnode *dvp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_chroot"); - MAC_CHECK(vnode_check_chroot, cred, dvp, dvp->v_label); + MAC_POLICY_CHECK(vnode_check_chroot, cred, dvp, dvp->v_label); MAC_CHECK_PROBE2(vnode_check_chroot, error, cred, dvp); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_create, "struct ucred *", "struct vnode *", "struct componentname *", "struct vattr *"); int mac_vnode_check_create(struct ucred *cred, struct vnode *dvp, struct componentname *cnp, struct vattr *vap) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_create"); - MAC_CHECK(vnode_check_create, cred, dvp, dvp->v_label, cnp, vap); + MAC_POLICY_CHECK(vnode_check_create, cred, dvp, dvp->v_label, cnp, + vap); MAC_CHECK_PROBE4(vnode_check_create, error, cred, dvp, cnp, vap); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_deleteacl, "struct ucred *", "struct vnode *", "acl_type_t"); int mac_vnode_check_deleteacl(struct ucred *cred, struct vnode *vp, acl_type_t type) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_deleteacl"); - MAC_CHECK(vnode_check_deleteacl, cred, vp, vp->v_label, type); + MAC_POLICY_CHECK(vnode_check_deleteacl, cred, vp, vp->v_label, type); MAC_CHECK_PROBE3(vnode_check_deleteacl, error, cred, vp, type); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_deleteextattr, "struct ucred *", "struct vnode *", "int", "const char *"); int mac_vnode_check_deleteextattr(struct ucred *cred, struct vnode *vp, int attrnamespace, const char *name) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_deleteextattr"); - MAC_CHECK(vnode_check_deleteextattr, cred, vp, vp->v_label, + MAC_POLICY_CHECK(vnode_check_deleteextattr, cred, vp, vp->v_label, attrnamespace, name); MAC_CHECK_PROBE4(vnode_check_deleteextattr, error, cred, vp, attrnamespace, name); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_exec, "struct ucred *", "struct vnode *", "struct image_params *"); int mac_vnode_check_exec(struct ucred *cred, struct vnode *vp, struct image_params *imgp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_exec"); - MAC_CHECK(vnode_check_exec, cred, vp, vp->v_label, imgp, + MAC_POLICY_CHECK(vnode_check_exec, cred, vp, vp->v_label, imgp, imgp->execlabel); MAC_CHECK_PROBE3(vnode_check_exec, error, cred, vp, imgp); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_getacl, "struct ucred *", "struct vnode *", "acl_type_t"); int mac_vnode_check_getacl(struct ucred *cred, struct vnode *vp, acl_type_t type) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_getacl"); - MAC_CHECK(vnode_check_getacl, cred, vp, vp->v_label, type); + MAC_POLICY_CHECK(vnode_check_getacl, cred, vp, vp->v_label, type); MAC_CHECK_PROBE3(vnode_check_getacl, error, cred, vp, type); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_getextattr, "struct ucred *", "struct vnode *", "int", "const char *"); int mac_vnode_check_getextattr(struct ucred *cred, struct vnode *vp, int attrnamespace, const char *name) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_getextattr"); - MAC_CHECK(vnode_check_getextattr, cred, vp, vp->v_label, + MAC_POLICY_CHECK(vnode_check_getextattr, cred, vp, vp->v_label, attrnamespace, name); MAC_CHECK_PROBE4(vnode_check_getextattr, error, cred, vp, attrnamespace, name); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_link, "struct ucred *", "struct vnode *", "struct vnode *", "struct componentname *"); int mac_vnode_check_link(struct ucred *cred, struct vnode *dvp, struct vnode *vp, struct componentname *cnp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_link"); ASSERT_VOP_LOCKED(vp, "mac_vnode_check_link"); - MAC_CHECK(vnode_check_link, cred, dvp, dvp->v_label, vp, + MAC_POLICY_CHECK(vnode_check_link, cred, dvp, dvp->v_label, vp, vp->v_label, cnp); MAC_CHECK_PROBE4(vnode_check_link, error, cred, dvp, vp, cnp); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_listextattr, "struct ucred *", "struct vnode *", "int"); int mac_vnode_check_listextattr(struct ucred *cred, struct vnode *vp, int attrnamespace) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_listextattr"); - MAC_CHECK(vnode_check_listextattr, cred, vp, vp->v_label, + MAC_POLICY_CHECK(vnode_check_listextattr, cred, vp, vp->v_label, attrnamespace); MAC_CHECK_PROBE3(vnode_check_listextattr, error, cred, vp, attrnamespace); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_lookup, "struct ucred *", "struct vnode *", "struct componentname *"); int mac_vnode_check_lookup(struct ucred *cred, struct vnode *dvp, struct componentname *cnp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_lookup"); - MAC_CHECK(vnode_check_lookup, cred, dvp, dvp->v_label, cnp); + MAC_POLICY_CHECK(vnode_check_lookup, cred, dvp, dvp->v_label, cnp); MAC_CHECK_PROBE3(vnode_check_lookup, error, cred, dvp, cnp); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_mmap, "struct ucred *", "struct vnode *", "int", "int"); int mac_vnode_check_mmap(struct ucred *cred, struct vnode *vp, int prot, int flags) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mmap"); - MAC_CHECK(vnode_check_mmap, cred, vp, vp->v_label, prot, flags); + MAC_POLICY_CHECK(vnode_check_mmap, cred, vp, vp->v_label, prot, flags); MAC_CHECK_PROBE4(vnode_check_mmap, error, cred, vp, prot, flags); return (error); } void mac_vnode_check_mmap_downgrade(struct ucred *cred, struct vnode *vp, int *prot) { int result = *prot; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mmap_downgrade"); - MAC_PERFORM(vnode_check_mmap_downgrade, cred, vp, vp->v_label, + MAC_POLICY_PERFORM(vnode_check_mmap_downgrade, cred, vp, vp->v_label, &result); *prot = result; } MAC_CHECK_PROBE_DEFINE3(vnode_check_mprotect, "struct ucred *", "struct vnode *", "int"); int mac_vnode_check_mprotect(struct ucred *cred, struct vnode *vp, int prot) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_mprotect"); - MAC_CHECK(vnode_check_mprotect, cred, vp, vp->v_label, prot); + MAC_POLICY_CHECK(vnode_check_mprotect, cred, vp, vp->v_label, prot); MAC_CHECK_PROBE3(vnode_check_mprotect, error, cred, vp, prot); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_open, "struct ucred *", "struct vnode *", "accmode_t"); int mac_vnode_check_open(struct ucred *cred, struct vnode *vp, accmode_t accmode) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_open"); - MAC_CHECK(vnode_check_open, cred, vp, vp->v_label, accmode); + MAC_POLICY_CHECK(vnode_check_open, cred, vp, vp->v_label, accmode); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_poll, "struct ucred *", "struct ucred *", "struct vnode *"); int mac_vnode_check_poll(struct ucred *active_cred, struct ucred *file_cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_poll"); - MAC_CHECK(vnode_check_poll, active_cred, file_cred, vp, + MAC_POLICY_CHECK(vnode_check_poll, active_cred, file_cred, vp, vp->v_label); MAC_CHECK_PROBE3(vnode_check_poll, error, active_cred, file_cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_read, "struct ucred *", "struct ucred *", "struct vnode *"); int mac_vnode_check_read(struct ucred *active_cred, struct ucred *file_cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_read"); - MAC_CHECK(vnode_check_read, active_cred, file_cred, vp, + MAC_POLICY_CHECK(vnode_check_read, active_cred, file_cred, vp, vp->v_label); MAC_CHECK_PROBE3(vnode_check_read, error, active_cred, file_cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE2(vnode_check_readdir, "struct ucred *", "struct vnode *"); int mac_vnode_check_readdir(struct ucred *cred, struct vnode *dvp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_readdir"); - MAC_CHECK(vnode_check_readdir, cred, dvp, dvp->v_label); + MAC_POLICY_CHECK(vnode_check_readdir, cred, dvp, dvp->v_label); MAC_CHECK_PROBE2(vnode_check_readdir, error, cred, dvp); return (error); } MAC_CHECK_PROBE_DEFINE2(vnode_check_readlink, "struct ucred *", "struct vnode *"); int mac_vnode_check_readlink(struct ucred *cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_readlink"); - MAC_CHECK(vnode_check_readlink, cred, vp, vp->v_label); + MAC_POLICY_CHECK(vnode_check_readlink, cred, vp, vp->v_label); MAC_CHECK_PROBE2(vnode_check_readlink, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_relabel, "struct ucred *", "struct vnode *", "struct label *"); static int mac_vnode_check_relabel(struct ucred *cred, struct vnode *vp, struct label *newlabel) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_relabel"); - MAC_CHECK(vnode_check_relabel, cred, vp, vp->v_label, newlabel); + MAC_POLICY_CHECK(vnode_check_relabel, cred, vp, vp->v_label, newlabel); MAC_CHECK_PROBE3(vnode_check_relabel, error, cred, vp, newlabel); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_from, "struct ucred *", "struct vnode *", "struct vnode *", "struct componentname *"); int mac_vnode_check_rename_from(struct ucred *cred, struct vnode *dvp, struct vnode *vp, struct componentname *cnp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_from"); ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_from"); - MAC_CHECK(vnode_check_rename_from, cred, dvp, dvp->v_label, vp, + MAC_POLICY_CHECK(vnode_check_rename_from, cred, dvp, dvp->v_label, vp, vp->v_label, cnp); MAC_CHECK_PROBE4(vnode_check_rename_from, error, cred, dvp, vp, cnp); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_rename_to, "struct ucred *", "struct vnode *", "struct vnode *", "struct componentname *"); int mac_vnode_check_rename_to(struct ucred *cred, struct vnode *dvp, struct vnode *vp, int samedir, struct componentname *cnp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_rename_to"); ASSERT_VOP_LOCKED(vp, "mac_vnode_check_rename_to"); - MAC_CHECK(vnode_check_rename_to, cred, dvp, dvp->v_label, vp, + MAC_POLICY_CHECK(vnode_check_rename_to, cred, dvp, dvp->v_label, vp, vp != NULL ? vp->v_label : NULL, samedir, cnp); MAC_CHECK_PROBE4(vnode_check_rename_to, error, cred, dvp, vp, cnp); return (error); } MAC_CHECK_PROBE_DEFINE2(vnode_check_revoke, "struct ucred *", "struct vnode *"); int mac_vnode_check_revoke(struct ucred *cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_revoke"); - MAC_CHECK(vnode_check_revoke, cred, vp, vp->v_label); + MAC_POLICY_CHECK(vnode_check_revoke, cred, vp, vp->v_label); MAC_CHECK_PROBE2(vnode_check_revoke, error, cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_setacl, "struct ucred *", "struct vnode *", "acl_tpe_t", "struct acl *"); int mac_vnode_check_setacl(struct ucred *cred, struct vnode *vp, acl_type_t type, struct acl *acl) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setacl"); - MAC_CHECK(vnode_check_setacl, cred, vp, vp->v_label, type, acl); + MAC_POLICY_CHECK(vnode_check_setacl, cred, vp, vp->v_label, type, acl); MAC_CHECK_PROBE4(vnode_check_setacl, error, cred, vp, type, acl); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_setextattr, "struct ucred *", "struct vnode *", "int", "const char *"); int mac_vnode_check_setextattr(struct ucred *cred, struct vnode *vp, int attrnamespace, const char *name) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setextattr"); - MAC_CHECK(vnode_check_setextattr, cred, vp, vp->v_label, + MAC_POLICY_CHECK(vnode_check_setextattr, cred, vp, vp->v_label, attrnamespace, name); MAC_CHECK_PROBE4(vnode_check_setextattr, error, cred, vp, attrnamespace, name); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_setflags, "struct ucred *", "struct vnode *", "u_long"); int mac_vnode_check_setflags(struct ucred *cred, struct vnode *vp, u_long flags) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setflags"); - MAC_CHECK(vnode_check_setflags, cred, vp, vp->v_label, flags); + MAC_POLICY_CHECK(vnode_check_setflags, cred, vp, vp->v_label, flags); MAC_CHECK_PROBE3(vnode_check_setflags, error, cred, vp, flags); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_setmode, "struct ucred *", "struct vnode *", "mode_t"); int mac_vnode_check_setmode(struct ucred *cred, struct vnode *vp, mode_t mode) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setmode"); - MAC_CHECK(vnode_check_setmode, cred, vp, vp->v_label, mode); + MAC_POLICY_CHECK(vnode_check_setmode, cred, vp, vp->v_label, mode); MAC_CHECK_PROBE3(vnode_check_setmode, error, cred, vp, mode); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_setowner, "struct ucred *", "struct vnode *", "uid_t", "gid_t"); int mac_vnode_check_setowner(struct ucred *cred, struct vnode *vp, uid_t uid, gid_t gid) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setowner"); - MAC_CHECK(vnode_check_setowner, cred, vp, vp->v_label, uid, gid); + MAC_POLICY_CHECK(vnode_check_setowner, cred, vp, vp->v_label, uid, gid); MAC_CHECK_PROBE4(vnode_check_setowner, error, cred, vp, uid, gid); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_setutimes, "struct ucred *", "struct vnode *", "struct timespec *", "struct timespec *"); int mac_vnode_check_setutimes(struct ucred *cred, struct vnode *vp, struct timespec atime, struct timespec mtime) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_setutimes"); - MAC_CHECK(vnode_check_setutimes, cred, vp, vp->v_label, atime, + MAC_POLICY_CHECK(vnode_check_setutimes, cred, vp, vp->v_label, atime, mtime); MAC_CHECK_PROBE4(vnode_check_setutimes, error, cred, vp, &atime, &mtime); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_stat, "struct ucred *", "struct ucred *", "struct vnode *"); int mac_vnode_check_stat(struct ucred *active_cred, struct ucred *file_cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_stat"); - MAC_CHECK(vnode_check_stat, active_cred, file_cred, vp, + MAC_POLICY_CHECK(vnode_check_stat, active_cred, file_cred, vp, vp->v_label); MAC_CHECK_PROBE3(vnode_check_stat, error, active_cred, file_cred, vp); return (error); } MAC_CHECK_PROBE_DEFINE4(vnode_check_unlink, "struct ucred *", "struct vnode *", "struct vnode *", "struct componentname *"); int mac_vnode_check_unlink(struct ucred *cred, struct vnode *dvp, struct vnode *vp, struct componentname *cnp) { int error; ASSERT_VOP_LOCKED(dvp, "mac_vnode_check_unlink"); ASSERT_VOP_LOCKED(vp, "mac_vnode_check_unlink"); - MAC_CHECK(vnode_check_unlink, cred, dvp, dvp->v_label, vp, + MAC_POLICY_CHECK(vnode_check_unlink, cred, dvp, dvp->v_label, vp, vp->v_label, cnp); MAC_CHECK_PROBE4(vnode_check_unlink, error, cred, dvp, vp, cnp); return (error); } MAC_CHECK_PROBE_DEFINE3(vnode_check_write, "struct ucred *", "struct ucred *", "struct vnode *"); int mac_vnode_check_write(struct ucred *active_cred, struct ucred *file_cred, struct vnode *vp) { int error; ASSERT_VOP_LOCKED(vp, "mac_vnode_check_write"); - MAC_CHECK(vnode_check_write, active_cred, file_cred, vp, + MAC_POLICY_CHECK(vnode_check_write, active_cred, file_cred, vp, vp->v_label); MAC_CHECK_PROBE3(vnode_check_write, error, active_cred, file_cred, vp); return (error); } void mac_vnode_relabel(struct ucred *cred, struct vnode *vp, struct label *newlabel) { - MAC_PERFORM(vnode_relabel, cred, vp, vp->v_label, newlabel); + MAC_POLICY_PERFORM(vnode_relabel, cred, vp, vp->v_label, newlabel); } void mac_mount_create(struct ucred *cred, struct mount *mp) { - MAC_PERFORM(mount_create, cred, mp, mp->mnt_label); + MAC_POLICY_PERFORM(mount_create, cred, mp, mp->mnt_label); } MAC_CHECK_PROBE_DEFINE2(mount_check_stat, "struct ucred *", "struct mount *"); int mac_mount_check_stat(struct ucred *cred, struct mount *mount) { int error; - MAC_CHECK_NOSLEEP(mount_check_stat, cred, mount, mount->mnt_label); + MAC_POLICY_CHECK_NOSLEEP(mount_check_stat, cred, mount, mount->mnt_label); MAC_CHECK_PROBE2(mount_check_stat, error, cred, mount); return (error); } void mac_devfs_create_device(struct ucred *cred, struct mount *mp, struct cdev *dev, struct devfs_dirent *de) { - MAC_PERFORM_NOSLEEP(devfs_create_device, cred, mp, dev, de, + MAC_POLICY_PERFORM_NOSLEEP(devfs_create_device, cred, mp, dev, de, de->de_label); } void mac_devfs_create_symlink(struct ucred *cred, struct mount *mp, struct devfs_dirent *dd, struct devfs_dirent *de) { - MAC_PERFORM_NOSLEEP(devfs_create_symlink, cred, mp, dd, + MAC_POLICY_PERFORM_NOSLEEP(devfs_create_symlink, cred, mp, dd, dd->de_label, de, de->de_label); } void mac_devfs_create_directory(struct mount *mp, char *dirname, int dirnamelen, struct devfs_dirent *de) { - MAC_PERFORM_NOSLEEP(devfs_create_directory, mp, dirname, dirnamelen, - de, de->de_label); + MAC_POLICY_PERFORM_NOSLEEP(devfs_create_directory, mp, dirname, + dirnamelen, de, de->de_label); } /* * Implementation of VOP_SETLABEL() that relies on extended attributes to * store label data. Can be referenced by filesystems supporting extended * attributes. */ int vop_stdsetlabel_ea(struct vop_setlabel_args *ap) { struct vnode *vp = ap->a_vp; struct label *intlabel = ap->a_label; int error; ASSERT_VOP_LOCKED(vp, "vop_stdsetlabel_ea"); if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0) return (EOPNOTSUPP); error = mac_vnode_setlabel_extattr(ap->a_cred, vp, intlabel); if (error) return (error); mac_vnode_relabel(ap->a_cred, vp, intlabel); return (0); } int vn_setlabel(struct vnode *vp, struct label *intlabel, struct ucred *cred) { int error; if (vp->v_mount == NULL) { /* printf("vn_setlabel: null v_mount\n"); */ if (vp->v_type != VNON) printf("vn_setlabel: null v_mount with non-VNON\n"); return (EBADF); } if ((vp->v_mount->mnt_flag & MNT_MULTILABEL) == 0) return (EOPNOTSUPP); /* * Multi-phase commit. First check the policies to confirm the * change is OK. Then commit via the filesystem. Finally, update * the actual vnode label. * * Question: maybe the filesystem should update the vnode at the end * as part of VOP_SETLABEL()? */ error = mac_vnode_check_relabel(cred, vp, intlabel); if (error) return (error); /* * VADMIN provides the opportunity for the filesystem to make * decisions about who is and is not able to modify labels and * protections on files. This might not be right. We can't assume * VOP_SETLABEL() will do it, because we might implement that as part * of vop_stdsetlabel_ea(). */ error = VOP_ACCESS(vp, VADMIN, cred, curthread); if (error) return (error); error = VOP_SETLABEL(vp, intlabel, cred, curthread); if (error) return (error); return (0); }