audit.h revision 224181
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 224181 2011-07-18 12:58:18Z jonathan $ 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); 117224181Sjonathanvoid audit_arg_rights(cap_rights_t rights); 118156889Srwatsonvoid audit_sysclose(struct thread *td, int fd); 119170407Srwatsonvoid audit_cred_copy(struct ucred *src, struct ucred *dest); 120170407Srwatsonvoid audit_cred_destroy(struct ucred *cred); 121170407Srwatsonvoid audit_cred_init(struct ucred *cred); 122170407Srwatsonvoid audit_cred_kproc0(struct ucred *cred); 123170407Srwatsonvoid audit_cred_proc1(struct ucred *cred); 124172995Scsjpvoid audit_proc_coredump(struct thread *td, char *path, int errcode); 125156889Srwatsonvoid audit_thread_alloc(struct thread *td); 126156889Srwatsonvoid audit_thread_free(struct thread *td); 127155192Srwatson 128155192Srwatson/* 129195104Srwatson * Define macros to wrap the audit_arg_* calls by checking the global 130155192Srwatson * audit_enabled flag before performing the actual call. 131155192Srwatson */ 132195104Srwatson#define AUDITING_TD(td) ((td)->td_pflags & TDP_AUDITREC) 133195104Srwatson 134195104Srwatson#define AUDIT_ARG_ADDR(addr) do { \ 135195104Srwatson if (AUDITING_TD(curthread)) \ 136195104Srwatson audit_arg_addr((addr)); \ 137156889Srwatson} while (0) 138155192Srwatson 139195104Srwatson#define AUDIT_ARG_ARGV(argv, argc, length) do { \ 140195104Srwatson if (AUDITING_TD(curthread)) \ 141195104Srwatson audit_arg_argv((argv), (argc), (length)); \ 142195104Srwatson} while (0) 143195104Srwatson 144195925Srwatson#define AUDIT_ARG_ATFD1(atfd) do { \ 145195925Srwatson if (AUDITING_TD(curthread)) \ 146195925Srwatson audit_arg_atfd1((atfd)); \ 147195925Srwatson} while (0) 148195925Srwatson 149195925Srwatson#define AUDIT_ARG_ATFD2(atfd) do { \ 150195925Srwatson if (AUDITING_TD(curthread)) \ 151195925Srwatson audit_arg_atfd2((atfd)); \ 152195925Srwatson} while (0) 153195925Srwatson 154195104Srwatson#define AUDIT_ARG_AUDITON(udata) do { \ 155195104Srwatson if (AUDITING_TD(curthread)) \ 156195104Srwatson audit_arg_auditon((udata)); \ 157195104Srwatson} while (0) 158195104Srwatson 159195104Srwatson#define AUDIT_ARG_CMD(cmd) do { \ 160195104Srwatson if (AUDITING_TD(curthread)) \ 161195104Srwatson audit_arg_cmd((cmd)); \ 162195104Srwatson} while (0) 163195104Srwatson 164195104Srwatson#define AUDIT_ARG_DEV(dev) do { \ 165195104Srwatson if (AUDITING_TD(curthread)) \ 166195104Srwatson audit_arg_dev((dev)); \ 167195104Srwatson} while (0) 168195104Srwatson 169195104Srwatson#define AUDIT_ARG_EGID(egid) do { \ 170195104Srwatson if (AUDITING_TD(curthread)) \ 171195104Srwatson audit_arg_egid((egid)); \ 172195104Srwatson} while (0) 173195104Srwatson 174195104Srwatson#define AUDIT_ARG_ENVV(envv, envc, length) do { \ 175195104Srwatson if (AUDITING_TD(curthread)) \ 176195104Srwatson audit_arg_envv((envv), (envc), (length)); \ 177195104Srwatson} while (0) 178195104Srwatson 179195104Srwatson#define AUDIT_ARG_EXIT(status, retval) do { \ 180195104Srwatson if (AUDITING_TD(curthread)) \ 181195104Srwatson audit_arg_exit((status), (retval)); \ 182195104Srwatson} while (0) 183195104Srwatson 184195104Srwatson#define AUDIT_ARG_EUID(euid) do { \ 185195104Srwatson if (AUDITING_TD(curthread)) \ 186195104Srwatson audit_arg_euid((euid)); \ 187195104Srwatson} while (0) 188195104Srwatson 189195104Srwatson#define AUDIT_ARG_FD(fd) do { \ 190195104Srwatson if (AUDITING_TD(curthread)) \ 191195104Srwatson audit_arg_fd((fd)); \ 192195104Srwatson} while (0) 193195104Srwatson 194195104Srwatson#define AUDIT_ARG_FILE(p, fp) do { \ 195195104Srwatson if (AUDITING_TD(curthread)) \ 196195104Srwatson audit_arg_file((p), (fp)); \ 197195104Srwatson} while (0) 198195104Srwatson 199195104Srwatson#define AUDIT_ARG_FFLAGS(fflags) do { \ 200195104Srwatson if (AUDITING_TD(curthread)) \ 201195104Srwatson audit_arg_fflags((fflags)); \ 202195104Srwatson} while (0) 203195104Srwatson 204195104Srwatson#define AUDIT_ARG_GID(gid) do { \ 205195104Srwatson if (AUDITING_TD(curthread)) \ 206195104Srwatson audit_arg_gid((gid)); \ 207195104Srwatson} while (0) 208195104Srwatson 209195104Srwatson#define AUDIT_ARG_GROUPSET(gidset, gidset_size) do { \ 210195104Srwatson if (AUDITING_TD(curthread)) \ 211195104Srwatson audit_arg_groupset((gidset), (gidset_size)); \ 212195104Srwatson} while (0) 213195104Srwatson 214195104Srwatson#define AUDIT_ARG_MODE(mode) do { \ 215195104Srwatson if (AUDITING_TD(curthread)) \ 216195104Srwatson audit_arg_mode((mode)); \ 217195104Srwatson} while (0) 218195104Srwatson 219195104Srwatson#define AUDIT_ARG_OWNER(uid, gid) do { \ 220195104Srwatson if (AUDITING_TD(curthread)) \ 221195104Srwatson audit_arg_owner((uid), (gid)); \ 222195104Srwatson} while (0) 223195104Srwatson 224195104Srwatson#define AUDIT_ARG_PID(pid) do { \ 225195104Srwatson if (AUDITING_TD(curthread)) \ 226195104Srwatson audit_arg_pid((pid)); \ 227195104Srwatson} while (0) 228195104Srwatson 229195104Srwatson#define AUDIT_ARG_PROCESS(p) do { \ 230195104Srwatson if (AUDITING_TD(curthread)) \ 231195104Srwatson audit_arg_process((p)); \ 232195104Srwatson} while (0) 233195104Srwatson 234195104Srwatson#define AUDIT_ARG_RGID(rgid) do { \ 235195104Srwatson if (AUDITING_TD(curthread)) \ 236196122Srwatson audit_arg_rgid((rgid)); \ 237195104Srwatson} while (0) 238195104Srwatson 239224181Sjonathan#define AUDIT_ARG_RIGHTS(rights) do { \ 240224181Sjonathan if (AUDITING_TD(curthread)) \ 241224181Sjonathan audit_arg_rights((rights)); \ 242224181Sjonathan} while (0) 243224181Sjonathan 244195104Srwatson#define AUDIT_ARG_RUID(ruid) do { \ 245195104Srwatson if (AUDITING_TD(curthread)) \ 246195104Srwatson audit_arg_ruid((ruid)); \ 247195104Srwatson} while (0) 248195104Srwatson 249195104Srwatson#define AUDIT_ARG_SIGNUM(signum) do { \ 250195104Srwatson if (AUDITING_TD(curthread)) \ 251195104Srwatson audit_arg_signum((signum)); \ 252195104Srwatson} while (0) 253195104Srwatson 254195104Srwatson#define AUDIT_ARG_SGID(sgid) do { \ 255195104Srwatson if (AUDITING_TD(curthread)) \ 256195104Srwatson audit_arg_sgid((sgid)); \ 257195104Srwatson} while (0) 258195104Srwatson 259195252Srwatson#define AUDIT_ARG_SOCKET(sodomain, sotype, soprotocol) do { \ 260195252Srwatson if (AUDITING_TD(curthread)) \ 261195252Srwatson audit_arg_socket((sodomain), (sotype), (soprotocol)); \ 262195252Srwatson} while (0) 263195252Srwatson 264195104Srwatson#define AUDIT_ARG_SUID(suid) do { \ 265195104Srwatson if (AUDITING_TD(curthread)) \ 266195104Srwatson audit_arg_suid((suid)); \ 267195104Srwatson} while (0) 268195104Srwatson 269195104Srwatson#define AUDIT_ARG_TEXT(text) do { \ 270195104Srwatson if (AUDITING_TD(curthread)) \ 271195104Srwatson audit_arg_text((text)); \ 272195104Srwatson} while (0) 273195104Srwatson 274195104Srwatson#define AUDIT_ARG_UID(uid) do { \ 275195104Srwatson if (AUDITING_TD(curthread)) \ 276195104Srwatson audit_arg_uid((uid)); \ 277195104Srwatson} while (0) 278195104Srwatson 279195939Srwatson#define AUDIT_ARG_UPATH1(td, upath) do { \ 280195104Srwatson if (AUDITING_TD(curthread)) \ 281195939Srwatson audit_arg_upath1((td), (upath)); \ 282195104Srwatson} while (0) 283195104Srwatson 284195939Srwatson#define AUDIT_ARG_UPATH2(td, upath) do { \ 285195939Srwatson if (AUDITING_TD(curthread)) \ 286195939Srwatson audit_arg_upath2((td), (upath)); \ 287195939Srwatson} while (0) 288195939Srwatson 289195104Srwatson#define AUDIT_ARG_VALUE(value) do { \ 290195104Srwatson if (AUDITING_TD(curthread)) \ 291195104Srwatson audit_arg_value((value)); \ 292195104Srwatson} while (0) 293195104Srwatson 294195926Srwatson#define AUDIT_ARG_VNODE1(vp) do { \ 295195104Srwatson if (AUDITING_TD(curthread)) \ 296195926Srwatson audit_arg_vnode1((vp)); \ 297195104Srwatson} while (0) 298195104Srwatson 299195926Srwatson#define AUDIT_ARG_VNODE2(vp) do { \ 300195926Srwatson if (AUDITING_TD(curthread)) \ 301195926Srwatson audit_arg_vnode2((vp)); \ 302195926Srwatson} while (0) 303195926Srwatson 304161970Srwatson#define AUDIT_SYSCALL_ENTER(code, td) do { \ 305155192Srwatson if (audit_enabled) { \ 306155192Srwatson audit_syscall_enter(code, td); \ 307155192Srwatson } \ 308156889Srwatson} while (0) 309155192Srwatson 310155192Srwatson/* 311155192Srwatson * Wrap the audit_syscall_exit() function so that it is called only when 312186822Srwatson * we have a audit record on the thread. Audit records can persist after 313186822Srwatson * auditing is disabled, so we don't just check audit_enabled here. 314155192Srwatson */ 315161970Srwatson#define AUDIT_SYSCALL_EXIT(error, td) do { \ 316189570Srwatson if (td->td_pflags & TDP_AUDITREC) \ 317155192Srwatson audit_syscall_exit(error, td); \ 318156889Srwatson} while (0) 319155192Srwatson 320155192Srwatson/* 321155192Srwatson * A Macro to wrap the audit_sysclose() function. 322155192Srwatson */ 323155192Srwatson#define AUDIT_SYSCLOSE(td, fd) do { \ 324189570Srwatson if (td->td_pflags & TDP_AUDITREC) \ 325155192Srwatson audit_sysclose(td, fd); \ 326156889Srwatson} while (0) 327155192Srwatson 328155192Srwatson#else /* !AUDIT */ 329155192Srwatson 330195104Srwatson#define AUDIT_ARG_ADDR(addr) 331195104Srwatson#define AUDIT_ARG_ARGV(argv, argc, length) 332195925Srwatson#define AUDIT_ARG_ATFD1(atfd) 333195925Srwatson#define AUDIT_ARG_ATFD2(atfd) 334195104Srwatson#define AUDIT_ARG_AUDITON(udata) 335195104Srwatson#define AUDIT_ARG_CMD(cmd) 336195104Srwatson#define AUDIT_ARG_DEV(dev) 337195104Srwatson#define AUDIT_ARG_EGID(egid) 338195104Srwatson#define AUDIT_ARG_ENVV(envv, envc, length) 339195104Srwatson#define AUDIT_ARG_EXIT(status, retval) 340195104Srwatson#define AUDIT_ARG_EUID(euid) 341195104Srwatson#define AUDIT_ARG_FD(fd) 342195104Srwatson#define AUDIT_ARG_FILE(p, fp) 343195104Srwatson#define AUDIT_ARG_FFLAGS(fflags) 344195104Srwatson#define AUDIT_ARG_GID(gid) 345195104Srwatson#define AUDIT_ARG_GROUPSET(gidset, gidset_size) 346195104Srwatson#define AUDIT_ARG_MODE(mode) 347195104Srwatson#define AUDIT_ARG_OWNER(uid, gid) 348195104Srwatson#define AUDIT_ARG_PID(pid) 349195104Srwatson#define AUDIT_ARG_PROCESS(p) 350195104Srwatson#define AUDIT_ARG_RGID(rgid) 351224181Sjonathan#define AUDIT_ARG_RIGHTS(rights) 352195104Srwatson#define AUDIT_ARG_RUID(ruid) 353195104Srwatson#define AUDIT_ARG_SIGNUM(signum) 354195104Srwatson#define AUDIT_ARG_SGID(sgid) 355195252Srwatson#define AUDIT_ARG_SOCKET(sodomain, sotype, soprotocol) 356195104Srwatson#define AUDIT_ARG_SUID(suid) 357195104Srwatson#define AUDIT_ARG_TEXT(text) 358195104Srwatson#define AUDIT_ARG_UID(uid) 359195939Srwatson#define AUDIT_ARG_UPATH1(td, upath) 360195939Srwatson#define AUDIT_ARG_UPATH2(td, upath) 361195104Srwatson#define AUDIT_ARG_VALUE(value) 362195926Srwatson#define AUDIT_ARG_VNODE1(vp) 363195926Srwatson#define AUDIT_ARG_VNODE2(vp) 364155192Srwatson 365195104Srwatson#define AUDIT_SYSCALL_ENTER(code, td) 366195104Srwatson#define AUDIT_SYSCALL_EXIT(error, td) 367155192Srwatson 368195104Srwatson#define AUDIT_SYSCLOSE(p, fd) 369155192Srwatson 370155192Srwatson#endif /* AUDIT */ 371155192Srwatson 372156882Srwatson#endif /* !_SECURITY_AUDIT_KERNEL_H_ */ 373