audit.h revision 196122
1181053Srwatson/*- 2180701Srwatson * Copyright (c) 1999-2005 Apple Inc. 3155192Srwatson * All rights reserved. 4155192Srwatson * 5155192Srwatson * Redistribution and use in source and binary forms, with or without 6155192Srwatson * modification, are permitted provided that the following conditions 7155192Srwatson * are met: 8155192Srwatson * 1. Redistributions of source code must retain the above copyright 9155192Srwatson * notice, this list of conditions and the following disclaimer. 10155192Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11155192Srwatson * notice, this list of conditions and the following disclaimer in the 12155192Srwatson * documentation and/or other materials provided with the distribution. 13180701Srwatson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14155192Srwatson * its contributors may be used to endorse or promote products derived 15155192Srwatson * from this software without specific prior written permission. 16155192Srwatson * 17155192Srwatson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 18155192Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19155192Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20155192Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 21155192Srwatson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22155192Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23155192Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24155192Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25155192Srwatson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26155192Srwatson * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27155192Srwatson * POSSIBILITY OF SUCH DAMAGE. 28155192Srwatson * 29155192Srwatson * $FreeBSD: head/sys/security/audit/audit.h 196122 2009-08-12 10:45:45Z rwatson $ 30155192Srwatson */ 31155192Srwatson 32155192Srwatson/* 33155192Srwatson * This header includes function prototypes and type definitions that are 34155192Srwatson * necessary for the kernel as a whole to interact with the audit subsystem. 35155192Srwatson */ 36155192Srwatson 37156882Srwatson#ifndef _SECURITY_AUDIT_KERNEL_H_ 38178617Srwatson#define _SECURITY_AUDIT_KERNEL_H_ 39155192Srwatson 40155192Srwatson#ifndef _KERNEL 41155192Srwatson#error "no user-serviceable parts inside" 42155192Srwatson#endif 43155192Srwatson 44155192Srwatson#include <bsm/audit.h> 45155192Srwatson 46155192Srwatson#include <sys/file.h> 47155192Srwatson#include <sys/sysctl.h> 48155192Srwatson 49155192Srwatson/* 50155192Srwatson * Audit subsystem condition flags. The audit_enabled flag is set and 51170196Srwatson * removed automatically as a result of configuring log files, and can be 52170196Srwatson * observed but should not be directly manipulated. The audit suspension 53170196Srwatson * flag permits audit to be temporarily disabled without reconfiguring the 54170196Srwatson * audit target. 55155192Srwatson */ 56155192Srwatsonextern int audit_enabled; 57155192Srwatsonextern int audit_suspended; 58155192Srwatson 59156889Srwatsonvoid audit_syscall_enter(unsigned short code, struct thread *td); 60156889Srwatsonvoid audit_syscall_exit(int error, struct thread *td); 61155192Srwatson 62155192Srwatson/* 63170196Srwatson * The remaining kernel functions are conditionally compiled in as they are 64170196Srwatson * wrapped by a macro, and the macro should be the only place in the source 65170196Srwatson * tree where these functions are referenced. 66155192Srwatson */ 67155192Srwatson#ifdef AUDIT 68155192Srwatsonstruct ipc_perm; 69155192Srwatsonstruct sockaddr; 70155192Srwatsonunion auditon_udata; 71156889Srwatsonvoid audit_arg_addr(void * addr); 72156889Srwatsonvoid audit_arg_exit(int status, int retval); 73156889Srwatsonvoid audit_arg_len(int len); 74195925Srwatsonvoid audit_arg_atfd1(int atfd); 75195925Srwatsonvoid audit_arg_atfd2(int atfd); 76156889Srwatsonvoid audit_arg_fd(int fd); 77156889Srwatsonvoid audit_arg_fflags(int fflags); 78156889Srwatsonvoid audit_arg_gid(gid_t gid); 79156889Srwatsonvoid audit_arg_uid(uid_t uid); 80156889Srwatsonvoid audit_arg_egid(gid_t egid); 81156889Srwatsonvoid audit_arg_euid(uid_t euid); 82156889Srwatsonvoid audit_arg_rgid(gid_t rgid); 83156889Srwatsonvoid audit_arg_ruid(uid_t ruid); 84156889Srwatsonvoid audit_arg_sgid(gid_t sgid); 85156889Srwatsonvoid audit_arg_suid(uid_t suid); 86156889Srwatsonvoid audit_arg_groupset(gid_t *gidset, u_int gidset_size); 87156889Srwatsonvoid audit_arg_login(char *login); 88156889Srwatsonvoid audit_arg_ctlname(int *name, int namelen); 89156889Srwatsonvoid audit_arg_mask(int mask); 90156889Srwatsonvoid audit_arg_mode(mode_t mode); 91156889Srwatsonvoid audit_arg_dev(int dev); 92156889Srwatsonvoid audit_arg_value(long value); 93156889Srwatsonvoid audit_arg_owner(uid_t uid, gid_t gid); 94156889Srwatsonvoid audit_arg_pid(pid_t pid); 95156889Srwatsonvoid audit_arg_process(struct proc *p); 96156889Srwatsonvoid audit_arg_signum(u_int signum); 97156889Srwatsonvoid audit_arg_socket(int sodomain, int sotype, int soprotocol); 98160086Srwatsonvoid audit_arg_sockaddr(struct thread *td, struct sockaddr *sa); 99156889Srwatsonvoid audit_arg_auid(uid_t auid); 100156889Srwatsonvoid audit_arg_auditinfo(struct auditinfo *au_info); 101171066Scsjpvoid audit_arg_auditinfo_addr(struct auditinfo_addr *au_info); 102195939Srwatsonvoid audit_arg_upath1(struct thread *td, char *upath); 103195939Srwatsonvoid audit_arg_upath2(struct thread *td, char *upath); 104195926Srwatsonvoid audit_arg_vnode1(struct vnode *vp); 105195926Srwatsonvoid audit_arg_vnode2(struct vnode *vp); 106156889Srwatsonvoid audit_arg_text(char *text); 107156889Srwatsonvoid audit_arg_cmd(int cmd); 108156889Srwatsonvoid audit_arg_svipc_cmd(int cmd); 109156889Srwatsonvoid audit_arg_svipc_perm(struct ipc_perm *perm); 110156889Srwatsonvoid audit_arg_svipc_id(int id); 111156889Srwatsonvoid audit_arg_svipc_addr(void *addr); 112156889Srwatsonvoid audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, mode_t mode); 113156889Srwatsonvoid audit_arg_auditon(union auditon_udata *udata); 114156889Srwatsonvoid audit_arg_file(struct proc *p, struct file *fp); 115161813Swsalamonvoid audit_arg_argv(char *argv, int argc, int length); 116161813Swsalamonvoid audit_arg_envv(char *envv, int envc, int length); 117156889Srwatsonvoid audit_sysclose(struct thread *td, int fd); 118170407Srwatsonvoid audit_cred_copy(struct ucred *src, struct ucred *dest); 119170407Srwatsonvoid audit_cred_destroy(struct ucred *cred); 120170407Srwatsonvoid audit_cred_init(struct ucred *cred); 121170407Srwatsonvoid audit_cred_kproc0(struct ucred *cred); 122170407Srwatsonvoid audit_cred_proc1(struct ucred *cred); 123172995Scsjpvoid audit_proc_coredump(struct thread *td, char *path, int errcode); 124156889Srwatsonvoid audit_thread_alloc(struct thread *td); 125156889Srwatsonvoid audit_thread_free(struct thread *td); 126155192Srwatson 127155192Srwatson/* 128195104Srwatson * Define macros to wrap the audit_arg_* calls by checking the global 129155192Srwatson * audit_enabled flag before performing the actual call. 130155192Srwatson */ 131195104Srwatson#define AUDITING_TD(td) ((td)->td_pflags & TDP_AUDITREC) 132195104Srwatson 133195104Srwatson#define AUDIT_ARG_ADDR(addr) do { \ 134195104Srwatson if (AUDITING_TD(curthread)) \ 135195104Srwatson audit_arg_addr((addr)); \ 136156889Srwatson} while (0) 137155192Srwatson 138195104Srwatson#define AUDIT_ARG_ARGV(argv, argc, length) do { \ 139195104Srwatson if (AUDITING_TD(curthread)) \ 140195104Srwatson audit_arg_argv((argv), (argc), (length)); \ 141195104Srwatson} while (0) 142195104Srwatson 143195925Srwatson#define AUDIT_ARG_ATFD1(atfd) do { \ 144195925Srwatson if (AUDITING_TD(curthread)) \ 145195925Srwatson audit_arg_atfd1((atfd)); \ 146195925Srwatson} while (0) 147195925Srwatson 148195925Srwatson#define AUDIT_ARG_ATFD2(atfd) do { \ 149195925Srwatson if (AUDITING_TD(curthread)) \ 150195925Srwatson audit_arg_atfd2((atfd)); \ 151195925Srwatson} while (0) 152195925Srwatson 153195104Srwatson#define AUDIT_ARG_AUDITON(udata) do { \ 154195104Srwatson if (AUDITING_TD(curthread)) \ 155195104Srwatson audit_arg_auditon((udata)); \ 156195104Srwatson} while (0) 157195104Srwatson 158195104Srwatson#define AUDIT_ARG_CMD(cmd) do { \ 159195104Srwatson if (AUDITING_TD(curthread)) \ 160195104Srwatson audit_arg_cmd((cmd)); \ 161195104Srwatson} while (0) 162195104Srwatson 163195104Srwatson#define AUDIT_ARG_DEV(dev) do { \ 164195104Srwatson if (AUDITING_TD(curthread)) \ 165195104Srwatson audit_arg_dev((dev)); \ 166195104Srwatson} while (0) 167195104Srwatson 168195104Srwatson#define AUDIT_ARG_EGID(egid) do { \ 169195104Srwatson if (AUDITING_TD(curthread)) \ 170195104Srwatson audit_arg_egid((egid)); \ 171195104Srwatson} while (0) 172195104Srwatson 173195104Srwatson#define AUDIT_ARG_ENVV(envv, envc, length) do { \ 174195104Srwatson if (AUDITING_TD(curthread)) \ 175195104Srwatson audit_arg_envv((envv), (envc), (length)); \ 176195104Srwatson} while (0) 177195104Srwatson 178195104Srwatson#define AUDIT_ARG_EXIT(status, retval) do { \ 179195104Srwatson if (AUDITING_TD(curthread)) \ 180195104Srwatson audit_arg_exit((status), (retval)); \ 181195104Srwatson} while (0) 182195104Srwatson 183195104Srwatson#define AUDIT_ARG_EUID(euid) do { \ 184195104Srwatson if (AUDITING_TD(curthread)) \ 185195104Srwatson audit_arg_euid((euid)); \ 186195104Srwatson} while (0) 187195104Srwatson 188195104Srwatson#define AUDIT_ARG_FD(fd) do { \ 189195104Srwatson if (AUDITING_TD(curthread)) \ 190195104Srwatson audit_arg_fd((fd)); \ 191195104Srwatson} while (0) 192195104Srwatson 193195104Srwatson#define AUDIT_ARG_FILE(p, fp) do { \ 194195104Srwatson if (AUDITING_TD(curthread)) \ 195195104Srwatson audit_arg_file((p), (fp)); \ 196195104Srwatson} while (0) 197195104Srwatson 198195104Srwatson#define AUDIT_ARG_FFLAGS(fflags) do { \ 199195104Srwatson if (AUDITING_TD(curthread)) \ 200195104Srwatson audit_arg_fflags((fflags)); \ 201195104Srwatson} while (0) 202195104Srwatson 203195104Srwatson#define AUDIT_ARG_GID(gid) do { \ 204195104Srwatson if (AUDITING_TD(curthread)) \ 205195104Srwatson audit_arg_gid((gid)); \ 206195104Srwatson} while (0) 207195104Srwatson 208195104Srwatson#define AUDIT_ARG_GROUPSET(gidset, gidset_size) do { \ 209195104Srwatson if (AUDITING_TD(curthread)) \ 210195104Srwatson audit_arg_groupset((gidset), (gidset_size)); \ 211195104Srwatson} while (0) 212195104Srwatson 213195104Srwatson#define AUDIT_ARG_MODE(mode) do { \ 214195104Srwatson if (AUDITING_TD(curthread)) \ 215195104Srwatson audit_arg_mode((mode)); \ 216195104Srwatson} while (0) 217195104Srwatson 218195104Srwatson#define AUDIT_ARG_OWNER(uid, gid) do { \ 219195104Srwatson if (AUDITING_TD(curthread)) \ 220195104Srwatson audit_arg_owner((uid), (gid)); \ 221195104Srwatson} while (0) 222195104Srwatson 223195104Srwatson#define AUDIT_ARG_PID(pid) do { \ 224195104Srwatson if (AUDITING_TD(curthread)) \ 225195104Srwatson audit_arg_pid((pid)); \ 226195104Srwatson} while (0) 227195104Srwatson 228195104Srwatson#define AUDIT_ARG_PROCESS(p) do { \ 229195104Srwatson if (AUDITING_TD(curthread)) \ 230195104Srwatson audit_arg_process((p)); \ 231195104Srwatson} while (0) 232195104Srwatson 233195104Srwatson#define AUDIT_ARG_RGID(rgid) do { \ 234195104Srwatson if (AUDITING_TD(curthread)) \ 235196122Srwatson audit_arg_rgid((rgid)); \ 236195104Srwatson} while (0) 237195104Srwatson 238195104Srwatson#define AUDIT_ARG_RUID(ruid) do { \ 239195104Srwatson if (AUDITING_TD(curthread)) \ 240195104Srwatson audit_arg_ruid((ruid)); \ 241195104Srwatson} while (0) 242195104Srwatson 243195104Srwatson#define AUDIT_ARG_SIGNUM(signum) do { \ 244195104Srwatson if (AUDITING_TD(curthread)) \ 245195104Srwatson audit_arg_signum((signum)); \ 246195104Srwatson} while (0) 247195104Srwatson 248195104Srwatson#define AUDIT_ARG_SGID(sgid) do { \ 249195104Srwatson if (AUDITING_TD(curthread)) \ 250195104Srwatson audit_arg_sgid((sgid)); \ 251195104Srwatson} while (0) 252195104Srwatson 253195252Srwatson#define AUDIT_ARG_SOCKET(sodomain, sotype, soprotocol) do { \ 254195252Srwatson if (AUDITING_TD(curthread)) \ 255195252Srwatson audit_arg_socket((sodomain), (sotype), (soprotocol)); \ 256195252Srwatson} while (0) 257195252Srwatson 258195104Srwatson#define AUDIT_ARG_SUID(suid) do { \ 259195104Srwatson if (AUDITING_TD(curthread)) \ 260195104Srwatson audit_arg_suid((suid)); \ 261195104Srwatson} while (0) 262195104Srwatson 263195104Srwatson#define AUDIT_ARG_TEXT(text) do { \ 264195104Srwatson if (AUDITING_TD(curthread)) \ 265195104Srwatson audit_arg_text((text)); \ 266195104Srwatson} while (0) 267195104Srwatson 268195104Srwatson#define AUDIT_ARG_UID(uid) do { \ 269195104Srwatson if (AUDITING_TD(curthread)) \ 270195104Srwatson audit_arg_uid((uid)); \ 271195104Srwatson} while (0) 272195104Srwatson 273195939Srwatson#define AUDIT_ARG_UPATH1(td, upath) do { \ 274195104Srwatson if (AUDITING_TD(curthread)) \ 275195939Srwatson audit_arg_upath1((td), (upath)); \ 276195104Srwatson} while (0) 277195104Srwatson 278195939Srwatson#define AUDIT_ARG_UPATH2(td, upath) do { \ 279195939Srwatson if (AUDITING_TD(curthread)) \ 280195939Srwatson audit_arg_upath2((td), (upath)); \ 281195939Srwatson} while (0) 282195939Srwatson 283195104Srwatson#define AUDIT_ARG_VALUE(value) do { \ 284195104Srwatson if (AUDITING_TD(curthread)) \ 285195104Srwatson audit_arg_value((value)); \ 286195104Srwatson} while (0) 287195104Srwatson 288195926Srwatson#define AUDIT_ARG_VNODE1(vp) do { \ 289195104Srwatson if (AUDITING_TD(curthread)) \ 290195926Srwatson audit_arg_vnode1((vp)); \ 291195104Srwatson} while (0) 292195104Srwatson 293195926Srwatson#define AUDIT_ARG_VNODE2(vp) do { \ 294195926Srwatson if (AUDITING_TD(curthread)) \ 295195926Srwatson audit_arg_vnode2((vp)); \ 296195926Srwatson} while (0) 297195926Srwatson 298161970Srwatson#define AUDIT_SYSCALL_ENTER(code, td) do { \ 299155192Srwatson if (audit_enabled) { \ 300155192Srwatson audit_syscall_enter(code, td); \ 301155192Srwatson } \ 302156889Srwatson} while (0) 303155192Srwatson 304155192Srwatson/* 305155192Srwatson * Wrap the audit_syscall_exit() function so that it is called only when 306186822Srwatson * we have a audit record on the thread. Audit records can persist after 307186822Srwatson * auditing is disabled, so we don't just check audit_enabled here. 308155192Srwatson */ 309161970Srwatson#define AUDIT_SYSCALL_EXIT(error, td) do { \ 310189570Srwatson if (td->td_pflags & TDP_AUDITREC) \ 311155192Srwatson audit_syscall_exit(error, td); \ 312156889Srwatson} while (0) 313155192Srwatson 314155192Srwatson/* 315155192Srwatson * A Macro to wrap the audit_sysclose() function. 316155192Srwatson */ 317155192Srwatson#define AUDIT_SYSCLOSE(td, fd) do { \ 318189570Srwatson if (td->td_pflags & TDP_AUDITREC) \ 319155192Srwatson audit_sysclose(td, fd); \ 320156889Srwatson} while (0) 321155192Srwatson 322155192Srwatson#else /* !AUDIT */ 323155192Srwatson 324195104Srwatson#define AUDIT_ARG_ADDR(addr) 325195104Srwatson#define AUDIT_ARG_ARGV(argv, argc, length) 326195925Srwatson#define AUDIT_ARG_ATFD1(atfd) 327195925Srwatson#define AUDIT_ARG_ATFD2(atfd) 328195104Srwatson#define AUDIT_ARG_AUDITON(udata) 329195104Srwatson#define AUDIT_ARG_CMD(cmd) 330195104Srwatson#define AUDIT_ARG_DEV(dev) 331195104Srwatson#define AUDIT_ARG_EGID(egid) 332195104Srwatson#define AUDIT_ARG_ENVV(envv, envc, length) 333195104Srwatson#define AUDIT_ARG_EXIT(status, retval) 334195104Srwatson#define AUDIT_ARG_EUID(euid) 335195104Srwatson#define AUDIT_ARG_FD(fd) 336195104Srwatson#define AUDIT_ARG_FILE(p, fp) 337195104Srwatson#define AUDIT_ARG_FFLAGS(fflags) 338195104Srwatson#define AUDIT_ARG_GID(gid) 339195104Srwatson#define AUDIT_ARG_GROUPSET(gidset, gidset_size) 340195104Srwatson#define AUDIT_ARG_MODE(mode) 341195104Srwatson#define AUDIT_ARG_OWNER(uid, gid) 342195104Srwatson#define AUDIT_ARG_PID(pid) 343195104Srwatson#define AUDIT_ARG_PROCESS(p) 344195104Srwatson#define AUDIT_ARG_RGID(rgid) 345195104Srwatson#define AUDIT_ARG_RUID(ruid) 346195104Srwatson#define AUDIT_ARG_SIGNUM(signum) 347195104Srwatson#define AUDIT_ARG_SGID(sgid) 348195252Srwatson#define AUDIT_ARG_SOCKET(sodomain, sotype, soprotocol) 349195104Srwatson#define AUDIT_ARG_SUID(suid) 350195104Srwatson#define AUDIT_ARG_TEXT(text) 351195104Srwatson#define AUDIT_ARG_UID(uid) 352195939Srwatson#define AUDIT_ARG_UPATH1(td, upath) 353195939Srwatson#define AUDIT_ARG_UPATH2(td, upath) 354195104Srwatson#define AUDIT_ARG_VALUE(value) 355195926Srwatson#define AUDIT_ARG_VNODE1(vp) 356195926Srwatson#define AUDIT_ARG_VNODE2(vp) 357155192Srwatson 358195104Srwatson#define AUDIT_SYSCALL_ENTER(code, td) 359195104Srwatson#define AUDIT_SYSCALL_EXIT(error, td) 360155192Srwatson 361195104Srwatson#define AUDIT_SYSCLOSE(p, fd) 362155192Srwatson 363155192Srwatson#endif /* AUDIT */ 364155192Srwatson 365156882Srwatson#endif /* !_SECURITY_AUDIT_KERNEL_H_ */ 366