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