audit.h revision 246446
1/*- 2 * Copyright (c) 1999-2005 Apple Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $FreeBSD: head/sys/security/audit/audit.h 246446 2013-02-07 00:24:23Z pjd $ 30 */ 31 32/* 33 * This header includes function prototypes and type definitions that are 34 * necessary for the kernel as a whole to interact with the audit subsystem. 35 */ 36 37#ifndef _SECURITY_AUDIT_KERNEL_H_ 38#define _SECURITY_AUDIT_KERNEL_H_ 39 40#ifndef _KERNEL 41#error "no user-serviceable parts inside" 42#endif 43 44#include <bsm/audit.h> 45 46#include <sys/file.h> 47#include <sys/sysctl.h> 48 49/* 50 * Audit subsystem condition flags. The audit_enabled flag is set and 51 * removed automatically as a result of configuring log files, and can be 52 * observed but should not be directly manipulated. The audit suspension 53 * flag permits audit to be temporarily disabled without reconfiguring the 54 * audit target. 55 */ 56extern int audit_enabled; 57extern int audit_suspended; 58 59void audit_syscall_enter(unsigned short code, struct thread *td); 60void audit_syscall_exit(int error, struct thread *td); 61 62/* 63 * The remaining kernel functions are conditionally compiled in as they are 64 * wrapped by a macro, and the macro should be the only place in the source 65 * tree where these functions are referenced. 66 */ 67#ifdef AUDIT 68struct ipc_perm; 69struct sockaddr; 70union auditon_udata; 71void audit_arg_addr(void * addr); 72void audit_arg_exit(int status, int retval); 73void audit_arg_len(int len); 74void audit_arg_atfd1(int atfd); 75void audit_arg_atfd2(int atfd); 76void audit_arg_fd(int fd); 77void audit_arg_fflags(int fflags); 78void audit_arg_gid(gid_t gid); 79void audit_arg_uid(uid_t uid); 80void audit_arg_egid(gid_t egid); 81void audit_arg_euid(uid_t euid); 82void audit_arg_rgid(gid_t rgid); 83void audit_arg_ruid(uid_t ruid); 84void audit_arg_sgid(gid_t sgid); 85void audit_arg_suid(uid_t suid); 86void audit_arg_groupset(gid_t *gidset, u_int gidset_size); 87void audit_arg_login(char *login); 88void audit_arg_ctlname(int *name, int namelen); 89void audit_arg_mask(int mask); 90void audit_arg_mode(mode_t mode); 91void audit_arg_dev(int dev); 92void audit_arg_value(long value); 93void audit_arg_owner(uid_t uid, gid_t gid); 94void audit_arg_pid(pid_t pid); 95void audit_arg_process(struct proc *p); 96void audit_arg_signum(u_int signum); 97void audit_arg_socket(int sodomain, int sotype, int soprotocol); 98void audit_arg_sockaddr(struct thread *td, struct sockaddr *sa); 99void audit_arg_auid(uid_t auid); 100void audit_arg_auditinfo(struct auditinfo *au_info); 101void audit_arg_auditinfo_addr(struct auditinfo_addr *au_info); 102void audit_arg_upath1(struct thread *td, int dirfd, char *upath); 103void audit_arg_upath2(struct thread *td, int dirfd, char *upath); 104void audit_arg_vnode1(struct vnode *vp); 105void audit_arg_vnode2(struct vnode *vp); 106void audit_arg_text(char *text); 107void audit_arg_cmd(int cmd); 108void audit_arg_svipc_cmd(int cmd); 109void audit_arg_svipc_perm(struct ipc_perm *perm); 110void audit_arg_svipc_id(int id); 111void audit_arg_svipc_addr(void *addr); 112void audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, mode_t mode); 113void audit_arg_auditon(union auditon_udata *udata); 114void audit_arg_file(struct proc *p, struct file *fp); 115void audit_arg_argv(char *argv, int argc, int length); 116void audit_arg_envv(char *envv, int envc, int length); 117void audit_arg_rights(cap_rights_t rights); 118void audit_sysclose(struct thread *td, int fd); 119void audit_cred_copy(struct ucred *src, struct ucred *dest); 120void audit_cred_destroy(struct ucred *cred); 121void audit_cred_init(struct ucred *cred); 122void audit_cred_kproc0(struct ucred *cred); 123void audit_cred_proc1(struct ucred *cred); 124void audit_proc_coredump(struct thread *td, char *path, int errcode); 125void audit_thread_alloc(struct thread *td); 126void audit_thread_free(struct thread *td); 127 128/* 129 * Define macros to wrap the audit_arg_* calls by checking the global 130 * audit_enabled flag before performing the actual call. 131 */ 132#define AUDITING_TD(td) ((td)->td_pflags & TDP_AUDITREC) 133 134#define AUDIT_ARG_ADDR(addr) do { \ 135 if (AUDITING_TD(curthread)) \ 136 audit_arg_addr((addr)); \ 137} while (0) 138 139#define AUDIT_ARG_ARGV(argv, argc, length) do { \ 140 if (AUDITING_TD(curthread)) \ 141 audit_arg_argv((argv), (argc), (length)); \ 142} while (0) 143 144#define AUDIT_ARG_ATFD1(atfd) do { \ 145 if (AUDITING_TD(curthread)) \ 146 audit_arg_atfd1((atfd)); \ 147} while (0) 148 149#define AUDIT_ARG_ATFD2(atfd) do { \ 150 if (AUDITING_TD(curthread)) \ 151 audit_arg_atfd2((atfd)); \ 152} while (0) 153 154#define AUDIT_ARG_AUDITON(udata) do { \ 155 if (AUDITING_TD(curthread)) \ 156 audit_arg_auditon((udata)); \ 157} while (0) 158 159#define AUDIT_ARG_CMD(cmd) do { \ 160 if (AUDITING_TD(curthread)) \ 161 audit_arg_cmd((cmd)); \ 162} while (0) 163 164#define AUDIT_ARG_DEV(dev) do { \ 165 if (AUDITING_TD(curthread)) \ 166 audit_arg_dev((dev)); \ 167} while (0) 168 169#define AUDIT_ARG_EGID(egid) do { \ 170 if (AUDITING_TD(curthread)) \ 171 audit_arg_egid((egid)); \ 172} while (0) 173 174#define AUDIT_ARG_ENVV(envv, envc, length) do { \ 175 if (AUDITING_TD(curthread)) \ 176 audit_arg_envv((envv), (envc), (length)); \ 177} while (0) 178 179#define AUDIT_ARG_EXIT(status, retval) do { \ 180 if (AUDITING_TD(curthread)) \ 181 audit_arg_exit((status), (retval)); \ 182} while (0) 183 184#define AUDIT_ARG_EUID(euid) do { \ 185 if (AUDITING_TD(curthread)) \ 186 audit_arg_euid((euid)); \ 187} while (0) 188 189#define AUDIT_ARG_FD(fd) do { \ 190 if (AUDITING_TD(curthread)) \ 191 audit_arg_fd((fd)); \ 192} while (0) 193 194#define AUDIT_ARG_FILE(p, fp) do { \ 195 if (AUDITING_TD(curthread)) \ 196 audit_arg_file((p), (fp)); \ 197} while (0) 198 199#define AUDIT_ARG_FFLAGS(fflags) do { \ 200 if (AUDITING_TD(curthread)) \ 201 audit_arg_fflags((fflags)); \ 202} while (0) 203 204#define AUDIT_ARG_GID(gid) do { \ 205 if (AUDITING_TD(curthread)) \ 206 audit_arg_gid((gid)); \ 207} while (0) 208 209#define AUDIT_ARG_GROUPSET(gidset, gidset_size) do { \ 210 if (AUDITING_TD(curthread)) \ 211 audit_arg_groupset((gidset), (gidset_size)); \ 212} while (0) 213 214#define AUDIT_ARG_MODE(mode) do { \ 215 if (AUDITING_TD(curthread)) \ 216 audit_arg_mode((mode)); \ 217} while (0) 218 219#define AUDIT_ARG_OWNER(uid, gid) do { \ 220 if (AUDITING_TD(curthread)) \ 221 audit_arg_owner((uid), (gid)); \ 222} while (0) 223 224#define AUDIT_ARG_PID(pid) do { \ 225 if (AUDITING_TD(curthread)) \ 226 audit_arg_pid((pid)); \ 227} while (0) 228 229#define AUDIT_ARG_PROCESS(p) do { \ 230 if (AUDITING_TD(curthread)) \ 231 audit_arg_process((p)); \ 232} while (0) 233 234#define AUDIT_ARG_RGID(rgid) do { \ 235 if (AUDITING_TD(curthread)) \ 236 audit_arg_rgid((rgid)); \ 237} while (0) 238 239#define AUDIT_ARG_RIGHTS(rights) do { \ 240 if (AUDITING_TD(curthread)) \ 241 audit_arg_rights((rights)); \ 242} while (0) 243 244#define AUDIT_ARG_RUID(ruid) do { \ 245 if (AUDITING_TD(curthread)) \ 246 audit_arg_ruid((ruid)); \ 247} while (0) 248 249#define AUDIT_ARG_SIGNUM(signum) do { \ 250 if (AUDITING_TD(curthread)) \ 251 audit_arg_signum((signum)); \ 252} while (0) 253 254#define AUDIT_ARG_SGID(sgid) do { \ 255 if (AUDITING_TD(curthread)) \ 256 audit_arg_sgid((sgid)); \ 257} while (0) 258 259#define AUDIT_ARG_SOCKET(sodomain, sotype, soprotocol) do { \ 260 if (AUDITING_TD(curthread)) \ 261 audit_arg_socket((sodomain), (sotype), (soprotocol)); \ 262} while (0) 263 264#define AUDIT_ARG_SOCKADDR(td, sa) do { \ 265 if (AUDITING_TD(curthread)) \ 266 audit_arg_sockaddr((td), (sa)); \ 267} while (0) 268 269#define AUDIT_ARG_SUID(suid) do { \ 270 if (AUDITING_TD(curthread)) \ 271 audit_arg_suid((suid)); \ 272} while (0) 273 274#define AUDIT_ARG_TEXT(text) do { \ 275 if (AUDITING_TD(curthread)) \ 276 audit_arg_text((text)); \ 277} while (0) 278 279#define AUDIT_ARG_UID(uid) do { \ 280 if (AUDITING_TD(curthread)) \ 281 audit_arg_uid((uid)); \ 282} while (0) 283 284#define AUDIT_ARG_UPATH1(td, dirfd, upath) do { \ 285 if (AUDITING_TD(curthread)) \ 286 audit_arg_upath1((td), (dirfd), (upath)); \ 287} while (0) 288 289#define AUDIT_ARG_UPATH2(td, dirfd, upath) do { \ 290 if (AUDITING_TD(curthread)) \ 291 audit_arg_upath2((td), (dirfd), (upath)); \ 292} while (0) 293 294#define AUDIT_ARG_VALUE(value) do { \ 295 if (AUDITING_TD(curthread)) \ 296 audit_arg_value((value)); \ 297} while (0) 298 299#define AUDIT_ARG_VNODE1(vp) do { \ 300 if (AUDITING_TD(curthread)) \ 301 audit_arg_vnode1((vp)); \ 302} while (0) 303 304#define AUDIT_ARG_VNODE2(vp) do { \ 305 if (AUDITING_TD(curthread)) \ 306 audit_arg_vnode2((vp)); \ 307} while (0) 308 309#define AUDIT_SYSCALL_ENTER(code, td) do { \ 310 if (audit_enabled) { \ 311 audit_syscall_enter(code, td); \ 312 } \ 313} while (0) 314 315/* 316 * Wrap the audit_syscall_exit() function so that it is called only when 317 * we have a audit record on the thread. Audit records can persist after 318 * auditing is disabled, so we don't just check audit_enabled here. 319 */ 320#define AUDIT_SYSCALL_EXIT(error, td) do { \ 321 if (td->td_pflags & TDP_AUDITREC) \ 322 audit_syscall_exit(error, td); \ 323} while (0) 324 325/* 326 * A Macro to wrap the audit_sysclose() function. 327 */ 328#define AUDIT_SYSCLOSE(td, fd) do { \ 329 if (td->td_pflags & TDP_AUDITREC) \ 330 audit_sysclose(td, fd); \ 331} while (0) 332 333#else /* !AUDIT */ 334 335#define AUDIT_ARG_ADDR(addr) 336#define AUDIT_ARG_ARGV(argv, argc, length) 337#define AUDIT_ARG_ATFD1(atfd) 338#define AUDIT_ARG_ATFD2(atfd) 339#define AUDIT_ARG_AUDITON(udata) 340#define AUDIT_ARG_CMD(cmd) 341#define AUDIT_ARG_DEV(dev) 342#define AUDIT_ARG_EGID(egid) 343#define AUDIT_ARG_ENVV(envv, envc, length) 344#define AUDIT_ARG_EXIT(status, retval) 345#define AUDIT_ARG_EUID(euid) 346#define AUDIT_ARG_FD(fd) 347#define AUDIT_ARG_FILE(p, fp) 348#define AUDIT_ARG_FFLAGS(fflags) 349#define AUDIT_ARG_GID(gid) 350#define AUDIT_ARG_GROUPSET(gidset, gidset_size) 351#define AUDIT_ARG_MODE(mode) 352#define AUDIT_ARG_OWNER(uid, gid) 353#define AUDIT_ARG_PID(pid) 354#define AUDIT_ARG_PROCESS(p) 355#define AUDIT_ARG_RGID(rgid) 356#define AUDIT_ARG_RIGHTS(rights) 357#define AUDIT_ARG_RUID(ruid) 358#define AUDIT_ARG_SIGNUM(signum) 359#define AUDIT_ARG_SGID(sgid) 360#define AUDIT_ARG_SOCKET(sodomain, sotype, soprotocol) 361#define AUDIT_ARG_SOCKADDR(td, sa) 362#define AUDIT_ARG_SUID(suid) 363#define AUDIT_ARG_TEXT(text) 364#define AUDIT_ARG_UID(uid) 365#define AUDIT_ARG_UPATH1(td, dirfd, upath) 366#define AUDIT_ARG_UPATH2(td, dirfd, upath) 367#define AUDIT_ARG_VALUE(value) 368#define AUDIT_ARG_VNODE1(vp) 369#define AUDIT_ARG_VNODE2(vp) 370 371#define AUDIT_SYSCALL_ENTER(code, td) 372#define AUDIT_SYSCALL_EXIT(error, td) 373 374#define AUDIT_SYSCLOSE(p, fd) 375 376#endif /* AUDIT */ 377 378#endif /* !_SECURITY_AUDIT_KERNEL_H_ */ 379