xref: /freebsd/sys/security/mac_bsdextended/ugidfw_system.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
14074f67fSRobert Watson /*-
24074f67fSRobert Watson  * Copyright (c) 1999-2002, 2007 Robert N. M. Watson
34074f67fSRobert Watson  * Copyright (c) 2001-2005 Networks Associates Technology, Inc.
44074f67fSRobert Watson  * Copyright (c) 2005 Tom Rhodes
54074f67fSRobert Watson  * Copyright (c) 2006 SPARTA, Inc.
64074f67fSRobert Watson  * All rights reserved.
74074f67fSRobert Watson  *
84074f67fSRobert Watson  * This software was developed by Robert Watson for the TrustedBSD Project.
94074f67fSRobert Watson  * It was later enhanced by Tom Rhodes for the TrustedBSD Project.
104074f67fSRobert Watson  *
114074f67fSRobert Watson  * This software was developed for the FreeBSD Project in part by Network
124074f67fSRobert Watson  * Associates Laboratories, the Security Research Division of Network
134074f67fSRobert Watson  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
144074f67fSRobert Watson  * as part of the DARPA CHATS research program.
154074f67fSRobert Watson  *
164074f67fSRobert Watson  * This software was enhanced by SPARTA ISSO under SPAWAR contract
174074f67fSRobert Watson  * N66001-04-C-6019 ("SEFOS").
184074f67fSRobert Watson  *
194074f67fSRobert Watson  * Redistribution and use in source and binary forms, with or without
204074f67fSRobert Watson  * modification, are permitted provided that the following conditions
214074f67fSRobert Watson  * are met:
224074f67fSRobert Watson  * 1. Redistributions of source code must retain the above copyright
234074f67fSRobert Watson  *    notice, this list of conditions and the following disclaimer.
244074f67fSRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
254074f67fSRobert Watson  *    notice, this list of conditions and the following disclaimer in the
264074f67fSRobert Watson  *    documentation and/or other materials provided with the distribution.
274074f67fSRobert Watson  *
284074f67fSRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
294074f67fSRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
304074f67fSRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
314074f67fSRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
324074f67fSRobert Watson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
334074f67fSRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
344074f67fSRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
354074f67fSRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
364074f67fSRobert Watson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
374074f67fSRobert Watson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
384074f67fSRobert Watson  * SUCH DAMAGE.
394074f67fSRobert Watson  */
404074f67fSRobert Watson 
414074f67fSRobert Watson #include <sys/param.h>
424074f67fSRobert Watson #include <sys/acl.h>
434074f67fSRobert Watson #include <sys/kernel.h>
444074f67fSRobert Watson #include <sys/jail.h>
454074f67fSRobert Watson #include <sys/lock.h>
464074f67fSRobert Watson #include <sys/malloc.h>
474074f67fSRobert Watson #include <sys/module.h>
484074f67fSRobert Watson #include <sys/mount.h>
494074f67fSRobert Watson #include <sys/mutex.h>
504074f67fSRobert Watson #include <sys/priv.h>
514074f67fSRobert Watson #include <sys/systm.h>
524074f67fSRobert Watson #include <sys/vnode.h>
534074f67fSRobert Watson #include <sys/sysctl.h>
544074f67fSRobert Watson #include <sys/syslog.h>
554074f67fSRobert Watson #include <sys/stat.h>
564074f67fSRobert Watson 
574074f67fSRobert Watson #include <security/mac/mac_policy.h>
584074f67fSRobert Watson #include <security/mac_bsdextended/mac_bsdextended.h>
5934f6230eSRobert Watson #include <security/mac_bsdextended/ugidfw_internal.h>
604074f67fSRobert Watson 
6134f6230eSRobert Watson int
ugidfw_system_check_acct(struct ucred * cred,struct vnode * vp,struct label * vplabel)624074f67fSRobert Watson ugidfw_system_check_acct(struct ucred *cred, struct vnode *vp,
634074f67fSRobert Watson     struct label *vplabel)
644074f67fSRobert Watson {
654074f67fSRobert Watson 
664074f67fSRobert Watson 	if (vp != NULL)
674074f67fSRobert Watson 		return (ugidfw_check_vp(cred, vp, MBI_WRITE));
684074f67fSRobert Watson 	else
694074f67fSRobert Watson 		return (0);
704074f67fSRobert Watson }
714074f67fSRobert Watson 
7234f6230eSRobert Watson int
ugidfw_system_check_auditctl(struct ucred * cred,struct vnode * vp,struct label * vplabel)734074f67fSRobert Watson ugidfw_system_check_auditctl(struct ucred *cred, struct vnode *vp,
744074f67fSRobert Watson     struct label *vplabel)
754074f67fSRobert Watson {
764074f67fSRobert Watson 
774074f67fSRobert Watson 	if (vp != NULL)
784074f67fSRobert Watson 		return (ugidfw_check_vp(cred, vp, MBI_WRITE));
794074f67fSRobert Watson 	else
804074f67fSRobert Watson 		return (0);
814074f67fSRobert Watson }
824074f67fSRobert Watson 
8334f6230eSRobert Watson int
ugidfw_system_check_swapon(struct ucred * cred,struct vnode * vp,struct label * vplabel)844074f67fSRobert Watson ugidfw_system_check_swapon(struct ucred *cred, struct vnode *vp,
854074f67fSRobert Watson     struct label *vplabel)
864074f67fSRobert Watson {
874074f67fSRobert Watson 
884074f67fSRobert Watson 	return (ugidfw_check_vp(cred, vp, MBI_WRITE));
894074f67fSRobert Watson }
90