xref: /freebsd/sys/security/audit/audit.h (revision bc9a43d6985fb1891bfa4ab81460a4975b007585)
1718c8510SRobert Watson /*
2bc9a43d6SRobert Watson  * Copyright (c) 1999-2005 Apple Inc.
3718c8510SRobert Watson  * All rights reserved.
4718c8510SRobert Watson  *
5718c8510SRobert Watson  * Redistribution and use in source and binary forms, with or without
6718c8510SRobert Watson  * modification, are permitted provided that the following conditions
7718c8510SRobert Watson  * are met:
8718c8510SRobert Watson  * 1.  Redistributions of source code must retain the above copyright
9718c8510SRobert Watson  *     notice, this list of conditions and the following disclaimer.
10718c8510SRobert Watson  * 2.  Redistributions in binary form must reproduce the above copyright
11718c8510SRobert Watson  *     notice, this list of conditions and the following disclaimer in the
12718c8510SRobert Watson  *     documentation and/or other materials provided with the distribution.
13bc9a43d6SRobert Watson  * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
14718c8510SRobert Watson  *     its contributors may be used to endorse or promote products derived
15718c8510SRobert Watson  *     from this software without specific prior written permission.
16718c8510SRobert Watson  *
17718c8510SRobert Watson  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
18718c8510SRobert Watson  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19718c8510SRobert Watson  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20718c8510SRobert Watson  * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
21718c8510SRobert Watson  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22718c8510SRobert Watson  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23718c8510SRobert Watson  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24718c8510SRobert Watson  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25718c8510SRobert Watson  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26718c8510SRobert Watson  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27718c8510SRobert Watson  * POSSIBILITY OF SUCH DAMAGE.
28718c8510SRobert Watson  *
29718c8510SRobert Watson  * $FreeBSD$
30718c8510SRobert Watson  */
31718c8510SRobert Watson 
32718c8510SRobert Watson /*
33718c8510SRobert Watson  * This header includes function prototypes and type definitions that are
34718c8510SRobert Watson  * necessary for the kernel as a whole to interact with the audit subsystem.
35718c8510SRobert Watson  */
36718c8510SRobert Watson 
3717363e6dSRobert Watson #ifndef _SECURITY_AUDIT_KERNEL_H_
38fa9e0a18SRobert Watson #define	_SECURITY_AUDIT_KERNEL_H_
39718c8510SRobert Watson 
40718c8510SRobert Watson #ifndef _KERNEL
41718c8510SRobert Watson #error "no user-serviceable parts inside"
42718c8510SRobert Watson #endif
43718c8510SRobert Watson 
44718c8510SRobert Watson #include <bsm/audit.h>
45718c8510SRobert Watson 
46718c8510SRobert Watson #include <sys/file.h>
47718c8510SRobert Watson #include <sys/sysctl.h>
48718c8510SRobert Watson 
49718c8510SRobert Watson /*
50718c8510SRobert Watson  * Audit subsystem condition flags.  The audit_enabled flag is set and
51d8c0f4dcSRobert Watson  * removed automatically as a result of configuring log files, and can be
52d8c0f4dcSRobert Watson  * observed but should not be directly manipulated.  The audit suspension
53d8c0f4dcSRobert Watson  * flag permits audit to be temporarily disabled without reconfiguring the
54d8c0f4dcSRobert Watson  * audit target.
55718c8510SRobert Watson  */
56718c8510SRobert Watson extern int	audit_enabled;
57718c8510SRobert Watson extern int	audit_suspended;
58718c8510SRobert Watson 
59718c8510SRobert Watson /*
60718c8510SRobert Watson  * Define the masks for the audited arguments.
61718c8510SRobert Watson  *
62718c8510SRobert Watson  * XXXRW: These need to remain in audit.h for now because our vnode and name
63718c8510SRobert Watson  * lookup audit calls rely on passing in flags to indicate which name or
64718c8510SRobert Watson  * vnode is being logged.  These should move to audit_private.h when that is
65718c8510SRobert Watson  * fixed.
66718c8510SRobert Watson  */
67718c8510SRobert Watson #define	ARG_EUID		0x0000000000000001ULL
68718c8510SRobert Watson #define	ARG_RUID		0x0000000000000002ULL
69718c8510SRobert Watson #define	ARG_SUID		0x0000000000000004ULL
70718c8510SRobert Watson #define	ARG_EGID		0x0000000000000008ULL
71718c8510SRobert Watson #define	ARG_RGID		0x0000000000000010ULL
72718c8510SRobert Watson #define	ARG_SGID		0x0000000000000020ULL
73718c8510SRobert Watson #define	ARG_PID			0x0000000000000040ULL
74718c8510SRobert Watson #define	ARG_UID			0x0000000000000080ULL
75718c8510SRobert Watson #define	ARG_AUID		0x0000000000000100ULL
76718c8510SRobert Watson #define	ARG_GID			0x0000000000000200ULL
77718c8510SRobert Watson #define	ARG_FD			0x0000000000000400ULL
78718c8510SRobert Watson #define	ARG_POSIX_IPC_PERM	0x0000000000000800ULL
79718c8510SRobert Watson #define	ARG_FFLAGS		0x0000000000001000ULL
80718c8510SRobert Watson #define	ARG_MODE		0x0000000000002000ULL
81718c8510SRobert Watson #define	ARG_DEV			0x0000000000004000ULL
82718c8510SRobert Watson #define	ARG_ADDR		0x0000000000008000ULL
83718c8510SRobert Watson #define	ARG_LEN			0x0000000000010000ULL
84718c8510SRobert Watson #define	ARG_MASK		0x0000000000020000ULL
85718c8510SRobert Watson #define	ARG_SIGNUM		0x0000000000040000ULL
86718c8510SRobert Watson #define	ARG_LOGIN		0x0000000000080000ULL
87718c8510SRobert Watson #define	ARG_SADDRINET		0x0000000000100000ULL
88718c8510SRobert Watson #define	ARG_SADDRINET6		0x0000000000200000ULL
89718c8510SRobert Watson #define	ARG_SADDRUNIX		0x0000000000400000ULL
90f0cbfcc4SChristian S.J. Peron #define	ARG_TERMID_ADDR		0x0000000000400000ULL
91718c8510SRobert Watson #define	ARG_UNUSED2		0x0000000001000000ULL
92718c8510SRobert Watson #define	ARG_UPATH1		0x0000000002000000ULL
93718c8510SRobert Watson #define	ARG_UPATH2		0x0000000004000000ULL
94718c8510SRobert Watson #define	ARG_TEXT		0x0000000008000000ULL
95718c8510SRobert Watson #define	ARG_VNODE1		0x0000000010000000ULL
96718c8510SRobert Watson #define	ARG_VNODE2		0x0000000020000000ULL
97718c8510SRobert Watson #define	ARG_SVIPC_CMD		0x0000000040000000ULL
98718c8510SRobert Watson #define	ARG_SVIPC_PERM		0x0000000080000000ULL
99718c8510SRobert Watson #define	ARG_SVIPC_ID		0x0000000100000000ULL
100718c8510SRobert Watson #define	ARG_SVIPC_ADDR		0x0000000200000000ULL
101718c8510SRobert Watson #define	ARG_GROUPSET		0x0000000400000000ULL
102718c8510SRobert Watson #define	ARG_CMD			0x0000000800000000ULL
103718c8510SRobert Watson #define	ARG_SOCKINFO		0x0000001000000000ULL
104718c8510SRobert Watson #define	ARG_ASID		0x0000002000000000ULL
105718c8510SRobert Watson #define	ARG_TERMID		0x0000004000000000ULL
106718c8510SRobert Watson #define	ARG_AUDITON		0x0000008000000000ULL
107718c8510SRobert Watson #define	ARG_VALUE		0x0000010000000000ULL
108718c8510SRobert Watson #define	ARG_AMASK		0x0000020000000000ULL
109718c8510SRobert Watson #define	ARG_CTLNAME		0x0000040000000000ULL
110718c8510SRobert Watson #define	ARG_PROCESS		0x0000080000000000ULL
111718c8510SRobert Watson #define	ARG_MACHPORT1		0x0000100000000000ULL
112718c8510SRobert Watson #define	ARG_MACHPORT2		0x0000200000000000ULL
113718c8510SRobert Watson #define	ARG_EXIT		0x0000400000000000ULL
114ae1078d6SWayne Salamon #define	ARG_IOVECSTR		0x0000800000000000ULL
115ae1078d6SWayne Salamon #define	ARG_ARGV		0x0001000000000000ULL
116ae1078d6SWayne Salamon #define	ARG_ENVV		0x0002000000000000ULL
117718c8510SRobert Watson #define	ARG_NONE		0x0000000000000000ULL
118718c8510SRobert Watson #define	ARG_ALL			0xFFFFFFFFFFFFFFFFULL
119718c8510SRobert Watson 
120871499feSRobert Watson void	 audit_syscall_enter(unsigned short code, struct thread *td);
121718c8510SRobert Watson void	 audit_syscall_exit(int error, struct thread *td);
122718c8510SRobert Watson 
123718c8510SRobert Watson /*
124d8c0f4dcSRobert Watson  * The remaining kernel functions are conditionally compiled in as they are
125d8c0f4dcSRobert Watson  * wrapped by a macro, and the macro should be the only place in the source
126d8c0f4dcSRobert Watson  * tree where these functions are referenced.
127718c8510SRobert Watson  */
128718c8510SRobert Watson #ifdef AUDIT
129718c8510SRobert Watson struct ipc_perm;
130718c8510SRobert Watson struct sockaddr;
131718c8510SRobert Watson union auditon_udata;
132718c8510SRobert Watson void	 audit_arg_addr(void * addr);
133718c8510SRobert Watson void	 audit_arg_exit(int status, int retval);
134718c8510SRobert Watson void	 audit_arg_len(int len);
135718c8510SRobert Watson void	 audit_arg_fd(int fd);
136718c8510SRobert Watson void	 audit_arg_fflags(int fflags);
137718c8510SRobert Watson void	 audit_arg_gid(gid_t gid);
138718c8510SRobert Watson void	 audit_arg_uid(uid_t uid);
139718c8510SRobert Watson void	 audit_arg_egid(gid_t egid);
140718c8510SRobert Watson void	 audit_arg_euid(uid_t euid);
141718c8510SRobert Watson void	 audit_arg_rgid(gid_t rgid);
142718c8510SRobert Watson void	 audit_arg_ruid(uid_t ruid);
143718c8510SRobert Watson void	 audit_arg_sgid(gid_t sgid);
144718c8510SRobert Watson void	 audit_arg_suid(uid_t suid);
145718c8510SRobert Watson void	 audit_arg_groupset(gid_t *gidset, u_int gidset_size);
146718c8510SRobert Watson void	 audit_arg_login(char *login);
147718c8510SRobert Watson void	 audit_arg_ctlname(int *name, int namelen);
148718c8510SRobert Watson void	 audit_arg_mask(int mask);
149718c8510SRobert Watson void	 audit_arg_mode(mode_t mode);
150718c8510SRobert Watson void	 audit_arg_dev(int dev);
151718c8510SRobert Watson void	 audit_arg_value(long value);
152718c8510SRobert Watson void	 audit_arg_owner(uid_t uid, gid_t gid);
153718c8510SRobert Watson void	 audit_arg_pid(pid_t pid);
154718c8510SRobert Watson void	 audit_arg_process(struct proc *p);
155718c8510SRobert Watson void	 audit_arg_signum(u_int signum);
156871499feSRobert Watson void	 audit_arg_socket(int sodomain, int sotype, int soprotocol);
157814fe9e9SRobert Watson void	 audit_arg_sockaddr(struct thread *td, struct sockaddr *sa);
158718c8510SRobert Watson void	 audit_arg_auid(uid_t auid);
159718c8510SRobert Watson void	 audit_arg_auditinfo(struct auditinfo *au_info);
160cac465aaSChristian S.J. Peron void	 audit_arg_auditinfo_addr(struct auditinfo_addr *au_info);
161871499feSRobert Watson void	 audit_arg_upath(struct thread *td, char *upath, u_int64_t flags);
162718c8510SRobert Watson void	 audit_arg_vnode(struct vnode *vp, u_int64_t flags);
163718c8510SRobert Watson void	 audit_arg_text(char *text);
164718c8510SRobert Watson void	 audit_arg_cmd(int cmd);
165718c8510SRobert Watson void	 audit_arg_svipc_cmd(int cmd);
166718c8510SRobert Watson void	 audit_arg_svipc_perm(struct ipc_perm *perm);
167718c8510SRobert Watson void	 audit_arg_svipc_id(int id);
168718c8510SRobert Watson void	 audit_arg_svipc_addr(void *addr);
169871499feSRobert Watson void	 audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, mode_t mode);
170718c8510SRobert Watson void	 audit_arg_auditon(union auditon_udata *udata);
171718c8510SRobert Watson void	 audit_arg_file(struct proc *p, struct file *fp);
172ae1078d6SWayne Salamon void	 audit_arg_argv(char *argv, int argc, int length);
173ae1078d6SWayne Salamon void	 audit_arg_envv(char *envv, int envc, int length);
174718c8510SRobert Watson void	 audit_sysclose(struct thread *td, int fd);
175faef5371SRobert Watson void	 audit_cred_copy(struct ucred *src, struct ucred *dest);
176faef5371SRobert Watson void	 audit_cred_destroy(struct ucred *cred);
177faef5371SRobert Watson void	 audit_cred_init(struct ucred *cred);
178faef5371SRobert Watson void	 audit_cred_kproc0(struct ucred *cred);
179faef5371SRobert Watson void	 audit_cred_proc1(struct ucred *cred);
18057274c51SChristian S.J. Peron void	 audit_proc_coredump(struct thread *td, char *path, int errcode);
181911b84b0SRobert Watson void	 audit_thread_alloc(struct thread *td);
1826e8525ceSRobert Watson void	 audit_thread_free(struct thread *td);
183718c8510SRobert Watson 
184718c8510SRobert Watson /*
185718c8510SRobert Watson  * Define a macro to wrap the audit_arg_* calls by checking the global
186718c8510SRobert Watson  * audit_enabled flag before performing the actual call.
187718c8510SRobert Watson  */
188718c8510SRobert Watson #define	AUDIT_ARG(op, args...)	do {					\
1897d8ab8baSRobert Watson 	if (td->td_ar != NULL)						\
190718c8510SRobert Watson 		audit_arg_ ## op (args);				\
191718c8510SRobert Watson } while (0)
192718c8510SRobert Watson 
193718c8510SRobert Watson #define	AUDIT_SYSCALL_ENTER(code, td)	do {				\
194718c8510SRobert Watson 	if (audit_enabled) {						\
195718c8510SRobert Watson 		audit_syscall_enter(code, td);				\
196718c8510SRobert Watson 	}								\
197718c8510SRobert Watson } while (0)
198718c8510SRobert Watson 
199718c8510SRobert Watson /*
200718c8510SRobert Watson  * Wrap the audit_syscall_exit() function so that it is called only when
201718c8510SRobert Watson  * auditing is enabled, or we have a audit record on the thread.  It is
202718c8510SRobert Watson  * possible that an audit record was begun before auditing was turned off.
203718c8510SRobert Watson  */
204718c8510SRobert Watson #define	AUDIT_SYSCALL_EXIT(error, td)	do {				\
20581efe39dSRobert Watson 	if (audit_enabled || (td->td_ar != NULL))			\
206718c8510SRobert Watson 		audit_syscall_exit(error, td);				\
207718c8510SRobert Watson } while (0)
208718c8510SRobert Watson 
209718c8510SRobert Watson /*
210718c8510SRobert Watson  * A Macro to wrap the audit_sysclose() function.
211718c8510SRobert Watson  */
212718c8510SRobert Watson #define	AUDIT_SYSCLOSE(td, fd)	do {					\
213718c8510SRobert Watson 	if (audit_enabled)						\
214718c8510SRobert Watson 		audit_sysclose(td, fd);					\
215718c8510SRobert Watson } while (0)
216718c8510SRobert Watson 
217718c8510SRobert Watson #else /* !AUDIT */
218718c8510SRobert Watson 
219718c8510SRobert Watson #define	AUDIT_ARG(op, args...)	do {					\
220718c8510SRobert Watson } while (0)
221718c8510SRobert Watson 
222718c8510SRobert Watson #define	AUDIT_SYSCALL_ENTER(code, td)	do {				\
223718c8510SRobert Watson } while (0)
224718c8510SRobert Watson 
225718c8510SRobert Watson #define	AUDIT_SYSCALL_EXIT(error, td)	do {				\
226718c8510SRobert Watson } while (0)
227718c8510SRobert Watson 
228718c8510SRobert Watson #define	AUDIT_SYSCLOSE(p, fd)	do {					\
229718c8510SRobert Watson } while (0)
230718c8510SRobert Watson 
231718c8510SRobert Watson #endif /* AUDIT */
232718c8510SRobert Watson 
23317363e6dSRobert Watson #endif /* !_SECURITY_AUDIT_KERNEL_H_ */
234