2006-02-01 20:01:18 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2005 Wayne J. Salamon
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by Wayne Salamon for the TrustedBSD Project.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND 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 THE AUTHOR OR 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>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/kernel.h>
|
Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.
EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).
As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.
LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).
No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
|
|
|
#include <sys/lock.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <sys/malloc.h>
|
Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.
EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).
As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.
LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).
No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
|
|
|
#include <sys/mutex.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#include <security/audit/audit.h>
|
|
|
|
#include <security/audit/audit_private.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Structures and operations to support the basic character special device
|
2006-12-28 22:18:43 +00:00
|
|
|
* used to communicate with userland. /dev/audit reliably delivers one-byte
|
|
|
|
* messages to a listening application (or discards them if there is no
|
|
|
|
* listening application).
|
|
|
|
*
|
|
|
|
* Currently, select/poll are not supported on the trigger device.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
|
|
|
struct trigger_info {
|
|
|
|
unsigned int trigger;
|
|
|
|
TAILQ_ENTRY(trigger_info) list;
|
|
|
|
};
|
2006-12-28 22:18:43 +00:00
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
static MALLOC_DEFINE(M_AUDITTRIGGER, "audit_trigger", "Audit trigger events");
|
|
|
|
static struct cdev *audit_dev;
|
|
|
|
static int audit_isopen = 0;
|
|
|
|
static TAILQ_HEAD(, trigger_info) trigger_list;
|
|
|
|
static struct mtx audit_trigger_mtx;
|
|
|
|
|
|
|
|
static int
|
|
|
|
audit_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2006-06-08 21:55:39 +00:00
|
|
|
/* Only one process may open the device at a time. */
|
2006-02-01 20:01:18 +00:00
|
|
|
mtx_lock(&audit_trigger_mtx);
|
|
|
|
if (!audit_isopen) {
|
|
|
|
error = 0;
|
|
|
|
audit_isopen = 1;
|
|
|
|
} else
|
|
|
|
error = EBUSY;
|
|
|
|
mtx_unlock(&audit_trigger_mtx);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
audit_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
|
|
|
|
{
|
|
|
|
struct trigger_info *ti;
|
|
|
|
|
|
|
|
/* Flush the queue of pending trigger events. */
|
|
|
|
mtx_lock(&audit_trigger_mtx);
|
|
|
|
audit_isopen = 0;
|
|
|
|
while (!TAILQ_EMPTY(&trigger_list)) {
|
|
|
|
ti = TAILQ_FIRST(&trigger_list);
|
|
|
|
TAILQ_REMOVE(&trigger_list, ti, list);
|
|
|
|
free(ti, M_AUDITTRIGGER);
|
|
|
|
}
|
|
|
|
mtx_unlock(&audit_trigger_mtx);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
audit_read(struct cdev *dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
struct trigger_info *ti = NULL;
|
|
|
|
|
|
|
|
mtx_lock(&audit_trigger_mtx);
|
|
|
|
while (TAILQ_EMPTY(&trigger_list)) {
|
|
|
|
error = msleep(&trigger_list, &audit_trigger_mtx,
|
|
|
|
PSOCK | PCATCH, "auditd", 0);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!error) {
|
|
|
|
ti = TAILQ_FIRST(&trigger_list);
|
|
|
|
TAILQ_REMOVE(&trigger_list, ti, list);
|
|
|
|
}
|
|
|
|
mtx_unlock(&audit_trigger_mtx);
|
|
|
|
if (!error) {
|
2008-03-02 21:34:17 +00:00
|
|
|
error = uiomove(&ti->trigger, sizeof(ti->trigger), uio);
|
2006-02-01 20:01:18 +00:00
|
|
|
free(ti, M_AUDITTRIGGER);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
audit_write(struct cdev *dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Communication is kernel->userspace only. */
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
|
2006-03-18 18:31:24 +00:00
|
|
|
int
|
2008-03-01 11:04:04 +00:00
|
|
|
audit_send_trigger(unsigned int trigger)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct trigger_info *ti;
|
|
|
|
|
|
|
|
ti = malloc(sizeof *ti, M_AUDITTRIGGER, M_WAITOK);
|
|
|
|
mtx_lock(&audit_trigger_mtx);
|
2007-06-13 21:17:23 +00:00
|
|
|
if (!audit_isopen) {
|
|
|
|
/* If nobody's listening, we ain't talking. */
|
|
|
|
mtx_unlock(&audit_trigger_mtx);
|
|
|
|
free(ti, M_AUDITTRIGGER);
|
|
|
|
return (ENODEV);
|
|
|
|
}
|
2006-02-01 20:01:18 +00:00
|
|
|
ti->trigger = trigger;
|
|
|
|
TAILQ_INSERT_TAIL(&trigger_list, ti, list);
|
|
|
|
wakeup(&trigger_list);
|
|
|
|
mtx_unlock(&audit_trigger_mtx);
|
2006-03-18 18:31:24 +00:00
|
|
|
return (0);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct cdevsw audit_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
2008-07-22 16:44:48 +00:00
|
|
|
.d_open = audit_open,
|
|
|
|
.d_close = audit_close,
|
|
|
|
.d_read = audit_read,
|
|
|
|
.d_write = audit_write,
|
|
|
|
.d_name = "audit"
|
2006-02-01 20:01:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_trigger_init(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
TAILQ_INIT(&trigger_list);
|
|
|
|
mtx_init(&audit_trigger_mtx, "audit_trigger_mtx", NULL, MTX_DEF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
audit_trigger_cdev_init(void *unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Create the special device file. */
|
|
|
|
audit_dev = make_dev(&audit_cdevsw, 0, UID_ROOT, GID_KMEM, 0600,
|
|
|
|
AUDITDEV_FILENAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSINIT(audit_trigger_cdev_init, SI_SUB_DRIVERS, SI_ORDER_MIDDLE,
|
|
|
|
audit_trigger_cdev_init, NULL);
|