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