2008-07-31 09:54:35 +00:00
|
|
|
/*-
|
2009-04-19 14:53:17 +00:00
|
|
|
* Copyright (c) 1999-2009 Apple Inc.
|
2006-02-01 20:01:18 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2008-07-22 15:29:48 +00:00
|
|
|
* 3. Neither the name of Apple Inc. ("Apple") nor the names of
|
2006-02-01 20:01:18 +00:00
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2008-04-13 22:06:56 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <sys/param.h>
|
2006-06-05 22:36:12 +00:00
|
|
|
#include <sys/mount.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <sys/namei.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/sysproto.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/vnode.h>
|
2006-10-10 15:49:10 +00:00
|
|
|
#include <sys/jail.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
|
|
|
|
#include <bsm/audit.h>
|
|
|
|
#include <bsm/audit_kevents.h>
|
2007-04-21 22:08:48 +00:00
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <security/audit/audit.h>
|
|
|
|
#include <security/audit/audit_private.h>
|
2007-04-21 22:08:48 +00:00
|
|
|
#include <security/mac/mac_framework.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
|
|
|
|
#ifdef AUDIT
|
|
|
|
|
|
|
|
/*
|
2006-03-19 17:34:00 +00:00
|
|
|
* System call to allow a user space application to submit a BSM audit record
|
2007-05-30 08:39:16 +00:00
|
|
|
* to the kernel for inclusion in the audit log. This function does little
|
2006-03-19 17:34:00 +00:00
|
|
|
* verification on the audit record that is submitted.
|
2006-02-01 20:01:18 +00:00
|
|
|
*
|
2006-03-19 17:34:00 +00:00
|
|
|
* XXXAUDIT: Audit preselection for user records does not currently work,
|
|
|
|
* since we pre-select only based on the AUE_audit event type, not the event
|
|
|
|
* type submitted as part of the user audit data.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_audit(struct thread *td, struct audit_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
void * rec;
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_AUDIT_SUBMIT);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((uap->length <= 0) || (uap->length > audit_qctrl.aq_bufsz))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
|
|
|
* If there's no current audit record (audit() itself not audited)
|
2006-02-01 20:01:18 +00:00
|
|
|
* commit the user audit record.
|
|
|
|
*/
|
|
|
|
if (ar == NULL) {
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
|
|
|
* This is not very efficient; we're required to allocate a
|
|
|
|
* complete kernel audit record just so the user record can
|
|
|
|
* tag along.
|
2006-02-01 20:01:18 +00:00
|
|
|
*
|
|
|
|
* XXXAUDIT: Maybe AUE_AUDIT in the system call context and
|
|
|
|
* special pre-select handling?
|
|
|
|
*/
|
|
|
|
td->td_ar = audit_new(AUE_NULL, td);
|
|
|
|
if (td->td_ar == NULL)
|
|
|
|
return (ENOTSUP);
|
2009-03-09 10:45:58 +00:00
|
|
|
td->td_pflags |= TDP_AUDITREC;
|
2006-02-01 20:01:18 +00:00
|
|
|
ar = td->td_ar;
|
|
|
|
}
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
if (uap->length > MAX_AUDIT_RECORD_SIZE)
|
2006-02-01 20:01:18 +00:00
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
rec = malloc(uap->length, M_AUDITDATA, M_WAITOK);
|
|
|
|
|
|
|
|
error = copyin(uap->record, rec, uap->length);
|
|
|
|
if (error)
|
|
|
|
goto free_out;
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/* Verify the record. */
|
2006-02-01 20:01:18 +00:00
|
|
|
if (bsm_rec_verify(rec) == 0) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto free_out;
|
|
|
|
}
|
|
|
|
|
2007-04-21 22:08:48 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_system_check_audit(td->td_ucred, rec, uap->length);
|
2007-04-21 22:08:48 +00:00
|
|
|
if (error)
|
|
|
|
goto free_out;
|
|
|
|
#endif
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
2007-05-30 08:39:16 +00:00
|
|
|
* Attach the user audit record to the kernel audit record. Because
|
2006-02-01 20:01:18 +00:00
|
|
|
* this system call is an auditable event, we will write the user
|
|
|
|
* record along with the record for this audit event.
|
|
|
|
*
|
|
|
|
* XXXAUDIT: KASSERT appropriate starting values of k_udata, k_ulen,
|
|
|
|
* k_ar_commit & AR_COMMIT_USER?
|
|
|
|
*/
|
|
|
|
ar->k_udata = rec;
|
|
|
|
ar->k_ulen = uap->length;
|
|
|
|
ar->k_ar_commit |= AR_COMMIT_USER;
|
2006-09-17 17:52:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently we assume that all preselection has been performed in
|
2007-05-30 08:39:16 +00:00
|
|
|
* userspace. We unconditionally set these masks so that the records
|
2006-09-17 17:52:57 +00:00
|
|
|
* get committed both to the trail and pipe. In the future we will
|
|
|
|
* want to setup kernel based preselection.
|
|
|
|
*/
|
|
|
|
ar->k_ar_commit |= (AR_PRESELECT_USER_TRAIL | AR_PRESELECT_USER_PIPE);
|
2006-02-01 20:01:18 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
free_out:
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
|
|
|
* audit_syscall_exit() will free the audit record on the thread even
|
|
|
|
* if we allocated it above.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
|
|
|
free(rec, M_AUDITDATA);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System call to manipulate auditing.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_auditon(struct thread *td, struct auditon_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
2008-11-14 01:24:52 +00:00
|
|
|
struct ucred *cred, *newcred, *oldcred;
|
2006-02-01 20:01:18 +00:00
|
|
|
int error;
|
|
|
|
union auditon_udata udata;
|
|
|
|
struct proc *tp;
|
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2009-06-27 13:58:44 +00:00
|
|
|
AUDIT_ARG_CMD(uap->cmd);
|
2007-04-21 22:08:48 +00:00
|
|
|
|
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_system_check_auditon(td->td_ucred, uap->cmd);
|
2007-04-21 22:08:48 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
#endif
|
|
|
|
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_AUDIT_CONTROL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if ((uap->length <= 0) || (uap->length > sizeof(union auditon_udata)))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
memset((void *)&udata, 0, sizeof(udata));
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
|
|
|
* Some of the GET commands use the arguments too.
|
|
|
|
*/
|
2006-02-01 20:01:18 +00:00
|
|
|
switch (uap->cmd) {
|
|
|
|
case A_SETPOLICY:
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDSETPOLICY:
|
2006-02-01 20:01:18 +00:00
|
|
|
case A_SETKMASK:
|
|
|
|
case A_SETQCTRL:
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDSETQCTRL:
|
2006-02-01 20:01:18 +00:00
|
|
|
case A_SETSTAT:
|
|
|
|
case A_SETUMASK:
|
|
|
|
case A_SETSMASK:
|
|
|
|
case A_SETCOND:
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDSETCOND:
|
2006-02-01 20:01:18 +00:00
|
|
|
case A_SETCLASS:
|
|
|
|
case A_SETPMASK:
|
|
|
|
case A_SETFSIZE:
|
|
|
|
case A_SETKAUDIT:
|
|
|
|
case A_GETCLASS:
|
|
|
|
case A_GETPINFO:
|
|
|
|
case A_GETPINFO_ADDR:
|
|
|
|
case A_SENDTRIGGER:
|
|
|
|
error = copyin(uap->data, (void *)&udata, uap->length);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
2009-06-27 13:58:44 +00:00
|
|
|
AUDIT_ARG_AUDITON(&udata);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
2006-02-01 20:01:18 +00:00
|
|
|
* XXXAUDIT: Locking?
|
|
|
|
*/
|
|
|
|
switch (uap->cmd) {
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDGETPOLICY:
|
2009-04-19 23:28:08 +00:00
|
|
|
case A_GETPOLICY:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length == sizeof(udata.au_policy64)) {
|
|
|
|
if (!audit_fail_stop)
|
|
|
|
udata.au_policy64 |= AUDIT_CNT;
|
|
|
|
if (audit_panic_on_write_fail)
|
|
|
|
udata.au_policy64 |= AUDIT_AHLT;
|
|
|
|
if (audit_argv)
|
|
|
|
udata.au_policy64 |= AUDIT_ARGV;
|
|
|
|
if (audit_arge)
|
|
|
|
udata.au_policy64 |= AUDIT_ARGE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (uap->length != sizeof(udata.au_policy))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (!audit_fail_stop)
|
|
|
|
udata.au_policy |= AUDIT_CNT;
|
|
|
|
if (audit_panic_on_write_fail)
|
|
|
|
udata.au_policy |= AUDIT_AHLT;
|
2006-09-01 11:45:40 +00:00
|
|
|
if (audit_argv)
|
|
|
|
udata.au_policy |= AUDIT_ARGV;
|
|
|
|
if (audit_arge)
|
|
|
|
udata.au_policy |= AUDIT_ARGE;
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDSETPOLICY:
|
2009-04-19 23:28:08 +00:00
|
|
|
case A_SETPOLICY:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length == sizeof(udata.au_policy64)) {
|
|
|
|
if (udata.au_policy & (~AUDIT_CNT|AUDIT_AHLT|
|
|
|
|
AUDIT_ARGV|AUDIT_ARGE))
|
|
|
|
return (EINVAL);
|
|
|
|
audit_fail_stop = ((udata.au_policy64 & AUDIT_CNT) ==
|
|
|
|
0);
|
|
|
|
audit_panic_on_write_fail = (udata.au_policy64 &
|
|
|
|
AUDIT_AHLT);
|
|
|
|
audit_argv = (udata.au_policy64 & AUDIT_ARGV);
|
|
|
|
audit_arge = (udata.au_policy64 & AUDIT_ARGE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (uap->length != sizeof(udata.au_policy))
|
|
|
|
return (EINVAL);
|
2006-09-01 11:45:40 +00:00
|
|
|
if (udata.au_policy & ~(AUDIT_CNT|AUDIT_AHLT|AUDIT_ARGV|
|
|
|
|
AUDIT_ARGE))
|
2006-02-01 20:01:18 +00:00
|
|
|
return (EINVAL);
|
|
|
|
/*
|
|
|
|
* XXX - Need to wake up waiters if the policy relaxes?
|
|
|
|
*/
|
|
|
|
audit_fail_stop = ((udata.au_policy & AUDIT_CNT) == 0);
|
|
|
|
audit_panic_on_write_fail = (udata.au_policy & AUDIT_AHLT);
|
2006-09-01 11:45:40 +00:00
|
|
|
audit_argv = (udata.au_policy & AUDIT_ARGV);
|
|
|
|
audit_arge = (udata.au_policy & AUDIT_ARGE);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETKMASK:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_mask))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
udata.au_mask = audit_nae_mask;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETKMASK:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_mask))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
audit_nae_mask = udata.au_mask;
|
|
|
|
break;
|
|
|
|
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDGETQCTRL:
|
2009-04-19 23:28:08 +00:00
|
|
|
case A_GETQCTRL:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length == sizeof(udata.au_qctrl64)) {
|
|
|
|
udata.au_qctrl64.aq64_hiwater =
|
|
|
|
(u_int64_t)audit_qctrl.aq_hiwater;
|
|
|
|
udata.au_qctrl64.aq64_lowater =
|
|
|
|
(u_int64_t)audit_qctrl.aq_lowater;
|
|
|
|
udata.au_qctrl64.aq64_bufsz =
|
|
|
|
(u_int64_t)audit_qctrl.aq_bufsz;
|
|
|
|
udata.au_qctrl64.aq64_minfree =
|
|
|
|
(u_int64_t)audit_qctrl.aq_minfree;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (uap->length != sizeof(udata.au_qctrl))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
udata.au_qctrl = audit_qctrl;
|
|
|
|
break;
|
|
|
|
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDSETQCTRL:
|
2009-04-19 23:28:08 +00:00
|
|
|
case A_SETQCTRL:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length == sizeof(udata.au_qctrl64)) {
|
2016-09-08 19:47:57 +00:00
|
|
|
/* NB: aq64_minfree is unsigned unlike aq_minfree. */
|
2009-04-19 14:53:17 +00:00
|
|
|
if ((udata.au_qctrl64.aq64_hiwater > AQ_MAXHIGH) ||
|
|
|
|
(udata.au_qctrl64.aq64_lowater >=
|
|
|
|
udata.au_qctrl.aq_hiwater) ||
|
|
|
|
(udata.au_qctrl64.aq64_bufsz > AQ_MAXBUFSZ) ||
|
2016-09-08 19:47:57 +00:00
|
|
|
(udata.au_qctrl64.aq64_minfree > 100))
|
2009-04-19 14:53:17 +00:00
|
|
|
return (EINVAL);
|
|
|
|
audit_qctrl.aq_hiwater =
|
|
|
|
(int)udata.au_qctrl64.aq64_hiwater;
|
|
|
|
audit_qctrl.aq_lowater =
|
|
|
|
(int)udata.au_qctrl64.aq64_lowater;
|
|
|
|
audit_qctrl.aq_bufsz =
|
|
|
|
(int)udata.au_qctrl64.aq64_bufsz;
|
|
|
|
audit_qctrl.aq_minfree =
|
|
|
|
(int)udata.au_qctrl64.aq64_minfree;
|
|
|
|
audit_qctrl.aq_delay = -1; /* Not used. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (uap->length != sizeof(udata.au_qctrl))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if ((udata.au_qctrl.aq_hiwater > AQ_MAXHIGH) ||
|
|
|
|
(udata.au_qctrl.aq_lowater >= udata.au_qctrl.aq_hiwater) ||
|
|
|
|
(udata.au_qctrl.aq_bufsz > AQ_MAXBUFSZ) ||
|
|
|
|
(udata.au_qctrl.aq_minfree < 0) ||
|
|
|
|
(udata.au_qctrl.aq_minfree > 100))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
audit_qctrl = udata.au_qctrl;
|
|
|
|
/* XXX The queue delay value isn't used with the kernel. */
|
|
|
|
audit_qctrl.aq_delay = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETCWD:
|
|
|
|
return (ENOSYS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETCAR:
|
|
|
|
return (ENOSYS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETSTAT:
|
|
|
|
return (ENOSYS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETSTAT:
|
|
|
|
return (ENOSYS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETUMASK:
|
|
|
|
return (ENOSYS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETSMASK:
|
|
|
|
return (ENOSYS);
|
|
|
|
break;
|
|
|
|
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDGETCOND:
|
2009-04-19 23:28:08 +00:00
|
|
|
case A_GETCOND:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length == sizeof(udata.au_cond64)) {
|
|
|
|
if (audit_enabled && !audit_suspended)
|
|
|
|
udata.au_cond64 = AUC_AUDITING;
|
|
|
|
else
|
|
|
|
udata.au_cond64 = AUC_NOAUDIT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (uap->length != sizeof(udata.au_cond))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (audit_enabled && !audit_suspended)
|
|
|
|
udata.au_cond = AUC_AUDITING;
|
|
|
|
else
|
|
|
|
udata.au_cond = AUC_NOAUDIT;
|
|
|
|
break;
|
|
|
|
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDSETCOND:
|
2009-04-19 23:28:08 +00:00
|
|
|
case A_SETCOND:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length == sizeof(udata.au_cond64)) {
|
|
|
|
if (udata.au_cond64 == AUC_NOAUDIT)
|
|
|
|
audit_suspended = 1;
|
|
|
|
if (udata.au_cond64 == AUC_AUDITING)
|
|
|
|
audit_suspended = 0;
|
|
|
|
if (udata.au_cond64 == AUC_DISABLED) {
|
|
|
|
audit_suspended = 1;
|
|
|
|
audit_shutdown(NULL, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (uap->length != sizeof(udata.au_cond))
|
|
|
|
return (EINVAL);
|
2006-03-19 17:34:00 +00:00
|
|
|
if (udata.au_cond == AUC_NOAUDIT)
|
2006-02-01 20:01:18 +00:00
|
|
|
audit_suspended = 1;
|
2006-03-19 17:34:00 +00:00
|
|
|
if (udata.au_cond == AUC_AUDITING)
|
2006-02-01 20:01:18 +00:00
|
|
|
audit_suspended = 0;
|
|
|
|
if (udata.au_cond == AUC_DISABLED) {
|
|
|
|
audit_suspended = 1;
|
|
|
|
audit_shutdown(NULL, 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETCLASS:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_evclass))
|
|
|
|
return (EINVAL);
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_evclass.ec_class = au_event_class(
|
|
|
|
udata.au_evclass.ec_number);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETCLASS:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_evclass))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
au_evclassmap_insert(udata.au_evclass.ec_number,
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_evclass.ec_class);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETPINFO:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_aupinfo))
|
|
|
|
return (EINVAL);
|
2006-03-19 17:34:00 +00:00
|
|
|
if (udata.au_aupinfo.ap_pid < 1)
|
2008-09-04 10:44:33 +00:00
|
|
|
return (ESRCH);
|
2006-02-01 20:01:18 +00:00
|
|
|
if ((tp = pfind(udata.au_aupinfo.ap_pid)) == NULL)
|
2008-09-04 10:44:33 +00:00
|
|
|
return (ESRCH);
|
2008-09-04 13:06:36 +00:00
|
|
|
if ((error = p_cansee(td, tp)) != 0) {
|
2006-12-29 10:49:13 +00:00
|
|
|
PROC_UNLOCK(tp);
|
2008-09-04 10:44:33 +00:00
|
|
|
return (error);
|
2006-12-29 10:49:13 +00:00
|
|
|
}
|
2008-11-14 01:24:52 +00:00
|
|
|
cred = tp->p_ucred;
|
|
|
|
if (cred->cr_audit.ai_termid.at_type == AU_IPv6) {
|
2007-04-13 14:55:19 +00:00
|
|
|
PROC_UNLOCK(tp);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2008-11-14 01:24:52 +00:00
|
|
|
udata.au_aupinfo.ap_auid = cred->cr_audit.ai_auid;
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_aupinfo.ap_mask.am_success =
|
2008-11-14 01:24:52 +00:00
|
|
|
cred->cr_audit.ai_mask.am_success;
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_aupinfo.ap_mask.am_failure =
|
2008-11-14 01:24:52 +00:00
|
|
|
cred->cr_audit.ai_mask.am_failure;
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_aupinfo.ap_termid.machine =
|
2008-11-14 01:24:52 +00:00
|
|
|
cred->cr_audit.ai_termid.at_addr[0];
|
2007-04-13 14:55:19 +00:00
|
|
|
udata.au_aupinfo.ap_termid.port =
|
2008-11-14 01:24:52 +00:00
|
|
|
(dev_t)cred->cr_audit.ai_termid.at_port;
|
|
|
|
udata.au_aupinfo.ap_asid = cred->cr_audit.ai_asid;
|
2006-02-01 20:01:18 +00:00
|
|
|
PROC_UNLOCK(tp);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETPMASK:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_aupinfo))
|
|
|
|
return (EINVAL);
|
2006-03-19 17:34:00 +00:00
|
|
|
if (udata.au_aupinfo.ap_pid < 1)
|
2008-09-04 10:44:33 +00:00
|
|
|
return (ESRCH);
|
2007-06-07 22:27:15 +00:00
|
|
|
newcred = crget();
|
|
|
|
if ((tp = pfind(udata.au_aupinfo.ap_pid)) == NULL) {
|
|
|
|
crfree(newcred);
|
2008-09-04 10:44:33 +00:00
|
|
|
return (ESRCH);
|
2007-06-07 22:27:15 +00:00
|
|
|
}
|
2008-09-04 13:06:36 +00:00
|
|
|
if ((error = p_cansee(td, tp)) != 0) {
|
2006-12-29 10:49:13 +00:00
|
|
|
PROC_UNLOCK(tp);
|
2007-06-07 22:27:15 +00:00
|
|
|
crfree(newcred);
|
2008-09-04 10:44:33 +00:00
|
|
|
return (error);
|
2006-12-29 10:49:13 +00:00
|
|
|
}
|
2007-06-07 22:27:15 +00:00
|
|
|
oldcred = tp->p_ucred;
|
|
|
|
crcopy(newcred, oldcred);
|
|
|
|
newcred->cr_audit.ai_mask.am_success =
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_aupinfo.ap_mask.am_success;
|
2007-06-07 22:27:15 +00:00
|
|
|
newcred->cr_audit.ai_mask.am_failure =
|
2006-03-19 17:34:00 +00:00
|
|
|
udata.au_aupinfo.ap_mask.am_failure;
|
2015-03-16 00:10:03 +00:00
|
|
|
proc_set_cred(tp, newcred);
|
2006-02-01 20:01:18 +00:00
|
|
|
PROC_UNLOCK(tp);
|
2007-06-07 22:27:15 +00:00
|
|
|
crfree(oldcred);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETFSIZE:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_fstat))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if ((udata.au_fstat.af_filesz != 0) &&
|
|
|
|
(udata.au_fstat.af_filesz < MIN_AUDIT_FILE_SIZE))
|
|
|
|
return (EINVAL);
|
|
|
|
audit_fstat.af_filesz = udata.au_fstat.af_filesz;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETFSIZE:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_fstat))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
udata.au_fstat.af_filesz = audit_fstat.af_filesz;
|
|
|
|
udata.au_fstat.af_currsz = audit_fstat.af_currsz;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETPINFO_ADDR:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_aupinfo_addr))
|
|
|
|
return (EINVAL);
|
2007-04-13 14:55:19 +00:00
|
|
|
if (udata.au_aupinfo_addr.ap_pid < 1)
|
2008-09-04 10:44:33 +00:00
|
|
|
return (ESRCH);
|
2007-04-13 14:55:19 +00:00
|
|
|
if ((tp = pfind(udata.au_aupinfo_addr.ap_pid)) == NULL)
|
2008-09-04 10:44:33 +00:00
|
|
|
return (ESRCH);
|
2008-11-14 01:24:52 +00:00
|
|
|
cred = tp->p_ucred;
|
|
|
|
udata.au_aupinfo_addr.ap_auid = cred->cr_audit.ai_auid;
|
2007-04-13 14:55:19 +00:00
|
|
|
udata.au_aupinfo_addr.ap_mask.am_success =
|
2008-11-14 01:24:52 +00:00
|
|
|
cred->cr_audit.ai_mask.am_success;
|
2007-04-13 14:55:19 +00:00
|
|
|
udata.au_aupinfo_addr.ap_mask.am_failure =
|
2008-11-14 01:24:52 +00:00
|
|
|
cred->cr_audit.ai_mask.am_failure;
|
|
|
|
udata.au_aupinfo_addr.ap_termid = cred->cr_audit.ai_termid;
|
|
|
|
udata.au_aupinfo_addr.ap_asid = cred->cr_audit.ai_asid;
|
2007-04-13 14:55:19 +00:00
|
|
|
PROC_UNLOCK(tp);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_GETKAUDIT:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_kau_info))
|
|
|
|
return (EINVAL);
|
2008-11-11 21:57:03 +00:00
|
|
|
audit_get_kinfo(&udata.au_kau_info);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SETKAUDIT:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_kau_info))
|
|
|
|
return (EINVAL);
|
2008-11-11 21:57:03 +00:00
|
|
|
if (udata.au_kau_info.ai_termid.at_type != AU_IPv4 &&
|
|
|
|
udata.au_kau_info.ai_termid.at_type != AU_IPv6)
|
|
|
|
return (EINVAL);
|
|
|
|
audit_set_kinfo(&udata.au_kau_info);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case A_SENDTRIGGER:
|
2009-04-19 14:53:17 +00:00
|
|
|
if (uap->length != sizeof(udata.au_trigger))
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if ((udata.au_trigger < AUDIT_TRIGGER_MIN) ||
|
|
|
|
(udata.au_trigger > AUDIT_TRIGGER_MAX))
|
|
|
|
return (EINVAL);
|
2008-03-01 11:04:04 +00:00
|
|
|
return (audit_send_trigger(udata.au_trigger));
|
2008-03-06 22:57:03 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
2006-03-19 17:34:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy data back to userspace for the GET comands.
|
|
|
|
*/
|
2006-02-01 20:01:18 +00:00
|
|
|
switch (uap->cmd) {
|
|
|
|
case A_GETPOLICY:
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDGETPOLICY:
|
2006-02-01 20:01:18 +00:00
|
|
|
case A_GETKMASK:
|
|
|
|
case A_GETQCTRL:
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDGETQCTRL:
|
2006-02-01 20:01:18 +00:00
|
|
|
case A_GETCWD:
|
|
|
|
case A_GETCAR:
|
|
|
|
case A_GETSTAT:
|
|
|
|
case A_GETCOND:
|
2009-04-19 14:53:17 +00:00
|
|
|
case A_OLDGETCOND:
|
2006-02-01 20:01:18 +00:00
|
|
|
case A_GETCLASS:
|
|
|
|
case A_GETPINFO:
|
|
|
|
case A_GETFSIZE:
|
|
|
|
case A_GETPINFO_ADDR:
|
|
|
|
case A_GETKAUDIT:
|
|
|
|
error = copyout((void *)&udata, uap->data, uap->length);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
2006-02-01 20:01:18 +00:00
|
|
|
* System calls to manage the user audit information.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_getauid(struct thread *td, struct getauid_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_AUDIT_GETAUDIT);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2007-06-07 22:27:15 +00:00
|
|
|
return (copyout(&td->td_ucred->cr_audit.ai_auid, uap->auid,
|
|
|
|
sizeof(td->td_ucred->cr_audit.ai_auid)));
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_setauid(struct thread *td, struct setauid_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
2007-06-07 22:27:15 +00:00
|
|
|
struct ucred *newcred, *oldcred;
|
2006-02-01 20:01:18 +00:00
|
|
|
au_id_t id;
|
2007-06-07 22:27:15 +00:00
|
|
|
int error;
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2006-02-01 20:01:18 +00:00
|
|
|
error = copyin(uap->auid, &id, sizeof(id));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
audit_arg_auid(id);
|
2007-06-07 22:27:15 +00:00
|
|
|
newcred = crget();
|
|
|
|
PROC_LOCK(td->td_proc);
|
|
|
|
oldcred = td->td_proc->p_ucred;
|
|
|
|
crcopy(newcred, oldcred);
|
2007-04-21 22:08:48 +00:00
|
|
|
#ifdef MAC
|
2009-03-08 10:58:37 +00:00
|
|
|
error = mac_cred_check_setauid(oldcred, id);
|
2007-04-21 22:08:48 +00:00
|
|
|
if (error)
|
2007-06-07 22:27:15 +00:00
|
|
|
goto fail;
|
2007-04-21 22:08:48 +00:00
|
|
|
#endif
|
2007-06-07 22:27:15 +00:00
|
|
|
error = priv_check_cred(oldcred, PRIV_AUDIT_SETAUDIT, 0);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
newcred->cr_audit.ai_auid = id;
|
2015-03-16 00:10:03 +00:00
|
|
|
proc_set_cred(td->td_proc, newcred);
|
2006-02-01 20:01:18 +00:00
|
|
|
PROC_UNLOCK(td->td_proc);
|
2007-06-07 22:27:15 +00:00
|
|
|
crfree(oldcred);
|
2006-02-01 20:01:18 +00:00
|
|
|
return (0);
|
2007-06-07 22:27:15 +00:00
|
|
|
fail:
|
|
|
|
PROC_UNLOCK(td->td_proc);
|
|
|
|
crfree(newcred);
|
|
|
|
return (error);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-03-19 17:34:00 +00:00
|
|
|
* System calls to get and set process audit information.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_getaudit(struct thread *td, struct getaudit_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct auditinfo ai;
|
2008-11-14 01:24:52 +00:00
|
|
|
struct ucred *cred;
|
2006-02-01 20:01:18 +00:00
|
|
|
int error;
|
|
|
|
|
2008-11-14 01:24:52 +00:00
|
|
|
cred = td->td_ucred;
|
|
|
|
if (jailed(cred))
|
2006-10-10 15:49:10 +00:00
|
|
|
return (ENOSYS);
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_AUDIT_GETAUDIT);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2008-11-14 01:24:52 +00:00
|
|
|
if (cred->cr_audit.ai_termid.at_type == AU_IPv6)
|
2008-11-30 19:58:03 +00:00
|
|
|
return (E2BIG);
|
2007-04-13 14:55:19 +00:00
|
|
|
bzero(&ai, sizeof(ai));
|
2008-11-14 01:24:52 +00:00
|
|
|
ai.ai_auid = cred->cr_audit.ai_auid;
|
|
|
|
ai.ai_mask = cred->cr_audit.ai_mask;
|
|
|
|
ai.ai_asid = cred->cr_audit.ai_asid;
|
|
|
|
ai.ai_termid.machine = cred->cr_audit.ai_termid.at_addr[0];
|
|
|
|
ai.ai_termid.port = cred->cr_audit.ai_termid.at_port;
|
2007-06-27 17:01:15 +00:00
|
|
|
return (copyout(&ai, uap->auditinfo, sizeof(ai)));
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_setaudit(struct thread *td, struct setaudit_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
2007-06-07 22:27:15 +00:00
|
|
|
struct ucred *newcred, *oldcred;
|
2006-02-01 20:01:18 +00:00
|
|
|
struct auditinfo ai;
|
|
|
|
int error;
|
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2006-02-01 20:01:18 +00:00
|
|
|
error = copyin(uap->auditinfo, &ai, sizeof(ai));
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
audit_arg_auditinfo(&ai);
|
2007-06-07 22:27:15 +00:00
|
|
|
newcred = crget();
|
|
|
|
PROC_LOCK(td->td_proc);
|
|
|
|
oldcred = td->td_proc->p_ucred;
|
|
|
|
crcopy(newcred, oldcred);
|
2007-04-21 22:08:48 +00:00
|
|
|
#ifdef MAC
|
2009-03-08 10:58:37 +00:00
|
|
|
error = mac_cred_check_setaudit(oldcred, &ai);
|
2007-04-21 22:08:48 +00:00
|
|
|
if (error)
|
2007-06-07 22:27:15 +00:00
|
|
|
goto fail;
|
2007-04-21 22:08:48 +00:00
|
|
|
#endif
|
2007-06-07 22:27:15 +00:00
|
|
|
error = priv_check_cred(oldcred, PRIV_AUDIT_SETAUDIT, 0);
|
|
|
|
if (error)
|
|
|
|
goto fail;
|
|
|
|
bzero(&newcred->cr_audit, sizeof(newcred->cr_audit));
|
|
|
|
newcred->cr_audit.ai_auid = ai.ai_auid;
|
|
|
|
newcred->cr_audit.ai_mask = ai.ai_mask;
|
|
|
|
newcred->cr_audit.ai_asid = ai.ai_asid;
|
|
|
|
newcred->cr_audit.ai_termid.at_addr[0] = ai.ai_termid.machine;
|
|
|
|
newcred->cr_audit.ai_termid.at_port = ai.ai_termid.port;
|
|
|
|
newcred->cr_audit.ai_termid.at_type = AU_IPv4;
|
2015-03-16 00:10:03 +00:00
|
|
|
proc_set_cred(td->td_proc, newcred);
|
2006-02-01 20:01:18 +00:00
|
|
|
PROC_UNLOCK(td->td_proc);
|
2007-06-07 22:27:15 +00:00
|
|
|
crfree(oldcred);
|
2006-02-01 20:01:18 +00:00
|
|
|
return (0);
|
2007-06-07 22:27:15 +00:00
|
|
|
fail:
|
|
|
|
PROC_UNLOCK(td->td_proc);
|
|
|
|
crfree(newcred);
|
|
|
|
return (error);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_getaudit_addr(struct thread *td, struct getaudit_addr_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2007-06-07 22:27:15 +00:00
|
|
|
if (uap->length < sizeof(*uap->auditinfo_addr))
|
|
|
|
return (EOVERFLOW);
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_AUDIT_GETAUDIT);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2007-06-07 22:27:15 +00:00
|
|
|
return (copyout(&td->td_ucred->cr_audit, uap->auditinfo_addr,
|
|
|
|
sizeof(*uap->auditinfo_addr)));
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_setaudit_addr(struct thread *td, struct setaudit_addr_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
2007-06-07 22:27:15 +00:00
|
|
|
struct ucred *newcred, *oldcred;
|
2007-04-13 14:55:19 +00:00
|
|
|
struct auditinfo_addr aia;
|
2006-02-01 20:01:18 +00:00
|
|
|
int error;
|
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2007-06-07 22:27:15 +00:00
|
|
|
error = copyin(uap->auditinfo_addr, &aia, sizeof(aia));
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2007-06-27 17:01:15 +00:00
|
|
|
audit_arg_auditinfo_addr(&aia);
|
|
|
|
if (aia.ai_termid.at_type != AU_IPv6 &&
|
|
|
|
aia.ai_termid.at_type != AU_IPv4)
|
|
|
|
return (EINVAL);
|
2007-06-07 22:27:15 +00:00
|
|
|
newcred = crget();
|
|
|
|
PROC_LOCK(td->td_proc);
|
|
|
|
oldcred = td->td_proc->p_ucred;
|
|
|
|
crcopy(newcred, oldcred);
|
2007-04-21 22:08:48 +00:00
|
|
|
#ifdef MAC
|
2009-03-08 10:58:37 +00:00
|
|
|
error = mac_cred_check_setaudit_addr(oldcred, &aia);
|
2007-04-21 22:08:48 +00:00
|
|
|
if (error)
|
2007-06-07 22:27:15 +00:00
|
|
|
goto fail;
|
2007-04-21 22:08:48 +00:00
|
|
|
#endif
|
2007-06-07 22:27:15 +00:00
|
|
|
error = priv_check_cred(oldcred, PRIV_AUDIT_SETAUDIT, 0);
|
2007-04-13 14:55:19 +00:00
|
|
|
if (error)
|
2007-06-07 22:27:15 +00:00
|
|
|
goto fail;
|
|
|
|
newcred->cr_audit = aia;
|
2015-03-16 00:10:03 +00:00
|
|
|
proc_set_cred(td->td_proc, newcred);
|
2007-04-13 14:55:19 +00:00
|
|
|
PROC_UNLOCK(td->td_proc);
|
2007-06-07 22:27:15 +00:00
|
|
|
crfree(oldcred);
|
|
|
|
return (0);
|
|
|
|
fail:
|
2007-06-15 15:20:56 +00:00
|
|
|
PROC_UNLOCK(td->td_proc);
|
2007-06-07 22:27:15 +00:00
|
|
|
crfree(newcred);
|
2007-04-13 14:55:19 +00:00
|
|
|
return (error);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Syscall to manage audit files.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_auditctl(struct thread *td, struct auditctl_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct nameidata nd;
|
|
|
|
struct ucred *cred;
|
|
|
|
struct vnode *vp;
|
|
|
|
int error = 0;
|
2012-10-22 17:50:54 +00:00
|
|
|
int flags;
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2006-10-10 15:49:10 +00:00
|
|
|
if (jailed(td->td_ucred))
|
|
|
|
return (ENOSYS);
|
2006-11-06 13:42:10 +00:00
|
|
|
error = priv_check(td, PRIV_AUDIT_CONTROL);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
vp = NULL;
|
|
|
|
cred = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If a path is specified, open the replacement vnode, perform
|
|
|
|
* validity checks, and grab another reference to the current
|
|
|
|
* credential.
|
|
|
|
*
|
2006-12-29 10:49:13 +00:00
|
|
|
* On Darwin, a NULL path argument is also used to disable audit.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
|
|
|
if (uap->path == NULL)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2012-10-22 17:50:54 +00:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1,
|
2006-10-02 06:56:10 +00:00
|
|
|
UIO_USERSPACE, uap->path, td);
|
2006-02-01 20:01:18 +00:00
|
|
|
flags = AUDIT_OPEN_FLAGS;
|
2007-06-01 14:33:11 +00:00
|
|
|
error = vn_open(&nd, &flags, 0, NULL);
|
2006-06-05 22:36:12 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
2006-02-01 20:01:18 +00:00
|
|
|
vp = nd.ni_vp;
|
2007-04-21 22:08:48 +00:00
|
|
|
#ifdef MAC
|
2007-10-24 19:04:04 +00:00
|
|
|
error = mac_system_check_auditctl(td->td_ucred, vp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2007-04-21 22:08:48 +00:00
|
|
|
if (error) {
|
|
|
|
vn_close(vp, AUDIT_CLOSE_FLAGS, td->td_ucred, td);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
#else
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2007-04-21 22:08:48 +00:00
|
|
|
#endif
|
2006-10-02 06:56:10 +00:00
|
|
|
NDFREE(&nd, NDF_ONLY_PNBUF);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (vp->v_type != VREG) {
|
|
|
|
vn_close(vp, AUDIT_CLOSE_FLAGS, td->td_ucred, td);
|
2006-06-05 22:36:12 +00:00
|
|
|
return (EINVAL);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
cred = td->td_ucred;
|
|
|
|
crhold(cred);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXXAUDIT: Should audit_suspended actually be cleared by
|
|
|
|
* audit_worker?
|
|
|
|
*/
|
|
|
|
audit_suspended = 0;
|
|
|
|
|
|
|
|
audit_rotate_vnode(cred, vp);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* !AUDIT */
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_audit(struct thread *td, struct audit_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_auditon(struct thread *td, struct auditon_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_getauid(struct thread *td, struct getauid_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_setauid(struct thread *td, struct setauid_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_getaudit(struct thread *td, struct getaudit_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_setaudit(struct thread *td, struct setaudit_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_getaudit_addr(struct thread *td, struct getaudit_addr_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_setaudit_addr(struct thread *td, struct setaudit_addr_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-09-16 13:58:51 +00:00
|
|
|
sys_auditctl(struct thread *td, struct auditctl_args *uap)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
return (ENOSYS);
|
|
|
|
}
|
|
|
|
#endif /* AUDIT */
|