1f6d4a8a7SRobert Watson /*- 2bc9a43d6SRobert Watson * Copyright (c) 1999-2005 Apple Inc. 3718c8510SRobert Watson * All rights reserved. 4718c8510SRobert Watson * 5718c8510SRobert Watson * Redistribution and use in source and binary forms, with or without 6718c8510SRobert Watson * modification, are permitted provided that the following conditions 7718c8510SRobert Watson * are met: 8718c8510SRobert Watson * 1. Redistributions of source code must retain the above copyright 9718c8510SRobert Watson * notice, this list of conditions and the following disclaimer. 10718c8510SRobert Watson * 2. Redistributions in binary form must reproduce the above copyright 11718c8510SRobert Watson * notice, this list of conditions and the following disclaimer in the 12718c8510SRobert Watson * documentation and/or other materials provided with the distribution. 13bc9a43d6SRobert Watson * 3. Neither the name of Apple Inc. ("Apple") nor the names of 14718c8510SRobert Watson * its contributors may be used to endorse or promote products derived 15718c8510SRobert Watson * from this software without specific prior written permission. 16718c8510SRobert Watson * 17718c8510SRobert Watson * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND 18718c8510SRobert Watson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19718c8510SRobert Watson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20718c8510SRobert Watson * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR 21718c8510SRobert Watson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22718c8510SRobert Watson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23718c8510SRobert Watson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24718c8510SRobert Watson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25718c8510SRobert Watson * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 26718c8510SRobert Watson * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27718c8510SRobert Watson * POSSIBILITY OF SUCH DAMAGE. 28718c8510SRobert Watson */ 29718c8510SRobert Watson 30dda409d4SRobert Watson #include <sys/cdefs.h> 31dda409d4SRobert Watson __FBSDID("$FreeBSD$"); 32dda409d4SRobert Watson 33718c8510SRobert Watson #include <sys/param.h> 34718c8510SRobert Watson #include <sys/filedesc.h> 359ef8328dSMateusz Guzik #include <sys/capsicum.h> 36718c8510SRobert Watson #include <sys/ipc.h> 37718c8510SRobert Watson #include <sys/mount.h> 38718c8510SRobert Watson #include <sys/proc.h> 39718c8510SRobert Watson #include <sys/socket.h> 40718c8510SRobert Watson #include <sys/socketvar.h> 41718c8510SRobert Watson #include <sys/protosw.h> 42718c8510SRobert Watson #include <sys/domain.h> 435619113cSRobert Watson #include <sys/sbuf.h> 44718c8510SRobert Watson #include <sys/systm.h> 45718c8510SRobert Watson #include <sys/un.h> 46718c8510SRobert Watson #include <sys/vnode.h> 47718c8510SRobert Watson 48718c8510SRobert Watson #include <netinet/in.h> 49718c8510SRobert Watson #include <netinet/in_pcb.h> 50718c8510SRobert Watson 51718c8510SRobert Watson #include <security/audit/audit.h> 52718c8510SRobert Watson #include <security/audit/audit_private.h> 53718c8510SRobert Watson 54718c8510SRobert Watson /* 55718c8510SRobert Watson * Calls to manipulate elements of the audit record structure from system 56d8c0f4dcSRobert Watson * call code. Macro wrappers will prevent this functions from being entered 57d8c0f4dcSRobert Watson * if auditing is disabled, avoiding the function call cost. We check the 58d8c0f4dcSRobert Watson * thread audit record pointer anyway, as the audit condition could change, 59d8c0f4dcSRobert Watson * and pre-selection may not have allocated an audit record for this event. 60718c8510SRobert Watson * 61718c8510SRobert Watson * XXXAUDIT: Should we assert, in each case, that this field of the record 62718c8510SRobert Watson * hasn't already been filled in? 63718c8510SRobert Watson */ 64718c8510SRobert Watson void 65718c8510SRobert Watson audit_arg_addr(void *addr) 66718c8510SRobert Watson { 67718c8510SRobert Watson struct kaudit_record *ar; 68718c8510SRobert Watson 69718c8510SRobert Watson ar = currecord(); 70718c8510SRobert Watson if (ar == NULL) 71718c8510SRobert Watson return; 72718c8510SRobert Watson 73718c8510SRobert Watson ar->k_ar.ar_arg_addr = addr; 74718c8510SRobert Watson ARG_SET_VALID(ar, ARG_ADDR); 75718c8510SRobert Watson } 76718c8510SRobert Watson 77718c8510SRobert Watson void 78718c8510SRobert Watson audit_arg_exit(int status, int retval) 79718c8510SRobert Watson { 80718c8510SRobert Watson struct kaudit_record *ar; 81718c8510SRobert Watson 82718c8510SRobert Watson ar = currecord(); 83718c8510SRobert Watson if (ar == NULL) 84718c8510SRobert Watson return; 85718c8510SRobert Watson 86718c8510SRobert Watson ar->k_ar.ar_arg_exitstatus = status; 87718c8510SRobert Watson ar->k_ar.ar_arg_exitretval = retval; 88718c8510SRobert Watson ARG_SET_VALID(ar, ARG_EXIT); 89718c8510SRobert Watson } 90718c8510SRobert Watson 91718c8510SRobert Watson void 92718c8510SRobert Watson audit_arg_len(int len) 93718c8510SRobert Watson { 94718c8510SRobert Watson struct kaudit_record *ar; 95718c8510SRobert Watson 96718c8510SRobert Watson ar = currecord(); 97718c8510SRobert Watson if (ar == NULL) 98718c8510SRobert Watson return; 99718c8510SRobert Watson 100718c8510SRobert Watson ar->k_ar.ar_arg_len = len; 101718c8510SRobert Watson ARG_SET_VALID(ar, ARG_LEN); 102718c8510SRobert Watson } 103718c8510SRobert Watson 104718c8510SRobert Watson void 105e4b4bbb6SRobert Watson audit_arg_atfd1(int atfd) 106e4b4bbb6SRobert Watson { 107e4b4bbb6SRobert Watson struct kaudit_record *ar; 108e4b4bbb6SRobert Watson 109e4b4bbb6SRobert Watson ar = currecord(); 110e4b4bbb6SRobert Watson if (ar == NULL) 111e4b4bbb6SRobert Watson return; 112e4b4bbb6SRobert Watson 113e4b4bbb6SRobert Watson ar->k_ar.ar_arg_atfd1 = atfd; 114e4b4bbb6SRobert Watson ARG_SET_VALID(ar, ARG_ATFD1); 115e4b4bbb6SRobert Watson } 116e4b4bbb6SRobert Watson 117e4b4bbb6SRobert Watson void 118e4b4bbb6SRobert Watson audit_arg_atfd2(int atfd) 119e4b4bbb6SRobert Watson { 120e4b4bbb6SRobert Watson struct kaudit_record *ar; 121e4b4bbb6SRobert Watson 122e4b4bbb6SRobert Watson ar = currecord(); 123e4b4bbb6SRobert Watson if (ar == NULL) 124e4b4bbb6SRobert Watson return; 125e4b4bbb6SRobert Watson 126e4b4bbb6SRobert Watson ar->k_ar.ar_arg_atfd2 = atfd; 127e4b4bbb6SRobert Watson ARG_SET_VALID(ar, ARG_ATFD2); 128e4b4bbb6SRobert Watson } 129e4b4bbb6SRobert Watson 130e4b4bbb6SRobert Watson void 131718c8510SRobert Watson audit_arg_fd(int fd) 132718c8510SRobert Watson { 133718c8510SRobert Watson struct kaudit_record *ar; 134718c8510SRobert Watson 135718c8510SRobert Watson ar = currecord(); 136718c8510SRobert Watson if (ar == NULL) 137718c8510SRobert Watson return; 138718c8510SRobert Watson 139718c8510SRobert Watson ar->k_ar.ar_arg_fd = fd; 140718c8510SRobert Watson ARG_SET_VALID(ar, ARG_FD); 141718c8510SRobert Watson } 142718c8510SRobert Watson 143718c8510SRobert Watson void 144718c8510SRobert Watson audit_arg_fflags(int fflags) 145718c8510SRobert Watson { 146718c8510SRobert Watson struct kaudit_record *ar; 147718c8510SRobert Watson 148718c8510SRobert Watson ar = currecord(); 149718c8510SRobert Watson if (ar == NULL) 150718c8510SRobert Watson return; 151718c8510SRobert Watson 152718c8510SRobert Watson ar->k_ar.ar_arg_fflags = fflags; 153718c8510SRobert Watson ARG_SET_VALID(ar, ARG_FFLAGS); 154718c8510SRobert Watson } 155718c8510SRobert Watson 156718c8510SRobert Watson void 157718c8510SRobert Watson audit_arg_gid(gid_t gid) 158718c8510SRobert Watson { 159718c8510SRobert Watson struct kaudit_record *ar; 160718c8510SRobert Watson 161718c8510SRobert Watson ar = currecord(); 162718c8510SRobert Watson if (ar == NULL) 163718c8510SRobert Watson return; 164718c8510SRobert Watson 165718c8510SRobert Watson ar->k_ar.ar_arg_gid = gid; 166718c8510SRobert Watson ARG_SET_VALID(ar, ARG_GID); 167718c8510SRobert Watson } 168718c8510SRobert Watson 169718c8510SRobert Watson void 170718c8510SRobert Watson audit_arg_uid(uid_t uid) 171718c8510SRobert Watson { 172718c8510SRobert Watson struct kaudit_record *ar; 173718c8510SRobert Watson 174718c8510SRobert Watson ar = currecord(); 175718c8510SRobert Watson if (ar == NULL) 176718c8510SRobert Watson return; 177718c8510SRobert Watson 178718c8510SRobert Watson ar->k_ar.ar_arg_uid = uid; 179718c8510SRobert Watson ARG_SET_VALID(ar, ARG_UID); 180718c8510SRobert Watson } 181718c8510SRobert Watson 182718c8510SRobert Watson void 183718c8510SRobert Watson audit_arg_egid(gid_t egid) 184718c8510SRobert Watson { 185718c8510SRobert Watson struct kaudit_record *ar; 186718c8510SRobert Watson 187718c8510SRobert Watson ar = currecord(); 188718c8510SRobert Watson if (ar == NULL) 189718c8510SRobert Watson return; 190718c8510SRobert Watson 191718c8510SRobert Watson ar->k_ar.ar_arg_egid = egid; 192718c8510SRobert Watson ARG_SET_VALID(ar, ARG_EGID); 193718c8510SRobert Watson } 194718c8510SRobert Watson 195718c8510SRobert Watson void 196718c8510SRobert Watson audit_arg_euid(uid_t euid) 197718c8510SRobert Watson { 198718c8510SRobert Watson struct kaudit_record *ar; 199718c8510SRobert Watson 200718c8510SRobert Watson ar = currecord(); 201718c8510SRobert Watson if (ar == NULL) 202718c8510SRobert Watson return; 203718c8510SRobert Watson 204718c8510SRobert Watson ar->k_ar.ar_arg_euid = euid; 205718c8510SRobert Watson ARG_SET_VALID(ar, ARG_EUID); 206718c8510SRobert Watson } 207718c8510SRobert Watson 208718c8510SRobert Watson void 209718c8510SRobert Watson audit_arg_rgid(gid_t rgid) 210718c8510SRobert Watson { 211718c8510SRobert Watson struct kaudit_record *ar; 212718c8510SRobert Watson 213718c8510SRobert Watson ar = currecord(); 214718c8510SRobert Watson if (ar == NULL) 215718c8510SRobert Watson return; 216718c8510SRobert Watson 217718c8510SRobert Watson ar->k_ar.ar_arg_rgid = rgid; 218718c8510SRobert Watson ARG_SET_VALID(ar, ARG_RGID); 219718c8510SRobert Watson } 220718c8510SRobert Watson 221718c8510SRobert Watson void 222718c8510SRobert Watson audit_arg_ruid(uid_t ruid) 223718c8510SRobert Watson { 224718c8510SRobert Watson struct kaudit_record *ar; 225718c8510SRobert Watson 226718c8510SRobert Watson ar = currecord(); 227718c8510SRobert Watson if (ar == NULL) 228718c8510SRobert Watson return; 229718c8510SRobert Watson 230718c8510SRobert Watson ar->k_ar.ar_arg_ruid = ruid; 231718c8510SRobert Watson ARG_SET_VALID(ar, ARG_RUID); 232718c8510SRobert Watson } 233718c8510SRobert Watson 234718c8510SRobert Watson void 235718c8510SRobert Watson audit_arg_sgid(gid_t sgid) 236718c8510SRobert Watson { 237718c8510SRobert Watson struct kaudit_record *ar; 238718c8510SRobert Watson 239718c8510SRobert Watson ar = currecord(); 240718c8510SRobert Watson if (ar == NULL) 241718c8510SRobert Watson return; 242718c8510SRobert Watson 243718c8510SRobert Watson ar->k_ar.ar_arg_sgid = sgid; 244718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SGID); 245718c8510SRobert Watson } 246718c8510SRobert Watson 247718c8510SRobert Watson void 248718c8510SRobert Watson audit_arg_suid(uid_t suid) 249718c8510SRobert Watson { 250718c8510SRobert Watson struct kaudit_record *ar; 251718c8510SRobert Watson 252718c8510SRobert Watson ar = currecord(); 253718c8510SRobert Watson if (ar == NULL) 254718c8510SRobert Watson return; 255718c8510SRobert Watson 256718c8510SRobert Watson ar->k_ar.ar_arg_suid = suid; 257718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SUID); 258718c8510SRobert Watson } 259718c8510SRobert Watson 260718c8510SRobert Watson void 261718c8510SRobert Watson audit_arg_groupset(gid_t *gidset, u_int gidset_size) 262718c8510SRobert Watson { 26359b622e6SRobert Watson u_int i; 264718c8510SRobert Watson struct kaudit_record *ar; 265718c8510SRobert Watson 266412f9500SBrooks Davis KASSERT(gidset_size <= ngroups_max + 1, 267412f9500SBrooks Davis ("audit_arg_groupset: gidset_size > (kern.ngroups + 1)")); 26886120afaSStacey Son 269718c8510SRobert Watson ar = currecord(); 270718c8510SRobert Watson if (ar == NULL) 271718c8510SRobert Watson return; 272718c8510SRobert Watson 27386120afaSStacey Son if (ar->k_ar.ar_arg_groups.gidset == NULL) 27486120afaSStacey Son ar->k_ar.ar_arg_groups.gidset = malloc( 27586120afaSStacey Son sizeof(gid_t) * gidset_size, M_AUDITGIDSET, M_WAITOK); 27686120afaSStacey Son 277718c8510SRobert Watson for (i = 0; i < gidset_size; i++) 278718c8510SRobert Watson ar->k_ar.ar_arg_groups.gidset[i] = gidset[i]; 279718c8510SRobert Watson ar->k_ar.ar_arg_groups.gidset_size = gidset_size; 280718c8510SRobert Watson ARG_SET_VALID(ar, ARG_GROUPSET); 281718c8510SRobert Watson } 282718c8510SRobert Watson 283718c8510SRobert Watson void 284718c8510SRobert Watson audit_arg_login(char *login) 285718c8510SRobert Watson { 286718c8510SRobert Watson struct kaudit_record *ar; 287718c8510SRobert Watson 288718c8510SRobert Watson ar = currecord(); 289718c8510SRobert Watson if (ar == NULL) 290718c8510SRobert Watson return; 291718c8510SRobert Watson 292718c8510SRobert Watson strlcpy(ar->k_ar.ar_arg_login, login, MAXLOGNAME); 293718c8510SRobert Watson ARG_SET_VALID(ar, ARG_LOGIN); 294718c8510SRobert Watson } 295718c8510SRobert Watson 296718c8510SRobert Watson void 297718c8510SRobert Watson audit_arg_ctlname(int *name, int namelen) 298718c8510SRobert Watson { 299718c8510SRobert Watson struct kaudit_record *ar; 300718c8510SRobert Watson 301718c8510SRobert Watson ar = currecord(); 302718c8510SRobert Watson if (ar == NULL) 303718c8510SRobert Watson return; 304718c8510SRobert Watson 305718c8510SRobert Watson bcopy(name, &ar->k_ar.ar_arg_ctlname, namelen * sizeof(int)); 306718c8510SRobert Watson ar->k_ar.ar_arg_len = namelen; 307718c8510SRobert Watson ARG_SET_VALID(ar, ARG_CTLNAME | ARG_LEN); 308718c8510SRobert Watson } 309718c8510SRobert Watson 310718c8510SRobert Watson void 311718c8510SRobert Watson audit_arg_mask(int mask) 312718c8510SRobert Watson { 313718c8510SRobert Watson struct kaudit_record *ar; 314718c8510SRobert Watson 315718c8510SRobert Watson ar = currecord(); 316718c8510SRobert Watson if (ar == NULL) 317718c8510SRobert Watson return; 318718c8510SRobert Watson 319718c8510SRobert Watson ar->k_ar.ar_arg_mask = mask; 320718c8510SRobert Watson ARG_SET_VALID(ar, ARG_MASK); 321718c8510SRobert Watson } 322718c8510SRobert Watson 323718c8510SRobert Watson void 324718c8510SRobert Watson audit_arg_mode(mode_t mode) 325718c8510SRobert Watson { 326718c8510SRobert Watson struct kaudit_record *ar; 327718c8510SRobert Watson 328718c8510SRobert Watson ar = currecord(); 329718c8510SRobert Watson if (ar == NULL) 330718c8510SRobert Watson return; 331718c8510SRobert Watson 332718c8510SRobert Watson ar->k_ar.ar_arg_mode = mode; 333718c8510SRobert Watson ARG_SET_VALID(ar, ARG_MODE); 334718c8510SRobert Watson } 335718c8510SRobert Watson 336718c8510SRobert Watson void 337718c8510SRobert Watson audit_arg_dev(int dev) 338718c8510SRobert Watson { 339718c8510SRobert Watson struct kaudit_record *ar; 340718c8510SRobert Watson 341718c8510SRobert Watson ar = currecord(); 342718c8510SRobert Watson if (ar == NULL) 343718c8510SRobert Watson return; 344718c8510SRobert Watson 345718c8510SRobert Watson ar->k_ar.ar_arg_dev = dev; 346718c8510SRobert Watson ARG_SET_VALID(ar, ARG_DEV); 347718c8510SRobert Watson } 348718c8510SRobert Watson 349718c8510SRobert Watson void 350718c8510SRobert Watson audit_arg_value(long value) 351718c8510SRobert Watson { 352718c8510SRobert Watson struct kaudit_record *ar; 353718c8510SRobert Watson 354718c8510SRobert Watson ar = currecord(); 355718c8510SRobert Watson if (ar == NULL) 356718c8510SRobert Watson return; 357718c8510SRobert Watson 358718c8510SRobert Watson ar->k_ar.ar_arg_value = value; 359718c8510SRobert Watson ARG_SET_VALID(ar, ARG_VALUE); 360718c8510SRobert Watson } 361718c8510SRobert Watson 362718c8510SRobert Watson void 363718c8510SRobert Watson audit_arg_owner(uid_t uid, gid_t gid) 364718c8510SRobert Watson { 365718c8510SRobert Watson struct kaudit_record *ar; 366718c8510SRobert Watson 367718c8510SRobert Watson ar = currecord(); 368718c8510SRobert Watson if (ar == NULL) 369718c8510SRobert Watson return; 370718c8510SRobert Watson 371718c8510SRobert Watson ar->k_ar.ar_arg_uid = uid; 372718c8510SRobert Watson ar->k_ar.ar_arg_gid = gid; 373718c8510SRobert Watson ARG_SET_VALID(ar, ARG_UID | ARG_GID); 374718c8510SRobert Watson } 375718c8510SRobert Watson 376718c8510SRobert Watson void 377718c8510SRobert Watson audit_arg_pid(pid_t pid) 378718c8510SRobert Watson { 379718c8510SRobert Watson struct kaudit_record *ar; 380718c8510SRobert Watson 381718c8510SRobert Watson ar = currecord(); 382718c8510SRobert Watson if (ar == NULL) 383718c8510SRobert Watson return; 384718c8510SRobert Watson 385718c8510SRobert Watson ar->k_ar.ar_arg_pid = pid; 386718c8510SRobert Watson ARG_SET_VALID(ar, ARG_PID); 387718c8510SRobert Watson } 388718c8510SRobert Watson 389718c8510SRobert Watson void 390718c8510SRobert Watson audit_arg_process(struct proc *p) 391718c8510SRobert Watson { 392718c8510SRobert Watson struct kaudit_record *ar; 393e6870c95SRobert Watson struct ucred *cred; 394718c8510SRobert Watson 395814fe9e9SRobert Watson KASSERT(p != NULL, ("audit_arg_process: p == NULL")); 396814fe9e9SRobert Watson 397814fe9e9SRobert Watson PROC_LOCK_ASSERT(p, MA_OWNED); 398814fe9e9SRobert Watson 399718c8510SRobert Watson ar = currecord(); 400814fe9e9SRobert Watson if (ar == NULL) 401718c8510SRobert Watson return; 402718c8510SRobert Watson 403e6870c95SRobert Watson cred = p->p_ucred; 404e6870c95SRobert Watson ar->k_ar.ar_arg_auid = cred->cr_audit.ai_auid; 405e6870c95SRobert Watson ar->k_ar.ar_arg_euid = cred->cr_uid; 406e6870c95SRobert Watson ar->k_ar.ar_arg_egid = cred->cr_groups[0]; 407e6870c95SRobert Watson ar->k_ar.ar_arg_ruid = cred->cr_ruid; 408e6870c95SRobert Watson ar->k_ar.ar_arg_rgid = cred->cr_rgid; 409e6870c95SRobert Watson ar->k_ar.ar_arg_asid = cred->cr_audit.ai_asid; 410e6870c95SRobert Watson ar->k_ar.ar_arg_termid_addr = cred->cr_audit.ai_termid; 4115619113cSRobert Watson ar->k_ar.ar_arg_pid = p->p_pid; 412718c8510SRobert Watson ARG_SET_VALID(ar, ARG_AUID | ARG_EUID | ARG_EGID | ARG_RUID | 413f0cbfcc4SChristian S.J. Peron ARG_RGID | ARG_ASID | ARG_TERMID_ADDR | ARG_PID | ARG_PROCESS); 414718c8510SRobert Watson } 415718c8510SRobert Watson 416718c8510SRobert Watson void 417718c8510SRobert Watson audit_arg_signum(u_int signum) 418718c8510SRobert Watson { 419718c8510SRobert Watson struct kaudit_record *ar; 420718c8510SRobert Watson 421718c8510SRobert Watson ar = currecord(); 422718c8510SRobert Watson if (ar == NULL) 423718c8510SRobert Watson return; 424718c8510SRobert Watson 425718c8510SRobert Watson ar->k_ar.ar_arg_signum = signum; 426718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SIGNUM); 427718c8510SRobert Watson } 428718c8510SRobert Watson 429718c8510SRobert Watson void 430718c8510SRobert Watson audit_arg_socket(int sodomain, int sotype, int soprotocol) 431718c8510SRobert Watson { 432718c8510SRobert Watson struct kaudit_record *ar; 433718c8510SRobert Watson 434718c8510SRobert Watson ar = currecord(); 435718c8510SRobert Watson if (ar == NULL) 436718c8510SRobert Watson return; 437718c8510SRobert Watson 438718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_domain = sodomain; 439718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_type = sotype; 440718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_protocol = soprotocol; 441718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SOCKINFO); 442718c8510SRobert Watson } 443718c8510SRobert Watson 444718c8510SRobert Watson void 4457493f24eSPawel Jakub Dawidek audit_arg_sockaddr(struct thread *td, int dirfd, struct sockaddr *sa) 446718c8510SRobert Watson { 447718c8510SRobert Watson struct kaudit_record *ar; 448718c8510SRobert Watson 449814fe9e9SRobert Watson KASSERT(td != NULL, ("audit_arg_sockaddr: td == NULL")); 450814fe9e9SRobert Watson KASSERT(sa != NULL, ("audit_arg_sockaddr: sa == NULL")); 451814fe9e9SRobert Watson 452718c8510SRobert Watson ar = currecord(); 453814fe9e9SRobert Watson if (ar == NULL) 454718c8510SRobert Watson return; 455718c8510SRobert Watson 456130b1468SChristian S.J. Peron bcopy(sa, &ar->k_ar.ar_arg_sockaddr, sa->sa_len); 457814fe9e9SRobert Watson switch (sa->sa_family) { 458718c8510SRobert Watson case AF_INET: 459718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SADDRINET); 460718c8510SRobert Watson break; 461718c8510SRobert Watson 462718c8510SRobert Watson case AF_INET6: 463718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SADDRINET6); 464718c8510SRobert Watson break; 465718c8510SRobert Watson 466718c8510SRobert Watson case AF_UNIX: 4677493f24eSPawel Jakub Dawidek if (dirfd != AT_FDCWD) 4687493f24eSPawel Jakub Dawidek audit_arg_atfd1(dirfd); 4697493f24eSPawel Jakub Dawidek audit_arg_upath1(td, dirfd, 470499f0f4dSPawel Jakub Dawidek ((struct sockaddr_un *)sa)->sun_path); 471718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SADDRUNIX); 472718c8510SRobert Watson break; 473718c8510SRobert Watson /* XXXAUDIT: default:? */ 474718c8510SRobert Watson } 475718c8510SRobert Watson } 476718c8510SRobert Watson 477718c8510SRobert Watson void 478718c8510SRobert Watson audit_arg_auid(uid_t auid) 479718c8510SRobert Watson { 480718c8510SRobert Watson struct kaudit_record *ar; 481718c8510SRobert Watson 482718c8510SRobert Watson ar = currecord(); 483718c8510SRobert Watson if (ar == NULL) 484718c8510SRobert Watson return; 485718c8510SRobert Watson 486718c8510SRobert Watson ar->k_ar.ar_arg_auid = auid; 487718c8510SRobert Watson ARG_SET_VALID(ar, ARG_AUID); 488718c8510SRobert Watson } 489718c8510SRobert Watson 490718c8510SRobert Watson void 491718c8510SRobert Watson audit_arg_auditinfo(struct auditinfo *au_info) 492718c8510SRobert Watson { 493718c8510SRobert Watson struct kaudit_record *ar; 494718c8510SRobert Watson 495718c8510SRobert Watson ar = currecord(); 496718c8510SRobert Watson if (ar == NULL) 497718c8510SRobert Watson return; 498718c8510SRobert Watson 499718c8510SRobert Watson ar->k_ar.ar_arg_auid = au_info->ai_auid; 500718c8510SRobert Watson ar->k_ar.ar_arg_asid = au_info->ai_asid; 501718c8510SRobert Watson ar->k_ar.ar_arg_amask.am_success = au_info->ai_mask.am_success; 502718c8510SRobert Watson ar->k_ar.ar_arg_amask.am_failure = au_info->ai_mask.am_failure; 503718c8510SRobert Watson ar->k_ar.ar_arg_termid.port = au_info->ai_termid.port; 504718c8510SRobert Watson ar->k_ar.ar_arg_termid.machine = au_info->ai_termid.machine; 505718c8510SRobert Watson ARG_SET_VALID(ar, ARG_AUID | ARG_ASID | ARG_AMASK | ARG_TERMID); 506718c8510SRobert Watson } 507718c8510SRobert Watson 508718c8510SRobert Watson void 509cac465aaSChristian S.J. Peron audit_arg_auditinfo_addr(struct auditinfo_addr *au_info) 510cac465aaSChristian S.J. Peron { 511cac465aaSChristian S.J. Peron struct kaudit_record *ar; 512cac465aaSChristian S.J. Peron 513cac465aaSChristian S.J. Peron ar = currecord(); 514cac465aaSChristian S.J. Peron if (ar == NULL) 515cac465aaSChristian S.J. Peron return; 516cac465aaSChristian S.J. Peron 517cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_auid = au_info->ai_auid; 518cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_asid = au_info->ai_asid; 519cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_amask.am_success = au_info->ai_mask.am_success; 520cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_amask.am_failure = au_info->ai_mask.am_failure; 521cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_termid_addr.at_type = au_info->ai_termid.at_type; 522cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_termid_addr.at_port = au_info->ai_termid.at_port; 523cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_termid_addr.at_addr[0] = au_info->ai_termid.at_addr[0]; 524cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_termid_addr.at_addr[1] = au_info->ai_termid.at_addr[1]; 525cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_termid_addr.at_addr[2] = au_info->ai_termid.at_addr[2]; 526cac465aaSChristian S.J. Peron ar->k_ar.ar_arg_termid_addr.at_addr[3] = au_info->ai_termid.at_addr[3]; 527cac465aaSChristian S.J. Peron ARG_SET_VALID(ar, ARG_AUID | ARG_ASID | ARG_AMASK | ARG_TERMID_ADDR); 528cac465aaSChristian S.J. Peron } 529cac465aaSChristian S.J. Peron 530cac465aaSChristian S.J. Peron void 531718c8510SRobert Watson audit_arg_text(char *text) 532718c8510SRobert Watson { 533718c8510SRobert Watson struct kaudit_record *ar; 534718c8510SRobert Watson 535814fe9e9SRobert Watson KASSERT(text != NULL, ("audit_arg_text: text == NULL")); 536814fe9e9SRobert Watson 537718c8510SRobert Watson ar = currecord(); 538718c8510SRobert Watson if (ar == NULL) 539718c8510SRobert Watson return; 540718c8510SRobert Watson 541718c8510SRobert Watson /* Invalidate the text string */ 542718c8510SRobert Watson ar->k_ar.ar_valid_arg &= (ARG_ALL ^ ARG_TEXT); 543718c8510SRobert Watson 544718c8510SRobert Watson if (ar->k_ar.ar_arg_text == NULL) 545718c8510SRobert Watson ar->k_ar.ar_arg_text = malloc(MAXPATHLEN, M_AUDITTEXT, 546718c8510SRobert Watson M_WAITOK); 547718c8510SRobert Watson 548718c8510SRobert Watson strncpy(ar->k_ar.ar_arg_text, text, MAXPATHLEN); 549718c8510SRobert Watson ARG_SET_VALID(ar, ARG_TEXT); 550718c8510SRobert Watson } 551718c8510SRobert Watson 552718c8510SRobert Watson void 553718c8510SRobert Watson audit_arg_cmd(int cmd) 554718c8510SRobert Watson { 555718c8510SRobert Watson struct kaudit_record *ar; 556718c8510SRobert Watson 557718c8510SRobert Watson ar = currecord(); 558718c8510SRobert Watson if (ar == NULL) 559718c8510SRobert Watson return; 560718c8510SRobert Watson 561718c8510SRobert Watson ar->k_ar.ar_arg_cmd = cmd; 562718c8510SRobert Watson ARG_SET_VALID(ar, ARG_CMD); 563718c8510SRobert Watson } 564718c8510SRobert Watson 565718c8510SRobert Watson void 566718c8510SRobert Watson audit_arg_svipc_cmd(int cmd) 567718c8510SRobert Watson { 568718c8510SRobert Watson struct kaudit_record *ar; 569718c8510SRobert Watson 570718c8510SRobert Watson ar = currecord(); 571718c8510SRobert Watson if (ar == NULL) 572718c8510SRobert Watson return; 573718c8510SRobert Watson 574718c8510SRobert Watson ar->k_ar.ar_arg_svipc_cmd = cmd; 575718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SVIPC_CMD); 576718c8510SRobert Watson } 577718c8510SRobert Watson 578718c8510SRobert Watson void 579718c8510SRobert Watson audit_arg_svipc_perm(struct ipc_perm *perm) 580718c8510SRobert Watson { 581718c8510SRobert Watson struct kaudit_record *ar; 582718c8510SRobert Watson 583718c8510SRobert Watson ar = currecord(); 584718c8510SRobert Watson if (ar == NULL) 585718c8510SRobert Watson return; 586718c8510SRobert Watson 587718c8510SRobert Watson bcopy(perm, &ar->k_ar.ar_arg_svipc_perm, 588718c8510SRobert Watson sizeof(ar->k_ar.ar_arg_svipc_perm)); 589718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SVIPC_PERM); 590718c8510SRobert Watson } 591718c8510SRobert Watson 592718c8510SRobert Watson void 593718c8510SRobert Watson audit_arg_svipc_id(int id) 594718c8510SRobert Watson { 595718c8510SRobert Watson struct kaudit_record *ar; 596718c8510SRobert Watson 597718c8510SRobert Watson ar = currecord(); 598718c8510SRobert Watson if (ar == NULL) 599718c8510SRobert Watson return; 600718c8510SRobert Watson 601718c8510SRobert Watson ar->k_ar.ar_arg_svipc_id = id; 602718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SVIPC_ID); 603718c8510SRobert Watson } 604718c8510SRobert Watson 605718c8510SRobert Watson void 606718c8510SRobert Watson audit_arg_svipc_addr(void * addr) 607718c8510SRobert Watson { 608718c8510SRobert Watson struct kaudit_record *ar; 609718c8510SRobert Watson 610718c8510SRobert Watson ar = currecord(); 611718c8510SRobert Watson if (ar == NULL) 612718c8510SRobert Watson return; 613718c8510SRobert Watson 614718c8510SRobert Watson ar->k_ar.ar_arg_svipc_addr = addr; 615718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SVIPC_ADDR); 616718c8510SRobert Watson } 617718c8510SRobert Watson 618718c8510SRobert Watson void 619718c8510SRobert Watson audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, mode_t mode) 620718c8510SRobert Watson { 621718c8510SRobert Watson struct kaudit_record *ar; 622718c8510SRobert Watson 623718c8510SRobert Watson ar = currecord(); 624718c8510SRobert Watson if (ar == NULL) 625718c8510SRobert Watson return; 626718c8510SRobert Watson 627718c8510SRobert Watson ar->k_ar.ar_arg_pipc_perm.pipc_uid = uid; 628718c8510SRobert Watson ar->k_ar.ar_arg_pipc_perm.pipc_gid = gid; 629718c8510SRobert Watson ar->k_ar.ar_arg_pipc_perm.pipc_mode = mode; 630718c8510SRobert Watson ARG_SET_VALID(ar, ARG_POSIX_IPC_PERM); 631718c8510SRobert Watson } 632718c8510SRobert Watson 633718c8510SRobert Watson void 634718c8510SRobert Watson audit_arg_auditon(union auditon_udata *udata) 635718c8510SRobert Watson { 636718c8510SRobert Watson struct kaudit_record *ar; 637718c8510SRobert Watson 638718c8510SRobert Watson ar = currecord(); 639718c8510SRobert Watson if (ar == NULL) 640718c8510SRobert Watson return; 641718c8510SRobert Watson 642718c8510SRobert Watson bcopy((void *)udata, &ar->k_ar.ar_arg_auditon, 643718c8510SRobert Watson sizeof(ar->k_ar.ar_arg_auditon)); 644718c8510SRobert Watson ARG_SET_VALID(ar, ARG_AUDITON); 645718c8510SRobert Watson } 646718c8510SRobert Watson 647718c8510SRobert Watson /* 648718c8510SRobert Watson * Audit information about a file, either the file's vnode info, or its 649718c8510SRobert Watson * socket address info. 650718c8510SRobert Watson */ 651718c8510SRobert Watson void 652718c8510SRobert Watson audit_arg_file(struct proc *p, struct file *fp) 653718c8510SRobert Watson { 654718c8510SRobert Watson struct kaudit_record *ar; 655718c8510SRobert Watson struct socket *so; 656718c8510SRobert Watson struct inpcb *pcb; 657718c8510SRobert Watson struct vnode *vp; 658718c8510SRobert Watson 659814fe9e9SRobert Watson ar = currecord(); 660814fe9e9SRobert Watson if (ar == NULL) 661814fe9e9SRobert Watson return; 662814fe9e9SRobert Watson 663718c8510SRobert Watson switch (fp->f_type) { 664718c8510SRobert Watson case DTYPE_VNODE: 665718c8510SRobert Watson case DTYPE_FIFO: 666718c8510SRobert Watson /* 667718c8510SRobert Watson * XXXAUDIT: Only possibly to record as first vnode? 668718c8510SRobert Watson */ 669718c8510SRobert Watson vp = fp->f_vnode; 670927edcc9SJohn Baldwin vn_lock(vp, LK_SHARED | LK_RETRY); 671b146fc1bSRobert Watson audit_arg_vnode1(vp); 67222db15c0SAttilio Rao VOP_UNLOCK(vp, 0); 673718c8510SRobert Watson break; 674718c8510SRobert Watson 675718c8510SRobert Watson case DTYPE_SOCKET: 676718c8510SRobert Watson so = (struct socket *)fp->f_data; 677718c8510SRobert Watson if (INP_CHECK_SOCKAF(so, PF_INET)) { 678a1f3b839SRobert Watson SOCK_LOCK(so); 679718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_type = 680718c8510SRobert Watson so->so_type; 681718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_domain = 682718c8510SRobert Watson INP_SOCKAF(so); 683718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_protocol = 684718c8510SRobert Watson so->so_proto->pr_protocol; 685a1f3b839SRobert Watson SOCK_UNLOCK(so); 686718c8510SRobert Watson pcb = (struct inpcb *)so->so_pcb; 6871a46aa80SRobert Watson INP_RLOCK(pcb); 688718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_raddr = 689718c8510SRobert Watson pcb->inp_faddr.s_addr; 690718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_laddr = 691718c8510SRobert Watson pcb->inp_laddr.s_addr; 692718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_rport = 693718c8510SRobert Watson pcb->inp_fport; 694718c8510SRobert Watson ar->k_ar.ar_arg_sockinfo.so_lport = 695718c8510SRobert Watson pcb->inp_lport; 6961a46aa80SRobert Watson INP_RUNLOCK(pcb); 697718c8510SRobert Watson ARG_SET_VALID(ar, ARG_SOCKINFO); 698718c8510SRobert Watson } 699718c8510SRobert Watson break; 700718c8510SRobert Watson 701718c8510SRobert Watson default: 702718c8510SRobert Watson /* XXXAUDIT: else? */ 703718c8510SRobert Watson break; 704718c8510SRobert Watson } 705718c8510SRobert Watson } 706718c8510SRobert Watson 707718c8510SRobert Watson /* 708718c8510SRobert Watson * Store a path as given by the user process for auditing into the audit 709871499feSRobert Watson * record stored on the user thread. This function will allocate the memory 710c2f027ffSRobert Watson * to store the path info if not already available. This memory will be 711*d422682fSRobert Watson * freed when the audit record is freed. The path is canonlicalised with 712*d422682fSRobert Watson * respect to the thread and directory descriptor passed. 713718c8510SRobert Watson */ 714791b0ad2SRobert Watson static void 715499f0f4dSPawel Jakub Dawidek audit_arg_upath(struct thread *td, int dirfd, char *upath, char **pathp) 716791b0ad2SRobert Watson { 717791b0ad2SRobert Watson 718791b0ad2SRobert Watson if (*pathp == NULL) 719791b0ad2SRobert Watson *pathp = malloc(MAXPATHLEN, M_AUDITPATH, M_WAITOK); 720499f0f4dSPawel Jakub Dawidek audit_canon_path(td, dirfd, upath, *pathp); 721791b0ad2SRobert Watson } 722791b0ad2SRobert Watson 723718c8510SRobert Watson void 724499f0f4dSPawel Jakub Dawidek audit_arg_upath1(struct thread *td, int dirfd, char *upath) 725718c8510SRobert Watson { 726718c8510SRobert Watson struct kaudit_record *ar; 727814fe9e9SRobert Watson 728814fe9e9SRobert Watson ar = currecord(); 729814fe9e9SRobert Watson if (ar == NULL) 730814fe9e9SRobert Watson return; 731718c8510SRobert Watson 732499f0f4dSPawel Jakub Dawidek audit_arg_upath(td, dirfd, upath, &ar->k_ar.ar_arg_upath1); 733791b0ad2SRobert Watson ARG_SET_VALID(ar, ARG_UPATH1); 734791b0ad2SRobert Watson } 735718c8510SRobert Watson 736791b0ad2SRobert Watson void 737499f0f4dSPawel Jakub Dawidek audit_arg_upath2(struct thread *td, int dirfd, char *upath) 738791b0ad2SRobert Watson { 739791b0ad2SRobert Watson struct kaudit_record *ar; 740718c8510SRobert Watson 741791b0ad2SRobert Watson ar = currecord(); 742791b0ad2SRobert Watson if (ar == NULL) 743791b0ad2SRobert Watson return; 744718c8510SRobert Watson 745499f0f4dSPawel Jakub Dawidek audit_arg_upath(td, dirfd, upath, &ar->k_ar.ar_arg_upath2); 746791b0ad2SRobert Watson ARG_SET_VALID(ar, ARG_UPATH2); 747718c8510SRobert Watson } 748718c8510SRobert Watson 749718c8510SRobert Watson /* 750718c8510SRobert Watson * Function to save the path and vnode attr information into the audit 751718c8510SRobert Watson * record. 752718c8510SRobert Watson * 753718c8510SRobert Watson * It is assumed that the caller will hold any vnode locks necessary to 754718c8510SRobert Watson * perform a VOP_GETATTR() on the passed vnode. 755718c8510SRobert Watson * 756d8c0f4dcSRobert Watson * XXX: The attr code is very similar to vfs_vnops.c:vn_stat(), but always 757d8c0f4dcSRobert Watson * provides access to the generation number as we need that to construct the 758d8c0f4dcSRobert Watson * BSM file ID. 759d8c0f4dcSRobert Watson * 760d8c0f4dcSRobert Watson * XXX: We should accept the process argument from the caller, since it's 761d8c0f4dcSRobert Watson * very likely they already have a reference. 762d8c0f4dcSRobert Watson * 763718c8510SRobert Watson * XXX: Error handling in this function is poor. 764718c8510SRobert Watson * 765718c8510SRobert Watson * XXXAUDIT: Possibly KASSERT the path pointer is NULL? 766718c8510SRobert Watson */ 767b146fc1bSRobert Watson static int 768b146fc1bSRobert Watson audit_arg_vnode(struct vnode *vp, struct vnode_au_info *vnp) 769718c8510SRobert Watson { 770718c8510SRobert Watson struct vattr vattr; 771718c8510SRobert Watson int error; 772718c8510SRobert Watson 773718c8510SRobert Watson ASSERT_VOP_LOCKED(vp, "audit_arg_vnode"); 774718c8510SRobert Watson 7750359a12eSAttilio Rao error = VOP_GETATTR(vp, &vattr, curthread->td_ucred); 776718c8510SRobert Watson if (error) { 777718c8510SRobert Watson /* XXX: How to handle this case? */ 778b146fc1bSRobert Watson return (error); 779718c8510SRobert Watson } 780718c8510SRobert Watson 781718c8510SRobert Watson vnp->vn_mode = vattr.va_mode; 782718c8510SRobert Watson vnp->vn_uid = vattr.va_uid; 783718c8510SRobert Watson vnp->vn_gid = vattr.va_gid; 784718c8510SRobert Watson vnp->vn_dev = vattr.va_rdev; 785718c8510SRobert Watson vnp->vn_fsid = vattr.va_fsid; 786718c8510SRobert Watson vnp->vn_fileid = vattr.va_fileid; 787718c8510SRobert Watson vnp->vn_gen = vattr.va_gen; 788b146fc1bSRobert Watson return (0); 789b146fc1bSRobert Watson } 790b146fc1bSRobert Watson 791b146fc1bSRobert Watson void 792b146fc1bSRobert Watson audit_arg_vnode1(struct vnode *vp) 793b146fc1bSRobert Watson { 794b146fc1bSRobert Watson struct kaudit_record *ar; 795b146fc1bSRobert Watson int error; 796b146fc1bSRobert Watson 797b146fc1bSRobert Watson ar = currecord(); 798b146fc1bSRobert Watson if (ar == NULL) 799b146fc1bSRobert Watson return; 800b146fc1bSRobert Watson 801b146fc1bSRobert Watson ARG_CLEAR_VALID(ar, ARG_VNODE1); 802b146fc1bSRobert Watson error = audit_arg_vnode(vp, &ar->k_ar.ar_arg_vnode1); 803b146fc1bSRobert Watson if (error == 0) 804718c8510SRobert Watson ARG_SET_VALID(ar, ARG_VNODE1); 805b146fc1bSRobert Watson } 806b146fc1bSRobert Watson 807b146fc1bSRobert Watson void 808b146fc1bSRobert Watson audit_arg_vnode2(struct vnode *vp) 809b146fc1bSRobert Watson { 810b146fc1bSRobert Watson struct kaudit_record *ar; 811b146fc1bSRobert Watson int error; 812b146fc1bSRobert Watson 813b146fc1bSRobert Watson ar = currecord(); 814b146fc1bSRobert Watson if (ar == NULL) 815b146fc1bSRobert Watson return; 816b146fc1bSRobert Watson 817b146fc1bSRobert Watson ARG_CLEAR_VALID(ar, ARG_VNODE2); 818b146fc1bSRobert Watson error = audit_arg_vnode(vp, &ar->k_ar.ar_arg_vnode2); 819b146fc1bSRobert Watson if (error == 0) 820718c8510SRobert Watson ARG_SET_VALID(ar, ARG_VNODE2); 821718c8510SRobert Watson } 822718c8510SRobert Watson 823718c8510SRobert Watson /* 824ae1078d6SWayne Salamon * Audit the argument strings passed to exec. 825ae1078d6SWayne Salamon */ 826ae1078d6SWayne Salamon void 827ae1078d6SWayne Salamon audit_arg_argv(char *argv, int argc, int length) 828ae1078d6SWayne Salamon { 829ae1078d6SWayne Salamon struct kaudit_record *ar; 830ae1078d6SWayne Salamon 831ae1078d6SWayne Salamon if (audit_argv == 0) 832ae1078d6SWayne Salamon return; 833ae1078d6SWayne Salamon 834ae1078d6SWayne Salamon ar = currecord(); 835ae1078d6SWayne Salamon if (ar == NULL) 836ae1078d6SWayne Salamon return; 837ae1078d6SWayne Salamon 838ae1078d6SWayne Salamon ar->k_ar.ar_arg_argv = malloc(length, M_AUDITTEXT, M_WAITOK); 839ae1078d6SWayne Salamon bcopy(argv, ar->k_ar.ar_arg_argv, length); 840ae1078d6SWayne Salamon ar->k_ar.ar_arg_argc = argc; 841ae1078d6SWayne Salamon ARG_SET_VALID(ar, ARG_ARGV); 842ae1078d6SWayne Salamon } 843ae1078d6SWayne Salamon 844ae1078d6SWayne Salamon /* 845ae1078d6SWayne Salamon * Audit the environment strings passed to exec. 846ae1078d6SWayne Salamon */ 847ae1078d6SWayne Salamon void 848ae1078d6SWayne Salamon audit_arg_envv(char *envv, int envc, int length) 849ae1078d6SWayne Salamon { 850ae1078d6SWayne Salamon struct kaudit_record *ar; 851ae1078d6SWayne Salamon 852ae1078d6SWayne Salamon if (audit_arge == 0) 853ae1078d6SWayne Salamon return; 854ae1078d6SWayne Salamon 855ae1078d6SWayne Salamon ar = currecord(); 856ae1078d6SWayne Salamon if (ar == NULL) 857ae1078d6SWayne Salamon return; 858ae1078d6SWayne Salamon 859ae1078d6SWayne Salamon ar->k_ar.ar_arg_envv = malloc(length, M_AUDITTEXT, M_WAITOK); 860ae1078d6SWayne Salamon bcopy(envv, ar->k_ar.ar_arg_envv, length); 861ae1078d6SWayne Salamon ar->k_ar.ar_arg_envc = envc; 862ae1078d6SWayne Salamon ARG_SET_VALID(ar, ARG_ENVV); 863ae1078d6SWayne Salamon } 864ae1078d6SWayne Salamon 865778b0e42SJonathan Anderson void 8667008be5bSPawel Jakub Dawidek audit_arg_rights(cap_rights_t *rightsp) 867778b0e42SJonathan Anderson { 868778b0e42SJonathan Anderson struct kaudit_record *ar; 869778b0e42SJonathan Anderson 870778b0e42SJonathan Anderson ar = currecord(); 871778b0e42SJonathan Anderson if (ar == NULL) 872778b0e42SJonathan Anderson return; 873778b0e42SJonathan Anderson 8747008be5bSPawel Jakub Dawidek ar->k_ar.ar_arg_rights = *rightsp; 875778b0e42SJonathan Anderson ARG_SET_VALID(ar, ARG_RIGHTS); 876778b0e42SJonathan Anderson } 877778b0e42SJonathan Anderson 8782609222aSPawel Jakub Dawidek void 8792609222aSPawel Jakub Dawidek audit_arg_fcntl_rights(uint32_t fcntlrights) 8802609222aSPawel Jakub Dawidek { 8812609222aSPawel Jakub Dawidek struct kaudit_record *ar; 8822609222aSPawel Jakub Dawidek 8832609222aSPawel Jakub Dawidek ar = currecord(); 8842609222aSPawel Jakub Dawidek if (ar == NULL) 8852609222aSPawel Jakub Dawidek return; 8862609222aSPawel Jakub Dawidek 8872609222aSPawel Jakub Dawidek ar->k_ar.ar_arg_fcntl_rights = fcntlrights; 8882609222aSPawel Jakub Dawidek ARG_SET_VALID(ar, ARG_FCNTL_RIGHTS); 8892609222aSPawel Jakub Dawidek } 8902609222aSPawel Jakub Dawidek 891ae1078d6SWayne Salamon /* 892871499feSRobert Watson * The close() system call uses it's own audit call to capture the path/vnode 893871499feSRobert Watson * information because those pieces are not easily obtained within the system 894871499feSRobert Watson * call itself. 895718c8510SRobert Watson */ 896718c8510SRobert Watson void 897718c8510SRobert Watson audit_sysclose(struct thread *td, int fd) 898718c8510SRobert Watson { 8999ef8328dSMateusz Guzik cap_rights_t rights; 900814fe9e9SRobert Watson struct kaudit_record *ar; 901718c8510SRobert Watson struct vnode *vp; 902718c8510SRobert Watson struct file *fp; 903718c8510SRobert Watson 904814fe9e9SRobert Watson KASSERT(td != NULL, ("audit_sysclose: td == NULL")); 905814fe9e9SRobert Watson 906814fe9e9SRobert Watson ar = currecord(); 907814fe9e9SRobert Watson if (ar == NULL) 908814fe9e9SRobert Watson return; 909814fe9e9SRobert Watson 910718c8510SRobert Watson audit_arg_fd(fd); 911718c8510SRobert Watson 9124da8456fSMateusz Guzik if (getvnode(td, fd, cap_rights_init(&rights), &fp) != 0) 913718c8510SRobert Watson return; 914718c8510SRobert Watson 915718c8510SRobert Watson vp = fp->f_vnode; 916927edcc9SJohn Baldwin vn_lock(vp, LK_SHARED | LK_RETRY); 917b146fc1bSRobert Watson audit_arg_vnode1(vp); 91822db15c0SAttilio Rao VOP_UNLOCK(vp, 0); 919718c8510SRobert Watson fdrop(fp, td); 920718c8510SRobert Watson } 921