audit.h revision 186822
10Sstevel@tonic-gate/*-
20Sstevel@tonic-gate * Copyright (c) 1999-2005 Apple Inc.
30Sstevel@tonic-gate * All rights reserved.
40Sstevel@tonic-gate *
53704Svv149972 * Redistribution and use in source and binary forms, with or without
63704Svv149972 * modification, are permitted provided that the following conditions
70Sstevel@tonic-gate * are met:
80Sstevel@tonic-gate * 1.  Redistributions of source code must retain the above copyright
90Sstevel@tonic-gate *     notice, this list of conditions and the following disclaimer.
100Sstevel@tonic-gate * 2.  Redistributions in binary form must reproduce the above copyright
110Sstevel@tonic-gate *     notice, this list of conditions and the following disclaimer in the
120Sstevel@tonic-gate *     documentation and/or other materials provided with the distribution.
130Sstevel@tonic-gate * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
140Sstevel@tonic-gate *     its contributors may be used to endorse or promote products derived
150Sstevel@tonic-gate *     from this software without specific prior written permission.
160Sstevel@tonic-gate *
170Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
180Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
190Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
200Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
210Sstevel@tonic-gate * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2210079SGarrett.Damore@Sun.COM * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
230Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
240Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
250Sstevel@tonic-gate * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
260Sstevel@tonic-gate * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
270Sstevel@tonic-gate * POSSIBILITY OF SUCH DAMAGE.
280Sstevel@tonic-gate *
290Sstevel@tonic-gate * $FreeBSD: head/sys/security/audit/audit.h 186822 2009-01-06 13:59:59Z rwatson $
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate/*
330Sstevel@tonic-gate * This header includes function prototypes and type definitions that are
340Sstevel@tonic-gate * necessary for the kernel as a whole to interact with the audit subsystem.
350Sstevel@tonic-gate */
360Sstevel@tonic-gate
370Sstevel@tonic-gate#ifndef _SECURITY_AUDIT_KERNEL_H_
380Sstevel@tonic-gate#define	_SECURITY_AUDIT_KERNEL_H_
390Sstevel@tonic-gate
400Sstevel@tonic-gate#ifndef _KERNEL
410Sstevel@tonic-gate#error "no user-serviceable parts inside"
420Sstevel@tonic-gate#endif
430Sstevel@tonic-gate
440Sstevel@tonic-gate#include <bsm/audit.h>
450Sstevel@tonic-gate
460Sstevel@tonic-gate#include <sys/file.h>
470Sstevel@tonic-gate#include <sys/sysctl.h>
480Sstevel@tonic-gate
490Sstevel@tonic-gate/*
503898Srsb * Audit subsystem condition flags.  The audit_enabled flag is set and
510Sstevel@tonic-gate * removed automatically as a result of configuring log files, and can be
520Sstevel@tonic-gate * observed but should not be directly manipulated.  The audit suspension
530Sstevel@tonic-gate * flag permits audit to be temporarily disabled without reconfiguring the
540Sstevel@tonic-gate * audit target.
550Sstevel@tonic-gate */
560Sstevel@tonic-gateextern int	audit_enabled;
570Sstevel@tonic-gateextern int	audit_suspended;
580Sstevel@tonic-gate
590Sstevel@tonic-gate/*
600Sstevel@tonic-gate * Define the masks for the audited arguments.
610Sstevel@tonic-gate *
620Sstevel@tonic-gate * XXXRW: These need to remain in audit.h for now because our vnode and name
630Sstevel@tonic-gate * lookup audit calls rely on passing in flags to indicate which name or
640Sstevel@tonic-gate * vnode is being logged.  These should move to audit_private.h when that is
650Sstevel@tonic-gate * fixed.
660Sstevel@tonic-gate */
670Sstevel@tonic-gate#define	ARG_EUID		0x0000000000000001ULL
680Sstevel@tonic-gate#define	ARG_RUID		0x0000000000000002ULL
690Sstevel@tonic-gate#define	ARG_SUID		0x0000000000000004ULL
700Sstevel@tonic-gate#define	ARG_EGID		0x0000000000000008ULL
714845Svikram#define	ARG_RGID		0x0000000000000010ULL
720Sstevel@tonic-gate#define	ARG_SGID		0x0000000000000020ULL
730Sstevel@tonic-gate#define	ARG_PID			0x0000000000000040ULL
740Sstevel@tonic-gate#define	ARG_UID			0x0000000000000080ULL
750Sstevel@tonic-gate#define	ARG_AUID		0x0000000000000100ULL
760Sstevel@tonic-gate#define	ARG_GID			0x0000000000000200ULL
770Sstevel@tonic-gate#define	ARG_FD			0x0000000000000400ULL
780Sstevel@tonic-gate#define	ARG_POSIX_IPC_PERM	0x0000000000000800ULL
790Sstevel@tonic-gate#define	ARG_FFLAGS		0x0000000000001000ULL
800Sstevel@tonic-gate#define	ARG_MODE		0x0000000000002000ULL
810Sstevel@tonic-gate#define	ARG_DEV			0x0000000000004000ULL
820Sstevel@tonic-gate#define	ARG_ADDR		0x0000000000008000ULL
830Sstevel@tonic-gate#define	ARG_LEN			0x0000000000010000ULL
840Sstevel@tonic-gate#define	ARG_MASK		0x0000000000020000ULL
850Sstevel@tonic-gate#define	ARG_SIGNUM		0x0000000000040000ULL
860Sstevel@tonic-gate#define	ARG_LOGIN		0x0000000000080000ULL
870Sstevel@tonic-gate#define	ARG_SADDRINET		0x0000000000100000ULL
880Sstevel@tonic-gate#define	ARG_SADDRINET6		0x0000000000200000ULL
890Sstevel@tonic-gate#define	ARG_SADDRUNIX		0x0000000000400000ULL
900Sstevel@tonic-gate#define	ARG_TERMID_ADDR		0x0000000000400000ULL
910Sstevel@tonic-gate#define	ARG_UNUSED2		0x0000000001000000ULL
920Sstevel@tonic-gate#define	ARG_UPATH1		0x0000000002000000ULL
930Sstevel@tonic-gate#define	ARG_UPATH2		0x0000000004000000ULL
940Sstevel@tonic-gate#define	ARG_TEXT		0x0000000008000000ULL
950Sstevel@tonic-gate#define	ARG_VNODE1		0x0000000010000000ULL
960Sstevel@tonic-gate#define	ARG_VNODE2		0x0000000020000000ULL
970Sstevel@tonic-gate#define	ARG_SVIPC_CMD		0x0000000040000000ULL
980Sstevel@tonic-gate#define	ARG_SVIPC_PERM		0x0000000080000000ULL
990Sstevel@tonic-gate#define	ARG_SVIPC_ID		0x0000000100000000ULL
1000Sstevel@tonic-gate#define	ARG_SVIPC_ADDR		0x0000000200000000ULL
1010Sstevel@tonic-gate#define	ARG_GROUPSET		0x0000000400000000ULL
1020Sstevel@tonic-gate#define	ARG_CMD			0x0000000800000000ULL
1030Sstevel@tonic-gate#define	ARG_SOCKINFO		0x0000001000000000ULL
1040Sstevel@tonic-gate#define	ARG_ASID		0x0000002000000000ULL
1050Sstevel@tonic-gate#define	ARG_TERMID		0x0000004000000000ULL
1060Sstevel@tonic-gate#define	ARG_AUDITON		0x0000008000000000ULL
1070Sstevel@tonic-gate#define	ARG_VALUE		0x0000010000000000ULL
1080Sstevel@tonic-gate#define	ARG_AMASK		0x0000020000000000ULL
1090Sstevel@tonic-gate#define	ARG_CTLNAME		0x0000040000000000ULL
1100Sstevel@tonic-gate#define	ARG_PROCESS		0x0000080000000000ULL
1110Sstevel@tonic-gate#define	ARG_MACHPORT1		0x0000100000000000ULL
1120Sstevel@tonic-gate#define	ARG_MACHPORT2		0x0000200000000000ULL
1130Sstevel@tonic-gate#define	ARG_EXIT		0x0000400000000000ULL
1140Sstevel@tonic-gate#define	ARG_IOVECSTR		0x0000800000000000ULL
1150Sstevel@tonic-gate#define	ARG_ARGV		0x0001000000000000ULL
1160Sstevel@tonic-gate#define	ARG_ENVV		0x0002000000000000ULL
1170Sstevel@tonic-gate#define	ARG_NONE		0x0000000000000000ULL
1180Sstevel@tonic-gate#define	ARG_ALL			0xFFFFFFFFFFFFFFFFULL
1190Sstevel@tonic-gate
1200Sstevel@tonic-gatevoid	 audit_syscall_enter(unsigned short code, struct thread *td);
1210Sstevel@tonic-gatevoid	 audit_syscall_exit(int error, struct thread *td);
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate/*
1240Sstevel@tonic-gate * The remaining kernel functions are conditionally compiled in as they are
1250Sstevel@tonic-gate * wrapped by a macro, and the macro should be the only place in the source
1260Sstevel@tonic-gate * tree where these functions are referenced.
1270Sstevel@tonic-gate */
1280Sstevel@tonic-gate#ifdef AUDIT
1290Sstevel@tonic-gatestruct ipc_perm;
1300Sstevel@tonic-gatestruct sockaddr;
1310Sstevel@tonic-gateunion auditon_udata;
1320Sstevel@tonic-gatevoid	 audit_arg_addr(void * addr);
1330Sstevel@tonic-gatevoid	 audit_arg_exit(int status, int retval);
1340Sstevel@tonic-gatevoid	 audit_arg_len(int len);
1350Sstevel@tonic-gatevoid	 audit_arg_fd(int fd);
1360Sstevel@tonic-gatevoid	 audit_arg_fflags(int fflags);
1370Sstevel@tonic-gatevoid	 audit_arg_gid(gid_t gid);
1380Sstevel@tonic-gatevoid	 audit_arg_uid(uid_t uid);
1390Sstevel@tonic-gatevoid	 audit_arg_egid(gid_t egid);
1400Sstevel@tonic-gatevoid	 audit_arg_euid(uid_t euid);
1410Sstevel@tonic-gatevoid	 audit_arg_rgid(gid_t rgid);
1420Sstevel@tonic-gatevoid	 audit_arg_ruid(uid_t ruid);
1435331Samwvoid	 audit_arg_sgid(gid_t sgid);
1440Sstevel@tonic-gatevoid	 audit_arg_suid(uid_t suid);
1450Sstevel@tonic-gatevoid	 audit_arg_groupset(gid_t *gidset, u_int gidset_size);
1460Sstevel@tonic-gatevoid	 audit_arg_login(char *login);
1470Sstevel@tonic-gatevoid	 audit_arg_ctlname(int *name, int namelen);
1480Sstevel@tonic-gatevoid	 audit_arg_mask(int mask);
1490Sstevel@tonic-gatevoid	 audit_arg_mode(mode_t mode);
1500Sstevel@tonic-gatevoid	 audit_arg_dev(int dev);
1510Sstevel@tonic-gatevoid	 audit_arg_value(long value);
1520Sstevel@tonic-gatevoid	 audit_arg_owner(uid_t uid, gid_t gid);
1530Sstevel@tonic-gatevoid	 audit_arg_pid(pid_t pid);
1540Sstevel@tonic-gatevoid	 audit_arg_process(struct proc *p);
1550Sstevel@tonic-gatevoid	 audit_arg_signum(u_int signum);
1560Sstevel@tonic-gatevoid	 audit_arg_socket(int sodomain, int sotype, int soprotocol);
1570Sstevel@tonic-gatevoid	 audit_arg_sockaddr(struct thread *td, struct sockaddr *sa);
1580Sstevel@tonic-gatevoid	 audit_arg_auid(uid_t auid);
1590Sstevel@tonic-gatevoid	 audit_arg_auditinfo(struct auditinfo *au_info);
1600Sstevel@tonic-gatevoid	 audit_arg_auditinfo_addr(struct auditinfo_addr *au_info);
1610Sstevel@tonic-gatevoid	 audit_arg_upath(struct thread *td, char *upath, u_int64_t flags);
1620Sstevel@tonic-gatevoid	 audit_arg_vnode(struct vnode *vp, u_int64_t flags);
1630Sstevel@tonic-gatevoid	 audit_arg_text(char *text);
1640Sstevel@tonic-gatevoid	 audit_arg_cmd(int cmd);
1650Sstevel@tonic-gatevoid	 audit_arg_svipc_cmd(int cmd);
1660Sstevel@tonic-gatevoid	 audit_arg_svipc_perm(struct ipc_perm *perm);
1670Sstevel@tonic-gatevoid	 audit_arg_svipc_id(int id);
1680Sstevel@tonic-gatevoid	 audit_arg_svipc_addr(void *addr);
1690Sstevel@tonic-gatevoid	 audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, mode_t mode);
1700Sstevel@tonic-gatevoid	 audit_arg_auditon(union auditon_udata *udata);
1710Sstevel@tonic-gatevoid	 audit_arg_file(struct proc *p, struct file *fp);
1720Sstevel@tonic-gatevoid	 audit_arg_argv(char *argv, int argc, int length);
1730Sstevel@tonic-gatevoid	 audit_arg_envv(char *envv, int envc, int length);
1740Sstevel@tonic-gatevoid	 audit_sysclose(struct thread *td, int fd);
1750Sstevel@tonic-gatevoid	 audit_cred_copy(struct ucred *src, struct ucred *dest);
1760Sstevel@tonic-gatevoid	 audit_cred_destroy(struct ucred *cred);
1770Sstevel@tonic-gatevoid	 audit_cred_init(struct ucred *cred);
1780Sstevel@tonic-gatevoid	 audit_cred_kproc0(struct ucred *cred);
1790Sstevel@tonic-gatevoid	 audit_cred_proc1(struct ucred *cred);
1800Sstevel@tonic-gatevoid	 audit_proc_coredump(struct thread *td, char *path, int errcode);
1810Sstevel@tonic-gatevoid	 audit_thread_alloc(struct thread *td);
1820Sstevel@tonic-gatevoid	 audit_thread_free(struct thread *td);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate/*
1850Sstevel@tonic-gate * Define a macro to wrap the audit_arg_* calls by checking the global
1860Sstevel@tonic-gate * audit_enabled flag before performing the actual call.
1870Sstevel@tonic-gate */
1880Sstevel@tonic-gate#define	AUDIT_ARG(op, args...)	do {					\
1890Sstevel@tonic-gate	if (td->td_ar != NULL)						\
1900Sstevel@tonic-gate		audit_arg_ ## op (args);				\
1910Sstevel@tonic-gate} while (0)
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate#define	AUDIT_SYSCALL_ENTER(code, td)	do {				\
1940Sstevel@tonic-gate	if (audit_enabled) {						\
1950Sstevel@tonic-gate		audit_syscall_enter(code, td);				\
1960Sstevel@tonic-gate	}								\
1970Sstevel@tonic-gate} while (0)
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate/*
2000Sstevel@tonic-gate * Wrap the audit_syscall_exit() function so that it is called only when
2010Sstevel@tonic-gate * we have a audit record on the thread.  Audit records can persist after
2020Sstevel@tonic-gate * auditing is disabled, so we don't just check audit_enabled here.
2030Sstevel@tonic-gate */
2040Sstevel@tonic-gate#define	AUDIT_SYSCALL_EXIT(error, td)	do {				\
2050Sstevel@tonic-gate	if (td->td_ar != NULL)						\
2060Sstevel@tonic-gate		audit_syscall_exit(error, td);				\
2070Sstevel@tonic-gate} while (0)
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate/*
2100Sstevel@tonic-gate * A Macro to wrap the audit_sysclose() function.
2110Sstevel@tonic-gate */
2120Sstevel@tonic-gate#define	AUDIT_SYSCLOSE(td, fd)	do {					\
2130Sstevel@tonic-gate	if (audit_enabled)						\
2140Sstevel@tonic-gate		audit_sysclose(td, fd);					\
2150Sstevel@tonic-gate} while (0)
2160Sstevel@tonic-gate
2170Sstevel@tonic-gate#else /* !AUDIT */
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate#define	AUDIT_ARG(op, args...)	do {					\
2200Sstevel@tonic-gate} while (0)
2210Sstevel@tonic-gate
2220Sstevel@tonic-gate#define	AUDIT_SYSCALL_ENTER(code, td)	do {				\
2230Sstevel@tonic-gate} while (0)
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate#define	AUDIT_SYSCALL_EXIT(error, td)	do {				\
2260Sstevel@tonic-gate} while (0)
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate#define	AUDIT_SYSCLOSE(p, fd)	do {					\
2290Sstevel@tonic-gate} while (0)
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate#endif /* AUDIT */
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate#endif /* !_SECURITY_AUDIT_KERNEL_H_ */
2340Sstevel@tonic-gate