xref: /f-stack/freebsd/security/mac/mac_audit.c (revision a9643ea8)
1*a9643ea8Slogwang /*-
2*a9643ea8Slogwang  * Copyright (c) 1999-2002, 2009 Robert N. M. Watson
3*a9643ea8Slogwang  * Copyright (c) 2001 Ilmar S. Habibulin
4*a9643ea8Slogwang  * Copyright (c) 2001-2004 Networks Associates Technology, Inc.
5*a9643ea8Slogwang  * Copyright (c) 2006 SPARTA, Inc.
6*a9643ea8Slogwang  *
7*a9643ea8Slogwang  * This software was developed by Robert Watson and Ilmar Habibulin for the
8*a9643ea8Slogwang  * TrustedBSD Project.
9*a9643ea8Slogwang  *
10*a9643ea8Slogwang  * This software was developed for the FreeBSD Project in part by Network
11*a9643ea8Slogwang  * Associates Laboratories, the Security Research Division of Network
12*a9643ea8Slogwang  * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"),
13*a9643ea8Slogwang  * as part of the DARPA CHATS research program.
14*a9643ea8Slogwang  *
15*a9643ea8Slogwang  * This software was enhanced by SPARTA ISSO under SPAWAR contract
16*a9643ea8Slogwang  * N66001-04-C-6019 ("SEFOS").
17*a9643ea8Slogwang  *
18*a9643ea8Slogwang  * This software was developed at the University of Cambridge Computer
19*a9643ea8Slogwang  * Laboratory with support from a grant from Google, Inc.
20*a9643ea8Slogwang  *
21*a9643ea8Slogwang  * Redistribution and use in source and binary forms, with or without
22*a9643ea8Slogwang  * modification, are permitted provided that the following conditions
23*a9643ea8Slogwang  * are met:
24*a9643ea8Slogwang  * 1. Redistributions of source code must retain the above copyright
25*a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer.
26*a9643ea8Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
27*a9643ea8Slogwang  *    notice, this list of conditions and the following disclaimer in the
28*a9643ea8Slogwang  *    documentation and/or other materials provided with the distribution.
29*a9643ea8Slogwang  *
30*a9643ea8Slogwang  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
31*a9643ea8Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32*a9643ea8Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33*a9643ea8Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
34*a9643ea8Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35*a9643ea8Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36*a9643ea8Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37*a9643ea8Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38*a9643ea8Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39*a9643ea8Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40*a9643ea8Slogwang  * SUCH DAMAGE.
41*a9643ea8Slogwang  */
42*a9643ea8Slogwang 
43*a9643ea8Slogwang #include <sys/cdefs.h>
44*a9643ea8Slogwang __FBSDID("$FreeBSD$");
45*a9643ea8Slogwang 
46*a9643ea8Slogwang #include <sys/param.h>
47*a9643ea8Slogwang #include <sys/kernel.h>
48*a9643ea8Slogwang #include <sys/module.h>
49*a9643ea8Slogwang #include <sys/queue.h>
50*a9643ea8Slogwang #include <sys/sdt.h>
51*a9643ea8Slogwang #include <sys/vnode.h>
52*a9643ea8Slogwang 
53*a9643ea8Slogwang #include <security/audit/audit.h>
54*a9643ea8Slogwang 
55*a9643ea8Slogwang #include <security/mac/mac_framework.h>
56*a9643ea8Slogwang #include <security/mac/mac_internal.h>
57*a9643ea8Slogwang #include <security/mac/mac_policy.h>
58*a9643ea8Slogwang 
59*a9643ea8Slogwang MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit, "struct ucred *",
60*a9643ea8Slogwang     "struct auditinfo *");
61*a9643ea8Slogwang 
62*a9643ea8Slogwang int
mac_cred_check_setaudit(struct ucred * cred,struct auditinfo * ai)63*a9643ea8Slogwang mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai)
64*a9643ea8Slogwang {
65*a9643ea8Slogwang 	int error;
66*a9643ea8Slogwang 
67*a9643ea8Slogwang 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit, cred, ai);
68*a9643ea8Slogwang 	MAC_CHECK_PROBE2(cred_check_setaudit, error, cred, ai);
69*a9643ea8Slogwang 
70*a9643ea8Slogwang 	return (error);
71*a9643ea8Slogwang }
72*a9643ea8Slogwang 
73*a9643ea8Slogwang MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit_addr, "struct ucred *",
74*a9643ea8Slogwang     "struct auditinfo_addr *");
75*a9643ea8Slogwang 
76*a9643ea8Slogwang int
mac_cred_check_setaudit_addr(struct ucred * cred,struct auditinfo_addr * aia)77*a9643ea8Slogwang mac_cred_check_setaudit_addr(struct ucred *cred, struct auditinfo_addr *aia)
78*a9643ea8Slogwang {
79*a9643ea8Slogwang 	int error;
80*a9643ea8Slogwang 
81*a9643ea8Slogwang 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit_addr, cred, aia);
82*a9643ea8Slogwang 	MAC_CHECK_PROBE2(cred_check_setaudit_addr, error, cred, aia);
83*a9643ea8Slogwang 
84*a9643ea8Slogwang 	return (error);
85*a9643ea8Slogwang }
86*a9643ea8Slogwang 
87*a9643ea8Slogwang MAC_CHECK_PROBE_DEFINE2(cred_check_setauid, "struct ucred *", "uid_t");
88*a9643ea8Slogwang 
89*a9643ea8Slogwang int
mac_cred_check_setauid(struct ucred * cred,uid_t auid)90*a9643ea8Slogwang mac_cred_check_setauid(struct ucred *cred, uid_t auid)
91*a9643ea8Slogwang {
92*a9643ea8Slogwang 	int error;
93*a9643ea8Slogwang 
94*a9643ea8Slogwang 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setauid, cred, auid);
95*a9643ea8Slogwang 	MAC_CHECK_PROBE2(cred_check_setauid, error, cred, auid);
96*a9643ea8Slogwang 
97*a9643ea8Slogwang 	return (error);
98*a9643ea8Slogwang }
99*a9643ea8Slogwang 
100*a9643ea8Slogwang MAC_CHECK_PROBE_DEFINE3(system_check_audit, "struct ucred *", "void *",
101*a9643ea8Slogwang     "int");
102*a9643ea8Slogwang 
103*a9643ea8Slogwang int
mac_system_check_audit(struct ucred * cred,void * record,int length)104*a9643ea8Slogwang mac_system_check_audit(struct ucred *cred, void *record, int length)
105*a9643ea8Slogwang {
106*a9643ea8Slogwang 	int error;
107*a9643ea8Slogwang 
108*a9643ea8Slogwang 	MAC_POLICY_CHECK_NOSLEEP(system_check_audit, cred, record, length);
109*a9643ea8Slogwang 	MAC_CHECK_PROBE3(system_check_audit, error, cred, record, length);
110*a9643ea8Slogwang 
111*a9643ea8Slogwang 	return (error);
112*a9643ea8Slogwang }
113*a9643ea8Slogwang 
114*a9643ea8Slogwang MAC_CHECK_PROBE_DEFINE2(system_check_auditctl, "struct ucred *",
115*a9643ea8Slogwang     "struct vnode *");
116*a9643ea8Slogwang 
117*a9643ea8Slogwang int
mac_system_check_auditctl(struct ucred * cred,struct vnode * vp)118*a9643ea8Slogwang mac_system_check_auditctl(struct ucred *cred, struct vnode *vp)
119*a9643ea8Slogwang {
120*a9643ea8Slogwang 	int error;
121*a9643ea8Slogwang 	struct label *vl;
122*a9643ea8Slogwang 
123*a9643ea8Slogwang 	ASSERT_VOP_LOCKED(vp, "mac_system_check_auditctl");
124*a9643ea8Slogwang 
125*a9643ea8Slogwang 	vl = (vp != NULL) ? vp->v_label : NULL;
126*a9643ea8Slogwang 	MAC_POLICY_CHECK(system_check_auditctl, cred, vp, vl);
127*a9643ea8Slogwang 	MAC_CHECK_PROBE2(system_check_auditctl, error, cred, vp);
128*a9643ea8Slogwang 
129*a9643ea8Slogwang 	return (error);
130*a9643ea8Slogwang }
131*a9643ea8Slogwang 
132*a9643ea8Slogwang MAC_CHECK_PROBE_DEFINE2(system_check_auditon, "struct ucred *", "int");
133*a9643ea8Slogwang 
134*a9643ea8Slogwang int
mac_system_check_auditon(struct ucred * cred,int cmd)135*a9643ea8Slogwang mac_system_check_auditon(struct ucred *cred, int cmd)
136*a9643ea8Slogwang {
137*a9643ea8Slogwang 	int error;
138*a9643ea8Slogwang 
139*a9643ea8Slogwang 	MAC_POLICY_CHECK_NOSLEEP(system_check_auditon, cred, cmd);
140*a9643ea8Slogwang 	MAC_CHECK_PROBE2(system_check_auditon, error, cred, cmd);
141*a9643ea8Slogwang 
142*a9643ea8Slogwang 	return (error);
143*a9643ea8Slogwang }
144