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