1f6d4a8a7SRobert Watson /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4f4f93a63SRobert Watson * Copyright (c) 1999-2009 Apple Inc. 52ddefb6dSRobert Watson * Copyright (c) 2016, 2018 Robert N. M. Watson 6718c8510SRobert Watson * All rights reserved. 7718c8510SRobert Watson * 8759c8caaSRobert Watson * Portions of this software were developed by BAE Systems, the University of 9759c8caaSRobert Watson * Cambridge Computer Laboratory, and Memorial University under DARPA/AFRL 10759c8caaSRobert Watson * contract FA8650-15-C-7558 ("CADETS"), as part of the DARPA Transparent 11759c8caaSRobert Watson * Computing (TC) research program. 12759c8caaSRobert Watson * 13718c8510SRobert Watson * Redistribution and use in source and binary forms, with or without 14718c8510SRobert Watson * modification, are permitted provided that the following conditions 15718c8510SRobert Watson * are met: 16718c8510SRobert Watson * 1. Redistributions of source code must retain the above copyright 17718c8510SRobert Watson * notice, this list of conditions and the following disclaimer. 18718c8510SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 19718c8510SRobert Watson * notice, this list of conditions and the following disclaimer in the 20718c8510SRobert Watson * documentation and/or other materials provided with the distribution. 21bc9a43d6SRobert Watson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 22718c8510SRobert Watson * its contributors may be used to endorse or promote products derived 23718c8510SRobert Watson * from this software without specific prior written permission. 24718c8510SRobert Watson * 25718c8510SRobert Watson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 26718c8510SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27718c8510SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28718c8510SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 29718c8510SRobert Watson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30718c8510SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31718c8510SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32718c8510SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33718c8510SRobert Watson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 34718c8510SRobert Watson * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35718c8510SRobert Watson * POSSIBILITY OF SUCH DAMAGE. 36718c8510SRobert Watson */ 37718c8510SRobert Watson 38718c8510SRobert Watson /* 39718c8510SRobert Watson * This include file contains function prototypes and type definitions used 40718c8510SRobert Watson * within the audit implementation. 41718c8510SRobert Watson */ 42718c8510SRobert Watson 4317363e6dSRobert Watson #ifndef _SECURITY_AUDIT_PRIVATE_H_ 4417363e6dSRobert Watson #define _SECURITY_AUDIT_PRIVATE_H_ 45718c8510SRobert Watson 46718c8510SRobert Watson #ifndef _KERNEL 47718c8510SRobert Watson #error "no user-serviceable parts inside" 48718c8510SRobert Watson #endif 49718c8510SRobert Watson 507008be5bSPawel Jakub Dawidek #include <sys/caprights.h> 51718c8510SRobert Watson #include <sys/ipc.h> 52718c8510SRobert Watson #include <sys/socket.h> 53718c8510SRobert Watson #include <sys/ucred.h> 54718c8510SRobert Watson 55718c8510SRobert Watson #ifdef MALLOC_DECLARE 56718c8510SRobert Watson MALLOC_DECLARE(M_AUDITBSM); 57718c8510SRobert Watson MALLOC_DECLARE(M_AUDITDATA); 58718c8510SRobert Watson MALLOC_DECLARE(M_AUDITPATH); 59718c8510SRobert Watson MALLOC_DECLARE(M_AUDITTEXT); 6086120afaSStacey Son MALLOC_DECLARE(M_AUDITGIDSET); 61718c8510SRobert Watson #endif 62718c8510SRobert Watson 63718c8510SRobert Watson /* 64871499feSRobert Watson * Audit control variables that are usually set/read via system calls and 65871499feSRobert Watson * used to control various aspects of auditing. 66718c8510SRobert Watson */ 67718c8510SRobert Watson extern struct au_qctrl audit_qctrl; 68718c8510SRobert Watson extern struct audit_fstat audit_fstat; 69718c8510SRobert Watson extern struct au_mask audit_nae_mask; 70718c8510SRobert Watson extern int audit_panic_on_write_fail; 71718c8510SRobert Watson extern int audit_fail_stop; 72ae1078d6SWayne Salamon extern int audit_argv; 73ae1078d6SWayne Salamon extern int audit_arge; 74718c8510SRobert Watson 75718c8510SRobert Watson /* 76718c8510SRobert Watson * Success/failure conditions for the conversion of a kernel audit record to 77718c8510SRobert Watson * BSM format. 78718c8510SRobert Watson */ 79718c8510SRobert Watson #define BSM_SUCCESS 0 80718c8510SRobert Watson #define BSM_FAILURE 1 81718c8510SRobert Watson #define BSM_NOAUDIT 2 82718c8510SRobert Watson 83718c8510SRobert Watson /* 84e257c20eSRobert Watson * Defines for the kernel audit record k_ar_commit field. Flags are set to 85e257c20eSRobert Watson * indicate what sort of record it is, and which preselection mechanism 86e257c20eSRobert Watson * selected it. 87718c8510SRobert Watson */ 88718c8510SRobert Watson #define AR_COMMIT_KERNEL 0x00000001U 89718c8510SRobert Watson #define AR_COMMIT_USER 0x00000010U 90718c8510SRobert Watson 91e257c20eSRobert Watson #define AR_PRESELECT_TRAIL 0x00001000U 92e257c20eSRobert Watson #define AR_PRESELECT_PIPE 0x00002000U 93e257c20eSRobert Watson 94f07b8369SChristian S.J. Peron #define AR_PRESELECT_USER_TRAIL 0x00004000U 95f07b8369SChristian S.J. Peron #define AR_PRESELECT_USER_PIPE 0x00008000U 96f07b8369SChristian S.J. Peron 971811d6bfSRobert Watson #define AR_PRESELECT_DTRACE 0x00010000U 981811d6bfSRobert Watson 99718c8510SRobert Watson /* 100718c8510SRobert Watson * Audit data is generated as a stream of struct audit_record structures, 101718c8510SRobert Watson * linked by struct kaudit_record, and contain storage for possible audit so 102718c8510SRobert Watson * that it will not need to be allocated during the processing of a system 103718c8510SRobert Watson * call, both improving efficiency and avoiding sleeping at untimely moments. 104718c8510SRobert Watson * This structure is converted to BSM format before being written to disk. 105718c8510SRobert Watson */ 106718c8510SRobert Watson struct vnode_au_info { 107718c8510SRobert Watson mode_t vn_mode; 108718c8510SRobert Watson uid_t vn_uid; 109718c8510SRobert Watson gid_t vn_gid; 11069921123SKonstantin Belousov u_int32_t vn_dev; /* XXX dev_t compatibility */ 11169921123SKonstantin Belousov long vn_fsid; /* XXX uint64_t compatibility */ 11269921123SKonstantin Belousov long vn_fileid; /* XXX ino_t compatibility */ 113718c8510SRobert Watson long vn_gen; 114718c8510SRobert Watson }; 115718c8510SRobert Watson 116718c8510SRobert Watson struct groupset { 11786120afaSStacey Son gid_t *gidset; 118718c8510SRobert Watson u_int gidset_size; 119718c8510SRobert Watson }; 120718c8510SRobert Watson 121718c8510SRobert Watson struct socket_au_info { 122718c8510SRobert Watson int so_domain; 123718c8510SRobert Watson int so_type; 124718c8510SRobert Watson int so_protocol; 125871499feSRobert Watson in_addr_t so_raddr; /* Remote address if INET socket. */ 126871499feSRobert Watson in_addr_t so_laddr; /* Local address if INET socket. */ 127871499feSRobert Watson u_short so_rport; /* Remote port. */ 128871499feSRobert Watson u_short so_lport; /* Local port. */ 129718c8510SRobert Watson }; 130718c8510SRobert Watson 1314df4e335SRobert Watson /* 1324df4e335SRobert Watson * The following is used for A_OLDSETQCTRL and AU_OLDGETQCTRL and a 64-bit 1334df4e335SRobert Watson * userland. 1344df4e335SRobert Watson */ 1354df4e335SRobert Watson struct au_qctrl64 { 1364df4e335SRobert Watson u_int64_t aq64_hiwater; 1374df4e335SRobert Watson u_int64_t aq64_lowater; 1384df4e335SRobert Watson u_int64_t aq64_bufsz; 1394df4e335SRobert Watson u_int64_t aq64_delay; 1404df4e335SRobert Watson u_int64_t aq64_minfree; 1414df4e335SRobert Watson }; 1424df4e335SRobert Watson typedef struct au_qctrl64 au_qctrl64_t; 1434df4e335SRobert Watson 144718c8510SRobert Watson union auditon_udata { 145718c8510SRobert Watson char *au_path; 1464df4e335SRobert Watson int au_cond; 1474df4e335SRobert Watson int au_flags; 1484df4e335SRobert Watson int au_policy; 149718c8510SRobert Watson int au_trigger; 1504df4e335SRobert Watson int64_t au_cond64; 1514df4e335SRobert Watson int64_t au_policy64; 152718c8510SRobert Watson au_evclass_map_t au_evclass; 153718c8510SRobert Watson au_mask_t au_mask; 154718c8510SRobert Watson auditinfo_t au_auinfo; 155718c8510SRobert Watson auditpinfo_t au_aupinfo; 156718c8510SRobert Watson auditpinfo_addr_t au_aupinfo_addr; 157718c8510SRobert Watson au_qctrl_t au_qctrl; 1584df4e335SRobert Watson au_qctrl64_t au_qctrl64; 159718c8510SRobert Watson au_stat_t au_stat; 160718c8510SRobert Watson au_fstat_t au_fstat; 161ffbcef5aSChristian S.J. Peron auditinfo_addr_t au_kau_info; 162759c8caaSRobert Watson au_evname_map_t au_evname; 163718c8510SRobert Watson }; 164718c8510SRobert Watson 165718c8510SRobert Watson struct posix_ipc_perm { 166718c8510SRobert Watson uid_t pipc_uid; 167718c8510SRobert Watson gid_t pipc_gid; 168718c8510SRobert Watson mode_t pipc_mode; 169718c8510SRobert Watson }; 170718c8510SRobert Watson 171718c8510SRobert Watson struct audit_record { 172718c8510SRobert Watson /* Audit record header. */ 173718c8510SRobert Watson u_int32_t ar_magic; 174718c8510SRobert Watson int ar_event; 175718c8510SRobert Watson int ar_retval; /* value returned to the process */ 176718c8510SRobert Watson int ar_errno; /* return status of system call */ 177718c8510SRobert Watson struct timespec ar_starttime; 178718c8510SRobert Watson struct timespec ar_endtime; 179718c8510SRobert Watson u_int64_t ar_valid_arg; /* Bitmask of valid arguments */ 180718c8510SRobert Watson 181718c8510SRobert Watson /* Audit subject information. */ 182718c8510SRobert Watson struct xucred ar_subj_cred; 183718c8510SRobert Watson uid_t ar_subj_ruid; 184718c8510SRobert Watson gid_t ar_subj_rgid; 185718c8510SRobert Watson gid_t ar_subj_egid; 186718c8510SRobert Watson uid_t ar_subj_auid; /* Audit user ID */ 187718c8510SRobert Watson pid_t ar_subj_asid; /* Audit session ID */ 188718c8510SRobert Watson pid_t ar_subj_pid; 189718c8510SRobert Watson struct au_tid ar_subj_term; 190f0cbfcc4SChristian S.J. Peron struct au_tid_addr ar_subj_term_addr; 191718c8510SRobert Watson struct au_mask ar_subj_amask; 192718c8510SRobert Watson 193718c8510SRobert Watson /* Operation arguments. */ 194718c8510SRobert Watson uid_t ar_arg_euid; 195718c8510SRobert Watson uid_t ar_arg_ruid; 196718c8510SRobert Watson uid_t ar_arg_suid; 197718c8510SRobert Watson gid_t ar_arg_egid; 198718c8510SRobert Watson gid_t ar_arg_rgid; 199718c8510SRobert Watson gid_t ar_arg_sgid; 200718c8510SRobert Watson pid_t ar_arg_pid; 201718c8510SRobert Watson pid_t ar_arg_asid; 202718c8510SRobert Watson struct au_tid ar_arg_termid; 203f0cbfcc4SChristian S.J. Peron struct au_tid_addr ar_arg_termid_addr; 204718c8510SRobert Watson uid_t ar_arg_uid; 205718c8510SRobert Watson uid_t ar_arg_auid; 206718c8510SRobert Watson gid_t ar_arg_gid; 207718c8510SRobert Watson struct groupset ar_arg_groups; 208718c8510SRobert Watson int ar_arg_fd; 209e4b4bbb6SRobert Watson int ar_arg_atfd1; 210e4b4bbb6SRobert Watson int ar_arg_atfd2; 211718c8510SRobert Watson int ar_arg_fflags; 212718c8510SRobert Watson mode_t ar_arg_mode; 21369921123SKonstantin Belousov int ar_arg_dev; /* XXX dev_t compatibility */ 214718c8510SRobert Watson long ar_arg_value; 215718c8510SRobert Watson void *ar_arg_addr; 216718c8510SRobert Watson int ar_arg_len; 217718c8510SRobert Watson int ar_arg_mask; 218718c8510SRobert Watson u_int ar_arg_signum; 219718c8510SRobert Watson char ar_arg_login[MAXLOGNAME]; 220718c8510SRobert Watson int ar_arg_ctlname[CTL_MAXNAME]; 221718c8510SRobert Watson struct socket_au_info ar_arg_sockinfo; 222718c8510SRobert Watson char *ar_arg_upath1; 223718c8510SRobert Watson char *ar_arg_upath2; 224718c8510SRobert Watson char *ar_arg_text; 225718c8510SRobert Watson struct au_mask ar_arg_amask; 226718c8510SRobert Watson struct vnode_au_info ar_arg_vnode1; 227718c8510SRobert Watson struct vnode_au_info ar_arg_vnode2; 228718c8510SRobert Watson int ar_arg_cmd; 229b7830259SRobert Watson int ar_arg_svipc_which; 230718c8510SRobert Watson int ar_arg_svipc_cmd; 231718c8510SRobert Watson struct ipc_perm ar_arg_svipc_perm; 232718c8510SRobert Watson int ar_arg_svipc_id; 233718c8510SRobert Watson void *ar_arg_svipc_addr; 234718c8510SRobert Watson struct posix_ipc_perm ar_arg_pipc_perm; 235718c8510SRobert Watson union auditon_udata ar_arg_auditon; 236ae1078d6SWayne Salamon char *ar_arg_argv; 237ae1078d6SWayne Salamon int ar_arg_argc; 238ae1078d6SWayne Salamon char *ar_arg_envv; 239ae1078d6SWayne Salamon int ar_arg_envc; 240718c8510SRobert Watson int ar_arg_exitstatus; 241718c8510SRobert Watson int ar_arg_exitretval; 242130b1468SChristian S.J. Peron struct sockaddr_storage ar_arg_sockaddr; 243778b0e42SJonathan Anderson cap_rights_t ar_arg_rights; 2442609222aSPawel Jakub Dawidek uint32_t ar_arg_fcntl_rights; 24514bc5135SChristian S.J. Peron char ar_jailname[MAXHOSTNAMELEN]; 246718c8510SRobert Watson }; 247718c8510SRobert Watson 248718c8510SRobert Watson /* 249718c8510SRobert Watson * Arguments in the audit record are initially not defined; flags are set to 250718c8510SRobert Watson * indicate if they are present so they can be included in the audit log 251718c8510SRobert Watson * stream only if defined. 252718c8510SRobert Watson */ 253791b0ad2SRobert Watson #define ARG_EUID 0x0000000000000001ULL 254791b0ad2SRobert Watson #define ARG_RUID 0x0000000000000002ULL 255791b0ad2SRobert Watson #define ARG_SUID 0x0000000000000004ULL 256791b0ad2SRobert Watson #define ARG_EGID 0x0000000000000008ULL 257791b0ad2SRobert Watson #define ARG_RGID 0x0000000000000010ULL 258791b0ad2SRobert Watson #define ARG_SGID 0x0000000000000020ULL 259791b0ad2SRobert Watson #define ARG_PID 0x0000000000000040ULL 260791b0ad2SRobert Watson #define ARG_UID 0x0000000000000080ULL 261791b0ad2SRobert Watson #define ARG_AUID 0x0000000000000100ULL 262791b0ad2SRobert Watson #define ARG_GID 0x0000000000000200ULL 263791b0ad2SRobert Watson #define ARG_FD 0x0000000000000400ULL 264791b0ad2SRobert Watson #define ARG_POSIX_IPC_PERM 0x0000000000000800ULL 265791b0ad2SRobert Watson #define ARG_FFLAGS 0x0000000000001000ULL 266791b0ad2SRobert Watson #define ARG_MODE 0x0000000000002000ULL 267791b0ad2SRobert Watson #define ARG_DEV 0x0000000000004000ULL 268791b0ad2SRobert Watson #define ARG_ADDR 0x0000000000008000ULL 269791b0ad2SRobert Watson #define ARG_LEN 0x0000000000010000ULL 270791b0ad2SRobert Watson #define ARG_MASK 0x0000000000020000ULL 271791b0ad2SRobert Watson #define ARG_SIGNUM 0x0000000000040000ULL 272791b0ad2SRobert Watson #define ARG_LOGIN 0x0000000000080000ULL 273791b0ad2SRobert Watson #define ARG_SADDRINET 0x0000000000100000ULL 274791b0ad2SRobert Watson #define ARG_SADDRINET6 0x0000000000200000ULL 275791b0ad2SRobert Watson #define ARG_SADDRUNIX 0x0000000000400000ULL 276ebc0d559SAlan Somers #define ARG_TERMID_ADDR 0x0000000000800000ULL 277791b0ad2SRobert Watson #define ARG_UNUSED2 0x0000000001000000ULL 278791b0ad2SRobert Watson #define ARG_UPATH1 0x0000000002000000ULL 279791b0ad2SRobert Watson #define ARG_UPATH2 0x0000000004000000ULL 280791b0ad2SRobert Watson #define ARG_TEXT 0x0000000008000000ULL 281791b0ad2SRobert Watson #define ARG_VNODE1 0x0000000010000000ULL 282791b0ad2SRobert Watson #define ARG_VNODE2 0x0000000020000000ULL 283791b0ad2SRobert Watson #define ARG_SVIPC_CMD 0x0000000040000000ULL 284791b0ad2SRobert Watson #define ARG_SVIPC_PERM 0x0000000080000000ULL 285791b0ad2SRobert Watson #define ARG_SVIPC_ID 0x0000000100000000ULL 286791b0ad2SRobert Watson #define ARG_SVIPC_ADDR 0x0000000200000000ULL 287791b0ad2SRobert Watson #define ARG_GROUPSET 0x0000000400000000ULL 288791b0ad2SRobert Watson #define ARG_CMD 0x0000000800000000ULL 289791b0ad2SRobert Watson #define ARG_SOCKINFO 0x0000001000000000ULL 290791b0ad2SRobert Watson #define ARG_ASID 0x0000002000000000ULL 291791b0ad2SRobert Watson #define ARG_TERMID 0x0000004000000000ULL 292791b0ad2SRobert Watson #define ARG_AUDITON 0x0000008000000000ULL 293791b0ad2SRobert Watson #define ARG_VALUE 0x0000010000000000ULL 294791b0ad2SRobert Watson #define ARG_AMASK 0x0000020000000000ULL 295791b0ad2SRobert Watson #define ARG_CTLNAME 0x0000040000000000ULL 296791b0ad2SRobert Watson #define ARG_PROCESS 0x0000080000000000ULL 297791b0ad2SRobert Watson #define ARG_MACHPORT1 0x0000100000000000ULL 298791b0ad2SRobert Watson #define ARG_MACHPORT2 0x0000200000000000ULL 299791b0ad2SRobert Watson #define ARG_EXIT 0x0000400000000000ULL 300791b0ad2SRobert Watson #define ARG_IOVECSTR 0x0000800000000000ULL 301791b0ad2SRobert Watson #define ARG_ARGV 0x0001000000000000ULL 302791b0ad2SRobert Watson #define ARG_ENVV 0x0002000000000000ULL 303791b0ad2SRobert Watson #define ARG_ATFD1 0x0004000000000000ULL 304791b0ad2SRobert Watson #define ARG_ATFD2 0x0008000000000000ULL 305778b0e42SJonathan Anderson #define ARG_RIGHTS 0x0010000000000000ULL 3062609222aSPawel Jakub Dawidek #define ARG_FCNTL_RIGHTS 0x0020000000000000ULL 307b7830259SRobert Watson #define ARG_SVIPC_WHICH 0x0200000000000000ULL 308791b0ad2SRobert Watson #define ARG_NONE 0x0000000000000000ULL 309791b0ad2SRobert Watson #define ARG_ALL 0xFFFFFFFFFFFFFFFFULL 310791b0ad2SRobert Watson 311718c8510SRobert Watson #define ARG_IS_VALID(kar, arg) ((kar)->k_ar.ar_valid_arg & (arg)) 312718c8510SRobert Watson #define ARG_SET_VALID(kar, arg) do { \ 313718c8510SRobert Watson (kar)->k_ar.ar_valid_arg |= (arg); \ 314718c8510SRobert Watson } while (0) 315b146fc1bSRobert Watson #define ARG_CLEAR_VALID(kar, arg) do { \ 316b146fc1bSRobert Watson (kar)->k_ar.ar_valid_arg &= ~(arg); \ 317b146fc1bSRobert Watson } while (0) 318718c8510SRobert Watson 319718c8510SRobert Watson /* 320718c8510SRobert Watson * In-kernel version of audit record; the basic record plus queue meta-data. 321871499feSRobert Watson * This record can also have a pointer set to some opaque data that will be 322871499feSRobert Watson * passed through to the audit writing mechanism. 323718c8510SRobert Watson */ 324718c8510SRobert Watson struct kaudit_record { 325718c8510SRobert Watson struct audit_record k_ar; 326718c8510SRobert Watson u_int32_t k_ar_commit; 327871499feSRobert Watson void *k_udata; /* User data. */ 328871499feSRobert Watson u_int k_ulen; /* User data length. */ 329871499feSRobert Watson struct uthread *k_uthread; /* Audited thread. */ 3301811d6bfSRobert Watson void *k_dtaudit_state; 331718c8510SRobert Watson TAILQ_ENTRY(kaudit_record) k_q; 332718c8510SRobert Watson }; 33308e57af4SRobert Watson TAILQ_HEAD(kaudit_queue, kaudit_record); 334718c8510SRobert Watson 335718c8510SRobert Watson /* 336718c8510SRobert Watson * Functions to manage the allocation, release, and commit of kernel audit 337718c8510SRobert Watson * records. 338718c8510SRobert Watson */ 339718c8510SRobert Watson void audit_abort(struct kaudit_record *ar); 340718c8510SRobert Watson void audit_commit(struct kaudit_record *ar, int error, 341718c8510SRobert Watson int retval); 342718c8510SRobert Watson struct kaudit_record *audit_new(int event, struct thread *td); 343718c8510SRobert Watson 344718c8510SRobert Watson /* 3452ddefb6dSRobert Watson * Function to update the audit_syscalls_enabled flag, whose value is affected 3462ddefb6dSRobert Watson * by configuration of the audit trail/pipe mechanism and DTrace. Call this 3472ddefb6dSRobert Watson * function when any of the inputs to that policy change. 3482ddefb6dSRobert Watson */ 3492ddefb6dSRobert Watson void audit_syscalls_enabled_update(void); 3502ddefb6dSRobert Watson 3512ddefb6dSRobert Watson /* 352718c8510SRobert Watson * Functions relating to the conversion of internal kernel audit records to 353718c8510SRobert Watson * the BSM file format. 354718c8510SRobert Watson */ 35554205da0SRobert Watson struct au_record; 356871499feSRobert Watson int kaudit_to_bsm(struct kaudit_record *kar, struct au_record **pau); 357718c8510SRobert Watson int bsm_rec_verify(void *rec); 358718c8510SRobert Watson 359718c8510SRobert Watson /* 360718c8510SRobert Watson * Kernel versions of the libbsm audit record functions. 361718c8510SRobert Watson */ 362718c8510SRobert Watson void kau_free(struct au_record *rec); 363718c8510SRobert Watson void kau_init(void); 364718c8510SRobert Watson 365718c8510SRobert Watson /* 366718c8510SRobert Watson * Return values for pre-selection and post-selection decisions. 367718c8510SRobert Watson */ 368718c8510SRobert Watson #define AU_PRS_SUCCESS 1 369718c8510SRobert Watson #define AU_PRS_FAILURE 2 370718c8510SRobert Watson #define AU_PRS_BOTH (AU_PRS_SUCCESS|AU_PRS_FAILURE) 371718c8510SRobert Watson 372718c8510SRobert Watson /* 37308e57af4SRobert Watson * Data structures relating to the kernel audit queue. Ideally, these might 37408e57af4SRobert Watson * be abstracted so that only accessor methods are exposed. 37508e57af4SRobert Watson */ 37608e57af4SRobert Watson extern struct mtx audit_mtx; 37740c96d72SRobert Watson extern struct cv audit_watermark_cv; 37840c96d72SRobert Watson extern struct cv audit_worker_cv; 37908e57af4SRobert Watson extern struct kaudit_queue audit_q; 3804df4e335SRobert Watson extern int audit_q_len; 3814df4e335SRobert Watson extern int audit_pre_q_len; 38208e57af4SRobert Watson extern int audit_in_failure; 38308e57af4SRobert Watson 38408e57af4SRobert Watson /* 385718c8510SRobert Watson * Flags to use on audit files when opening and closing. 386718c8510SRobert Watson */ 387718c8510SRobert Watson #define AUDIT_OPEN_FLAGS (FWRITE | O_APPEND) 388718c8510SRobert Watson #define AUDIT_CLOSE_FLAGS (FWRITE | O_APPEND) 389718c8510SRobert Watson 390759c8caaSRobert Watson /* 391759c8caaSRobert Watson * Audit event-to-name mapping structure, maintained in audit_bsm_klib.c. It 392759c8caaSRobert Watson * appears in this header so that the DTrace audit provider can dereference 393759c8caaSRobert Watson * instances passed back in the au_evname_foreach() callbacks. Safe access to 3941811d6bfSRobert Watson * its fields requires holding ene_lock (after it is visible in the global 395759c8caaSRobert Watson * table). 396759c8caaSRobert Watson * 397759c8caaSRobert Watson * Locking: 398759c8caaSRobert Watson * (c) - Constant after inserted in the global table 399759c8caaSRobert Watson * (l) - Protected by ene_lock 400759c8caaSRobert Watson * (m) - Protected by evnamemap_lock (audit_bsm_klib.c) 401759c8caaSRobert Watson * (M) - Writes protected by evnamemap_lock; reads unprotected. 402759c8caaSRobert Watson */ 403759c8caaSRobert Watson struct evname_elem { 404759c8caaSRobert Watson au_event_t ene_event; /* (c) */ 405759c8caaSRobert Watson char ene_name[EVNAMEMAP_NAME_SIZE]; /* (l) */ 406759c8caaSRobert Watson LIST_ENTRY(evname_elem) ene_entry; /* (m) */ 407759c8caaSRobert Watson struct mtx ene_lock; 4081811d6bfSRobert Watson 4091811d6bfSRobert Watson /* DTrace probe IDs; 0 if not yet registered. */ 4101811d6bfSRobert Watson uint32_t ene_commit_probe_id; /* (M) */ 4111811d6bfSRobert Watson uint32_t ene_bsm_probe_id; /* (M) */ 4121811d6bfSRobert Watson 4131811d6bfSRobert Watson /* Flags indicating if the probes enabled or not. */ 4141811d6bfSRobert Watson int ene_commit_probe_enabled; /* (M) */ 4151811d6bfSRobert Watson int ene_bsm_probe_enabled; /* (M) */ 416759c8caaSRobert Watson }; 417759c8caaSRobert Watson 418759c8caaSRobert Watson #define EVNAME_LOCK(ene) mtx_lock(&(ene)->ene_lock) 419759c8caaSRobert Watson #define EVNAME_UNLOCK(ene) mtx_unlock(&(ene)->ene_lock) 420759c8caaSRobert Watson 421759c8caaSRobert Watson /* 422759c8caaSRobert Watson * Callback function typedef for the same. 423759c8caaSRobert Watson */ 424759c8caaSRobert Watson typedef void (*au_evnamemap_callback_t)(struct evname_elem *ene); 425759c8caaSRobert Watson 4261811d6bfSRobert Watson /* 4271811d6bfSRobert Watson * DTrace audit provider (dtaudit) hooks -- to be set non-NULL when the audit 4281811d6bfSRobert Watson * provider is loaded and ready to be called into. 4291811d6bfSRobert Watson */ 4301811d6bfSRobert Watson extern void *(*dtaudit_hook_preselect)(au_id_t auid, au_event_t event, 4311811d6bfSRobert Watson au_class_t class); 4321811d6bfSRobert Watson extern int (*dtaudit_hook_commit)(struct kaudit_record *kar, 4331811d6bfSRobert Watson au_id_t auid, au_event_t event, au_class_t class, 4341811d6bfSRobert Watson int sorf); 4351811d6bfSRobert Watson extern void (*dtaudit_hook_bsm)(struct kaudit_record *kar, au_id_t auid, 4361811d6bfSRobert Watson au_event_t event, au_class_t class, int sorf, 4371811d6bfSRobert Watson void *bsm_data, size_t bsm_len); 4381811d6bfSRobert Watson 439718c8510SRobert Watson #include <sys/fcntl.h> 440718c8510SRobert Watson #include <sys/kernel.h> 441718c8510SRobert Watson #include <sys/malloc.h> 442718c8510SRobert Watson 443718c8510SRobert Watson /* 444718c8510SRobert Watson * Some of the BSM tokenizer functions take different parameters in the 445871499feSRobert Watson * kernel implementations in order to save the copying of large kernel data 446871499feSRobert Watson * structures. The prototypes of these functions are declared here. 447718c8510SRobert Watson */ 448718c8510SRobert Watson token_t *kau_to_socket(struct socket_au_info *soi); 449718c8510SRobert Watson 450718c8510SRobert Watson /* 451718c8510SRobert Watson * audit_klib prototypes 452718c8510SRobert Watson */ 453e257c20eSRobert Watson int au_preselect(au_event_t event, au_class_t class, 454e257c20eSRobert Watson au_mask_t *mask_p, int sorf); 455718c8510SRobert Watson void au_evclassmap_init(void); 456718c8510SRobert Watson void au_evclassmap_insert(au_event_t event, au_class_t class); 457718c8510SRobert Watson au_class_t au_event_class(au_event_t event); 458759c8caaSRobert Watson void au_evnamemap_init(void); 459759c8caaSRobert Watson void au_evnamemap_insert(au_event_t event, const char *name); 460759c8caaSRobert Watson void au_evnamemap_foreach(au_evnamemap_callback_t callback); 4611811d6bfSRobert Watson struct evname_elem *au_evnamemap_lookup(au_event_t event); 462759c8caaSRobert Watson int au_event_name(au_event_t event, char *name); 4636cc18991SRobert Watson au_event_t audit_ctlname_to_sysctlevent(int name[], uint64_t valid_arg); 4646cc18991SRobert Watson au_event_t audit_flags_and_error_to_openevent(int oflags, int error); 465e4b4bbb6SRobert Watson au_event_t audit_flags_and_error_to_openatevent(int oflags, int error); 466f4f93a63SRobert Watson au_event_t audit_msgctl_to_event(int cmd); 467b7830259SRobert Watson au_event_t audit_msgsys_to_event(int which); 468b7830259SRobert Watson au_event_t audit_semctl_to_event(int cmd); 469b7830259SRobert Watson au_event_t audit_semsys_to_event(int which); 470b7830259SRobert Watson au_event_t audit_shmsys_to_event(int which); 471499f0f4dSPawel Jakub Dawidek void audit_canon_path(struct thread *td, int dirfd, char *path, 472499f0f4dSPawel Jakub Dawidek char *cpath); 473*7de6c5ebSMateusz Guzik void audit_canon_path_vp(struct thread *td, struct vnode *rdir, 474*7de6c5ebSMateusz Guzik struct vnode *cdir, char *path, char *cpath); 475f4f93a63SRobert Watson au_event_t auditon_command_event(int cmd); 476718c8510SRobert Watson 477718c8510SRobert Watson /* 478718c8510SRobert Watson * Audit trigger events notify user space of kernel audit conditions 479718c8510SRobert Watson * asynchronously. 480718c8510SRobert Watson */ 481718c8510SRobert Watson void audit_trigger_init(void); 482fb4ed8c9SRobert Watson int audit_send_trigger(unsigned int trigger); 483718c8510SRobert Watson 484718c8510SRobert Watson /* 4854ebff7e0SRobert Watson * Accessor functions to manage global audit state. 4864ebff7e0SRobert Watson */ 4874ebff7e0SRobert Watson void audit_set_kinfo(struct auditinfo_addr *); 4884ebff7e0SRobert Watson void audit_get_kinfo(struct auditinfo_addr *); 4894ebff7e0SRobert Watson 4904ebff7e0SRobert Watson /* 491718c8510SRobert Watson * General audit related functions. 492718c8510SRobert Watson */ 493718c8510SRobert Watson struct kaudit_record *currecord(void); 49408e57af4SRobert Watson void audit_free(struct kaudit_record *ar); 495718c8510SRobert Watson void audit_shutdown(void *arg, int howto); 496718c8510SRobert Watson void audit_rotate_vnode(struct ucred *cred, 497718c8510SRobert Watson struct vnode *vp); 49808e57af4SRobert Watson void audit_worker_init(void); 499718c8510SRobert Watson 50009daf1c8SRobert Watson /* 50109daf1c8SRobert Watson * Audit pipe functions. 50209daf1c8SRobert Watson */ 503e257c20eSRobert Watson int audit_pipe_preselect(au_id_t auid, au_event_t event, 504e257c20eSRobert Watson au_class_t class, int sorf, int trail_select); 505e257c20eSRobert Watson void audit_pipe_submit(au_id_t auid, au_event_t event, au_class_t class, 506e257c20eSRobert Watson int sorf, int trail_select, void *record, u_int record_len); 507e257c20eSRobert Watson void audit_pipe_submit_user(void *record, u_int record_len); 50809daf1c8SRobert Watson 50917363e6dSRobert Watson #endif /* ! _SECURITY_AUDIT_PRIVATE_H_ */ 510