]>
git.saurik.com Git - apple/xnu.git/blob - bsd/security/audit/audit_bsm.c
2 * Copyright (c) 1999-2009 Apple Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
31 * support for mandatory and extensible security protections. This notice
32 * is included in support of clause 2.2 (b) of the Apple Public License,
36 #include <sys/types.h>
37 #include <sys/vnode_internal.h>
40 #include <sys/socketvar.h>
41 #include <sys/socket.h>
42 #include <sys/queue.h>
43 #include <sys/fcntl.h>
47 #include <bsm/audit.h>
48 #include <bsm/audit_internal.h>
49 #include <bsm/audit_record.h>
50 #include <bsm/audit_kevents.h>
52 #include <security/audit/audit.h>
53 #include <security/audit/audit_bsd.h>
54 #include <security/audit/audit_private.h>
56 #include <netinet/in_systm.h>
57 #include <netinet/in.h>
58 #include <netinet/ip.h>
60 #include <kern/lock.h>
63 MALLOC_DEFINE(M_AUDITBSM
, "audit_bsm", "Audit BSM data");
66 #include <security/mac_framework.h>
69 static void audit_sys_auditon(struct audit_record
*ar
,
70 struct au_record
*rec
);
71 static void audit_sys_fcntl(struct kaudit_record
*kar
,
72 struct au_record
*rec
);
75 * Initialize the BSM auditing subsystem.
85 * This call reserves memory for the audit record. Memory must be guaranteed
86 * before any auditable event can be generated. The au_record structure
87 * maintains a reference to the memory allocated above and also the list of
88 * tokens associated with this record.
90 static struct au_record
*
93 struct au_record
*rec
;
95 rec
= malloc(sizeof(*rec
), M_AUDITBSM
, M_WAITOK
);
97 TAILQ_INIT(&rec
->token_q
);
105 * Store the token with the record descriptor.
108 kau_write(struct au_record
*rec
, struct au_token
*tok
)
111 KASSERT(tok
!= NULL
, ("kau_write: tok == NULL"));
113 TAILQ_INSERT_TAIL(&rec
->token_q
, tok
, tokens
);
114 rec
->len
+= tok
->len
;
118 * Close out the audit record by adding the header token, identifying any
119 * missing tokens. Write out the tokens to the record memory.
122 kau_close(struct au_record
*rec
, struct timespec
*ctime
, short event
)
126 token_t
*cur
, *hdr
, *trail
;
129 struct auditinfo_addr ak
;
132 audit_get_kinfo(&ak
);
134 switch (ak
.ai_termid
.at_type
) {
136 hdrsize
= (ak
.ai_termid
.at_addr
[0] == INADDR_ANY
) ?
137 AUDIT_HEADER_SIZE
: AUDIT_HEADER_EX_SIZE(&ak
);
140 ap
= (struct in6_addr
*)&ak
.ai_termid
.at_addr
[0];
141 hdrsize
= (IN6_IS_ADDR_UNSPECIFIED(ap
)) ? AUDIT_HEADER_SIZE
:
142 AUDIT_HEADER_EX_SIZE(&ak
);
145 panic("kau_close: invalid address family");
147 tot_rec_size
= rec
->len
+ AUDIT_HEADER_SIZE
+ AUDIT_TRAILER_SIZE
;
148 rec
->data
= malloc(tot_rec_size
, M_AUDITBSM
, M_WAITOK
| M_ZERO
);
150 tm
.tv_usec
= ctime
->tv_nsec
/ 1000;
151 tm
.tv_sec
= ctime
->tv_sec
;
152 if (hdrsize
!= AUDIT_HEADER_SIZE
)
153 hdr
= au_to_header32_ex_tm(tot_rec_size
, event
, 0, tm
, &ak
);
155 hdr
= au_to_header32_tm(tot_rec_size
, event
, 0, tm
);
156 TAILQ_INSERT_HEAD(&rec
->token_q
, hdr
, tokens
);
158 trail
= au_to_trailer(tot_rec_size
);
159 TAILQ_INSERT_TAIL(&rec
->token_q
, trail
, tokens
);
161 rec
->len
= tot_rec_size
;
163 TAILQ_FOREACH(cur
, &rec
->token_q
, tokens
) {
164 memcpy(dptr
, cur
->t_data
, cur
->len
);
170 * Free a BSM audit record by releasing all the tokens and clearing the audit
171 * record information.
174 kau_free(struct au_record
*rec
)
176 struct au_token
*tok
;
178 /* Free the token list. */
179 while ((tok
= TAILQ_FIRST(&rec
->token_q
))) {
180 TAILQ_REMOVE(&rec
->token_q
, tok
, tokens
);
181 free(tok
->t_data
, M_AUDITBSM
);
182 free(tok
, M_AUDITBSM
);
187 free(rec
->data
, M_AUDITBSM
);
188 free(rec
, M_AUDITBSM
);
192 * XXX: May want turn some (or all) of these macros into functions in order
193 * to reduce the generated code size.
195 * XXXAUDIT: These macros assume that 'kar', 'ar', 'rec', and 'tok' in the
196 * caller are OK with this.
199 #define MAC_VNODE1_LABEL_TOKEN do { \
200 if (ar->ar_vnode1_mac_labels != NULL && \
201 strlen(ar->ar_vnode1_mac_labels) != 0) { \
202 tok = au_to_text(ar->ar_vnode1_mac_labels); \
203 kau_write(rec, tok); \
207 #define MAC_VNODE2_LABEL_TOKEN do { \
208 if (ar->ar_vnode2_mac_labels != NULL && \
209 strlen(ar->ar_vnode2_mac_labels) != 0) { \
210 tok = au_to_text(ar->ar_vnode2_mac_labels); \
211 kau_write(rec, tok); \
215 #define MAC_VNODE1_LABEL_TOKEN
216 #define MAC_VNODE2_LABEL_TOKEN
218 #define UPATH1_TOKENS do { \
219 if (ARG_IS_VALID(kar, ARG_UPATH1)) { \
220 tok = au_to_path(ar->ar_arg_upath1); \
221 kau_write(rec, tok); \
225 #define UPATH2_TOKENS do { \
226 if (ARG_IS_VALID(kar, ARG_UPATH2)) { \
227 tok = au_to_path(ar->ar_arg_upath2); \
228 kau_write(rec, tok); \
232 #define VNODE1_TOKENS do { \
233 if (ARG_IS_VALID(kar, ARG_KPATH1)) { \
234 tok = au_to_path(ar->ar_arg_kpath1); \
235 kau_write(rec, tok); \
237 if (ARG_IS_VALID(kar, ARG_VNODE1)) { \
238 tok = au_to_attr32(&ar->ar_arg_vnode1); \
239 kau_write(rec, tok); \
240 MAC_VNODE1_LABEL_TOKEN; \
244 #define UPATH1_VNODE1_TOKENS do { \
245 if (ARG_IS_VALID(kar, ARG_UPATH1)) { \
246 tok = au_to_path(ar->ar_arg_upath1); \
247 kau_write(rec, tok); \
249 if (ARG_IS_VALID(kar, ARG_KPATH1)) { \
250 tok = au_to_path(ar->ar_arg_kpath1); \
251 kau_write(rec, tok); \
253 if (ARG_IS_VALID(kar, ARG_VNODE1)) { \
254 tok = au_to_attr32(&ar->ar_arg_vnode1); \
255 kau_write(rec, tok); \
256 MAC_VNODE1_LABEL_TOKEN; \
260 #define VNODE2_TOKENS do { \
261 if (ARG_IS_VALID(kar, ARG_VNODE2)) { \
262 tok = au_to_attr32(&ar->ar_arg_vnode2); \
263 kau_write(rec, tok); \
264 MAC_VNODE2_LABEL_TOKEN; \
268 #define FD_VNODE1_TOKENS do { \
269 if (ARG_IS_VALID(kar, ARG_VNODE1)) { \
270 if (ARG_IS_VALID(kar, ARG_KPATH1)) { \
271 tok = au_to_path(ar->ar_arg_kpath1); \
272 kau_write(rec, tok); \
274 if (ARG_IS_VALID(kar, ARG_FD)) { \
275 tok = au_to_arg32(1, "fd", ar->ar_arg_fd); \
276 kau_write(rec, tok); \
277 MAC_VNODE1_LABEL_TOKEN; \
279 tok = au_to_attr32(&ar->ar_arg_vnode1); \
280 kau_write(rec, tok); \
282 if (ARG_IS_VALID(kar, ARG_FD)) { \
283 tok = au_to_arg32(1, "fd", \
285 kau_write(rec, tok); \
286 MAC_VNODE1_LABEL_TOKEN; \
291 #define PROCESS_PID_TOKENS(argn) do { \
292 if ((ar->ar_arg_pid > 0) /* Reference a single process */ \
293 && (ARG_IS_VALID(kar, ARG_PROCESS))) { \
294 tok = au_to_process32_ex(ar->ar_arg_auid, \
295 ar->ar_arg_euid, ar->ar_arg_egid, \
296 ar->ar_arg_ruid, ar->ar_arg_rgid, \
297 ar->ar_arg_pid, ar->ar_arg_asid, \
298 &ar->ar_arg_termid_addr); \
299 kau_write(rec, tok); \
300 } else if (ARG_IS_VALID(kar, ARG_PID)) { \
301 tok = au_to_arg32(argn, "process", ar->ar_arg_pid); \
302 kau_write(rec, tok); \
306 #define EXTATTR_TOKENS do { \
307 if (ARG_IS_VALID(kar, ARG_VALUE32)) { \
308 switch (ar->ar_arg_value32) { \
309 case EXTATTR_NAMESPACE_USER: \
310 tok = au_to_text(EXTATTR_NAMESPACE_USER_STRING);\
312 case EXTATTR_NAMESPACE_SYSTEM: \
313 tok = au_to_text(EXTATTR_NAMESPACE_SYSTEM_STRING);\
316 tok = au_to_arg32(3, "attrnamespace", \
317 ar->ar_arg_value32); \
320 kau_write(rec, tok); \
322 /* attrname is in the text field */ \
323 if (ARG_IS_VALID(kar, ARG_TEXT)) { \
324 tok = au_to_text(ar->ar_arg_text); \
325 kau_write(rec, tok); \
329 #define EXTENDED_TOKENS(n) do { \
331 if (ARG_IS_VALID(kar, ARG_OPAQUE)) { \
332 tok = au_to_opaque(ar->ar_arg_opaque, \
333 ar->ar_arg_opq_size); \
334 kau_write(rec, tok); \
336 if (ARG_IS_VALID(kar, ARG_MODE)) { \
337 tok = au_to_arg32(n+2, "mode", ar->ar_arg_mode);\
338 kau_write(rec, tok); \
340 if (ARG_IS_VALID(kar, ARG_GID)) { \
341 tok = au_to_arg32(n+1, "gid", ar->ar_arg_gid); \
342 kau_write(rec, tok); \
344 if (ARG_IS_VALID(kar, ARG_UID)) { \
345 tok = au_to_arg32(n, "uid", ar->ar_arg_uid); \
346 kau_write(rec, tok); \
350 #define PROCESS_MAC_TOKENS do { \
351 if (ar->ar_valid_arg & ARG_MAC_STRING) { \
352 tok = au_to_text(ar->ar_arg_mac_string); \
353 kau_write(rec, tok); \
358 * Implement auditing for the auditon() system call. The audit tokens that
359 * are generated depend on the command that was sent into the auditon()
363 audit_sys_auditon(struct audit_record
*ar
, struct au_record
*rec
)
365 struct au_token
*tok
;
367 switch (ar
->ar_arg_cmd
) {
369 if (ar
->ar_arg_len
> sizeof(int)) {
370 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
372 tok
= au_to_arg64(2, "policy",
373 ar
->ar_arg_auditon
.au_policy64
);
379 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
381 tok
= au_to_arg32(2, "policy", ar
->ar_arg_auditon
.au_policy
);
386 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
388 tok
= au_to_arg32(2, "setkmask:as_success",
389 ar
->ar_arg_auditon
.au_mask
.am_success
);
391 tok
= au_to_arg32(2, "setkmask:as_failure",
392 ar
->ar_arg_auditon
.au_mask
.am_failure
);
397 if (ar
->ar_arg_len
> sizeof(au_qctrl_t
)) {
398 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
400 tok
= au_to_arg64(2, "setqctrl:aq_hiwater",
401 ar
->ar_arg_auditon
.au_qctrl64
.aq64_hiwater
);
403 tok
= au_to_arg64(2, "setqctrl:aq_lowater",
404 ar
->ar_arg_auditon
.au_qctrl64
.aq64_lowater
);
406 tok
= au_to_arg64(2, "setqctrl:aq_bufsz",
407 ar
->ar_arg_auditon
.au_qctrl64
.aq64_bufsz
);
409 tok
= au_to_arg64(2, "setqctrl:aq_delay",
410 ar
->ar_arg_auditon
.au_qctrl64
.aq64_delay
);
412 tok
= au_to_arg32(2, "setqctrl:aq_minfree",
413 ar
->ar_arg_auditon
.au_qctrl64
.aq64_minfree
);
419 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
421 tok
= au_to_arg32(2, "setqctrl:aq_hiwater",
422 ar
->ar_arg_auditon
.au_qctrl
.aq_hiwater
);
424 tok
= au_to_arg32(2, "setqctrl:aq_lowater",
425 ar
->ar_arg_auditon
.au_qctrl
.aq_lowater
);
427 tok
= au_to_arg32(2, "setqctrl:aq_bufsz",
428 ar
->ar_arg_auditon
.au_qctrl
.aq_bufsz
);
430 tok
= au_to_arg32(2, "setqctrl:aq_delay",
431 ar
->ar_arg_auditon
.au_qctrl
.aq_delay
);
433 tok
= au_to_arg32(2, "setqctrl:aq_minfree",
434 ar
->ar_arg_auditon
.au_qctrl
.aq_minfree
);
439 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
441 tok
= au_to_arg32(2, "setumask:as_success",
442 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
444 tok
= au_to_arg32(2, "setumask:as_failure",
445 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
450 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
452 tok
= au_to_arg32(2, "setsmask:as_success",
453 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_success
);
455 tok
= au_to_arg32(2, "setsmask:as_failure",
456 ar
->ar_arg_auditon
.au_auinfo
.ai_mask
.am_failure
);
461 if (ar
->ar_arg_len
> sizeof(int)) {
462 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
464 tok
= au_to_arg64(2, "setcond",
465 ar
->ar_arg_auditon
.au_cond64
);
471 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
473 tok
= au_to_arg32(2, "setcond", ar
->ar_arg_auditon
.au_cond
);
478 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
480 tok
= au_to_arg32(2, "setclass:ec_event",
481 ar
->ar_arg_auditon
.au_evclass
.ec_number
);
483 tok
= au_to_arg32(3, "setclass:ec_class",
484 ar
->ar_arg_auditon
.au_evclass
.ec_class
);
489 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
491 tok
= au_to_arg32(2, "setpmask:as_success",
492 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_success
);
494 tok
= au_to_arg32(2, "setpmask:as_failure",
495 ar
->ar_arg_auditon
.au_aupinfo
.ap_mask
.am_failure
);
500 tok
= au_to_arg32(3, "length", ar
->ar_arg_len
);
502 tok
= au_to_arg32(2, "setfsize:filesize",
503 ar
->ar_arg_auditon
.au_fstat
.af_filesz
);
510 tok
= au_to_arg32(1, "cmd", ar
->ar_arg_cmd
);
515 * Implement auditing for the fcntl() system call. The audit tokens that
516 * are generated depend on the command that was sent into the fcntl()
520 audit_sys_fcntl(struct kaudit_record
*kar
, struct au_record
*rec
)
522 struct au_token
*tok
;
523 struct audit_record
*ar
= &kar
->k_ar
;
525 switch (ar
->ar_arg_cmd
) {
528 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
529 tok
= au_to_arg32(3, "min fd", ar
->ar_arg_value32
);
535 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
536 tok
= au_to_arg32(3, "close-on-exec flag",
543 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
544 tok
= au_to_arg32(3, "fd flags", ar
->ar_arg_value32
);
550 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
551 tok
= au_to_arg32(3, "pid", ar
->ar_arg_value32
);
558 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
559 tok
= au_to_arg64(3, "offset", ar
->ar_arg_value64
);
563 #endif /* F_SETSIZE */
565 #ifdef F_PATHPKG_CHECK
566 case F_PATHPKG_CHECK
:
567 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
568 tok
= au_to_text(ar
->ar_arg_text
);
577 tok
= au_to_arg32(2, "cmd", au_fcntl_cmd_to_bsm(ar
->ar_arg_cmd
));
582 * Convert an internal kernel audit record to a BSM record and return a
583 * success/failure indicator. The BSM record is passed as an out parameter to
587 * BSM_SUCCESS: The BSM record is valid
588 * BSM_FAILURE: Failure; the BSM record is NULL.
589 * BSM_NOAUDIT: The event is not auditable for BSM; the BSM record is NULL.
592 kaudit_to_bsm(struct kaudit_record
*kar
, struct au_record
**pau
)
594 struct au_token
*tok
= NULL
, *subj_tok
;
595 struct au_record
*rec
;
597 struct audit_record
*ar
;
601 KASSERT(kar
!= NULL
, ("kaudit_to_bsm: kar == NULL"));
608 * Create the subject token.
610 switch (ar
->ar_subj_term_addr
.at_type
) {
612 tid
.port
= ar
->ar_subj_term_addr
.at_port
;
613 tid
.machine
= ar
->ar_subj_term_addr
.at_addr
[0];
614 subj_tok
= au_to_subject32(ar
->ar_subj_auid
, /* audit ID */
615 ar
->ar_subj_cred
.cr_uid
, /* eff uid */
616 ar
->ar_subj_egid
, /* eff group id */
617 ar
->ar_subj_ruid
, /* real uid */
618 ar
->ar_subj_rgid
, /* real group id */
619 ar
->ar_subj_pid
, /* process id */
620 ar
->ar_subj_asid
, /* session ID */
624 subj_tok
= au_to_subject32_ex(ar
->ar_subj_auid
,
625 ar
->ar_subj_cred
.cr_uid
,
631 &ar
->ar_subj_term_addr
);
634 bzero(&tid
, sizeof(tid
));
635 subj_tok
= au_to_subject32(ar
->ar_subj_auid
,
636 ar
->ar_subj_cred
.cr_uid
,
646 * The logic inside each case fills in the tokens required for the
647 * event, except for the header, trailer, and return tokens. The
648 * header and trailer tokens are added by the kau_close() function.
649 * The return token is added outside of the switch statement.
651 switch(ar
->ar_event
) {
653 /* For sendfile the file and socket descriptor are both saved */
654 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
655 tok
= au_to_arg32(2, "sd", ar
->ar_arg_value32
);
668 * Socket-related events.
670 if (ARG_IS_VALID(kar
, ARG_FD
)) {
671 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
674 if (ARG_IS_VALID(kar
, ARG_SADDRINET
)) {
675 tok
= au_to_sock_inet((struct sockaddr_in
*)
676 &ar
->ar_arg_sockaddr
);
679 if (ARG_IS_VALID(kar
, ARG_SADDRUNIX
)) {
680 tok
= au_to_sock_unix((struct sockaddr_un
*)
681 &ar
->ar_arg_sockaddr
);
685 if (ARG_IS_VALID(kar
, ARG_SADDRINET6
)) {
686 tok
= au_to_sock_inet128((struct sockaddr_in6
*)
687 &ar
->ar_arg_sockaddr
);
694 if (ARG_IS_VALID(kar
, ARG_SOCKINFO
)) {
695 tok
= au_to_arg32(1,"domain",
696 au_domain_to_bsm(ar
->ar_arg_sockinfo
.sai_domain
));
698 tok
= au_to_arg32(2,"type",
699 au_socket_type_to_bsm(ar
->ar_arg_sockinfo
.sai_type
));
701 tok
= au_to_arg32(3,"protocol",
702 ar
->ar_arg_sockinfo
.sai_protocol
);
709 if (ARG_IS_VALID(kar
, ARG_FD
)) {
710 tok
= au_to_arg32(1, "fd", ar
->ar_arg_fd
);
716 if (ARG_IS_VALID(kar
, (ARG_KPATH1
| ARG_UPATH1
))) {
717 UPATH1_VNODE1_TOKENS
;
719 tok
= au_to_arg32(1, "accounting off", 0);
725 if (ARG_IS_VALID(kar
, ARG_AUID
)) {
726 tok
= au_to_arg32(2, "setauid", ar
->ar_arg_auid
);
732 if (ARG_IS_VALID(kar
, ARG_AUID
) &&
733 ARG_IS_VALID(kar
, ARG_ASID
) &&
734 ARG_IS_VALID(kar
, ARG_AMASK
) &&
735 ARG_IS_VALID(kar
, ARG_TERMID
)) {
736 tok
= au_to_arg32(1, "setaudit:auid",
739 tok
= au_to_arg32(1, "setaudit:port",
740 ar
->ar_arg_termid
.port
);
742 tok
= au_to_arg32(1, "setaudit:machine",
743 ar
->ar_arg_termid
.machine
);
745 tok
= au_to_arg32(1, "setaudit:as_success",
746 ar
->ar_arg_amask
.am_success
);
748 tok
= au_to_arg32(1, "setaudit:as_failure",
749 ar
->ar_arg_amask
.am_failure
);
751 tok
= au_to_arg32(1, "setaudit:asid",
757 case AUE_SETAUDIT_ADDR
:
758 if (ARG_IS_VALID(kar
, ARG_AUID
) &&
759 ARG_IS_VALID(kar
, ARG_ASID
) &&
760 ARG_IS_VALID(kar
, ARG_AMASK
) &&
761 ARG_IS_VALID(kar
, ARG_TERMID_ADDR
)) {
762 tok
= au_to_arg32(1, "setaudit_addr:auid",
765 tok
= au_to_arg32(1, "setaudit_addr:as_success",
766 ar
->ar_arg_amask
.am_success
);
768 tok
= au_to_arg32(1, "setaudit_addr:as_failure",
769 ar
->ar_arg_amask
.am_failure
);
771 tok
= au_to_arg32(1, "setaudit_addr:asid",
774 tok
= au_to_arg32(1, "setaudit_addr:type",
775 ar
->ar_arg_termid_addr
.at_type
);
777 tok
= au_to_arg32(1, "setaudit_addr:port",
778 ar
->ar_arg_termid_addr
.at_port
);
780 if (ar
->ar_arg_termid_addr
.at_type
== AU_IPv6
)
781 tok
= au_to_in_addr_ex((struct in6_addr
*)
782 &ar
->ar_arg_termid_addr
.at_addr
[0]);
783 if (ar
->ar_arg_termid_addr
.at_type
== AU_IPv4
)
784 tok
= au_to_in_addr((struct in_addr
*)
785 &ar
->ar_arg_termid_addr
.at_addr
[0]);
792 * For AUDITON commands without own event, audit the cmd.
794 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
795 tok
= au_to_arg32(1, "cmd", ar
->ar_arg_cmd
);
800 case AUE_AUDITON_GETCAR
:
801 case AUE_AUDITON_GETCLASS
:
802 case AUE_AUDITON_GETCOND
:
803 case AUE_AUDITON_GETCWD
:
804 case AUE_AUDITON_GETKMASK
:
805 case AUE_AUDITON_GETSTAT
:
806 case AUE_AUDITON_GPOLICY
:
807 case AUE_AUDITON_GQCTRL
:
808 case AUE_AUDITON_SETCLASS
:
809 case AUE_AUDITON_SETCOND
:
810 case AUE_AUDITON_SETKMASK
:
811 case AUE_AUDITON_SETSMASK
:
812 case AUE_AUDITON_SETSTAT
:
813 case AUE_AUDITON_SETUMASK
:
814 case AUE_AUDITON_SPOLICY
:
815 case AUE_AUDITON_SQCTRL
:
816 if (ARG_IS_VALID(kar
, ARG_AUDITON
))
817 audit_sys_auditon(ar
, rec
);
821 UPATH1_VNODE1_TOKENS
;
825 if (ARG_IS_VALID(kar
, ARG_EXIT
)) {
826 tok
= au_to_exit(ar
->ar_arg_exitretval
,
827 ar
->ar_arg_exitstatus
);
836 case AUE_GETAUDIT_ADDR
:
842 /* XXXss replace with kext */
846 case AUE_MAC_GETFSSTAT
:
854 case AUE_SETTIMEOFDAY
:
855 case AUE_KDEBUGTRACE
:
856 case AUE_PTHREADSIGMASK
:
858 * Header, subject, and return tokens added at end.
863 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
864 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
867 UPATH1_VNODE1_TOKENS
;
870 case AUE_ACCESS_EXTENDED
:
872 * The access_extended() argument vector is stored in an
875 if (ARG_IS_VALID(kar
, ARG_OPAQUE
)) {
876 tok
= au_to_opaque(ar
->ar_arg_opaque
,
877 ar
->ar_arg_opq_size
);
881 * The access_extended() result vector is stored in an arbitrary
884 if (ARG_IS_VALID(kar
, ARG_DATA
)) {
885 tok
= au_to_data(AUP_DECIMAL
, ar
->ar_arg_data_type
,
886 ar
->ar_arg_data_count
, ar
->ar_arg_data
);
889 UPATH1_VNODE1_TOKENS
;
892 case AUE_LSTAT_EXTENDED
:
893 case AUE_STAT_EXTENDED
:
897 case AUE_GETATTRLIST
:
905 case AUE_SETATTRLIST
:
912 UPATH1_VNODE1_TOKENS
;
919 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
920 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
923 UPATH1_VNODE1_TOKENS
;
927 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
928 tok
= au_to_arg32(2, "new file mode",
932 UPATH1_VNODE1_TOKENS
;
937 if (ARG_IS_VALID(kar
, ARG_UID
)) {
938 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
941 if (ARG_IS_VALID(kar
, ARG_GID
)) {
942 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
945 UPATH1_VNODE1_TOKENS
;
948 case AUE_EXCHANGEDATA
:
949 UPATH1_VNODE1_TOKENS
;
954 if (ARG_IS_VALID(kar
, ARG_FD
)) {
955 tok
= au_to_arg32(2, "fd", ar
->ar_arg_fd
);
958 UPATH1_VNODE1_TOKENS
;
962 if (ARG_IS_VALID(kar
, ARG_SIGNUM
)) {
963 tok
= au_to_arg32(0, "signal", ar
->ar_arg_signum
);
966 UPATH1_VNODE1_TOKENS
;
969 case AUE_POSIX_SPAWN
:
970 if (ARG_IS_VALID(kar
, ARG_PID
)) {
971 tok
= au_to_arg32(0, "child PID", ar
->ar_arg_pid
);
977 if (ARG_IS_VALID(kar
, ARG_ARGV
)) {
978 tok
= au_to_exec_args(ar
->ar_arg_argv
,
982 if (ARG_IS_VALID(kar
, ARG_ENVV
)) {
983 tok
= au_to_exec_env(ar
->ar_arg_envv
,
987 UPATH1_VNODE1_TOKENS
;
990 case AUE_FCHMOD_EXTENDED
:
996 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
997 tok
= au_to_arg32(2, "new file mode",
1005 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
1006 kau_write(rec
, tok
);
1007 if (ar
->ar_valid_arg
& (ARG_KPATH1
| ARG_UPATH1
)) {
1008 UPATH1_VNODE1_TOKENS
;
1013 * XXXRW: Some of these need to handle non-vnode cases as well.
1015 case AUE_FSTAT_EXTENDED
:
1018 case AUE_FSTAT
: /* XXX Need to handle sockets and shm */
1023 case AUE_GETDIRENTRIES
:
1024 case AUE_GETDIRENTRIESATTR
:
1025 #if 0 /* XXXss new */
1038 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1039 tok
= au_to_arg32(2, "new file uid", ar
->ar_arg_uid
);
1040 kau_write(rec
, tok
);
1042 if (ARG_IS_VALID(kar
, ARG_GID
)) {
1043 tok
= au_to_arg32(3, "new file gid", ar
->ar_arg_gid
);
1044 kau_write(rec
, tok
);
1050 if (ARG_IS_VALID(kar
, ARG_CMD
))
1051 audit_sys_fcntl(kar
, rec
);
1056 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1057 tok
= au_to_arg32(4, "options", ar
->ar_arg_value32
);
1058 kau_write(rec
, tok
);
1060 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1061 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
1062 kau_write(rec
, tok
);
1064 UPATH1_VNODE1_TOKENS
;
1068 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1069 tok
= au_to_arg32(4, "options", ar
->ar_arg_value32
);
1070 kau_write(rec
, tok
);
1072 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1073 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
1074 kau_write(rec
, tok
);
1081 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1082 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1083 kau_write(rec
, tok
);
1089 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1090 tok
= au_to_arg32(2, "operation", ar
->ar_arg_cmd
);
1091 kau_write(rec
, tok
);
1098 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1099 tok
= au_to_arg32(0, "child PID", ar
->ar_arg_pid
);
1100 kau_write(rec
, tok
);
1105 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1106 tok
= au_to_arg32(1, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1107 kau_write(rec
, tok
);
1112 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1113 tok
= au_to_arg32(1, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1114 kau_write(rec
, tok
);
1116 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1117 tok
= au_to_arg32(2, "lcid",
1118 (u_int32_t
)ar
->ar_arg_value32
);
1119 kau_write(rec
, tok
);
1124 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1125 tok
= au_to_arg32(2, "cmd", ar
->ar_arg_cmd
);
1126 kau_write(rec
, tok
);
1128 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1129 tok
= au_to_arg64(2, "cmd", ar
->ar_arg_value64
);
1130 kau_write(rec
, tok
);
1132 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1133 tok
= au_to_arg64(3, "arg", ar
->ar_arg_addr
);
1134 kau_write(rec
, tok
);
1135 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1136 tok
= au_to_arg32(3, "arg",
1137 (u_int32_t
)ar
->ar_arg_addr
);
1138 kau_write(rec
, tok
);
1140 if (ARG_IS_VALID(kar
, ARG_VNODE1
))
1143 if (ARG_IS_VALID(kar
, ARG_SOCKINFO
)) {
1144 tok
= au_to_socket_ex(
1145 ar
->ar_arg_sockinfo
.sai_domain
,
1146 ar
->ar_arg_sockinfo
.sai_type
,
1148 &ar
->ar_arg_sockinfo
.sai_laddr
,
1150 &ar
->ar_arg_sockinfo
.sai_faddr
);
1151 kau_write(rec
, tok
);
1153 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1154 tok
= au_to_arg32(1, "fd",
1156 kau_write(rec
, tok
);
1163 if (ARG_IS_VALID(kar
, ARG_SIGNUM
)) {
1164 tok
= au_to_arg32(2, "signal", ar
->ar_arg_signum
);
1165 kau_write(rec
, tok
);
1167 PROCESS_PID_TOKENS(1);
1172 UPATH1_VNODE1_TOKENS
;
1176 case AUE_MKDIR_EXTENDED
:
1177 case AUE_CHMOD_EXTENDED
:
1178 case AUE_MKFIFO_EXTENDED
:
1180 UPATH1_VNODE1_TOKENS
;
1184 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1185 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
1186 kau_write(rec
, tok
);
1188 UPATH1_VNODE1_TOKENS
;
1192 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1193 tok
= au_to_arg32(2, "mode", ar
->ar_arg_mode
);
1194 kau_write(rec
, tok
);
1196 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1197 tok
= au_to_arg32(3, "dev", ar
->ar_arg_value32
);
1198 kau_write(rec
, tok
);
1200 UPATH1_VNODE1_TOKENS
;
1209 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1210 tok
= au_to_arg64(1, "addr", ar
->ar_arg_addr
);
1211 kau_write(rec
, tok
);
1212 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1213 tok
= au_to_arg32(1, "addr",
1214 (u_int32_t
)ar
->ar_arg_addr
);
1215 kau_write(rec
, tok
);
1217 if (ARG_IS_VALID(kar
, ARG_LEN
)) {
1218 tok
= au_to_arg64(2, "len", ar
->ar_arg_len
);
1219 kau_write(rec
, tok
);
1221 if (ar
->ar_event
== AUE_MMAP
)
1223 if (ar
->ar_event
== AUE_MPROTECT
) {
1224 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1225 tok
= au_to_arg32(3, "protection",
1226 ar
->ar_arg_value32
);
1227 kau_write(rec
, tok
);
1230 if (ar
->ar_event
== AUE_MINHERIT
) {
1231 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1232 tok
= au_to_arg32(3, "inherit",
1233 ar
->ar_arg_value32
);
1234 kau_write(rec
, tok
);
1245 /* XXX Need to handle NFS mounts */
1246 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1247 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1248 kau_write(rec
, tok
);
1250 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1251 tok
= au_to_text(ar
->ar_arg_text
);
1252 kau_write(rec
, tok
);
1258 UPATH1_VNODE1_TOKENS
;
1262 ar
->ar_event
= audit_msgctl_to_event(ar
->ar_arg_svipc_cmd
);
1267 tok
= au_to_arg32(1, "msg ID", ar
->ar_arg_svipc_id
);
1268 kau_write(rec
, tok
);
1269 if (ar
->ar_errno
!= EINVAL
) {
1270 tok
= au_to_ipc(AT_IPC_MSG
, ar
->ar_arg_svipc_id
);
1271 kau_write(rec
, tok
);
1276 if (ar
->ar_errno
== 0) {
1277 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1278 tok
= au_to_ipc(AT_IPC_MSG
,
1279 ar
->ar_arg_svipc_id
);
1280 kau_write(rec
, tok
);
1286 case AUE_OPENAT_RTC
:
1287 case AUE_OPENAT_RWC
:
1288 case AUE_OPENAT_RWTC
:
1290 case AUE_OPENAT_WTC
:
1291 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1292 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1293 kau_write(rec
, tok
);
1295 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1296 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1297 kau_write(rec
, tok
);
1299 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1300 tok
= au_to_arg32(1, "dir fd", ar
->ar_arg_fd
);
1301 kau_write(rec
, tok
);
1303 UPATH1_VNODE1_TOKENS
;
1306 case AUE_OPEN_EXTENDED_RC
:
1307 case AUE_OPEN_EXTENDED_RTC
:
1308 case AUE_OPEN_EXTENDED_RWC
:
1309 case AUE_OPEN_EXTENDED_RWTC
:
1310 case AUE_OPEN_EXTENDED_WC
:
1311 case AUE_OPEN_EXTENDED_WTC
:
1313 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1314 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1315 kau_write(rec
, tok
);
1317 UPATH1_VNODE1_TOKENS
;
1326 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1327 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1328 kau_write(rec
, tok
);
1330 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1331 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1332 kau_write(rec
, tok
);
1334 UPATH1_VNODE1_TOKENS
;
1341 case AUE_OPENAT_RWT
:
1344 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1345 tok
= au_to_arg32(3, "flags", ar
->ar_arg_fflags
);
1346 kau_write(rec
, tok
);
1348 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1349 tok
= au_to_arg32(1, "dir fd", ar
->ar_arg_fd
);
1350 kau_write(rec
, tok
);
1352 UPATH1_VNODE1_TOKENS
;
1355 case AUE_OPEN_EXTENDED
:
1356 case AUE_OPEN_EXTENDED_R
:
1357 case AUE_OPEN_EXTENDED_RT
:
1358 case AUE_OPEN_EXTENDED_RW
:
1359 case AUE_OPEN_EXTENDED_RWT
:
1360 case AUE_OPEN_EXTENDED_W
:
1361 case AUE_OPEN_EXTENDED_WT
:
1363 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1364 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1365 kau_write(rec
, tok
);
1367 UPATH1_VNODE1_TOKENS
;
1377 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1378 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1379 kau_write(rec
, tok
);
1381 UPATH1_VNODE1_TOKENS
;
1385 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1386 tok
= au_to_arg32(1, "dir fd", ar
->ar_arg_fd
);
1387 kau_write(rec
, tok
);
1389 UPATH1_VNODE1_TOKENS
;
1393 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1394 tok
= au_to_arg32(1, "request", ar
->ar_arg_cmd
);
1395 kau_write(rec
, tok
);
1397 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1398 tok
= au_to_arg64(3, "addr", ar
->ar_arg_addr
);
1399 kau_write(rec
, tok
);
1400 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1401 tok
= au_to_arg32(3, "addr",
1402 (u_int32_t
)ar
->ar_arg_addr
);
1403 kau_write(rec
, tok
);
1405 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1406 tok
= au_to_arg32(4, "data", ar
->ar_arg_value32
);
1407 kau_write(rec
, tok
);
1409 PROCESS_PID_TOKENS(2);
1413 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1414 tok
= au_to_arg32(2, "command", ar
->ar_arg_cmd
);
1415 kau_write(rec
, tok
);
1417 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1418 tok
= au_to_arg32(3, "uid", ar
->ar_arg_uid
);
1419 kau_write(rec
, tok
);
1421 UPATH1_VNODE1_TOKENS
;
1425 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1426 tok
= au_to_arg32(1, "howto", ar
->ar_arg_cmd
);
1427 kau_write(rec
, tok
);
1432 ar
->ar_event
= audit_semctl_to_event(ar
->ar_arg_svipc_cmd
);
1436 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1437 tok
= au_to_arg32(1, "sem ID", ar
->ar_arg_svipc_id
);
1438 kau_write(rec
, tok
);
1439 if (ar
->ar_errno
!= EINVAL
) {
1440 tok
= au_to_ipc(AT_IPC_SEM
,
1441 ar
->ar_arg_svipc_id
);
1442 kau_write(rec
, tok
);
1448 if (ar
->ar_errno
== 0) {
1449 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1450 tok
= au_to_ipc(AT_IPC_SEM
,
1451 ar
->ar_arg_svipc_id
);
1452 kau_write(rec
, tok
);
1458 if (ARG_IS_VALID(kar
, ARG_EGID
)) {
1459 tok
= au_to_arg32(1, "gid", ar
->ar_arg_egid
);
1460 kau_write(rec
, tok
);
1465 if (ARG_IS_VALID(kar
, ARG_EUID
)) {
1466 tok
= au_to_arg32(1, "uid", ar
->ar_arg_euid
);
1467 kau_write(rec
, tok
);
1472 if (ARG_IS_VALID(kar
, ARG_RGID
)) {
1473 tok
= au_to_arg32(1, "rgid", ar
->ar_arg_rgid
);
1474 kau_write(rec
, tok
);
1476 if (ARG_IS_VALID(kar
, ARG_EGID
)) {
1477 tok
= au_to_arg32(2, "egid", ar
->ar_arg_egid
);
1478 kau_write(rec
, tok
);
1483 if (ARG_IS_VALID(kar
, ARG_RUID
)) {
1484 tok
= au_to_arg32(1, "ruid", ar
->ar_arg_ruid
);
1485 kau_write(rec
, tok
);
1487 if (ARG_IS_VALID(kar
, ARG_EUID
)) {
1488 tok
= au_to_arg32(2, "euid", ar
->ar_arg_euid
);
1489 kau_write(rec
, tok
);
1494 if (ARG_IS_VALID(kar
, ARG_GID
)) {
1495 tok
= au_to_arg32(1, "gid", ar
->ar_arg_gid
);
1496 kau_write(rec
, tok
);
1501 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1502 tok
= au_to_arg32(1, "uid", ar
->ar_arg_uid
);
1503 kau_write(rec
, tok
);
1508 if (ARG_IS_VALID(kar
, ARG_GROUPSET
)) {
1509 for (uctr
= 0; uctr
< ar
->ar_arg_groups
.gidset_size
;
1511 tok
= au_to_arg32(1, "setgroups",
1512 ar
->ar_arg_groups
.gidset
[uctr
]);
1513 kau_write(rec
, tok
);
1519 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1520 tok
= au_to_text(ar
->ar_arg_text
);
1521 kau_write(rec
, tok
);
1525 case AUE_SETPRIORITY
:
1526 if (ARG_IS_VALID(kar
, ARG_CMD
)) {
1527 tok
= au_to_arg32(1, "which", ar
->ar_arg_cmd
);
1528 kau_write(rec
, tok
);
1530 if (ARG_IS_VALID(kar
, ARG_UID
)) {
1531 tok
= au_to_arg32(2, "who", ar
->ar_arg_uid
);
1532 kau_write(rec
, tok
);
1534 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1535 tok
= au_to_arg32(2, "priority", ar
->ar_arg_value32
);
1536 kau_write(rec
, tok
);
1540 case AUE_SETPRIVEXEC
:
1541 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1542 tok
= au_to_arg32(1, "flag", ar
->ar_arg_value32
);
1543 kau_write(rec
, tok
);
1547 /* AUE_SHMAT, AUE_SHMCTL, AUE_SHMDT and AUE_SHMGET are SysV IPC */
1549 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1550 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
1551 kau_write(rec
, tok
);
1552 /* XXXAUDIT: Does having the ipc token make sense? */
1553 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
1554 kau_write(rec
, tok
);
1556 if (ARG_IS_VALID(kar
, ARG_SVIPC_ADDR
)) {
1557 tok
= au_to_arg64(2, "shmaddr", ar
->ar_arg_svipc_addr
);
1558 kau_write(rec
, tok
);
1560 if (ARG_IS_VALID(kar
, ARG_SVIPC_PERM
)) {
1561 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
1562 kau_write(rec
, tok
);
1567 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1568 tok
= au_to_arg32(1, "shmid", ar
->ar_arg_svipc_id
);
1569 kau_write(rec
, tok
);
1570 /* XXXAUDIT: Does having the ipc token make sense? */
1571 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
1572 kau_write(rec
, tok
);
1574 switch (ar
->ar_arg_svipc_cmd
) {
1576 ar
->ar_event
= AUE_SHMCTL_STAT
;
1579 ar
->ar_event
= AUE_SHMCTL_RMID
;
1582 ar
->ar_event
= AUE_SHMCTL_SET
;
1583 if (ARG_IS_VALID(kar
, ARG_SVIPC_PERM
)) {
1584 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
1585 kau_write(rec
, tok
);
1589 break; /* We will audit a bad command */
1594 if (ARG_IS_VALID(kar
, ARG_SVIPC_ADDR
)) {
1595 tok
= au_to_arg64(1, "shmaddr",
1596 (int)(uintptr_t)ar
->ar_arg_svipc_addr
);
1597 kau_write(rec
, tok
);
1602 /* This is unusual; the return value is in an argument token */
1603 if (ARG_IS_VALID(kar
, ARG_SVIPC_ID
)) {
1604 tok
= au_to_arg32(0, "shmid", ar
->ar_arg_svipc_id
);
1605 kau_write(rec
, tok
);
1606 tok
= au_to_ipc(AT_IPC_SHM
, ar
->ar_arg_svipc_id
);
1607 kau_write(rec
, tok
);
1609 if (ARG_IS_VALID(kar
, ARG_SVIPC_PERM
)) {
1610 tok
= au_to_ipc_perm(&ar
->ar_arg_svipc_perm
);
1611 kau_write(rec
, tok
);
1615 /* AUE_SHMOPEN, AUE_SHMUNLINK, AUE_SEMOPEN, AUE_SEMCLOSE
1616 * and AUE_SEMUNLINK are Posix IPC */
1618 if (ARG_IS_VALID(kar
, ARG_SVIPC_ADDR
)) {
1619 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1620 kau_write(rec
, tok
);
1622 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1623 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1624 kau_write(rec
, tok
);
1629 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1630 tok
= au_to_text(ar
->ar_arg_text
);
1631 kau_write(rec
, tok
);
1633 if (ARG_IS_VALID(kar
, ARG_POSIX_IPC_PERM
)) {
1634 struct ipc_perm perm
;
1636 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1637 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1638 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1639 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1640 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1643 tok
= au_to_ipc_perm(&perm
);
1644 kau_write(rec
, tok
);
1649 if (ARG_IS_VALID(kar
, ARG_FFLAGS
)) {
1650 tok
= au_to_arg32(2, "flags", ar
->ar_arg_fflags
);
1651 kau_write(rec
, tok
);
1653 if (ARG_IS_VALID(kar
, ARG_MODE
)) {
1654 tok
= au_to_arg32(3, "mode", ar
->ar_arg_mode
);
1655 kau_write(rec
, tok
);
1657 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1658 tok
= au_to_arg32(4, "value", ar
->ar_arg_value32
);
1659 kau_write(rec
, tok
);
1664 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1665 tok
= au_to_text(ar
->ar_arg_text
);
1666 kau_write(rec
, tok
);
1668 if (ARG_IS_VALID(kar
, ARG_POSIX_IPC_PERM
)) {
1669 struct ipc_perm perm
;
1671 perm
.uid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1672 perm
.gid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1673 perm
.cuid
= ar
->ar_arg_pipc_perm
.pipc_uid
;
1674 perm
.cgid
= ar
->ar_arg_pipc_perm
.pipc_gid
;
1675 perm
.mode
= ar
->ar_arg_pipc_perm
.pipc_mode
;
1678 tok
= au_to_ipc_perm(&perm
);
1679 kau_write(rec
, tok
);
1684 if (ARG_IS_VALID(kar
, ARG_FD
)) {
1685 tok
= au_to_arg32(1, "sem", ar
->ar_arg_fd
);
1686 kau_write(rec
, tok
);
1691 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1692 tok
= au_to_text(ar
->ar_arg_text
);
1693 kau_write(rec
, tok
);
1695 UPATH1_VNODE1_TOKENS
;
1699 case AUE_SYSCTL_NONADMIN
:
1700 if (ARG_IS_VALID(kar
, ARG_CTLNAME
| ARG_LEN
)) {
1701 for (ctr
= 0; ctr
< (int)ar
->ar_arg_len
; ctr
++) {
1702 tok
= au_to_arg32(1, "name",
1703 ar
->ar_arg_ctlname
[ctr
]);
1704 kau_write(rec
, tok
);
1707 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1708 tok
= au_to_arg32(5, "newval", ar
->ar_arg_value32
);
1709 kau_write(rec
, tok
);
1711 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1712 tok
= au_to_text(ar
->ar_arg_text
);
1713 kau_write(rec
, tok
);
1717 case AUE_UMASK_EXTENDED
:
1719 if (ARG_IS_VALID(kar
, ARG_OPAQUE
)) {
1720 tok
= au_to_opaque(ar
->ar_arg_opaque
,
1721 ar
->ar_arg_opq_size
);
1722 kau_write(rec
, tok
);
1727 if (ARG_IS_VALID(kar
, ARG_MASK
)) {
1728 tok
= au_to_arg32(1, "new mask", ar
->ar_arg_mask
);
1729 kau_write(rec
, tok
);
1731 tok
= au_to_arg32(0, "prev mask", ar
->ar_retval
);
1732 kau_write(rec
, tok
);
1736 #if 0 /* XXXss - new */
1739 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1740 tok
= au_to_arg32(0, "pid", ar
->ar_arg_pid
);
1741 kau_write(rec
, tok
);
1746 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1747 tok
= au_to_arg32(3, "volfsid", ar
->ar_arg_value32
);
1748 kau_write(rec
, tok
);
1750 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1751 tok
= au_to_arg64(4, "objid", ar
->ar_arg_value64
);
1752 kau_write(rec
, tok
);
1754 if (ARG_IS_VALID(kar
, ARG_TEXT
)) {
1755 tok
= au_to_text(ar
->ar_arg_text
);
1756 kau_write(rec
, tok
);
1760 case AUE_SESSION_START
:
1761 case AUE_SESSION_UPDATE
:
1762 case AUE_SESSION_END
:
1763 case AUE_SESSION_CLOSE
:
1764 if (ARG_IS_VALID(kar
, ARG_VALUE64
)) {
1765 tok
= au_to_arg64(1, "sflags", ar
->ar_arg_value64
);
1766 kau_write(rec
, tok
);
1768 if (ARG_IS_VALID(kar
, ARG_AMASK
)) {
1769 tok
= au_to_arg32(2, "am_success",
1770 ar
->ar_arg_amask
.am_success
);
1771 kau_write(rec
, tok
);
1772 tok
= au_to_arg32(3, "am_failure",
1773 ar
->ar_arg_amask
.am_failure
);
1774 kau_write(rec
, tok
);
1778 /************************
1779 * Mach system calls *
1780 ************************/
1781 case AUE_INITPROCESS
:
1784 case AUE_PIDFORTASK
:
1785 if (ARG_IS_VALID(kar
, ARG_MACHPORT1
)) {
1786 tok
= au_to_arg32(1, "port",
1787 (u_int32_t
)ar
->ar_arg_mach_port1
);
1788 kau_write(rec
, tok
);
1790 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1791 tok
= au_to_arg32(2, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1792 kau_write(rec
, tok
);
1796 case AUE_TASKFORPID
:
1797 case AUE_TASKNAMEFORPID
:
1798 if (ARG_IS_VALID(kar
, ARG_MACHPORT1
)) {
1799 tok
= au_to_arg32(1, "target port",
1800 (u_int32_t
)ar
->ar_arg_mach_port1
);
1801 kau_write(rec
, tok
);
1803 if (ARG_IS_VALID(kar
, ARG_MACHPORT2
)) {
1804 tok
= au_to_arg32(3, "task port",
1805 (u_int32_t
)ar
->ar_arg_mach_port2
);
1806 kau_write(rec
, tok
);
1808 PROCESS_PID_TOKENS(2);
1812 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1813 tok
= au_to_arg32(4, "priority",
1814 (u_int32_t
)ar
->ar_arg_value32
);
1815 kau_write(rec
, tok
);
1817 UPATH1_VNODE1_TOKENS
;
1821 UPATH1_VNODE1_TOKENS
;
1825 if (ARG_IS_VALID(kar
, ARG_ADDR64
)) {
1826 tok
= au_to_arg64(3, "va", ar
->ar_arg_addr
);
1827 kau_write(rec
, tok
);
1828 } else if (ARG_IS_VALID(kar
, ARG_ADDR32
)) {
1829 tok
= au_to_arg32(3, "va",
1830 (u_int32_t
)ar
->ar_arg_addr
);
1831 kau_write(rec
, tok
);
1837 case AUE_MAC_GET_FILE
:
1838 case AUE_MAC_SET_FILE
:
1839 case AUE_MAC_GET_LINK
:
1840 case AUE_MAC_SET_LINK
:
1841 case AUE_MAC_GET_MOUNT
:
1842 UPATH1_VNODE1_TOKENS
;
1846 case AUE_MAC_GET_FD
:
1847 case AUE_MAC_SET_FD
:
1852 case AUE_MAC_SYSCALL
:
1854 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1855 tok
= au_to_arg32(3, "call", ar
->ar_arg_value32
);
1856 kau_write(rec
, tok
);
1860 case AUE_MAC_EXECVE
:
1861 UPATH1_VNODE1_TOKENS
;
1865 case AUE_MAC_GET_PID
:
1866 if (ARG_IS_VALID(kar
, ARG_PID
)) {
1867 tok
= au_to_arg32(1, "pid", (u_int32_t
)ar
->ar_arg_pid
);
1868 kau_write(rec
, tok
);
1873 case AUE_MAC_GET_LCID
:
1874 if (ARG_IS_VALID(kar
, ARG_VALUE32
)) {
1875 tok
= au_to_arg32(1, "lcid",
1876 (u_int32_t
)ar
->ar_arg_value32
);
1877 kau_write(rec
, tok
);
1882 case AUE_MAC_GET_PROC
:
1883 case AUE_MAC_SET_PROC
:
1884 case AUE_MAC_GET_LCTX
:
1885 case AUE_MAC_SET_LCTX
:
1892 printf("BSM conversion requested for unknown event %d\n",
1897 * Write the subject token so it is properly freed here.
1899 kau_write(rec
, subj_tok
);
1901 return (BSM_NOAUDIT
);
1905 if (NULL
!= ar
->ar_mac_records
) {
1906 /* Convert the audit data from the MAC policies */
1907 struct mac_audit_record
*mar
;
1909 LIST_FOREACH(mar
, ar
->ar_mac_records
, records
) {
1910 switch (mar
->type
) {
1911 case MAC_AUDIT_DATA_TYPE
:
1912 tok
= au_to_data(AUP_BINARY
, AUR_BYTE
,
1914 (const char *)mar
->data
);
1916 case MAC_AUDIT_TEXT_TYPE
:
1917 tok
= au_to_text((char*) mar
->data
);
1921 * XXX: we can either continue,
1922 * skipping this particular entry,
1923 * or we can pre-verify the list and
1924 * abort before writing any records
1926 printf("kaudit_to_bsm(): "
1927 "BSM conversion requested for"
1928 "unknown mac_audit data type %d\n",
1932 kau_write(rec
, tok
);
1937 kau_write(rec
, subj_tok
);
1940 if (ar
->ar_cred_mac_labels
!= NULL
&&
1941 strlen(ar
->ar_cred_mac_labels
) != 0) {
1942 tok
= au_to_text(ar
->ar_cred_mac_labels
);
1943 kau_write(rec
, tok
);
1947 tok
= au_to_return32(au_errno_to_bsm(ar
->ar_errno
), ar
->ar_retval
);
1948 kau_write(rec
, tok
); /* Every record gets a return token */
1950 kau_close(rec
, &ar
->ar_endtime
, ar
->ar_event
);
1953 return (BSM_SUCCESS
);
1957 * Verify that a record is a valid BSM record. This verification is simple
1958 * now, but may be expanded on sometime in the future. Return 1 if the
1959 * record is good, 0 otherwise.
1962 bsm_rec_verify(void *rec
)
1964 char c
= *(char *)rec
;
1967 * Check the token ID of the first token; it has to be a header
1970 * XXXAUDIT There needs to be a token structure to map a token.
1971 * XXXAUDIT 'Shouldn't be simply looking at the first char.
1973 if ((c
!= AUT_HEADER32
) && (c
!= AUT_HEADER32_EX
) &&
1974 (c
!= AUT_HEADER64
) && (c
!= AUT_HEADER64_EX
))
1978 #endif /* CONFIG_AUDIT */