xref: /freebsd/sys/security/mac/mac_audit.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
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 #include <sys/param.h>
45 #include <sys/kernel.h>
46 #include <sys/module.h>
47 #include <sys/queue.h>
48 #include <sys/sdt.h>
49 #include <sys/vnode.h>
50 
51 #include <security/audit/audit.h>
52 
53 #include <security/mac/mac_framework.h>
54 #include <security/mac/mac_internal.h>
55 #include <security/mac/mac_policy.h>
56 
57 MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit, "struct ucred *",
58     "struct auditinfo *");
59 
60 int
61 mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai)
62 {
63 	int error;
64 
65 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit, cred, ai);
66 	MAC_CHECK_PROBE2(cred_check_setaudit, error, cred, ai);
67 
68 	return (error);
69 }
70 
71 MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit_addr, "struct ucred *",
72     "struct auditinfo_addr *");
73 
74 int
75 mac_cred_check_setaudit_addr(struct ucred *cred, struct auditinfo_addr *aia)
76 {
77 	int error;
78 
79 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setaudit_addr, cred, aia);
80 	MAC_CHECK_PROBE2(cred_check_setaudit_addr, error, cred, aia);
81 
82 	return (error);
83 }
84 
85 MAC_CHECK_PROBE_DEFINE2(cred_check_setauid, "struct ucred *", "uid_t");
86 
87 int
88 mac_cred_check_setauid(struct ucred *cred, uid_t auid)
89 {
90 	int error;
91 
92 	MAC_POLICY_CHECK_NOSLEEP(cred_check_setauid, cred, auid);
93 	MAC_CHECK_PROBE2(cred_check_setauid, error, cred, auid);
94 
95 	return (error);
96 }
97 
98 MAC_CHECK_PROBE_DEFINE3(system_check_audit, "struct ucred *", "void *",
99     "int");
100 
101 int
102 mac_system_check_audit(struct ucred *cred, void *record, int length)
103 {
104 	int error;
105 
106 	MAC_POLICY_CHECK_NOSLEEP(system_check_audit, cred, record, length);
107 	MAC_CHECK_PROBE3(system_check_audit, error, cred, record, length);
108 
109 	return (error);
110 }
111 
112 MAC_CHECK_PROBE_DEFINE2(system_check_auditctl, "struct ucred *",
113     "struct vnode *");
114 
115 int
116 mac_system_check_auditctl(struct ucred *cred, struct vnode *vp)
117 {
118 	int error;
119 	struct label *vl;
120 
121 	ASSERT_VOP_LOCKED(vp, "mac_system_check_auditctl");
122 
123 	vl = (vp != NULL) ? vp->v_label : NULL;
124 	MAC_POLICY_CHECK(system_check_auditctl, cred, vp, vl);
125 	MAC_CHECK_PROBE2(system_check_auditctl, error, cred, vp);
126 
127 	return (error);
128 }
129 
130 MAC_CHECK_PROBE_DEFINE2(system_check_auditon, "struct ucred *", "int");
131 
132 int
133 mac_system_check_auditon(struct ucred *cred, int cmd)
134 {
135 	int error;
136 
137 	MAC_POLICY_CHECK_NOSLEEP(system_check_auditon, cred, cmd);
138 	MAC_CHECK_PROBE2(system_check_auditon, error, cred, cmd);
139 
140 	return (error);
141 }
142