118717f69SRobert Watson /*- 22087a58cSRobert Watson * Copyright (c) 1999-2002, 2009 Robert N. M. Watson 318717f69SRobert Watson * Copyright (c) 2001 Ilmar S. Habibulin 418717f69SRobert Watson * Copyright (c) 2001-2004 Networks Associates Technology, Inc. 530d239bcSRobert Watson * Copyright (c) 2006 SPARTA, Inc. 618717f69SRobert Watson * 718717f69SRobert Watson * This software was developed by Robert Watson and Ilmar Habibulin for the 818717f69SRobert Watson * TrustedBSD Project. 918717f69SRobert Watson * 1018717f69SRobert Watson * This software was developed for the FreeBSD Project in part by Network 1118717f69SRobert Watson * Associates Laboratories, the Security Research Division of Network 1218717f69SRobert Watson * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), 1318717f69SRobert Watson * as part of the DARPA CHATS research program. 1418717f69SRobert Watson * 1530d239bcSRobert Watson * This software was enhanced by SPARTA ISSO under SPAWAR contract 1630d239bcSRobert Watson * N66001-04-C-6019 ("SEFOS"). 1730d239bcSRobert Watson * 182087a58cSRobert Watson * This software was developed at the University of Cambridge Computer 192087a58cSRobert Watson * Laboratory with support from a grant from Google, Inc. 202087a58cSRobert Watson * 2118717f69SRobert Watson * Redistribution and use in source and binary forms, with or without 2218717f69SRobert Watson * modification, are permitted provided that the following conditions 2318717f69SRobert Watson * are met: 2418717f69SRobert Watson * 1. Redistributions of source code must retain the above copyright 2518717f69SRobert Watson * notice, this list of conditions and the following disclaimer. 2618717f69SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 2718717f69SRobert Watson * notice, this list of conditions and the following disclaimer in the 2818717f69SRobert Watson * documentation and/or other materials provided with the distribution. 2918717f69SRobert Watson * 3018717f69SRobert Watson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 3118717f69SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 3218717f69SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3318717f69SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 3418717f69SRobert Watson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3518717f69SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3618717f69SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3718717f69SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3818717f69SRobert Watson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3918717f69SRobert Watson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 4018717f69SRobert Watson * SUCH DAMAGE. 4118717f69SRobert Watson */ 4218717f69SRobert Watson 43c7ed8c0aSRobert Watson #include <sys/cdefs.h> 44c7ed8c0aSRobert Watson __FBSDID("$FreeBSD$"); 45c7ed8c0aSRobert Watson 462087a58cSRobert Watson #include "opt_kdtrace.h" 472087a58cSRobert Watson 4818717f69SRobert Watson #include <sys/param.h> 492087a58cSRobert Watson #include <sys/kernel.h> 5018717f69SRobert Watson #include <sys/module.h> 512087a58cSRobert Watson #include <sys/queue.h> 522087a58cSRobert Watson #include <sys/sdt.h> 5318717f69SRobert Watson #include <sys/vnode.h> 5418717f69SRobert Watson 5518717f69SRobert Watson #include <security/audit/audit.h> 5618717f69SRobert Watson 5718717f69SRobert Watson #include <security/mac/mac_framework.h> 5818717f69SRobert Watson #include <security/mac/mac_internal.h> 5918717f69SRobert Watson #include <security/mac/mac_policy.h> 6018717f69SRobert Watson 616f6174a7SRobert Watson MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit, "struct ucred *", 622087a58cSRobert Watson "struct auditinfo *"); 632087a58cSRobert Watson 6418717f69SRobert Watson int 656f6174a7SRobert Watson mac_cred_check_setaudit(struct ucred *cred, struct auditinfo *ai) 6618717f69SRobert Watson { 6718717f69SRobert Watson int error; 6818717f69SRobert Watson 696f6174a7SRobert Watson MAC_CHECK(cred_check_setaudit, cred, ai); 706f6174a7SRobert Watson MAC_CHECK_PROBE2(cred_check_setaudit, error, cred, ai); 7118717f69SRobert Watson 7218717f69SRobert Watson return (error); 7318717f69SRobert Watson } 7418717f69SRobert Watson 756f6174a7SRobert Watson MAC_CHECK_PROBE_DEFINE2(cred_check_setaudit_addr, "struct ucred *", 762087a58cSRobert Watson "struct auditinfo_addr *"); 772087a58cSRobert Watson 7818717f69SRobert Watson int 796f6174a7SRobert Watson mac_cred_check_setaudit_addr(struct ucred *cred, struct auditinfo_addr *aia) 80f1e8bf6dSRobert Watson { 81f1e8bf6dSRobert Watson int error; 82f1e8bf6dSRobert Watson 836f6174a7SRobert Watson MAC_CHECK(cred_check_setaudit_addr, cred, aia); 846f6174a7SRobert Watson MAC_CHECK_PROBE2(cred_check_setaudit_addr, error, cred, aia); 85f1e8bf6dSRobert Watson 86f1e8bf6dSRobert Watson return (error); 87f1e8bf6dSRobert Watson } 88f1e8bf6dSRobert Watson 896f6174a7SRobert Watson MAC_CHECK_PROBE_DEFINE2(cred_check_setauid, "struct ucred *", "uid_t"); 902087a58cSRobert Watson 91f1e8bf6dSRobert Watson int 926f6174a7SRobert Watson mac_cred_check_setauid(struct ucred *cred, uid_t auid) 9318717f69SRobert Watson { 9418717f69SRobert Watson int error; 9518717f69SRobert Watson 966f6174a7SRobert Watson MAC_CHECK(cred_check_setauid, cred, auid); 976f6174a7SRobert Watson MAC_CHECK_PROBE2(cred_check_setauid, error, cred, auid); 9818717f69SRobert Watson 9918717f69SRobert Watson return (error); 10018717f69SRobert Watson } 10118717f69SRobert Watson 1022087a58cSRobert Watson MAC_CHECK_PROBE_DEFINE3(system_check_audit, "struct ucred *", "void *", 1032087a58cSRobert Watson "int"); 1042087a58cSRobert Watson 10518717f69SRobert Watson int 10630d239bcSRobert Watson mac_system_check_audit(struct ucred *cred, void *record, int length) 10718717f69SRobert Watson { 10818717f69SRobert Watson int error; 10918717f69SRobert Watson 11030d239bcSRobert Watson MAC_CHECK(system_check_audit, cred, record, length); 1112087a58cSRobert Watson MAC_CHECK_PROBE3(system_check_audit, error, cred, record, length); 11218717f69SRobert Watson 11318717f69SRobert Watson return (error); 11418717f69SRobert Watson } 11518717f69SRobert Watson 1162087a58cSRobert Watson MAC_CHECK_PROBE_DEFINE2(system_check_auditctl, "struct ucred *", 1172087a58cSRobert Watson "struct vnode *"); 1182087a58cSRobert Watson 11918717f69SRobert Watson int 12030d239bcSRobert Watson mac_system_check_auditctl(struct ucred *cred, struct vnode *vp) 12118717f69SRobert Watson { 12218717f69SRobert Watson int error; 12318717f69SRobert Watson struct label *vl; 12418717f69SRobert Watson 12530d239bcSRobert Watson ASSERT_VOP_LOCKED(vp, "mac_system_check_auditctl"); 12618717f69SRobert Watson 12718717f69SRobert Watson vl = (vp != NULL) ? vp->v_label : NULL; 12830d239bcSRobert Watson MAC_CHECK(system_check_auditctl, cred, vp, vl); 1292087a58cSRobert Watson MAC_CHECK_PROBE2(system_check_auditctl, error, cred, vp); 13018717f69SRobert Watson 13118717f69SRobert Watson return (error); 13218717f69SRobert Watson } 13318717f69SRobert Watson 1342087a58cSRobert Watson MAC_CHECK_PROBE_DEFINE2(system_check_auditon, "struct ucred *", "int"); 1352087a58cSRobert Watson 13618717f69SRobert Watson int 13730d239bcSRobert Watson mac_system_check_auditon(struct ucred *cred, int cmd) 13818717f69SRobert Watson { 13918717f69SRobert Watson int error; 14018717f69SRobert Watson 14130d239bcSRobert Watson MAC_CHECK(system_check_auditon, cred, cmd); 1422087a58cSRobert Watson MAC_CHECK_PROBE2(system_check_auditon, error, cred, cmd); 14318717f69SRobert Watson 14418717f69SRobert Watson return (error); 14518717f69SRobert Watson } 146