2 * Copyright (c) 1999-2020 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
13 * its contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
30 * support for mandatory and extensible security protections. This notice
31 * is included in support of clause 2.2 (b) of the Apple Public License,
35 #include <sys/types.h>
36 #include <sys/vnode_internal.h>
39 #include <sys/socketvar.h>
40 #include <sys/socket.h>
41 #include <sys/queue.h>
42 #include <sys/fcntl.h>
46 #include <bsm/audit.h>
47 #include <bsm/audit_internal.h>
48 #include <bsm/audit_record.h>
49 #include <bsm/audit_kevents.h>
51 #include <security/audit/audit.h>
52 #include <security/audit/audit_bsd.h>
53 #include <security/audit/audit_private.h>
55 #include <netinet/in_systm.h>
56 #include <netinet/in.h>
57 #include <netinet/ip.h>
60 MALLOC_DEFINE(M_AUDITBSM
, "audit_bsm", "Audit BSM data");
63 #include <security/mac_framework.h>
66 static void audit_sys_auditon(struct audit_record
*ar
,
67 struct au_record
*rec
);
68 static void audit_sys_fcntl(struct kaudit_record
*kar
,
69 struct au_record
*rec
);
72 * Initialize the BSM auditing subsystem.
81 * This call reserves memory for the audit record. Memory must be guaranteed
82 * before any auditable event can be generated. The au_record structure
83 * maintains a reference to the memory allocated above and also the list of
84 * tokens associated with this record.
86 static struct au_record
*
89 struct au_record
*rec
;
91 rec
= malloc(sizeof(*rec
), M_AUDITBSM
, M_WAITOK
);
93 TAILQ_INIT(&rec
->token_q
);
101 * Store the token with the record descriptor.
104 kau_write(struct au_record
*rec
, struct au_token
*tok
)
106 KASSERT(tok
!= NULL
, ("kau_write: tok == NULL"));
108 TAILQ_INSERT_TAIL(&rec
->token_q
, tok
, tokens
);
109 rec
->len
+= tok
->len
;
113 * Close out the audit record by adding the header token, identifying any
114 * missing tokens. Write out the tokens to the record memory.
117 kau_close(struct au_record
*rec
, struct timespec
*ctime
, short event
)
121 token_t
*cur
, *hdr
, *trail
;
124 struct auditinfo_addr ak
;
127 audit_get_kinfo(&ak
);
129 switch (ak
.ai_termid
.at_type
) {
131 hdrsize
= (ak
.ai_termid
.at_addr
[0] == INADDR_ANY
) ?
132 AUDIT_HEADER_SIZE
: AUDIT_HEADER_EX_SIZE(&ak
);
135 ap
= (struct in6_addr
*)&ak
.ai_termid
.at_addr
[0];
136 hdrsize
= (IN6_IS_ADDR_UNSPECIFIED(ap
)) ? AUDIT_HEADER_SIZE
:
137 AUDIT_HEADER_EX_SIZE(&ak
);
140 panic("kau_close: invalid address family");
142 tot_rec_size
= rec
->len
+ AUDIT_HEADER_SIZE
+ AUDIT_TRAILER_SIZE
;
143 rec
->data
= malloc(tot_rec_size
, M_AUDITBSM
, M_WAITOK
| M_ZERO
);
145 tm
.tv_usec
= ctime
->tv_nsec
/ 1000;
146 tm
.tv_sec
= ctime
->tv_sec
;
147 if (hdrsize
!= AUDIT_HEADER_SIZE
) {
148 hdr
= au_to_header32_ex_tm(tot_rec_size
, event
, 0, tm
, &ak
);
150 hdr
= au_to_header32_tm(tot_rec_size
, event
, 0, tm
);
152 TAILQ_INSERT_HEAD(&rec
->token_q
, hdr
, tokens
);
154 trail
= au_to_trailer(tot_rec_size
);
155 TAILQ_INSERT_TAIL(&rec
->token_q
, trail
, tokens
);
157 rec
->len
= tot_rec_size
;
159 TAILQ_FOREACH(cur
, &rec
->token_q
, tokens
) {
160 memcpy(dptr
, cur
->t_data
, cur
->len
);
166 * Free a BSM audit record by releasing all the tokens and clearing the audit
167 * record information.
170 kau_free(struct au_record
*rec
)
172 struct au_token
*tok
;
174 /* Free the token list. */
175 while ((tok
= TAILQ_FIRST(&rec
->token_q
))) {
176 TAILQ_REMOVE(&rec
->token_q
, tok
, tokens
);
177 free(tok
->t_data
, M_AUDITBSM
);
178 free(tok
, M_AUDITBSM
);
183 free(rec
->data
, M_AUDITBSM
);
184 free(rec
, M_AUDITBSM
);
188 * XXX: May want turn some (or all) of these macros into functions in order
189 * to reduce the generated code size.
191 * XXXAUDIT: These macros assume that 'kar', 'ar', 'rec', and 'tok' in the
192 * caller are OK with this.
195 #define MAC_VNODE1_LABEL_TOKEN do { \
196 if (ar->ar_vnode1_mac_labels != NULL && \
197 strlen(ar->ar_vnode1_mac_labels) != 0) { \
198 tok = au_to_text(ar->ar_vnode1_mac_labels); \
199 kau_write(rec, tok); \
203 #define MAC_VNODE2_LABEL_TOKEN do { \
204 if (ar->ar_vnode2_mac_labels != NULL && \
205 strlen(ar->ar_vnode2_mac_labels) != 0) { \
206 tok = au_to_text(ar->ar_vnode2_mac_labels); \
207 kau_write(rec, tok); \
211 #define MAC_VNODE1_LABEL_TOKEN
212 #define MAC_VNODE2_LABEL_TOKEN
214 #define UPATH1_TOKENS do { \
215 if (ARG_IS_VALID(kar, ARG_UPATH1)) { \
216 tok = au_to_path(ar->ar_arg_upath1); \
217 kau_write(rec, tok); \
221 #define UPATH2_TOKENS do { \
222 if (ARG_IS_VALID(kar, ARG_UPATH2)) { \
223 tok = au_to_path(ar->ar_arg_upath2); \
224 kau_write(rec, tok); \
228 #define KPATH2_TOKENS do { \
229 if (ARG_IS_VALID(kar, ARG_KPATH2)) { \
230 tok = au_to_path(ar->ar_arg_kpath2); \
231 kau_write(rec, tok); \
235 #define VNODE1_TOKENS do { \
236 if (ARG_IS_VALID(kar, ARG_KPATH1)) { \
237 tok = au_to_path(ar->ar_arg_kpath1); \
238 kau_write(rec, tok); \
240 if (ARG_IS_VALID(kar, ARG_VNODE1)) { \
241 tok = au_to_attr32(&ar->ar_arg_vnode1); \
242 kau_write(rec, tok); \
243 MAC_VNODE1_LABEL_TOKEN; \
247 #define UPATH1_VNODE1_TOKENS do { \
248 if (ARG_IS_VALID(kar, ARG_UPATH1)) { \
249 tok = au_to_path(ar->ar_arg_upath1); \
250 kau_write(rec, tok); \
252 if (ARG_IS_VALID(kar, ARG_KPATH1)) { \
253 tok = au_to_path(ar->ar_arg_kpath1); \
254 kau_write(rec, tok); \
256 if (ARG_IS_VALID(kar, ARG_VNODE1)) { \
257 tok = au_to_attr32(&ar->ar_arg_vnode1); \
258 kau_write(rec, tok); \
259 MAC_VNODE1_LABEL_TOKEN; \
263 #define VNODE2_TOKENS do { \
264 if (ARG_IS_VALID(kar, ARG_VNODE2)) { \
265 tok = au_to_attr32(&ar->ar_arg_vnode2); \
266 kau_write(rec, tok); \
267 MAC_VNODE2_LABEL_TOKEN; \
271 #define VNODE2_PATH_TOKENS do { \
272 if (ARG_IS_VALID(kar, ARG_KPATH2)) { \
273 tok = au_to_path(ar->ar_arg_kpath2); \
274 kau_write(rec, tok); \
276 if (ARG_IS_VALID(kar, ARG_VNODE2)) { \
277 tok = au_to_attr32(&ar->ar_arg_vnode2); \
278 kau_write(rec, tok); \
279 MAC_VNODE2_LABEL_TOKEN; \
283 #define FD_VNODE1_TOKENS do { \
284 if (ARG_IS_VALID(kar, ARG_VNODE1)) { \
285 if (ARG_IS_VALID(kar, ARG_KPATH1)) { \
286 tok = au_to_path(ar->ar_arg_kpath1); \
287 kau_write(rec, tok); \
289 if (ARG_IS_VALID(kar, ARG_FD)) { \
290 tok = au_to_arg32(1, "fd", ar->ar_arg_fd); \
291 kau_write(rec, tok); \
292 MAC_VNODE1_LABEL_TOKEN; \
294 tok = au_to_attr32(&ar->ar_arg_vnode1); \
295 kau_write(rec, tok); \
297 if (ARG_IS_VALID(kar, ARG_FD)) { \
298 tok = au_to_arg32(1, "fd", \
300 kau_write(rec, tok); \
301 MAC_VNODE1_LABEL_TOKEN; \
306 #define PROCESS_PID_TOKENS(argn) do { \
307 if ((ar->ar_arg_pid > 0) /* Reference a single process */ \
308 && (ARG_IS_VALID(kar, ARG_PROCESS))) { \
309 tok = au_to_process32_ex(ar->ar_arg_auid, \
310 ar->ar_arg_euid, ar->ar_arg_egid, \
311 ar->ar_arg_ruid, ar->ar_arg_rgid, \
312 ar->ar_arg_pid, ar->ar_arg_asid, \
313 &ar->ar_arg_termid_addr); \
314 kau_write(rec, tok); \
315 } else if (ARG_IS_VALID(kar, ARG_PID)) { \
316 tok = au_to_arg32(argn, "process", ar->ar_arg_pid); \
317 kau_write(rec, tok); \
321 #define EXTATTR_TOKENS do { \
322 if (ARG_IS_VALID(kar, ARG_VALUE32)) { \
323 switch (ar->ar_arg_value32) { \
324 case EXTATTR_NAMESPACE_USER: \
325 tok = au_to_text(EXTATTR_NAMESPACE_USER_STRING);\
327 case EXTATTR_NAMESPACE_SYSTEM: \
328 tok = au_to_text(EXTATTR_NAMESPACE_SYSTEM_STRING);\
331 tok = au_to_arg32(3, "attrnamespace", \
332 ar->ar_arg_value32); \
335 kau_write(rec, tok); \
337 /* attrname is in the text field */ \
338 if (ARG_IS_VALID(kar, ARG_TEXT)) { \
339 tok = au_to_text(ar->ar_arg_text); \
340 kau_write(rec, tok); \
344 #define EXTENDED_TOKENS(n) do { \
346 if (ARG_IS_VALID(kar, ARG_OPAQUE)) { \
347 tok = au_to_opaque(ar->ar_arg_opaque, \
348 ar->ar_arg_opq_size); \
349 kau_write(rec, tok); \
351 if (ARG_IS_VALID(kar, ARG_MODE)) { \
352 tok = au_to_arg32(n+2, "mode", ar->ar_arg_mode);\
353 kau_write(rec, tok); \
355 if (ARG_IS_VALID(kar, ARG_GID)) { \
356 tok = au_to_arg32(n+1, "gid", ar->ar_arg_gid); \
357 kau_write(rec, tok); \
359 if (ARG_IS_VALID(kar, ARG_UID)) { \
360 tok = au_to_arg32(n, "uid", ar->ar_arg_uid); \
361 kau_write(rec, tok); \
365 #define PROCESS_MAC_TOKENS do { \
366 if (ar->ar_valid_arg & ARG_MAC_STRING) { \
367 tok = au_to_text(ar->ar_arg_mac_string); \
368 kau_write(rec, tok); \
373 * Implement auditing for the auditon() system call. The audit tokens that
374 * are generated depend on the command that was sent into the auditon()
378 audit_sys_auditon(struct audit_record
*ar
, struct au_record
*rec
)
380 struct au_token
*tok
;
382 switch (ar
->ar_arg_cmd
) {
384 if (ar
->ar_arg_len
> sizeof(int)) {
385 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
387 tok
= au_to_arg64(2, "policy",
388 ar
->ar_arg_auditon
.au_policy64
);
394 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
396 tok
= au_to_arg32(2, "policy", ar
->ar_arg_auditon
.au_policy
);
401 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
403 tok
= au_to_arg32(2, "setkmask:as_success",
404 ar
->ar_arg_auditon
.au_mask
.am_success
);
406 tok
= au_to_arg32(2, "setkmask:as_failure",
407 ar
->ar_arg_auditon
.au_mask
.am_failure
);
412 if (ar
->ar_arg_len
> sizeof(au_qctrl_t
)) {
413 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
415 tok
= au_to_arg64(2, "setqctrl:aq_hiwater",
416 ar
->ar_arg_auditon
.au_qctrl64
.aq64_hiwater
);
418 tok
= au_to_arg64(2, "setqctrl:aq_lowater",
419 ar
->ar_arg_auditon
.au_qctrl64
.aq64_lowater
);
421 tok
= au_to_arg64(2, "setqctrl:aq_bufsz",
422 ar
->ar_arg_auditon
.au_qctrl64
.aq64_bufsz
);
424 tok
= au_to_arg64(2, "setqctrl:aq_delay",
425 ar
->ar_arg_auditon
.au_qctrl64
.aq64_delay
);
427 tok
= au_to_arg32(2, "setqctrl:aq_minfree",
428 ar
->ar_arg_auditon
.au_qctrl64
.aq64_minfree
);
434 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
436 tok
= au_to_arg32(2, "setqctrl:aq_hiwater",
437 ar
->ar_arg_auditon
.au_qctrl
.aq_hiwater
);
439 tok
= au_to_arg32(2, "setqctrl:aq_lowater",
440 ar
->ar_arg_auditon
.au_qctrl
.aq_lowater
);
442 tok
= au_to_arg32(2, "setqctrl:aq_bufsz",
443 ar
->ar_arg_auditon
.au_qctrl
.aq_bufsz
);
445 tok
= au_to_arg32(2, "setqctrl:aq_delay",
446 ar
->ar_arg_auditon
.au_qctrl
.aq_delay
);
448 tok
= au_to_arg32(2, "setqctrl:aq_minfree",
449 ar
->ar_arg_auditon
.au_qctrl
.aq_minfree
);
454 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
456 tok
= au_to_arg32(2, "setumask:as_success",
457 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
459 tok
= au_to_arg32(2, "setumask:as_failure",
460 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
465 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
467 tok
= au_to_arg32(2, "setsmask:as_success",
468 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
470 tok
= au_to_arg32(2, "setsmask:as_failure",
471 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
476 if (ar
->ar_arg_len
> sizeof(int)) {
477 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
479 tok
= au_to_arg64(2, "setcond",
480 ar
->ar_arg_auditon
.au_cond64
);
486 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
488 tok
= au_to_arg32(2, "setcond", ar
->ar_arg_auditon
.au_cond
);
493 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
495 tok
= au_to_arg32(2, "setclass:ec_event",
496 ar
->ar_arg_auditon
.au_evclass
.ec_number
);
498 tok
= au_to_arg32(3, "setclass:ec_class",
499 ar
->ar_arg_auditon
.au_evclass
.ec_class
);
504 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
506 tok
= au_to_arg32(2, "setpmask:as_success",
507 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_success
);
509 tok
= au_to_arg32(2, "setpmask:as_failure",
510 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_failure
);
515 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
517 tok
= au_to_arg32(2, "setfsize:filesize",
518 ar
->ar_arg_auditon
.au_fstat
.af_filesz
);
525 tok
= au_to_arg32(1, "cmd", ar
->ar_arg_cmd
);
530 * Implement auditing for the fcntl() system call. The audit tokens that
531 * are generated depend on the command that was sent into the fcntl()
535 audit_sys_fcntl(struct kaudit_record
*kar
, struct au_record
*rec
)
537 struct au_token
*tok
;
538 struct audit_record
*ar
= &kar
->k_ar
;
540 switch (ar
->ar_arg_cmd
) {
542 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
543 tok
= au_to_arg32(3, "min fd", ar
->ar_arg_value32
);
549 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
550 tok
= au_to_arg32(3, "close-on-exec flag",
557 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
558 tok
= au_to_arg32(3, "fd flags", ar
->ar_arg_value32
);
564 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
565 tok
= au_to_arg32(3, "pid", ar
->ar_arg_value32
);
572 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
573 tok
= au_to_arg64(3, "offset", ar
->ar_arg_value64
);
577 #endif /* F_SETSIZE */
579 #ifdef F_PATHPKG_CHECK
580 case F_PATHPKG_CHECK
:
581 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
582 tok
= au_to_text(ar
->ar_arg_text
);
591 tok
= au_to_arg32(2, "cmd", au_fcntl_cmd_to_bsm(ar
->ar_arg_cmd
));
596 * Convert an internal kernel audit record to a BSM record and return a
597 * success/failure indicator. The BSM record is passed as an out parameter to
601 * BSM_SUCCESS: The BSM record is valid
602 * BSM_FAILURE: Failure; the BSM record is NULL.
603 * BSM_NOAUDIT: The event is not auditable for BSM; the BSM record is NULL.
606 kaudit_to_bsm(struct kaudit_record
*kar
, struct au_record
**pau
)
608 struct au_token
*tok
= NULL
, *subj_tok
;
609 struct au_record
*rec
;
611 struct audit_record
*ar
;
615 KASSERT(kar
!= NULL
, ("kaudit_to_bsm: kar == NULL"));
622 * Create the subject token.
624 switch (ar
->ar_subj_term_addr
.at_type
) {
626 tid
.port
= ar
->ar_subj_term_addr
.at_port
;
627 tid
.machine
= ar
->ar_subj_term_addr
.at_addr
[0];
628 subj_tok
= au_to_subject32(ar
->ar_subj_auid
, /* audit ID */
629 ar
->ar_subj_cred
.cr_uid
, /* eff uid */
630 ar
->ar_subj_egid
, /* eff group id */
631 ar
->ar_subj_ruid
, /* real uid */
632 ar
->ar_subj_rgid
, /* real group id */
633 ar
->ar_subj_pid
, /* process id */
634 ar
->ar_subj_asid
, /* session ID */
638 subj_tok
= au_to_subject32_ex(ar
->ar_subj_auid
,
639 ar
->ar_subj_cred
.cr_uid
,
645 &ar
->ar_subj_term_addr
);
648 bzero(&tid
, sizeof(tid
));
649 subj_tok
= au_to_subject32(ar
->ar_subj_auid
,
650 ar
->ar_subj_cred
.cr_uid
,
660 * The logic inside each case fills in the tokens required for the
661 * event, except for the header, trailer, and return tokens. The
662 * header and trailer tokens are added by the kau_close() function.
663 * The return token is added outside of the switch statement.
665 switch (ar
->ar_event
) {
667 /* For sendfile the file and socket descriptor are both saved */
668 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
669 tok
= au_to_arg32(2, "sd", ar
->ar_arg_value32
);
682 * Socket-related events.
684 if (ARG_IS_VALID(kar
, ARG_FD
)) {
685 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
688 if (ARG_IS_VALID(kar
, ARG_SADDRINET
)) {
689 tok
= au_to_sock_inet((struct sockaddr_in
*)
690 &ar
->ar_arg_sockaddr
);
693 if (ARG_IS_VALID(kar
, ARG_SADDRUNIX
)) {
694 tok
= au_to_sock_unix((struct sockaddr_un
*)
695 &ar
->ar_arg_sockaddr
);
699 if (ARG_IS_VALID(kar
, ARG_SADDRINET6
)) {
700 tok
= au_to_sock_inet128((struct sockaddr_in6
*)
701 &ar
->ar_arg_sockaddr
);
708 if (ARG_IS_VALID(kar
, ARG_SOCKINFO
)) {
709 tok
= au_to_arg32(1, "domain",
710 au_domain_to_bsm(ar
->ar_arg_sockinfo
.sai_domain
));
712 tok
= au_to_arg32(2, "type",
713 au_socket_type_to_bsm(ar
->ar_arg_sockinfo
.sai_type
));
715 tok
= au_to_arg32(3, "protocol",
716 ar
->ar_arg_sockinfo
.sai_protocol
);
723 if (ARG_IS_VALID(kar
, ARG_FD
)) {
724 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
730 if (ARG_IS_VALID(kar
, (ARG_KPATH1
| ARG_UPATH1
))) {
731 UPATH1_VNODE1_TOKENS
;
733 tok
= au_to_arg32(1, "accounting off", 0);
739 if (ARG_IS_VALID(kar
, ARG_AUID
)) {
740 tok
= au_to_arg32(2, "setauid", ar
->ar_arg_auid
);
746 if (ARG_IS_VALID(kar
, ARG_AUID
) &&
747 ARG_IS_VALID(kar
, ARG_ASID
) &&
748 ARG_IS_VALID(kar
, ARG_AMASK
) &&
749 ARG_IS_VALID(kar
, ARG_TERMID
)) {
750 tok
= au_to_arg32(1, "setaudit:auid",
753 tok
= au_to_arg32(1, "setaudit:port",
754 ar
->ar_arg_termid
.port
);
756 tok
= au_to_arg32(1, "setaudit:machine",
757 ar
->ar_arg_termid
.machine
);
759 tok
= au_to_arg32(1, "setaudit:as_success",
760 ar
->ar_arg_amask
.am_success
);
762 tok
= au_to_arg32(1, "setaudit:as_failure",
763 ar
->ar_arg_amask
.am_failure
);
765 tok
= au_to_arg32(1, "setaudit:asid",
771 case AUE_SETAUDIT_ADDR
:
772 if (ARG_IS_VALID(kar
, ARG_AUID
) &&
773 ARG_IS_VALID(kar
, ARG_ASID
) &&
774 ARG_IS_VALID(kar
, ARG_AMASK
) &&
775 ARG_IS_VALID(kar
, ARG_TERMID_ADDR
)) {
776 tok
= au_to_arg32(1, "setaudit_addr:auid",
779 tok
= au_to_arg32(1, "setaudit_addr:as_success",
780 ar
->ar_arg_amask
.am_success
);
782 tok
= au_to_arg32(1, "setaudit_addr:as_failure",
783 ar
->ar_arg_amask
.am_failure
);
785 tok
= au_to_arg32(1, "setaudit_addr:asid",
788 tok
= au_to_arg32(1, "setaudit_addr:type",
789 ar
->ar_arg_termid_addr
.at_type
);
791 tok
= au_to_arg32(1, "setaudit_addr:port",
792 ar
->ar_arg_termid_addr
.at_port
);
794 switch (ar
->ar_arg_termid_addr
.at_type
) {
796 tok
= au_to_in_addr_ex((struct in6_addr
*)
797 &ar
->ar_arg_termid_addr
.at_addr
[0]);
801 tok
= au_to_in_addr((struct in_addr
*)
802 &ar
->ar_arg_termid_addr
.at_addr
[0]);
811 * For AUDITON commands without own event, audit the cmd.
813 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
814 tok
= au_to_arg32(1, "cmd", ar
->ar_arg_cmd
);
819 case AUE_AUDITON_GETCAR
:
820 case AUE_AUDITON_GETCLASS
:
821 case AUE_AUDITON_GETCOND
:
822 case AUE_AUDITON_GETCWD
:
823 case AUE_AUDITON_GETKMASK
:
824 case AUE_AUDITON_GETSTAT
:
825 case AUE_AUDITON_GPOLICY
:
826 case AUE_AUDITON_GQCTRL
:
827 case AUE_AUDITON_SETCLASS
:
828 case AUE_AUDITON_SETCOND
:
829 case AUE_AUDITON_SETKMASK
:
830 case AUE_AUDITON_SETSMASK
:
831 case AUE_AUDITON_SETSTAT
:
832 case AUE_AUDITON_SETUMASK
:
833 case AUE_AUDITON_SPOLICY
:
834 case AUE_AUDITON_SQCTRL
:
835 if (ARG_IS_VALID(kar
, ARG_AUDITON
)) {
836 audit_sys_auditon(ar
, rec
);
841 UPATH1_VNODE1_TOKENS
;
845 if (ARG_IS_VALID(kar
, ARG_EXIT
)) {
846 tok
= au_to_exit(ar
->ar_arg_exitretval
,
847 ar
->ar_arg_exitstatus
);
856 case AUE_GETAUDIT_ADDR
:
862 /* XXXss replace with kext */
866 case AUE_MAC_GETFSSTAT
:
874 case AUE_SETTIMEOFDAY
:
875 case AUE_KDEBUGTRACE
:
876 case AUE_PTHREADSIGMASK
:
878 * Header, subject, and return tokens added at end.
883 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
884 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
887 UPATH1_VNODE1_TOKENS
;
890 case AUE_ACCESS_EXTENDED
:
892 * The access_extended() argument vector is stored in an
895 if (ARG_IS_VALID(kar
, ARG_OPAQUE
)) {
896 tok
= au_to_opaque(ar
->ar_arg_opaque
,
897 ar
->ar_arg_opq_size
);
901 * The access_extended() result vector is stored in an arbitrary
904 if (ARG_IS_VALID(kar
, ARG_DATA
)) {
905 tok
= au_to_data(AUP_DECIMAL
, ar
->ar_arg_data_type
,
906 ar
->ar_arg_data_count
, ar
->ar_arg_data
);
909 UPATH1_VNODE1_TOKENS
;
912 case AUE_LSTAT_EXTENDED
:
913 case AUE_STAT_EXTENDED
:
917 case AUE_GETATTRLIST
:
925 case AUE_SETATTRLIST
:
932 UPATH1_VNODE1_TOKENS
;
939 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
940 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
943 UPATH1_VNODE1_TOKENS
;
947 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
948 tok
= au_to_arg32(2, "new file mode",
952 UPATH1_VNODE1_TOKENS
;
957 if (ARG_IS_VALID(kar
, ARG_UID
)) {
958 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
961 if (ARG_IS_VALID(kar
, ARG_GID
)) {
962 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
965 UPATH1_VNODE1_TOKENS
;
968 case AUE_EXCHANGEDATA
:
969 UPATH1_VNODE1_TOKENS
;
974 if (ARG_IS_VALID(kar
, ARG_FD
)) {
975 tok
= au_to_arg32(2, "fd", ar
->ar_arg_fd
);
978 UPATH1_VNODE1_TOKENS
;
982 if (ARG_IS_VALID(kar
, ARG_SIGNUM
)) {
983 tok
= au_to_arg32(0, "signal", ar
->ar_arg_signum
);
986 UPATH1_VNODE1_TOKENS
;
989 case AUE_POSIX_SPAWN
:
990 if (ARG_IS_VALID(kar
, ARG_PID
)) {
991 tok
= au_to_arg32(0, "child PID", ar
->ar_arg_pid
);
997 if (ARG_IS_VALID(kar
, ARG_ARGV
)) {
998 tok
= au_to_exec_args(ar
->ar_arg_argv
,
1000 kau_write(rec
, tok
);
1002 if (ARG_IS_VALID(kar
, ARG_ENVV
)) {
1003 tok
= au_to_exec_env(ar
->ar_arg_envv
,
1005 kau_write(rec
, tok
);
1007 UPATH1_VNODE1_TOKENS
;
1009 if (ARG_IS_VALID(kar
, ARG_DATA
)) {
1010 tok
= au_to_data(AUP_HEX
, ar
->ar_arg_data_type
,
1011 ar
->ar_arg_data_count
, ar
->ar_arg_data
);
1012 kau_write(rec
, tok
);
1016 case AUE_FCHMOD_EXTENDED
:
1022 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1023 tok
= au_to_arg32(2, "new file mode",
1025 kau_write(rec
, tok
);
1031 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
1032 kau_write(rec
, tok
);
1033 if (ar
->ar_valid_arg
& (ARG_KPATH1
| ARG_UPATH1
)) {
1034 UPATH1_VNODE1_TOKENS
;
1039 * XXXRW: Some of these need to handle non-vnode cases as well.
1041 case AUE_FSTAT_EXTENDED
:
1044 case AUE_FSTAT
: /* XXX Need to handle sockets and shm */
1049 case AUE_GETDIRENTRIES
:
1050 case AUE_GETDIRENTRIESATTR
:
1051 case AUE_GETATTRLISTBULK
:
1052 #if 0 /* XXXss new */
1067 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1068 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
1069 kau_write(rec
, tok
);
1071 if (ARG_IS_VALID(kar
, ARG_GID
)) {
1072 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
1073 kau_write(rec
, tok
);
1079 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1080 audit_sys_fcntl(kar
, rec
);
1086 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1087 tok
= au_to_arg32(4, "options", ar
->ar_arg_value32
);
1088 kau_write(rec
, tok
);
1090 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1091 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
1092 kau_write(rec
, tok
);
1094 UPATH1_VNODE1_TOKENS
;
1098 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1099 tok
= au_to_arg32(4, "options", ar
->ar_arg_value32
);
1100 kau_write(rec
, tok
);
1102 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1103 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
1104 kau_write(rec
, tok
);
1111 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1112 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1113 kau_write(rec
, tok
);
1119 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1120 tok
= au_to_arg32(2, "operation", ar
->ar_arg_cmd
);
1121 kau_write(rec
, tok
);
1128 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1129 tok
= au_to_arg32(0, "child PID", ar
->ar_arg_pid
);
1130 kau_write(rec
, tok
);
1135 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1136 tok
= au_to_arg32(1, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1137 kau_write(rec
, tok
);
1142 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1143 tok
= au_to_arg32(1, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1144 kau_write(rec
, tok
);
1146 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1147 tok
= au_to_arg32(2, "lcid",
1148 (u_int32_t
)ar
->ar_arg_value32
);
1149 kau_write(rec
, tok
);
1154 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1155 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
1156 kau_write(rec
, tok
);
1158 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1159 tok
= au_to_arg64(2, "cmd", ar
->ar_arg_value64
);
1160 kau_write(rec
, tok
);
1162 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1163 tok
= au_to_arg64(3, "arg", ar
->ar_arg_addr
);
1164 kau_write(rec
, tok
);
1165 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1166 tok
= au_to_arg32(3, "arg",
1167 (u_int32_t
)ar
->ar_arg_addr
);
1168 kau_write(rec
, tok
);
1170 if (ARG_IS_VALID(kar
, ARG_VNODE1
)) {
1173 if (ARG_IS_VALID(kar
, ARG_SOCKINFO
)) {
1174 tok
= au_to_socket_ex(
1175 ar
->ar_arg_sockinfo
.sai_domain
,
1176 ar
->ar_arg_sockinfo
.sai_type
,
1178 &ar
->ar_arg_sockinfo
.sai_laddr
,
1180 &ar
->ar_arg_sockinfo
.sai_faddr
);
1181 kau_write(rec
, tok
);
1183 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1184 tok
= au_to_arg32(1, "fd",
1186 kau_write(rec
, tok
);
1193 if (ARG_IS_VALID(kar
, ARG_SIGNUM
)) {
1194 tok
= au_to_arg32(2, "signal", ar
->ar_arg_signum
);
1195 kau_write(rec
, tok
);
1197 PROCESS_PID_TOKENS(1);
1202 UPATH1_VNODE1_TOKENS
;
1207 case AUE_MKDIR_EXTENDED
:
1208 case AUE_CHMOD_EXTENDED
:
1209 case AUE_MKFIFO_EXTENDED
:
1211 UPATH1_VNODE1_TOKENS
;
1215 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1216 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
1217 kau_write(rec
, tok
);
1219 UPATH1_VNODE1_TOKENS
;
1223 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1224 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
1225 kau_write(rec
, tok
);
1227 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1228 tok
= au_to_arg32(3, "dev", ar
->ar_arg_value32
);
1229 kau_write(rec
, tok
);
1231 UPATH1_VNODE1_TOKENS
;
1240 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1241 tok
= au_to_arg64(1, "addr", ar
->ar_arg_addr
);
1242 kau_write(rec
, tok
);
1243 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1244 tok
= au_to_arg32(1, "addr",
1245 (u_int32_t
)ar
->ar_arg_addr
);
1246 kau_write(rec
, tok
);
1248 if (ARG_IS_VALID(kar
, ARG_LEN
)) {
1249 tok
= au_to_arg64(2, "len", ar
->ar_arg_len
);
1250 kau_write(rec
, tok
);
1252 if (ar
->ar_event
== AUE_MMAP
) {
1255 if (ar
->ar_event
== AUE_MPROTECT
) {
1256 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1257 tok
= au_to_arg32(3, "protection",
1258 ar
->ar_arg_value32
);
1259 kau_write(rec
, tok
);
1262 if (ar
->ar_event
== AUE_MINHERIT
) {
1263 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1264 tok
= au_to_arg32(3, "inherit",
1265 ar
->ar_arg_value32
);
1266 kau_write(rec
, tok
);
1277 /* XXX Need to handle NFS mounts */
1278 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1279 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1280 kau_write(rec
, tok
);
1282 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1283 tok
= au_to_text(ar
->ar_arg_text
);
1284 kau_write(rec
, tok
);
1290 UPATH1_VNODE1_TOKENS
;
1293 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1294 tok
= au_to_arg32(2, "dir fd", ar
->ar_arg_fd
);
1295 kau_write(rec
, tok
);
1297 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1298 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1299 kau_write(rec
, tok
);
1301 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1302 tok
= au_to_text(ar
->ar_arg_text
);
1303 kau_write(rec
, tok
);
1308 ar
->ar_event
= audit_msgctl_to_event(ar
->ar_arg_svipc_cmd
);
1313 tok
= au_to_arg32(1, "msg ID", ar
->ar_arg_svipc_id
);
1314 kau_write(rec
, tok
);
1315 if (ar
->ar_errno
!= EINVAL
) {
1316 tok
= au_to_ipc(AT_IPC_MSG
, ar
->ar_arg_svipc_id
);
1317 kau_write(rec
, tok
);
1322 if (ar
->ar_errno
== 0) {
1323 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1324 tok
= au_to_ipc(AT_IPC_MSG
,
1325 ar
->ar_arg_svipc_id
);
1326 kau_write(rec
, tok
);
1338 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1339 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1340 kau_write(rec
, tok
);
1342 UPATH1_VNODE1_TOKENS
;
1351 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1352 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1353 kau_write(rec
, tok
);
1355 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1356 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1357 kau_write(rec
, tok
);
1359 UPATH1_VNODE1_TOKENS
;
1362 case AUE_OPEN_EXTENDED
:
1363 case AUE_OPEN_EXTENDED_R
:
1364 case AUE_OPEN_EXTENDED_RT
:
1365 case AUE_OPEN_EXTENDED_RW
:
1366 case AUE_OPEN_EXTENDED_RWT
:
1367 case AUE_OPEN_EXTENDED_W
:
1368 case AUE_OPEN_EXTENDED_WT
:
1370 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1371 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1372 kau_write(rec
, tok
);
1374 UPATH1_VNODE1_TOKENS
;
1377 case AUE_OPEN_EXTENDED_RC
:
1378 case AUE_OPEN_EXTENDED_RTC
:
1379 case AUE_OPEN_EXTENDED_RWC
:
1380 case AUE_OPEN_EXTENDED_RWTC
:
1381 case AUE_OPEN_EXTENDED_WC
:
1382 case AUE_OPEN_EXTENDED_WTC
:
1384 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1385 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1386 kau_write(rec
, tok
);
1388 UPATH1_VNODE1_TOKENS
;
1395 case AUE_OPENAT_RWT
:
1398 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1399 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1400 kau_write(rec
, tok
);
1402 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1403 tok
= au_to_arg32(1, "dir fd", ar
->ar_arg_fd
);
1404 kau_write(rec
, tok
);
1406 UPATH1_VNODE1_TOKENS
;
1410 case AUE_OPENAT_RTC
:
1411 case AUE_OPENAT_RWC
:
1412 case AUE_OPENAT_RWTC
:
1414 case AUE_OPENAT_WTC
:
1415 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1416 tok
= au_to_arg32(4, "mode", ar
->ar_arg_mode
);
1417 kau_write(rec
, tok
);
1419 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1420 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1421 kau_write(rec
, tok
);
1423 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1424 tok
= au_to_arg32(1, "dir fd", ar
->ar_arg_fd
);
1425 kau_write(rec
, tok
);
1427 UPATH1_VNODE1_TOKENS
;
1431 case AUE_OPENBYID_R
:
1432 case AUE_OPENBYID_RT
:
1433 case AUE_OPENBYID_RW
:
1434 case AUE_OPENBYID_RWT
:
1435 case AUE_OPENBYID_W
:
1436 case AUE_OPENBYID_WT
:
1437 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1438 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1439 kau_write(rec
, tok
);
1441 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1442 tok
= au_to_arg32(1, "volfsid", ar
->ar_arg_value32
);
1443 kau_write(rec
, tok
);
1445 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1446 tok
= au_to_arg64(2, "objid", ar
->ar_arg_value64
);
1447 kau_write(rec
, tok
);
1458 case AUE_READLINKAT
:
1461 case AUE_GETATTRLISTAT
:
1462 case AUE_SETATTRLISTAT
:
1463 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1464 tok
= au_to_arg32(1, "dir fd", ar
->ar_arg_fd
);
1465 kau_write(rec
, tok
);
1467 UPATH1_VNODE1_TOKENS
;
1470 case AUE_CLONEFILEAT
:
1471 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1472 tok
= au_to_arg32(1, "src dir fd", ar
->ar_arg_fd
);
1473 kau_write(rec
, tok
);
1475 UPATH1_VNODE1_TOKENS
;
1476 if (ARG_IS_VALID(kar
, ARG_FD2
)) {
1477 tok
= au_to_arg32(1, "dst dir fd", ar
->ar_arg_fd2
);
1478 kau_write(rec
, tok
);
1481 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1482 tok
= au_to_arg32(1, "flags", ar
->ar_arg_value32
);
1483 kau_write(rec
, tok
);
1487 case AUE_FCLONEFILEAT
:
1489 if (ARG_IS_VALID(kar
, ARG_FD2
)) {
1490 tok
= au_to_arg32(1, "dst dir fd", ar
->ar_arg_fd2
);
1491 kau_write(rec
, tok
);
1494 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1495 tok
= au_to_arg32(1, "flags", ar
->ar_arg_value32
);
1496 kau_write(rec
, tok
);
1501 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1502 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
1503 kau_write(rec
, tok
);
1505 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1506 tok
= au_to_arg64(3, "addr", ar
->ar_arg_addr
);
1507 kau_write(rec
, tok
);
1508 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1509 tok
= au_to_arg32(3, "addr",
1510 (u_int32_t
)ar
->ar_arg_addr
);
1511 kau_write(rec
, tok
);
1513 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1514 tok
= au_to_arg32(4, "data", ar
->ar_arg_value32
);
1515 kau_write(rec
, tok
);
1517 PROCESS_PID_TOKENS(2);
1521 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1522 tok
= au_to_arg32(2, "command", ar
->ar_arg_cmd
);
1523 kau_write(rec
, tok
);
1525 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1526 tok
= au_to_arg32(3, "uid", ar
->ar_arg_uid
);
1527 kau_write(rec
, tok
);
1529 UPATH1_VNODE1_TOKENS
;
1533 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1534 tok
= au_to_arg32(1, "howto", ar
->ar_arg_cmd
);
1535 kau_write(rec
, tok
);
1540 ar
->ar_event
= audit_semctl_to_event(ar
->ar_arg_svipc_cmd
);
1544 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1545 tok
= au_to_arg32(1, "sem ID", ar
->ar_arg_svipc_id
);
1546 kau_write(rec
, tok
);
1547 if (ar
->ar_errno
!= EINVAL
) {
1548 tok
= au_to_ipc(AT_IPC_SEM
,
1549 ar
->ar_arg_svipc_id
);
1550 kau_write(rec
, tok
);
1556 if (ar
->ar_errno
== 0) {
1557 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1558 tok
= au_to_ipc(AT_IPC_SEM
,
1559 ar
->ar_arg_svipc_id
);
1560 kau_write(rec
, tok
);
1566 if (ARG_IS_VALID(kar
, ARG_EGID
)) {
1567 tok
= au_to_arg32(1, "gid", ar
->ar_arg_egid
);
1568 kau_write(rec
, tok
);
1573 if (ARG_IS_VALID(kar
, ARG_EUID
)) {
1574 tok
= au_to_arg32(1, "uid", ar
->ar_arg_euid
);
1575 kau_write(rec
, tok
);
1580 if (ARG_IS_VALID(kar
, ARG_RGID
)) {
1581 tok
= au_to_arg32(1, "rgid", ar
->ar_arg_rgid
);
1582 kau_write(rec
, tok
);
1584 if (ARG_IS_VALID(kar
, ARG_EGID
)) {
1585 tok
= au_to_arg32(2, "egid", ar
->ar_arg_egid
);
1586 kau_write(rec
, tok
);
1591 if (ARG_IS_VALID(kar
, ARG_RUID
)) {
1592 tok
= au_to_arg32(1, "ruid", ar
->ar_arg_ruid
);
1593 kau_write(rec
, tok
);
1595 if (ARG_IS_VALID(kar
, ARG_EUID
)) {
1596 tok
= au_to_arg32(2, "euid", ar
->ar_arg_euid
);
1597 kau_write(rec
, tok
);
1602 if (ARG_IS_VALID(kar
, ARG_GID
)) {
1603 tok
= au_to_arg32(1, "gid", ar
->ar_arg_gid
);
1604 kau_write(rec
, tok
);
1609 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1610 tok
= au_to_arg32(1, "uid", ar
->ar_arg_uid
);
1611 kau_write(rec
, tok
);
1616 if (ARG_IS_VALID(kar
, ARG_GROUPSET
)) {
1617 for (uctr
= 0; uctr
< ar
->ar_arg_groups
.gidset_size
;
1619 tok
= au_to_arg32(1, "setgroups",
1620 ar
->ar_arg_groups
.gidset
[uctr
]);
1621 kau_write(rec
, tok
);
1627 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1628 tok
= au_to_text(ar
->ar_arg_text
);
1629 kau_write(rec
, tok
);
1633 case AUE_SETPRIORITY
:
1634 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1635 tok
= au_to_arg32(1, "which", ar
->ar_arg_cmd
);
1636 kau_write(rec
, tok
);
1638 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1639 tok
= au_to_arg32(2, "who", ar
->ar_arg_uid
);
1640 kau_write(rec
, tok
);
1642 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1643 tok
= au_to_arg32(2, "priority", ar
->ar_arg_value32
);
1644 kau_write(rec
, tok
);
1648 case AUE_SETPRIVEXEC
:
1649 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1650 tok
= au_to_arg32(1, "flag", ar
->ar_arg_value32
);
1651 kau_write(rec
, tok
);
1655 /* AUE_SHMAT, AUE_SHMCTL, AUE_SHMDT and AUE_SHMGET are SysV IPC */
1657 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1658 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
1659 kau_write(rec
, tok
);
1660 /* XXXAUDIT: Does having the ipc token make sense? */
1661 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
1662 kau_write(rec
, tok
);
1664 if (ARG_IS_VALID(kar
, ARG_SVIPC_ADDR
)) {
1665 tok
= au_to_arg64(2, "shmaddr", ar
->ar_arg_svipc_addr
);
1666 kau_write(rec
, tok
);
1668 if (ARG_IS_VALID(kar
, ARG_SVIPC_PERM
)) {
1669 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
1670 kau_write(rec
, tok
);
1675 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1676 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
1677 kau_write(rec
, tok
);
1678 /* XXXAUDIT: Does having the ipc token make sense? */
1679 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
1680 kau_write(rec
, tok
);
1682 switch (ar
->ar_arg_svipc_cmd
) {
1684 ar
->ar_event
= AUE_SHMCTL_STAT
;
1687 ar
->ar_event
= AUE_SHMCTL_RMID
;
1690 ar
->ar_event
= AUE_SHMCTL_SET
;
1691 if (ARG_IS_VALID(kar
, ARG_SVIPC_PERM
)) {
1692 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
1693 kau_write(rec
, tok
);
1697 break; /* We will audit a bad command */
1702 if (ARG_IS_VALID(kar
, ARG_SVIPC_ADDR
)) {
1703 tok
= au_to_arg64(1, "shmaddr",
1704 (int)(uintptr_t)ar
->ar_arg_svipc_addr
);
1705 kau_write(rec
, tok
);
1710 /* This is unusual; the return value is in an argument token */
1711 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1712 tok
= au_to_arg32(0, "shmid", ar
->ar_arg_svipc_id
);
1713 kau_write(rec
, tok
);
1714 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
1715 kau_write(rec
, tok
);
1717 if (ARG_IS_VALID(kar
, ARG_SVIPC_PERM
)) {
1718 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
1719 kau_write(rec
, tok
);
1723 /* AUE_SHMOPEN, AUE_SHMUNLINK, AUE_SEMOPEN, AUE_SEMCLOSE
1724 * and AUE_SEMUNLINK are Posix IPC */
1726 if (ARG_IS_VALID(kar
, ARG_SVIPC_ADDR
)) {
1727 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1728 kau_write(rec
, tok
);
1730 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1731 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1732 kau_write(rec
, tok
);
1737 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1738 tok
= au_to_text(ar
->ar_arg_text
);
1739 kau_write(rec
, tok
);
1741 if (ARG_IS_VALID(kar
, ARG_POSIX_IPC_PERM
)) {
1742 struct ipc_perm perm
;
1744 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1745 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1746 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1747 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1748 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1751 tok
= au_to_ipc_perm(&perm
);
1752 kau_write(rec
, tok
);
1757 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1758 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1759 kau_write(rec
, tok
);
1761 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1762 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1763 kau_write(rec
, tok
);
1765 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1766 tok
= au_to_arg32(4, "value", ar
->ar_arg_value32
);
1767 kau_write(rec
, tok
);
1772 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1773 tok
= au_to_text(ar
->ar_arg_text
);
1774 kau_write(rec
, tok
);
1776 if (ARG_IS_VALID(kar
, ARG_POSIX_IPC_PERM
)) {
1777 struct ipc_perm perm
;
1779 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1780 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1781 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1782 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1783 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1786 tok
= au_to_ipc_perm(&perm
);
1787 kau_write(rec
, tok
);
1792 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1793 tok
= au_to_arg32(1, "sem", ar
->ar_arg_fd
);
1794 kau_write(rec
, tok
);
1799 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1800 tok
= au_to_text(ar
->ar_arg_text
);
1801 kau_write(rec
, tok
);
1803 UPATH1_VNODE1_TOKENS
;
1807 case AUE_SYSCTL_NONADMIN
:
1808 if (ARG_IS_VALID(kar
, ARG_CTLNAME
| ARG_LEN
)) {
1809 for (ctr
= 0; ctr
< (int)ar
->ar_arg_len
; ctr
++) {
1810 tok
= au_to_arg32(1, "name",
1811 ar
->ar_arg_ctlname
[ctr
]);
1812 kau_write(rec
, tok
);
1815 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1816 tok
= au_to_arg32(5, "newval", ar
->ar_arg_value32
);
1817 kau_write(rec
, tok
);
1819 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1820 tok
= au_to_text(ar
->ar_arg_text
);
1821 kau_write(rec
, tok
);
1825 case AUE_UMASK_EXTENDED
:
1827 if (ARG_IS_VALID(kar
, ARG_OPAQUE
)) {
1828 tok
= au_to_opaque(ar
->ar_arg_opaque
,
1829 ar
->ar_arg_opq_size
);
1830 kau_write(rec
, tok
);
1835 if (ARG_IS_VALID(kar
, ARG_MASK
)) {
1836 tok
= au_to_arg32(1, "new mask", ar
->ar_arg_mask
);
1837 kau_write(rec
, tok
);
1839 tok
= au_to_arg32(0, "prev mask", ar
->ar_retval
);
1840 kau_write(rec
, tok
);
1844 #if 0 /* XXXss - new */
1847 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1848 tok
= au_to_arg32(0, "pid", ar
->ar_arg_pid
);
1849 kau_write(rec
, tok
);
1853 case AUE_FSGETPATH_EXTENDED
:
1855 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1856 tok
= au_to_arg32(3, "volfsid", ar
->ar_arg_value32
);
1857 kau_write(rec
, tok
);
1859 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1860 tok
= au_to_arg64(4, "objid", ar
->ar_arg_value64
);
1861 kau_write(rec
, tok
);
1863 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1864 tok
= au_to_text(ar
->ar_arg_text
);
1865 kau_write(rec
, tok
);
1869 case AUE_SESSION_START
:
1870 case AUE_SESSION_UPDATE
:
1871 case AUE_SESSION_END
:
1872 case AUE_SESSION_CLOSE
:
1873 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1874 tok
= au_to_arg64(1, "sflags", ar
->ar_arg_value64
);
1875 kau_write(rec
, tok
);
1877 if (ARG_IS_VALID(kar
, ARG_AMASK
)) {
1878 tok
= au_to_arg32(2, "am_success",
1879 ar
->ar_arg_amask
.am_success
);
1880 kau_write(rec
, tok
);
1881 tok
= au_to_arg32(3, "am_failure",
1882 ar
->ar_arg_amask
.am_failure
);
1883 kau_write(rec
, tok
);
1887 /************************
1888 * Mach system calls *
1889 ************************/
1890 case AUE_INITPROCESS
:
1893 case AUE_PIDFORTASK
:
1894 if (ARG_IS_VALID(kar
, ARG_MACHPORT1
)) {
1895 tok
= au_to_arg32(1, "port",
1896 (u_int32_t
)ar
->ar_arg_mach_port1
);
1897 kau_write(rec
, tok
);
1899 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1900 tok
= au_to_arg32(2, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1901 kau_write(rec
, tok
);
1905 case AUE_TASKFORPID
:
1906 case AUE_TASKNAMEFORPID
:
1907 if (ARG_IS_VALID(kar
, ARG_MACHPORT1
)) {
1908 tok
= au_to_arg32(1, "target port",
1909 (u_int32_t
)ar
->ar_arg_mach_port1
);
1910 kau_write(rec
, tok
);
1912 if (ARG_IS_VALID(kar
, ARG_MACHPORT2
)) {
1913 tok
= au_to_arg32(3, "task port",
1914 (u_int32_t
)ar
->ar_arg_mach_port2
);
1915 kau_write(rec
, tok
);
1917 PROCESS_PID_TOKENS(2);
1921 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1922 tok
= au_to_arg32(4, "priority",
1923 (u_int32_t
)ar
->ar_arg_value32
);
1924 kau_write(rec
, tok
);
1926 UPATH1_VNODE1_TOKENS
;
1930 UPATH1_VNODE1_TOKENS
;
1934 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1935 tok
= au_to_arg64(3, "va", ar
->ar_arg_addr
);
1936 kau_write(rec
, tok
);
1937 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1938 tok
= au_to_arg32(3, "va",
1939 (u_int32_t
)ar
->ar_arg_addr
);
1940 kau_write(rec
, tok
);
1946 case AUE_MAC_GET_FILE
:
1947 case AUE_MAC_SET_FILE
:
1948 case AUE_MAC_GET_LINK
:
1949 case AUE_MAC_SET_LINK
:
1950 case AUE_MAC_GET_MOUNT
:
1951 UPATH1_VNODE1_TOKENS
;
1955 case AUE_MAC_GET_FD
:
1956 case AUE_MAC_SET_FD
:
1961 case AUE_MAC_SYSCALL
:
1963 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1964 tok
= au_to_arg32(3, "call", ar
->ar_arg_value32
);
1965 kau_write(rec
, tok
);
1969 case AUE_MAC_EXECVE
:
1970 UPATH1_VNODE1_TOKENS
;
1974 case AUE_MAC_GET_PID
:
1975 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1976 tok
= au_to_arg32(1, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1977 kau_write(rec
, tok
);
1982 case AUE_MAC_GET_LCID
:
1983 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1984 tok
= au_to_arg32(1, "lcid",
1985 (u_int32_t
)ar
->ar_arg_value32
);
1986 kau_write(rec
, tok
);
1991 case AUE_MAC_GET_PROC
:
1992 case AUE_MAC_SET_PROC
:
1999 printf("BSM conversion requested for unknown event %d\n",
2004 * Write the subject token so it is properly freed here.
2006 kau_write(rec
, subj_tok
);
2012 if (NULL
!= ar
->ar_mac_records
) {
2013 /* Convert the audit data from the MAC policies */
2014 struct mac_audit_record
*mar
;
2016 LIST_FOREACH(mar
, ar
->ar_mac_records
, records
) {
2017 switch (mar
->type
) {
2018 case MAC_AUDIT_DATA_TYPE
:
2019 tok
= au_to_data(AUP_BINARY
, AUR_BYTE
,
2021 (const char *)mar
->data
);
2023 case MAC_AUDIT_TEXT_TYPE
:
2024 tok
= au_to_text((char*) mar
->data
);
2028 * XXX: we can either continue,
2029 * skipping this particular entry,
2030 * or we can pre-verify the list and
2031 * abort before writing any records
2033 printf("kaudit_to_bsm(): "
2034 "BSM conversion requested for"
2035 "unknown mac_audit data type %d\n",
2039 kau_write(rec
, tok
);
2044 kau_write(rec
, subj_tok
);
2047 if (ar
->ar_cred_mac_labels
!= NULL
&&
2048 strlen(ar
->ar_cred_mac_labels
) != 0) {
2049 tok
= au_to_text(ar
->ar_cred_mac_labels
);
2050 kau_write(rec
, tok
);
2054 tok
= au_to_return32(au_errno_to_bsm(ar
->ar_errno
), ar
->ar_retval
);
2055 kau_write(rec
, tok
); /* Every record gets a return token */
2057 if (ARG_IS_VALID(kar
, ARG_IDENTITY
)) {
2058 struct au_identity_info
*id
= &ar
->ar_arg_identity
;
2059 tok
= au_to_identity(id
->signer_type
, id
->signing_id
,
2060 id
->signing_id_trunc
, id
->team_id
, id
->team_id_trunc
,
2061 id
->cdhash
, id
->cdhash_len
);
2062 kau_write(rec
, tok
);
2065 kau_close(rec
, &ar
->ar_endtime
, ar
->ar_event
);
2072 * Verify that a record is a valid BSM record. Return 1 if the
2073 * record is good, 0 otherwise.
2076 bsm_rec_verify(void *rec
, int length
, boolean_t kern_events_allowed
)
2078 /* Used to partially deserialize the buffer */
2079 struct hdr_tok_partial
*hdr
;
2080 struct trl_tok_partial
*trl
;
2082 /* A record requires a complete header and trailer token */
2083 if (length
< (AUDIT_HEADER_SIZE
+ AUDIT_TRAILER_SIZE
)) {
2087 hdr
= (struct hdr_tok_partial
*)rec
;
2089 /* Ensure the provided length matches what the record shows */
2090 if ((uint32_t)length
!= ntohl(hdr
->len
)) {
2094 trl
= (struct trl_tok_partial
*)(rec
+ (length
- AUDIT_TRAILER_SIZE
));
2096 /* Ensure the buffer contains what look like header and trailer tokens */
2097 if (((hdr
->type
!= AUT_HEADER32
) && (hdr
->type
!= AUT_HEADER32_EX
) &&
2098 (hdr
->type
!= AUT_HEADER64
) && (hdr
->type
!= AUT_HEADER64_EX
)) ||
2099 (trl
->type
!= AUT_TRAILER
)) {
2103 /* Ensure the header and trailer agree on the length */
2104 if (hdr
->len
!= trl
->len
) {
2108 /* Ensure the trailer token has a proper magic value */
2109 if (ntohs(trl
->magic
) != AUT_TRAILER_MAGIC
) {
2113 if (!kern_events_allowed
&& AUE_IS_A_KEVENT(ntohs(hdr
->e_type
))) {
2119 #endif /* CONFIG_AUDIT */