xref: /illumos-gate/usr/src/uts/common/c2/audit.h (revision ddc42f88)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22469aa27fSJan Friedel  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * This file contains the declarations of the various data structures
287c478bd9Sstevel@tonic-gate  * used by the auditing module(s).
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifndef	_BSM_AUDIT_H
327c478bd9Sstevel@tonic-gate #define	_BSM_AUDIT_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef __cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/shm.h>	/* for shmid_ds structure */
407c478bd9Sstevel@tonic-gate #include <sys/sem.h>	/* for semid_ds structure */
417c478bd9Sstevel@tonic-gate #include <sys/msg.h>	/* for msqid_ds structure */
427c478bd9Sstevel@tonic-gate #include <sys/atomic.h>	/* using atomics */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Audit conditions, statements reguarding what's to be done with
467c478bd9Sstevel@tonic-gate  * audit records.  Neither AUC_ENABLED, AUC_DISABLED, nor AUC_UNSET
477c478bd9Sstevel@tonic-gate  * are returned on an auditconfig -getcond call.
487c478bd9Sstevel@tonic-gate  */
497c478bd9Sstevel@tonic-gate /* global state */
507c478bd9Sstevel@tonic-gate #define	AUC_DISABLED	-1	/* audit module loaded but not enabled */
517c478bd9Sstevel@tonic-gate #define	AUC_UNSET	0	/* on/off hasn't been decided */
527c478bd9Sstevel@tonic-gate #define	AUC_ENABLED	1	/* loaded and enabled */
537c478bd9Sstevel@tonic-gate /* local zone state */
547c478bd9Sstevel@tonic-gate #define	AUC_INIT_AUDIT	4	/* c2audit is ready but auditd has not run */
557c478bd9Sstevel@tonic-gate #define	AUC_AUDITING	1	/* auditing is being done */
567c478bd9Sstevel@tonic-gate #define	AUC_NOAUDIT	2	/* auditing is not being done */
577c478bd9Sstevel@tonic-gate #define	AUC_NOSPACE	3	/* audit enabled, no space for audit records */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * The user id -2 is never audited - in fact, a setauid(AU_NOAUDITID)
617c478bd9Sstevel@tonic-gate  * will turn off auditing.
627c478bd9Sstevel@tonic-gate  */
63f48205beScasper #define	AU_NOAUDITID	((au_id_t)-2)
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * success/failure bits for asynchronous events
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	AUM_SUCC	1	/* use the system success preselection mask */
707c478bd9Sstevel@tonic-gate #define	AUM_FAIL	2	/* use the system failure preselection mask */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate /*
747c478bd9Sstevel@tonic-gate  * Defines for event modifier field
757c478bd9Sstevel@tonic-gate  */
767c478bd9Sstevel@tonic-gate #define	PAD_READ	0x0001		/* object read */
777c478bd9Sstevel@tonic-gate #define	PAD_WRITE	0x0002		/* object write */
787c478bd9Sstevel@tonic-gate #define	PAD_NONATTR	0x4000		/* non-attributable event */
797c478bd9Sstevel@tonic-gate #define	PAD_FAILURE	0x8000		/* fail audit event */
807c478bd9Sstevel@tonic-gate #define	PAD_SPRIVUSE	0x0080		/* successfully used privileged */
817c478bd9Sstevel@tonic-gate #define	PAD_FPRIVUSE	0x0100		/* failed use of privileged */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * Some typedefs for the fundamentals
857c478bd9Sstevel@tonic-gate  */
86d0fa49b7STony Nguyen typedef uint_t au_asid_t;
877c478bd9Sstevel@tonic-gate typedef uint_t  au_class_t;
88d0fa49b7STony Nguyen typedef ushort_t au_event_t;
89d0fa49b7STony Nguyen typedef ushort_t au_emod_t;
907c478bd9Sstevel@tonic-gate typedef uid_t au_id_t;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate /*
937c478bd9Sstevel@tonic-gate  * An audit event mask.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #define	AU_MASK_ALL	0xFFFFFFFF	/* all bits on for unsigned int */
967c478bd9Sstevel@tonic-gate #define	AU_MASK_NONE	0x0		/* all bits off = no:invalid class */
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate struct au_mask {
997c478bd9Sstevel@tonic-gate 	unsigned int	am_success;	/* success bits */
1007c478bd9Sstevel@tonic-gate 	unsigned int	am_failure;	/* failure bits */
1017c478bd9Sstevel@tonic-gate };
1027c478bd9Sstevel@tonic-gate typedef struct au_mask au_mask_t;
1037c478bd9Sstevel@tonic-gate #define	as_success am_success
1047c478bd9Sstevel@tonic-gate #define	as_failure am_failure
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * The structure of the terminal ID (ipv4)
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate struct au_tid {
1107c478bd9Sstevel@tonic-gate 	dev_t port;
1117c478bd9Sstevel@tonic-gate 	uint_t machine;
1127c478bd9Sstevel@tonic-gate };
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1157c478bd9Sstevel@tonic-gate struct au_tid32 {
1167c478bd9Sstevel@tonic-gate 	uint_t port;
1177c478bd9Sstevel@tonic-gate 	uint_t machine;
1187c478bd9Sstevel@tonic-gate };
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate typedef struct au_tid32 au_tid32_t;
1217c478bd9Sstevel@tonic-gate #endif
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate typedef struct au_tid au_tid_t;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * The structure of the terminal ID (ipv6)
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate struct au_tid_addr {
1297c478bd9Sstevel@tonic-gate 	dev_t  at_port;
1307c478bd9Sstevel@tonic-gate 	uint_t at_type;
1317c478bd9Sstevel@tonic-gate 	uint_t at_addr[4];
1327c478bd9Sstevel@tonic-gate };
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate struct au_port_s {
1357c478bd9Sstevel@tonic-gate 	uint32_t at_major;	/* major # */
1367c478bd9Sstevel@tonic-gate 	uint32_t at_minor;	/* minor # */
1377c478bd9Sstevel@tonic-gate };
1387c478bd9Sstevel@tonic-gate typedef struct au_port_s au_port_t;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate struct au_tid_addr64 {
1417c478bd9Sstevel@tonic-gate 	au_port_t	at_port;
1427c478bd9Sstevel@tonic-gate 	uint_t		at_type;
1437c478bd9Sstevel@tonic-gate 	uint_t		at_addr[4];
1447c478bd9Sstevel@tonic-gate };
1457c478bd9Sstevel@tonic-gate typedef struct au_tid_addr64 au_tid64_addr_t;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
1487c478bd9Sstevel@tonic-gate struct au_tid_addr32 {
1497c478bd9Sstevel@tonic-gate 	uint_t at_port;
1507c478bd9Sstevel@tonic-gate 	uint_t at_type;
1517c478bd9Sstevel@tonic-gate 	uint_t at_addr[4];
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate typedef struct au_tid_addr32 au_tid32_addr_t;
1557c478bd9Sstevel@tonic-gate #endif
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate typedef struct au_tid_addr au_tid_addr_t;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate struct au_ip {
1607c478bd9Sstevel@tonic-gate 	uint16_t	at_r_port;	/* remote port */
1617c478bd9Sstevel@tonic-gate 	uint16_t	at_l_port;	/* local port */
1627c478bd9Sstevel@tonic-gate 	uint32_t	at_type;	/* AU_IPv4,... */
1637c478bd9Sstevel@tonic-gate 	uint32_t	at_addr[4];	/* remote IP */
1647c478bd9Sstevel@tonic-gate };
1657c478bd9Sstevel@tonic-gate typedef struct au_ip au_ip_t;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate /*
1687c478bd9Sstevel@tonic-gate  * Generic network address structure
1697c478bd9Sstevel@tonic-gate  */
1707c478bd9Sstevel@tonic-gate struct au_generic_tid {
1717c478bd9Sstevel@tonic-gate 	uchar_t	gt_type;	/* AU_IPADR, AU_DEVICE,... */
1727c478bd9Sstevel@tonic-gate 	union {
1737c478bd9Sstevel@tonic-gate 		au_ip_t		at_ip;
1747c478bd9Sstevel@tonic-gate 		au_port_t	at_dev;
1757c478bd9Sstevel@tonic-gate 	} gt_adr;
1767c478bd9Sstevel@tonic-gate };
1777c478bd9Sstevel@tonic-gate typedef struct au_generic_tid au_generic_tid_t;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate /*
1807c478bd9Sstevel@tonic-gate  * au_generic_tid_t gt_type values
1817c478bd9Sstevel@tonic-gate  * 0 is reserved for uninitialized data
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate #define	AU_IPADR	1
1847c478bd9Sstevel@tonic-gate #define	AU_ETHER	2
1857c478bd9Sstevel@tonic-gate #define	AU_DEVICE	3
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate  * at_type values - address length used to identify address type
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate #define	AU_IPv4 4	/* ipv4 type IP address */
1917c478bd9Sstevel@tonic-gate #define	AU_IPv6 16	/* ipv6 type IP address */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * Compatability with SunOS 4.x BSM module
1957c478bd9Sstevel@tonic-gate  *
1967c478bd9Sstevel@tonic-gate  * New code should not contain audit_state_t,
1977c478bd9Sstevel@tonic-gate  * au_state_t, nor au_termid as these types
1987c478bd9Sstevel@tonic-gate  * may go away in future releases.
1997c478bd9Sstevel@tonic-gate  *
2007c478bd9Sstevel@tonic-gate  * typedef new-5.x-bsm-name old-4.x-bsm-name
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate typedef au_class_t au_state_t;
2047c478bd9Sstevel@tonic-gate typedef au_mask_t audit_state_t;
2057c478bd9Sstevel@tonic-gate typedef au_id_t auid_t;
2067c478bd9Sstevel@tonic-gate #define	ai_state ai_mask;
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate /*
2097c478bd9Sstevel@tonic-gate  * Opcodes for bsm system calls
2107c478bd9Sstevel@tonic-gate  */
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate #define	BSM_GETAUID		19
2137c478bd9Sstevel@tonic-gate #define	BSM_SETAUID		20
2147c478bd9Sstevel@tonic-gate #define	BSM_GETAUDIT		21
2157c478bd9Sstevel@tonic-gate #define	BSM_SETAUDIT		22
216469aa27fSJan Friedel /*				23	OBSOLETE */
217469aa27fSJan Friedel /*				24	OBSOLETE */
2187c478bd9Sstevel@tonic-gate #define	BSM_AUDIT		25
219731b94c1Stz /* 				26	OBSOLETE */
220787b48eaSgww /* 				27	EOL announced for Sol 10 */
221*ddc42f88SMarek Pospisil /*				28	OBSOLETE */
2227c478bd9Sstevel@tonic-gate #define	BSM_AUDITCTL		29
223469aa27fSJan Friedel /*				30	OBSOLETE */
224469aa27fSJan Friedel /*				31	OBSOLETE */
225469aa27fSJan Friedel /*				32	OBSOLETE */
226469aa27fSJan Friedel /*				33	OBSOLETE */
227469aa27fSJan Friedel /*				34	OBSOLETE */
2287c478bd9Sstevel@tonic-gate #define	BSM_GETAUDIT_ADDR	35
2297c478bd9Sstevel@tonic-gate #define	BSM_SETAUDIT_ADDR	36
2307c478bd9Sstevel@tonic-gate #define	BSM_AUDITDOOR		37
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * Auditctl(2) commands
2347c478bd9Sstevel@tonic-gate  */
2357c478bd9Sstevel@tonic-gate #define	A_GETPOLICY	2	/* get audit policy */
2367c478bd9Sstevel@tonic-gate #define	A_SETPOLICY	3	/* set audit policy */
2377c478bd9Sstevel@tonic-gate #define	A_GETKMASK	4	/* get kernel event preselection mask */
2387c478bd9Sstevel@tonic-gate #define	A_SETKMASK	5	/* set kernel event preselection mask */
2397c478bd9Sstevel@tonic-gate #define	A_GETQCTRL	6	/* get kernel audit queue ctrl parameters */
2407c478bd9Sstevel@tonic-gate #define	A_SETQCTRL	7	/* set kernel audit queue ctrl parameters */
2417c478bd9Sstevel@tonic-gate #define	A_GETCWD	8	/* get process current working directory */
2427c478bd9Sstevel@tonic-gate #define	A_GETCAR	9	/* get process current active root */
2437c478bd9Sstevel@tonic-gate #define	A_GETSTAT	12	/* get audit statistics */
2447c478bd9Sstevel@tonic-gate #define	A_SETSTAT	13	/* (re)set audit statistics */
2457c478bd9Sstevel@tonic-gate #define	A_SETUMASK	14	/* set preselection mask for procs with auid */
2467c478bd9Sstevel@tonic-gate #define	A_SETSMASK	15	/* set preselection mask for procs with asid */
2477c478bd9Sstevel@tonic-gate #define	A_GETCOND	20	/* get audit system on/off condition */
2487c478bd9Sstevel@tonic-gate #define	A_SETCOND	21	/* set audit system on/off condition */
2497c478bd9Sstevel@tonic-gate #define	A_GETCLASS	22	/* get audit event to class mapping */
2507c478bd9Sstevel@tonic-gate #define	A_SETCLASS	23	/* set audit event to class mapping */
2517c478bd9Sstevel@tonic-gate #define	A_GETPINFO	24	/* get audit info for an arbitrary pid */
2527c478bd9Sstevel@tonic-gate #define	A_SETPMASK	25	/* set preselection mask for an given pid */
2537c478bd9Sstevel@tonic-gate #define	A_GETPINFO_ADDR	28	/* get audit info for an arbitrary pid */
2547c478bd9Sstevel@tonic-gate #define	A_GETKAUDIT	29	/* get kernel audit characteristics */
2557c478bd9Sstevel@tonic-gate #define	A_SETKAUDIT	30	/* set kernel audit characteristics */
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /*
2587c478bd9Sstevel@tonic-gate  * Audit Policy parameters (32 bits)
2597c478bd9Sstevel@tonic-gate  */
2607c478bd9Sstevel@tonic-gate #define	AUDIT_CNT	0x0001	/* do NOT sleep undelivered synch events */
2617c478bd9Sstevel@tonic-gate #define	AUDIT_AHLT	0x0002	/* HALT machine on undelivered async event */
2627c478bd9Sstevel@tonic-gate #define	AUDIT_ARGV	0x0004	/* include argv with execv system call events */
2637c478bd9Sstevel@tonic-gate #define	AUDIT_ARGE	0x0008	/* include arge with execv system call events */
2647bce2ddcSgww #define	AUDIT_SEQ	0x0010	/* include sequence attribute */
2657bce2ddcSgww #define	AUDIT_WINDATA	0x0020	/* include interwindow moved data */
266731b94c1Stz #define	AUDIT_GROUP	0x0040	/* include group attribute with each record */
267731b94c1Stz #define	AUDIT_TRAIL	0x0080	/* include trailer token */
268731b94c1Stz #define	AUDIT_PATH	0x0100	/* allow multiple paths per event */
269731b94c1Stz #define	AUDIT_SCNT	0x0200	/* sleep user events but not kernel events */
270731b94c1Stz #define	AUDIT_PUBLIC	0x0400	/* audit even "public" files */
271731b94c1Stz #define	AUDIT_ZONENAME	0x0800	/* emit zonename token */
272731b94c1Stz #define	AUDIT_PERZONE	0x1000	/* auditd and audit queue for each zone */
273731b94c1Stz #define	AUDIT_WINDATA_DOWN	0x2000	/* include paste downgraded data */
274731b94c1Stz #define	AUDIT_WINDATA_UP	0x4000	/* include paste upgraded data */
27545916cd2Sjpk 
2767c478bd9Sstevel@tonic-gate /*
2777c478bd9Sstevel@tonic-gate  * If AUDIT_GLOBAL changes, corresponding changes are required in
2787c478bd9Sstevel@tonic-gate  * audit_syscalls.c's setpolicy().
2797c478bd9Sstevel@tonic-gate  */
2807c478bd9Sstevel@tonic-gate #define	AUDIT_GLOBAL	(AUDIT_AHLT | AUDIT_PERZONE)
2817c478bd9Sstevel@tonic-gate #define	AUDIT_LOCAL	(AUDIT_CNT | AUDIT_ARGV | AUDIT_ARGE |\
282731b94c1Stz 			AUDIT_SEQ | AUDIT_WINDATA |\
2837bce2ddcSgww 			AUDIT_GROUP | AUDIT_TRAIL | AUDIT_PATH |\
28445916cd2Sjpk 			AUDIT_PUBLIC | AUDIT_SCNT | AUDIT_ZONENAME |\
28545916cd2Sjpk 			AUDIT_WINDATA_DOWN | AUDIT_WINDATA_UP)
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate /*
2887c478bd9Sstevel@tonic-gate  * Kernel audit queue control parameters
2897c478bd9Sstevel@tonic-gate  *
2907c478bd9Sstevel@tonic-gate  *	audit record recording blocks at hiwater # undelived records
2917c478bd9Sstevel@tonic-gate  *	audit record recording resumes at lowwater # undelivered audit records
2927c478bd9Sstevel@tonic-gate  *	bufsz determines how big the data xfers will be to the audit trail
2937c478bd9Sstevel@tonic-gate  */
2947c478bd9Sstevel@tonic-gate struct au_qctrl {
2957c478bd9Sstevel@tonic-gate 	size_t	aq_hiwater;	/* kernel audit queue, high water mark */
2967c478bd9Sstevel@tonic-gate 	size_t	aq_lowater;	/* kernel audit queue, low  water mark */
2977c478bd9Sstevel@tonic-gate 	size_t	aq_bufsz;	/* kernel audit queue, write size to trail */
2987c478bd9Sstevel@tonic-gate 	clock_t	aq_delay;	/* delay before flushing audit queue */
2997c478bd9Sstevel@tonic-gate };
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
3027c478bd9Sstevel@tonic-gate struct au_qctrl32 {
3037c478bd9Sstevel@tonic-gate 	size32_t	aq_hiwater;
3047c478bd9Sstevel@tonic-gate 	size32_t	aq_lowater;
3057c478bd9Sstevel@tonic-gate 	size32_t	aq_bufsz;
3067c478bd9Sstevel@tonic-gate 	clock32_t	aq_delay;
3077c478bd9Sstevel@tonic-gate };
3087c478bd9Sstevel@tonic-gate #endif
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate /*
3127c478bd9Sstevel@tonic-gate  * default values of hiwater and lowater (note hi > lo)
3137c478bd9Sstevel@tonic-gate  */
3147c478bd9Sstevel@tonic-gate #define	AQ_HIWATER  100
3157c478bd9Sstevel@tonic-gate #define	AQ_MAXHIGH  100000
3167c478bd9Sstevel@tonic-gate #define	AQ_LOWATER  10
3177c478bd9Sstevel@tonic-gate #define	AQ_BUFSZ    8192
3187c478bd9Sstevel@tonic-gate #define	AQ_MAXBUFSZ 1048576
3197c478bd9Sstevel@tonic-gate #define	AQ_DELAY    20
3207c478bd9Sstevel@tonic-gate #define	AQ_MAXDELAY 20000
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate struct auditinfo {
3237c478bd9Sstevel@tonic-gate 	au_id_t		ai_auid;
3247c478bd9Sstevel@tonic-gate 	au_mask_t	ai_mask;
3257c478bd9Sstevel@tonic-gate 	au_tid_t	ai_termid;
3267c478bd9Sstevel@tonic-gate 	au_asid_t	ai_asid;
3277c478bd9Sstevel@tonic-gate };
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
3307c478bd9Sstevel@tonic-gate struct auditinfo32 {
3317c478bd9Sstevel@tonic-gate 	au_id_t		ai_auid;
3327c478bd9Sstevel@tonic-gate 	au_mask_t	ai_mask;
3337c478bd9Sstevel@tonic-gate 	au_tid32_t	ai_termid;
3347c478bd9Sstevel@tonic-gate 	au_asid_t	ai_asid;
3357c478bd9Sstevel@tonic-gate };
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate typedef struct auditinfo32 auditinfo32_t;
3387c478bd9Sstevel@tonic-gate #endif
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate typedef struct auditinfo auditinfo_t;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate struct auditinfo_addr {
3437c478bd9Sstevel@tonic-gate 	au_id_t		ai_auid;
3447c478bd9Sstevel@tonic-gate 	au_mask_t	ai_mask;
3457c478bd9Sstevel@tonic-gate 	au_tid_addr_t	ai_termid;
3467c478bd9Sstevel@tonic-gate 	au_asid_t	ai_asid;
3477c478bd9Sstevel@tonic-gate };
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate struct auditinfo_addr64 {
3507c478bd9Sstevel@tonic-gate 	au_id_t		ai_auid;
3517c478bd9Sstevel@tonic-gate 	au_mask_t	ai_mask;
3527c478bd9Sstevel@tonic-gate 	au_tid64_addr_t	ai_termid;
3537c478bd9Sstevel@tonic-gate 	au_asid_t	ai_asid;
3547c478bd9Sstevel@tonic-gate };
3557c478bd9Sstevel@tonic-gate typedef struct auditinfo_addr64 auditinfo64_addr_t;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
3587c478bd9Sstevel@tonic-gate struct auditinfo_addr32 {
3597c478bd9Sstevel@tonic-gate 	au_id_t		ai_auid;
3607c478bd9Sstevel@tonic-gate 	au_mask_t	ai_mask;
3617c478bd9Sstevel@tonic-gate 	au_tid32_addr_t	ai_termid;
3627c478bd9Sstevel@tonic-gate 	au_asid_t	ai_asid;
3637c478bd9Sstevel@tonic-gate };
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate typedef struct auditinfo_addr32 auditinfo32_addr_t;
3667c478bd9Sstevel@tonic-gate #endif
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate typedef struct auditinfo_addr auditinfo_addr_t;
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate struct auditpinfo {
3717c478bd9Sstevel@tonic-gate 	pid_t		ap_pid;
3727c478bd9Sstevel@tonic-gate 	au_id_t		ap_auid;
3737c478bd9Sstevel@tonic-gate 	au_mask_t	ap_mask;
3747c478bd9Sstevel@tonic-gate 	au_tid_t	ap_termid;
3757c478bd9Sstevel@tonic-gate 	au_asid_t	ap_asid;
3767c478bd9Sstevel@tonic-gate };
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
3797c478bd9Sstevel@tonic-gate struct auditpinfo32 {
3807c478bd9Sstevel@tonic-gate 	pid_t		ap_pid;
3817c478bd9Sstevel@tonic-gate 	au_id_t		ap_auid;
3827c478bd9Sstevel@tonic-gate 	au_mask_t	ap_mask;
3837c478bd9Sstevel@tonic-gate 	au_tid32_t	ap_termid;
3847c478bd9Sstevel@tonic-gate 	au_asid_t	ap_asid;
3857c478bd9Sstevel@tonic-gate };
3867c478bd9Sstevel@tonic-gate #endif
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate struct auditpinfo_addr {
3907c478bd9Sstevel@tonic-gate 	pid_t		ap_pid;
3917c478bd9Sstevel@tonic-gate 	au_id_t		ap_auid;
3927c478bd9Sstevel@tonic-gate 	au_mask_t	ap_mask;
3937c478bd9Sstevel@tonic-gate 	au_tid_addr_t	ap_termid;
3947c478bd9Sstevel@tonic-gate 	au_asid_t	ap_asid;
3957c478bd9Sstevel@tonic-gate };
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32)
3987c478bd9Sstevel@tonic-gate struct auditpinfo_addr32 {
3997c478bd9Sstevel@tonic-gate 	pid_t		ap_pid;
4007c478bd9Sstevel@tonic-gate 	au_id_t		ap_auid;
4017c478bd9Sstevel@tonic-gate 	au_mask_t	ap_mask;
4027c478bd9Sstevel@tonic-gate 	au_tid32_addr_t	ap_termid;
4037c478bd9Sstevel@tonic-gate 	au_asid_t	ap_asid;
4047c478bd9Sstevel@tonic-gate };
4057c478bd9Sstevel@tonic-gate #endif
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate struct au_evclass_map {
4097c478bd9Sstevel@tonic-gate 	au_event_t	ec_number;
4107c478bd9Sstevel@tonic-gate 	au_class_t	ec_class;
4117c478bd9Sstevel@tonic-gate };
4127c478bd9Sstevel@tonic-gate typedef struct au_evclass_map au_evclass_map_t;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate /*
4157c478bd9Sstevel@tonic-gate  * Audit stat structures (used to be in audit_stat.h
4167c478bd9Sstevel@tonic-gate  */
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate struct audit_stat {
4197c478bd9Sstevel@tonic-gate 	unsigned int as_version;	/* version of kernel audit code */
4207c478bd9Sstevel@tonic-gate 	unsigned int as_numevent;	/* number of kernel audit events */
4217c478bd9Sstevel@tonic-gate 	uint32_t as_generated;		/* # records processed */
4227c478bd9Sstevel@tonic-gate 	uint32_t as_nonattrib;		/* # non-attributed records produced */
4237c478bd9Sstevel@tonic-gate 	uint32_t as_kernel;		/* # records produced by kernel */
4247c478bd9Sstevel@tonic-gate 	uint32_t as_audit;		/* # records processed by audit(2) */
4257c478bd9Sstevel@tonic-gate 	uint32_t as_auditctl;		/* # records processed by auditctl(2) */
4267c478bd9Sstevel@tonic-gate 	uint32_t as_enqueue;		/* # records put onto audit queue */
4277c478bd9Sstevel@tonic-gate 	uint32_t as_written;		/* # records written to audit trail */
4287c478bd9Sstevel@tonic-gate 	uint32_t as_wblocked;		/* # times write blked on audit queue */
4297c478bd9Sstevel@tonic-gate 	uint32_t as_rblocked;		/* # times read blked on audit queue */
4307c478bd9Sstevel@tonic-gate 	uint32_t as_dropped;		/* # of dropped audit records */
4317c478bd9Sstevel@tonic-gate 	uint32_t as_totalsize;		/* total number bytes of audit data */
4327c478bd9Sstevel@tonic-gate 	uint32_t as_memused;		/* no longer used */
4337c478bd9Sstevel@tonic-gate };
4347c478bd9Sstevel@tonic-gate typedef struct audit_stat au_stat_t;
4357c478bd9Sstevel@tonic-gate 
4369e9e6ab8Spaulson /* get kernel audit context dependent on AUDIT_PERZONE policy */
4379e9e6ab8Spaulson #define	GET_KCTX_PZ	(audit_policy & AUDIT_PERZONE) ?\
4389e9e6ab8Spaulson 			    curproc->p_zone->zone_audit_kctxt :\
4399e9e6ab8Spaulson 			    global_zone->zone_audit_kctxt
4409e9e6ab8Spaulson /* get kernel audit context of global zone */
4419e9e6ab8Spaulson #define	GET_KCTX_GZ	global_zone->zone_audit_kctxt
4429e9e6ab8Spaulson /* get kernel audit context of non-global zone */
4439e9e6ab8Spaulson #define	GET_KCTX_NGZ	curproc->p_zone->zone_audit_kctxt
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate #define	AS_INC(a, b, c) atomic_add_32(&(c->auk_statistics.a), (b))
4467c478bd9Sstevel@tonic-gate #define	AS_DEC(a, b, c) atomic_add_32(&(c->auk_statistics.a), -(b))
4477c478bd9Sstevel@tonic-gate 
4487c478bd9Sstevel@tonic-gate /*
4497c478bd9Sstevel@tonic-gate  * audit token IPC types (shm, sem, msg) [for ipc attribute]
4507c478bd9Sstevel@tonic-gate  */
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate #define	AT_IPC_MSG	((char)1)		/* message IPC id */
4537c478bd9Sstevel@tonic-gate #define	AT_IPC_SEM	((char)2)		/* semaphore IPC id */
4547c478bd9Sstevel@tonic-gate #define	AT_IPC_SHM	((char)3)		/* shared memory IPC id */
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate #endif
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate #include <sys/types.h>
4637c478bd9Sstevel@tonic-gate #include <sys/model.h>
4647c478bd9Sstevel@tonic-gate #include <sys/proc.h>
4657c478bd9Sstevel@tonic-gate #include <sys/stream.h>
4667c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
4677c478bd9Sstevel@tonic-gate #include <sys/file.h>
4687c478bd9Sstevel@tonic-gate #include <sys/pathname.h>
4697c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
4707c478bd9Sstevel@tonic-gate #include <sys/systm.h>
4717c478bd9Sstevel@tonic-gate #include <netinet/in.h>
4727c478bd9Sstevel@tonic-gate #include <c2/audit_door_infc.h>
4737c478bd9Sstevel@tonic-gate #include <sys/crypto/ioctladmin.h>
474799bd290Spwernau #include <sys/netstack.h>
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate #ifdef __cplusplus
4777c478bd9Sstevel@tonic-gate extern "C" {
4787c478bd9Sstevel@tonic-gate #endif
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate struct fcntla;
4817c478bd9Sstevel@tonic-gate struct t_audit_data;
4827c478bd9Sstevel@tonic-gate struct audit_path;
4837c478bd9Sstevel@tonic-gate struct priv_set;
4847c478bd9Sstevel@tonic-gate struct devplcysys;
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate struct auditcalls {
4877c478bd9Sstevel@tonic-gate 	long	code;
4887c478bd9Sstevel@tonic-gate 	long	a1;
4897c478bd9Sstevel@tonic-gate 	long	a2;
4907c478bd9Sstevel@tonic-gate 	long	a3;
4917c478bd9Sstevel@tonic-gate 	long	a4;
4927c478bd9Sstevel@tonic-gate 	long	a5;
4937c478bd9Sstevel@tonic-gate };
4947c478bd9Sstevel@tonic-gate 
4957c478bd9Sstevel@tonic-gate int	audit(caddr_t, int);
4967c478bd9Sstevel@tonic-gate int	_audit(caddr_t, int);
4977c478bd9Sstevel@tonic-gate int	auditsys(struct auditcalls *, union rval *); /* fake stub */
4987c478bd9Sstevel@tonic-gate int	_auditsys(struct auditcalls *, union rval *); /* real deal */
4997c478bd9Sstevel@tonic-gate void	audit_cryptoadm(int, char *, crypto_mech_name_t *,
5007c478bd9Sstevel@tonic-gate 	    uint_t, uint_t, uint32_t, int);
5017c478bd9Sstevel@tonic-gate void	audit_init(void);
5027c478bd9Sstevel@tonic-gate void	audit_newproc(struct proc *);
5037c478bd9Sstevel@tonic-gate void	audit_pfree(struct proc *);
5047c478bd9Sstevel@tonic-gate void	audit_thread_create(kthread_id_t);
5057c478bd9Sstevel@tonic-gate void	audit_thread_free(kthread_id_t);
5067c478bd9Sstevel@tonic-gate int	audit_savepath(struct pathname *, struct vnode *, int, cred_t *);
5077c478bd9Sstevel@tonic-gate void	audit_addcomponent(struct pathname *);
5087c478bd9Sstevel@tonic-gate void	audit_anchorpath(struct pathname *, int);
5097c478bd9Sstevel@tonic-gate void	audit_symlink(struct pathname *, struct pathname *);
5107c478bd9Sstevel@tonic-gate void	audit_symlink_create(struct vnode *, char *, char *, int);
5117c478bd9Sstevel@tonic-gate int	file_is_public(struct vattr *);
5127c478bd9Sstevel@tonic-gate void	audit_attributes(struct vnode *);
5137c478bd9Sstevel@tonic-gate void	audit_falloc(struct file *);
5147c478bd9Sstevel@tonic-gate void	audit_unfalloc(struct file *);
5157c478bd9Sstevel@tonic-gate void	audit_exit(int, int);
5167c478bd9Sstevel@tonic-gate void	audit_core_start(int);
5177c478bd9Sstevel@tonic-gate void	audit_core_finish(int);
5187c478bd9Sstevel@tonic-gate void	audit_stropen(struct vnode *, dev_t *, int, struct cred *);
5197c478bd9Sstevel@tonic-gate void	audit_strclose(struct vnode *, int, struct cred *);
5207c478bd9Sstevel@tonic-gate void	audit_strioctl(struct vnode *, int, intptr_t, int, int, struct cred *,
5217c478bd9Sstevel@tonic-gate 		int *);
5227c478bd9Sstevel@tonic-gate void	audit_strgetmsg(struct vnode *, struct strbuf *, struct strbuf *,
5237c478bd9Sstevel@tonic-gate 		unsigned char *, int *, int);
5247c478bd9Sstevel@tonic-gate void	audit_strputmsg(struct vnode *, struct strbuf *, struct strbuf *,
5257c478bd9Sstevel@tonic-gate 		unsigned char, int, int);
5267c478bd9Sstevel@tonic-gate void	audit_closef(struct file *);
5277c478bd9Sstevel@tonic-gate int	audit_getf(int);
5287c478bd9Sstevel@tonic-gate void	audit_setf(struct file *, int);
5297c478bd9Sstevel@tonic-gate void	audit_copen(int, struct file *, struct vnode *);
5307c478bd9Sstevel@tonic-gate void	audit_reboot(void);
5317c478bd9Sstevel@tonic-gate void	audit_vncreate_start(void);
5327c478bd9Sstevel@tonic-gate void	audit_setfsat_path(int argnum);
5337c478bd9Sstevel@tonic-gate void	audit_vncreate_finish(struct vnode *, int);
5347c478bd9Sstevel@tonic-gate void	audit_exec(const char *, const char *, ssize_t, ssize_t);
5357c478bd9Sstevel@tonic-gate void	audit_enterprom(int);
5367c478bd9Sstevel@tonic-gate void	audit_exitprom(int);
5377c478bd9Sstevel@tonic-gate void	audit_chdirec(struct vnode *, struct vnode **);
5387c478bd9Sstevel@tonic-gate void	audit_sock(int, struct queue *, struct msgb *, int);
5397c478bd9Sstevel@tonic-gate void	audit_free(void);
5407c478bd9Sstevel@tonic-gate int	audit_start(unsigned int, unsigned int, int, klwp_t *);
5417c478bd9Sstevel@tonic-gate void	audit_finish(unsigned int, unsigned int, int, union rval *);
542d0fa49b7STony Nguyen int	audit_async_start(label_t *, au_event_t, int);
543d0fa49b7STony Nguyen void	audit_async_finish(caddr_t *, au_event_t, au_emod_t);
5447c478bd9Sstevel@tonic-gate void	audit_async_discard_backend(void *);
5457c478bd9Sstevel@tonic-gate void	audit_async_done(caddr_t *, int);
5467c478bd9Sstevel@tonic-gate void	audit_async_drop(caddr_t *, int);
5477c478bd9Sstevel@tonic-gate 
5487c478bd9Sstevel@tonic-gate #ifndef AUK_CONTEXT_T
5497c478bd9Sstevel@tonic-gate #define	AUK_CONTEXT_T
5507c478bd9Sstevel@tonic-gate typedef struct au_kcontext au_kcontext_t;
5517c478bd9Sstevel@tonic-gate #endif
5527c478bd9Sstevel@tonic-gate 
553799bd290Spwernau int	audit_success(au_kcontext_t *, struct t_audit_data *, int, cred_t *);
5547c478bd9Sstevel@tonic-gate int	auditme(au_kcontext_t *, struct t_audit_data *, au_state_t);
5557c478bd9Sstevel@tonic-gate void	audit_fixpath(struct audit_path *, int);
5567c478bd9Sstevel@tonic-gate void	audit_ipc(int, int, void *);
5577c478bd9Sstevel@tonic-gate void	audit_ipcget(int, void *);
5587c478bd9Sstevel@tonic-gate void	audit_lookupname();
5597c478bd9Sstevel@tonic-gate int	audit_pathcomp(struct pathname *, vnode_t *, cred_t *);
5607c478bd9Sstevel@tonic-gate void	audit_fdsend(int, struct file *, int);
5617c478bd9Sstevel@tonic-gate void	audit_fdrecv(int, struct file *);
5627c478bd9Sstevel@tonic-gate int	audit_c2_revoke(struct fcntla *, rval_t *);
5637c478bd9Sstevel@tonic-gate void	audit_priv(int, const struct priv_set *, int);
5647c478bd9Sstevel@tonic-gate void	audit_setppriv(int, int, const struct priv_set *, const cred_t *);
5657c478bd9Sstevel@tonic-gate void	audit_devpolicy(int, const struct devplcysys *);
5667c478bd9Sstevel@tonic-gate void	audit_update_context(proc_t *, cred_t *);
567c28749e9Skais void	audit_kssl(int, void *, int);
568799bd290Spwernau void	audit_pf_policy(int, cred_t *, netstack_t *, char *, boolean_t, int,
569799bd290Spwernau     pid_t);
57045916cd2Sjpk void	audit_sec_attributes(caddr_t *, struct vnode *);
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate #endif
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate #ifdef __cplusplus
5757c478bd9Sstevel@tonic-gate }
5767c478bd9Sstevel@tonic-gate #endif
5777c478bd9Sstevel@tonic-gate 
5787c478bd9Sstevel@tonic-gate #endif /* _BSM_AUDIT_H */
579