xref: /freebsd/sys/security/mac/mac_audit.c (revision fdafd315)
118717f69SRobert Watson /*-
22087a58cSRobert Watson  * Copyright (c) 1999-2002, 2009 Robert N. M. Watson
318717f69SRobert Watson  * Copyright (c) 2001 Ilmar S. Habibulin
418717f69SRobert Watson  * Copyright (c) 2001-2004 Networks Associates Technology, Inc.
530d239bcSRobert Watson  * Copyright (c) 2006 SPARTA, Inc.
618717f69SRobert Watson  *
718717f69SRobert Watson  * This software was developed by Robert Watson and Ilmar Habibulin for the
818717f69SRobert Watson  * TrustedBSD Project.
918717f69SRobert Watson  *
1018717f69SRobert Watson  * This software was developed for the FreeBSD Project in part by Network
1118717f69SRobert Watson  * Associates Laboratories, the Security Research Division of Network
1218717f69SRobert Watson  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
1318717f69SRobert Watson  * as part of the DARPA CHATS research program.
1418717f69SRobert Watson  *
1530d239bcSRobert Watson  * This software was enhanced by SPARTA ISSO under SPAWAR contract
1630d239bcSRobert Watson  * N66001-04-C-6019 ("SEFOS").
1730d239bcSRobert Watson  *
182087a58cSRobert Watson  * This software was developed at the University of Cambridge Computer
192087a58cSRobert Watson  * Laboratory with support from a grant from Google, Inc.
202087a58cSRobert Watson  *
2118717f69SRobert Watson  * Redistribution and use in source and binary forms, with or without
2218717f69SRobert Watson  * modification, are permitted provided that the following conditions
2318717f69SRobert Watson  * are met:
2418717f69SRobert Watson  * 1. Redistributions of source code must retain the above copyright
2518717f69SRobert Watson  *    notice, this list of conditions and the following disclaimer.
2618717f69SRobert Watson  * 2. Redistributions in binary form must reproduce the above copyright
2718717f69SRobert Watson  *    notice, this list of conditions and the following disclaimer in the
2818717f69SRobert Watson  *    documentation and/or other materials provided with the distribution.
2918717f69SRobert Watson  *
3018717f69SRobert Watson  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
3118717f69SRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3218717f69SRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3318717f69SRobert Watson  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
3418717f69SRobert Watson  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3518717f69SRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3618717f69SRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3718717f69SRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3818717f69SRobert Watson  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3918717f69SRobert Watson  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4018717f69SRobert Watson  * SUCH DAMAGE.
4118717f69SRobert Watson  */
4218717f69SRobert Watson 
4318717f69SRobert Watson #include <sys/param.h>
442087a58cSRobert Watson #include <sys/kernel.h>
4518717f69SRobert Watson #include <sys/module.h>
462087a58cSRobert Watson #include <sys/queue.h>
472087a58cSRobert Watson #include <sys/sdt.h>
4818717f69SRobert Watson #include <sys/vnode.h>
4918717f69SRobert Watson 
5018717f69SRobert Watson #include <security/audit/audit.h>
5118717f69SRobert Watson 
5218717f69SRobert Watson #include <security/mac/mac_framework.h>
5318717f69SRobert Watson #include <security/mac/mac_internal.h>
5418717f69SRobert Watson #include <security/mac/mac_policy.h>
5518717f69SRobert Watson 
566f6174a7SRobert Watson MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit, "struct ucred *",
572087a58cSRobert Watson     "struct auditinfo *");
582087a58cSRobert Watson 
5918717f69SRobert Watson int
mac_cred_check_setaudit(struct ucred * cred,struct auditinfo * ai)606f6174a7SRobert Watson mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai)
6118717f69SRobert Watson {
6218717f69SRobert Watson 	int error;
6318717f69SRobert Watson 
64fa765671SRobert Watson 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit, cred, ai);
656f6174a7SRobert Watson 	MAC_CHECK_PROBE2(cred_check_setaudit, error, cred, ai);
6618717f69SRobert Watson 
6718717f69SRobert Watson 	return (error);
6818717f69SRobert Watson }
6918717f69SRobert Watson 
706f6174a7SRobert Watson MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit_addr, "struct ucred *",
712087a58cSRobert Watson     "struct auditinfo_addr *");
722087a58cSRobert Watson 
7318717f69SRobert Watson int
mac_cred_check_setaudit_addr(struct ucred * cred,struct auditinfo_addr * aia)746f6174a7SRobert Watson mac_cred_check_setaudit_addr(struct ucred *cred, struct auditinfo_addr *aia)
75f1e8bf6dSRobert Watson {
76f1e8bf6dSRobert Watson 	int error;
77f1e8bf6dSRobert Watson 
78fa765671SRobert Watson 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit_addr, cred, aia);
796f6174a7SRobert Watson 	MAC_CHECK_PROBE2(cred_check_setaudit_addr, error, cred, aia);
80f1e8bf6dSRobert Watson 
81f1e8bf6dSRobert Watson 	return (error);
82f1e8bf6dSRobert Watson }
83f1e8bf6dSRobert Watson 
846f6174a7SRobert Watson MAC_CHECK_PROBE_DEFINE2(cred_check_setauid, "struct ucred *", "uid_t");
852087a58cSRobert Watson 
86f1e8bf6dSRobert Watson int
mac_cred_check_setauid(struct ucred * cred,uid_t auid)876f6174a7SRobert Watson mac_cred_check_setauid(struct ucred *cred, uid_t auid)
8818717f69SRobert Watson {
8918717f69SRobert Watson 	int error;
9018717f69SRobert Watson 
91fa765671SRobert Watson 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setauid, cred, auid);
926f6174a7SRobert Watson 	MAC_CHECK_PROBE2(cred_check_setauid, error, cred, auid);
9318717f69SRobert Watson 
9418717f69SRobert Watson 	return (error);
9518717f69SRobert Watson }
9618717f69SRobert Watson 
972087a58cSRobert Watson MAC_CHECK_PROBE_DEFINE3(system_check_audit, "struct ucred *", "void *",
982087a58cSRobert Watson     "int");
992087a58cSRobert Watson 
10018717f69SRobert Watson int
mac_system_check_audit(struct ucred * cred,void * record,int length)10130d239bcSRobert Watson mac_system_check_audit(struct ucred *cred, void *record, int length)
10218717f69SRobert Watson {
10318717f69SRobert Watson 	int error;
10418717f69SRobert Watson 
105fa765671SRobert Watson 	MAC_POLICY_CHECK_NOSLEEP(system_check_audit, cred, record, length);
1062087a58cSRobert Watson 	MAC_CHECK_PROBE3(system_check_audit, error, cred, record, length);
10718717f69SRobert Watson 
10818717f69SRobert Watson 	return (error);
10918717f69SRobert Watson }
11018717f69SRobert Watson 
1112087a58cSRobert Watson MAC_CHECK_PROBE_DEFINE2(system_check_auditctl, "struct ucred *",
1122087a58cSRobert Watson     "struct vnode *");
1132087a58cSRobert Watson 
11418717f69SRobert Watson int
mac_system_check_auditctl(struct ucred * cred,struct vnode * vp)11530d239bcSRobert Watson mac_system_check_auditctl(struct ucred *cred, struct vnode *vp)
11618717f69SRobert Watson {
11718717f69SRobert Watson 	int error;
11818717f69SRobert Watson 	struct label *vl;
11918717f69SRobert Watson 
12030d239bcSRobert Watson 	ASSERT_VOP_LOCKED(vp, "mac_system_check_auditctl");
12118717f69SRobert Watson 
12218717f69SRobert Watson 	vl = (vp != NULL) ? vp->v_label : NULL;
123fa765671SRobert Watson 	MAC_POLICY_CHECK(system_check_auditctl, cred, vp, vl);
1242087a58cSRobert Watson 	MAC_CHECK_PROBE2(system_check_auditctl, error, cred, vp);
12518717f69SRobert Watson 
12618717f69SRobert Watson 	return (error);
12718717f69SRobert Watson }
12818717f69SRobert Watson 
1292087a58cSRobert Watson MAC_CHECK_PROBE_DEFINE2(system_check_auditon, "struct ucred *", "int");
1302087a58cSRobert Watson 
13118717f69SRobert Watson int
mac_system_check_auditon(struct ucred * cred,int cmd)13230d239bcSRobert Watson mac_system_check_auditon(struct ucred *cred, int cmd)
13318717f69SRobert Watson {
13418717f69SRobert Watson 	int error;
13518717f69SRobert Watson 
136fa765671SRobert Watson 	MAC_POLICY_CHECK_NOSLEEP(system_check_auditon, cred, cmd);
1372087a58cSRobert Watson 	MAC_CHECK_PROBE2(system_check_auditon, error, cred, cmd);
13818717f69SRobert Watson 
13918717f69SRobert Watson 	return (error);
14018717f69SRobert Watson }
141