2008-07-31 09:54:35 +00:00
|
|
|
/*-
|
2008-07-22 15:29:48 +00:00
|
|
|
* Copyright (c) 1999-2005 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>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/domain.h>
|
2006-06-05 16:12:00 +00:00
|
|
|
#include <sys/sbuf.h>
|
2006-02-01 20:01:18 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
|
|
|
|
#include <security/audit/audit.h>
|
|
|
|
#include <security/audit/audit_private.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calls to manipulate elements of the audit record structure from system
|
2007-06-01 21:58:59 +00:00
|
|
|
* call code. Macro wrappers will prevent this functions from being entered
|
|
|
|
* if auditing is disabled, avoiding the function call cost. We check the
|
|
|
|
* thread audit record pointer anyway, as the audit condition could change,
|
|
|
|
* and pre-selection may not have allocated an audit record for this event.
|
2006-02-01 20:01:18 +00:00
|
|
|
*
|
|
|
|
* XXXAUDIT: Should we assert, in each case, that this field of the record
|
|
|
|
* hasn't already been filled in?
|
|
|
|
*/
|
|
|
|
void
|
2007-06-11 22:10:54 +00:00
|
|
|
audit_arg_addr(void *addr)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_addr = addr;
|
|
|
|
ARG_SET_VALID(ar, ARG_ADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_exit(int status, int retval)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_exitstatus = status;
|
|
|
|
ar->k_ar.ar_arg_exitretval = retval;
|
|
|
|
ARG_SET_VALID(ar, ARG_EXIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_len(int len)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_len = len;
|
|
|
|
ARG_SET_VALID(ar, ARG_LEN);
|
|
|
|
}
|
|
|
|
|
2009-07-28 21:39:58 +00:00
|
|
|
void
|
|
|
|
audit_arg_atfd1(int atfd)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_atfd1 = atfd;
|
|
|
|
ARG_SET_VALID(ar, ARG_ATFD1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_atfd2(int atfd)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_atfd2 = atfd;
|
|
|
|
ARG_SET_VALID(ar, ARG_ATFD2);
|
|
|
|
}
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
void
|
|
|
|
audit_arg_fd(int fd)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_fd = fd;
|
|
|
|
ARG_SET_VALID(ar, ARG_FD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_fflags(int fflags)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_fflags = fflags;
|
|
|
|
ARG_SET_VALID(ar, ARG_FFLAGS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_gid(gid_t gid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_gid = gid;
|
|
|
|
ARG_SET_VALID(ar, ARG_GID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_uid(uid_t uid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_uid = uid;
|
|
|
|
ARG_SET_VALID(ar, ARG_UID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_egid(gid_t egid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_egid = egid;
|
|
|
|
ARG_SET_VALID(ar, ARG_EGID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_euid(uid_t euid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_euid = euid;
|
|
|
|
ARG_SET_VALID(ar, ARG_EUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_rgid(gid_t rgid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_rgid = rgid;
|
|
|
|
ARG_SET_VALID(ar, ARG_RGID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_ruid(uid_t ruid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_ruid = ruid;
|
|
|
|
ARG_SET_VALID(ar, ARG_RUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_sgid(gid_t sgid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_sgid = sgid;
|
|
|
|
ARG_SET_VALID(ar, ARG_SGID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_suid(uid_t suid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_suid = suid;
|
|
|
|
ARG_SET_VALID(ar, ARG_SUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_groupset(gid_t *gidset, u_int gidset_size)
|
|
|
|
{
|
2008-07-22 15:17:21 +00:00
|
|
|
u_int i;
|
2006-02-01 20:01:18 +00:00
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
2010-01-12 07:49:34 +00:00
|
|
|
KASSERT(gidset_size <= ngroups_max + 1,
|
|
|
|
("audit_arg_groupset: gidset_size > (kern.ngroups + 1)"));
|
2009-06-29 20:19:19 +00:00
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
2009-06-29 20:19:19 +00:00
|
|
|
if (ar->k_ar.ar_arg_groups.gidset == NULL)
|
|
|
|
ar->k_ar.ar_arg_groups.gidset = malloc(
|
|
|
|
sizeof(gid_t) * gidset_size, M_AUDITGIDSET, M_WAITOK);
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
for (i = 0; i < gidset_size; i++)
|
|
|
|
ar->k_ar.ar_arg_groups.gidset[i] = gidset[i];
|
|
|
|
ar->k_ar.ar_arg_groups.gidset_size = gidset_size;
|
|
|
|
ARG_SET_VALID(ar, ARG_GROUPSET);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_login(char *login)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strlcpy(ar->k_ar.ar_arg_login, login, MAXLOGNAME);
|
|
|
|
ARG_SET_VALID(ar, ARG_LOGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_ctlname(int *name, int namelen)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bcopy(name, &ar->k_ar.ar_arg_ctlname, namelen * sizeof(int));
|
|
|
|
ar->k_ar.ar_arg_len = namelen;
|
|
|
|
ARG_SET_VALID(ar, ARG_CTLNAME | ARG_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_mask(int mask)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_mask = mask;
|
|
|
|
ARG_SET_VALID(ar, ARG_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_mode(mode_t mode)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_mode = mode;
|
|
|
|
ARG_SET_VALID(ar, ARG_MODE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_dev(int dev)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_dev = dev;
|
|
|
|
ARG_SET_VALID(ar, ARG_DEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_value(long value)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_value = value;
|
|
|
|
ARG_SET_VALID(ar, ARG_VALUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_owner(uid_t uid, gid_t gid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_uid = uid;
|
|
|
|
ar->k_ar.ar_arg_gid = gid;
|
|
|
|
ARG_SET_VALID(ar, ARG_UID | ARG_GID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_pid(pid_t pid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_pid = pid;
|
|
|
|
ARG_SET_VALID(ar, ARG_PID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_process(struct proc *p)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
2008-11-14 01:24:52 +00:00
|
|
|
struct ucred *cred;
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2006-07-03 14:55:55 +00:00
|
|
|
KASSERT(p != NULL, ("audit_arg_process: p == NULL"));
|
|
|
|
|
|
|
|
PROC_LOCK_ASSERT(p, MA_OWNED);
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
ar = currecord();
|
2006-07-03 14:55:55 +00:00
|
|
|
if (ar == NULL)
|
2006-02-01 20:01:18 +00:00
|
|
|
return;
|
|
|
|
|
2008-11-14 01:24:52 +00:00
|
|
|
cred = p->p_ucred;
|
|
|
|
ar->k_ar.ar_arg_auid = cred->cr_audit.ai_auid;
|
|
|
|
ar->k_ar.ar_arg_euid = cred->cr_uid;
|
|
|
|
ar->k_ar.ar_arg_egid = cred->cr_groups[0];
|
|
|
|
ar->k_ar.ar_arg_ruid = cred->cr_ruid;
|
|
|
|
ar->k_ar.ar_arg_rgid = cred->cr_rgid;
|
|
|
|
ar->k_ar.ar_arg_asid = cred->cr_audit.ai_asid;
|
|
|
|
ar->k_ar.ar_arg_termid_addr = cred->cr_audit.ai_termid;
|
2006-06-05 16:12:00 +00:00
|
|
|
ar->k_ar.ar_arg_pid = p->p_pid;
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_AUID | ARG_EUID | ARG_EGID | ARG_RUID |
|
2007-04-13 14:55:19 +00:00
|
|
|
ARG_RGID | ARG_ASID | ARG_TERMID_ADDR | ARG_PID | ARG_PROCESS);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_signum(u_int signum)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_signum = signum;
|
|
|
|
ARG_SET_VALID(ar, ARG_SIGNUM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_socket(int sodomain, int sotype, int soprotocol)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
2006-03-19 17:34:00 +00:00
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_sockinfo.so_domain = sodomain;
|
|
|
|
ar->k_ar.ar_arg_sockinfo.so_type = sotype;
|
|
|
|
ar->k_ar.ar_arg_sockinfo.so_protocol = soprotocol;
|
|
|
|
ARG_SET_VALID(ar, ARG_SOCKINFO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-03-02 21:11:30 +00:00
|
|
|
audit_arg_sockaddr(struct thread *td, int dirfd, struct sockaddr *sa)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
2006-07-03 14:55:55 +00:00
|
|
|
KASSERT(td != NULL, ("audit_arg_sockaddr: td == NULL"));
|
|
|
|
KASSERT(sa != NULL, ("audit_arg_sockaddr: sa == NULL"));
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
ar = currecord();
|
2006-07-03 14:55:55 +00:00
|
|
|
if (ar == NULL)
|
2006-02-01 20:01:18 +00:00
|
|
|
return;
|
|
|
|
|
2006-11-06 00:15:44 +00:00
|
|
|
bcopy(sa, &ar->k_ar.ar_arg_sockaddr, sa->sa_len);
|
2006-07-03 14:55:55 +00:00
|
|
|
switch (sa->sa_family) {
|
2006-02-01 20:01:18 +00:00
|
|
|
case AF_INET:
|
|
|
|
ARG_SET_VALID(ar, ARG_SADDRINET);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_INET6:
|
|
|
|
ARG_SET_VALID(ar, ARG_SADDRINET6);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AF_UNIX:
|
2013-03-02 21:11:30 +00:00
|
|
|
if (dirfd != AT_FDCWD)
|
|
|
|
audit_arg_atfd1(dirfd);
|
|
|
|
audit_arg_upath1(td, dirfd,
|
2012-11-30 23:18:49 +00:00
|
|
|
((struct sockaddr_un *)sa)->sun_path);
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_SADDRUNIX);
|
|
|
|
break;
|
|
|
|
/* XXXAUDIT: default:? */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_auid(uid_t auid)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_auid = auid;
|
|
|
|
ARG_SET_VALID(ar, ARG_AUID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_auditinfo(struct auditinfo *au_info)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_auid = au_info->ai_auid;
|
|
|
|
ar->k_ar.ar_arg_asid = au_info->ai_asid;
|
|
|
|
ar->k_ar.ar_arg_amask.am_success = au_info->ai_mask.am_success;
|
|
|
|
ar->k_ar.ar_arg_amask.am_failure = au_info->ai_mask.am_failure;
|
|
|
|
ar->k_ar.ar_arg_termid.port = au_info->ai_termid.port;
|
|
|
|
ar->k_ar.ar_arg_termid.machine = au_info->ai_termid.machine;
|
|
|
|
ARG_SET_VALID(ar, ARG_AUID | ARG_ASID | ARG_AMASK | ARG_TERMID);
|
|
|
|
}
|
|
|
|
|
2007-06-27 17:01:15 +00:00
|
|
|
void
|
|
|
|
audit_arg_auditinfo_addr(struct auditinfo_addr *au_info)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_auid = au_info->ai_auid;
|
|
|
|
ar->k_ar.ar_arg_asid = au_info->ai_asid;
|
|
|
|
ar->k_ar.ar_arg_amask.am_success = au_info->ai_mask.am_success;
|
|
|
|
ar->k_ar.ar_arg_amask.am_failure = au_info->ai_mask.am_failure;
|
|
|
|
ar->k_ar.ar_arg_termid_addr.at_type = au_info->ai_termid.at_type;
|
|
|
|
ar->k_ar.ar_arg_termid_addr.at_port = au_info->ai_termid.at_port;
|
|
|
|
ar->k_ar.ar_arg_termid_addr.at_addr[0] = au_info->ai_termid.at_addr[0];
|
|
|
|
ar->k_ar.ar_arg_termid_addr.at_addr[1] = au_info->ai_termid.at_addr[1];
|
|
|
|
ar->k_ar.ar_arg_termid_addr.at_addr[2] = au_info->ai_termid.at_addr[2];
|
|
|
|
ar->k_ar.ar_arg_termid_addr.at_addr[3] = au_info->ai_termid.at_addr[3];
|
|
|
|
ARG_SET_VALID(ar, ARG_AUID | ARG_ASID | ARG_AMASK | ARG_TERMID_ADDR);
|
|
|
|
}
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
void
|
|
|
|
audit_arg_text(char *text)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
2006-07-03 14:55:55 +00:00
|
|
|
KASSERT(text != NULL, ("audit_arg_text: text == NULL"));
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Invalidate the text string */
|
|
|
|
ar->k_ar.ar_valid_arg &= (ARG_ALL ^ ARG_TEXT);
|
|
|
|
|
|
|
|
if (ar->k_ar.ar_arg_text == NULL)
|
|
|
|
ar->k_ar.ar_arg_text = malloc(MAXPATHLEN, M_AUDITTEXT,
|
|
|
|
M_WAITOK);
|
|
|
|
|
|
|
|
strncpy(ar->k_ar.ar_arg_text, text, MAXPATHLEN);
|
|
|
|
ARG_SET_VALID(ar, ARG_TEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_cmd(int cmd)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_cmd = cmd;
|
|
|
|
ARG_SET_VALID(ar, ARG_CMD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_svipc_cmd(int cmd)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_svipc_cmd = cmd;
|
|
|
|
ARG_SET_VALID(ar, ARG_SVIPC_CMD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_svipc_perm(struct ipc_perm *perm)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
bcopy(perm, &ar->k_ar.ar_arg_svipc_perm,
|
|
|
|
sizeof(ar->k_ar.ar_arg_svipc_perm));
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_SVIPC_PERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_svipc_id(int id)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_svipc_id = id;
|
|
|
|
ARG_SET_VALID(ar, ARG_SVIPC_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_svipc_addr(void * addr)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_svipc_addr = addr;
|
|
|
|
ARG_SET_VALID(ar, ARG_SVIPC_ADDR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_posix_ipc_perm(uid_t uid, gid_t gid, mode_t mode)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_pipc_perm.pipc_uid = uid;
|
|
|
|
ar->k_ar.ar_arg_pipc_perm.pipc_gid = gid;
|
|
|
|
ar->k_ar.ar_arg_pipc_perm.pipc_mode = mode;
|
|
|
|
ARG_SET_VALID(ar, ARG_POSIX_IPC_PERM);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_auditon(union auditon_udata *udata)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
bcopy((void *)udata, &ar->k_ar.ar_arg_auditon,
|
|
|
|
sizeof(ar->k_ar.ar_arg_auditon));
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_AUDITON);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Audit information about a file, either the file's vnode info, or its
|
|
|
|
* socket address info.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
audit_arg_file(struct proc *p, struct file *fp)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
struct socket *so;
|
|
|
|
struct inpcb *pcb;
|
|
|
|
struct vnode *vp;
|
|
|
|
|
2006-07-03 14:55:55 +00:00
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
switch (fp->f_type) {
|
|
|
|
case DTYPE_VNODE:
|
|
|
|
case DTYPE_FIFO:
|
|
|
|
/*
|
|
|
|
* XXXAUDIT: Only possibly to record as first vnode?
|
|
|
|
*/
|
|
|
|
vp = fp->f_vnode;
|
2008-11-04 22:31:04 +00:00
|
|
|
vn_lock(vp, LK_SHARED | LK_RETRY);
|
2009-07-28 21:52:24 +00:00
|
|
|
audit_arg_vnode1(vp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2006-02-01 20:01:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTYPE_SOCKET:
|
|
|
|
so = (struct socket *)fp->f_data;
|
|
|
|
if (INP_CHECK_SOCKAF(so, PF_INET)) {
|
2007-02-20 13:38:11 +00:00
|
|
|
SOCK_LOCK(so);
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_type =
|
2006-03-19 17:34:00 +00:00
|
|
|
so->so_type;
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_domain =
|
2006-03-19 17:34:00 +00:00
|
|
|
INP_SOCKAF(so);
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_protocol =
|
2006-03-19 17:34:00 +00:00
|
|
|
so->so_proto->pr_protocol;
|
2007-02-20 13:38:11 +00:00
|
|
|
SOCK_UNLOCK(so);
|
2006-02-01 20:01:18 +00:00
|
|
|
pcb = (struct inpcb *)so->so_pcb;
|
2008-04-19 18:37:08 +00:00
|
|
|
INP_RLOCK(pcb);
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_raddr =
|
2006-03-19 17:34:00 +00:00
|
|
|
pcb->inp_faddr.s_addr;
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_laddr =
|
2006-03-19 17:34:00 +00:00
|
|
|
pcb->inp_laddr.s_addr;
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_rport =
|
2006-03-19 17:34:00 +00:00
|
|
|
pcb->inp_fport;
|
2006-02-01 20:01:18 +00:00
|
|
|
ar->k_ar.ar_arg_sockinfo.so_lport =
|
2006-03-19 17:34:00 +00:00
|
|
|
pcb->inp_lport;
|
2008-04-19 18:37:08 +00:00
|
|
|
INP_RUNLOCK(pcb);
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_SOCKINFO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* XXXAUDIT: else? */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-19 17:34:00 +00:00
|
|
|
/*
|
|
|
|
* Store a path as given by the user process for auditing into the audit
|
2008-07-22 15:49:19 +00:00
|
|
|
* record stored on the user thread. This function will allocate the memory
|
|
|
|
* to store the path info if not already available. This memory will be
|
|
|
|
* freed when the audit record is freed.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
2009-07-29 07:44:43 +00:00
|
|
|
static void
|
2012-11-30 23:18:49 +00:00
|
|
|
audit_arg_upath(struct thread *td, int dirfd, char *upath, char **pathp)
|
2009-07-29 07:44:43 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (*pathp == NULL)
|
|
|
|
*pathp = malloc(MAXPATHLEN, M_AUDITPATH, M_WAITOK);
|
2012-11-30 23:18:49 +00:00
|
|
|
audit_canon_path(td, dirfd, upath, *pathp);
|
2009-07-29 07:44:43 +00:00
|
|
|
}
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
void
|
2012-11-30 23:18:49 +00:00
|
|
|
audit_arg_upath1(struct thread *td, int dirfd, char *upath)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
2006-07-03 14:55:55 +00:00
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2012-11-30 23:18:49 +00:00
|
|
|
audit_arg_upath(td, dirfd, upath, &ar->k_ar.ar_arg_upath1);
|
2009-07-29 07:44:43 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_UPATH1);
|
|
|
|
}
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2009-07-29 07:44:43 +00:00
|
|
|
void
|
2012-11-30 23:18:49 +00:00
|
|
|
audit_arg_upath2(struct thread *td, int dirfd, char *upath)
|
2009-07-29 07:44:43 +00:00
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2009-07-29 07:44:43 +00:00
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
2006-02-01 20:01:18 +00:00
|
|
|
|
2012-11-30 23:18:49 +00:00
|
|
|
audit_arg_upath(td, dirfd, upath, &ar->k_ar.ar_arg_upath2);
|
2009-07-29 07:44:43 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_UPATH2);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-03-19 17:34:00 +00:00
|
|
|
* Function to save the path and vnode attr information into the audit
|
|
|
|
* record.
|
2006-02-01 20:01:18 +00:00
|
|
|
*
|
|
|
|
* It is assumed that the caller will hold any vnode locks necessary to
|
|
|
|
* perform a VOP_GETATTR() on the passed vnode.
|
|
|
|
*
|
2007-06-01 21:58:59 +00:00
|
|
|
* XXX: The attr code is very similar to vfs_vnops.c:vn_stat(), but always
|
|
|
|
* provides access to the generation number as we need that to construct the
|
|
|
|
* BSM file ID.
|
|
|
|
*
|
|
|
|
* XXX: We should accept the process argument from the caller, since it's
|
|
|
|
* very likely they already have a reference.
|
|
|
|
*
|
2006-02-01 20:01:18 +00:00
|
|
|
* XXX: Error handling in this function is poor.
|
|
|
|
*
|
|
|
|
* XXXAUDIT: Possibly KASSERT the path pointer is NULL?
|
|
|
|
*/
|
2009-07-28 21:52:24 +00:00
|
|
|
static int
|
|
|
|
audit_arg_vnode(struct vnode *vp, struct vnode_au_info *vnp)
|
2006-02-01 20:01:18 +00:00
|
|
|
{
|
|
|
|
struct vattr vattr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ASSERT_VOP_LOCKED(vp, "audit_arg_vnode");
|
|
|
|
|
2008-08-28 15:23:18 +00:00
|
|
|
error = VOP_GETATTR(vp, &vattr, curthread->td_ucred);
|
2006-02-01 20:01:18 +00:00
|
|
|
if (error) {
|
|
|
|
/* XXX: How to handle this case? */
|
2009-07-28 21:52:24 +00:00
|
|
|
return (error);
|
2006-02-01 20:01:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vnp->vn_mode = vattr.va_mode;
|
|
|
|
vnp->vn_uid = vattr.va_uid;
|
|
|
|
vnp->vn_gid = vattr.va_gid;
|
|
|
|
vnp->vn_dev = vattr.va_rdev;
|
|
|
|
vnp->vn_fsid = vattr.va_fsid;
|
|
|
|
vnp->vn_fileid = vattr.va_fileid;
|
|
|
|
vnp->vn_gen = vattr.va_gen;
|
2009-07-28 21:52:24 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_vnode1(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ARG_CLEAR_VALID(ar, ARG_VNODE1);
|
|
|
|
error = audit_arg_vnode(vp, &ar->k_ar.ar_arg_vnode1);
|
|
|
|
if (error == 0)
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_VNODE1);
|
2009-07-28 21:52:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
audit_arg_vnode2(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ARG_CLEAR_VALID(ar, ARG_VNODE2);
|
|
|
|
error = audit_arg_vnode(vp, &ar->k_ar.ar_arg_vnode2);
|
|
|
|
if (error == 0)
|
2006-02-01 20:01:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_VNODE2);
|
|
|
|
}
|
|
|
|
|
2006-09-01 11:45:40 +00:00
|
|
|
/*
|
|
|
|
* Audit the argument strings passed to exec.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
audit_arg_argv(char *argv, int argc, int length)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
if (audit_argv == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_argv = malloc(length, M_AUDITTEXT, M_WAITOK);
|
|
|
|
bcopy(argv, ar->k_ar.ar_arg_argv, length);
|
|
|
|
ar->k_ar.ar_arg_argc = argc;
|
|
|
|
ARG_SET_VALID(ar, ARG_ARGV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Audit the environment strings passed to exec.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
audit_arg_envv(char *envv, int envc, int length)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
if (audit_arge == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_envv = malloc(length, M_AUDITTEXT, M_WAITOK);
|
|
|
|
bcopy(envv, ar->k_ar.ar_arg_envv, length);
|
|
|
|
ar->k_ar.ar_arg_envc = envc;
|
|
|
|
ARG_SET_VALID(ar, ARG_ENVV);
|
|
|
|
}
|
|
|
|
|
2011-07-18 12:58:18 +00:00
|
|
|
void
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
audit_arg_rights(cap_rights_t *rightsp)
|
2011-07-18 12:58:18 +00:00
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.
The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.
The structure definition looks like this:
struct cap_rights {
uint64_t cr_rights[CAP_RIGHTS_VERSION + 2];
};
The initial CAP_RIGHTS_VERSION is 0.
The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.
The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.
To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.
#define CAP_PDKILL CAPRIGHT(1, 0x0000000000000800ULL)
We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:
#define CAP_LOOKUP CAPRIGHT(0, 0x0000000000000400ULL)
#define CAP_FCHMOD CAPRIGHT(0, 0x0000000000002000ULL)
#define CAP_FCHMODAT (CAP_FCHMOD | CAP_LOOKUP)
There is new API to manage the new cap_rights_t structure:
cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
void cap_rights_set(cap_rights_t *rights, ...);
void cap_rights_clear(cap_rights_t *rights, ...);
bool cap_rights_is_set(const cap_rights_t *rights, ...);
bool cap_rights_is_valid(const cap_rights_t *rights);
void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);
Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:
cap_rights_t rights;
cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);
There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:
#define cap_rights_set(rights, ...) \
__cap_rights_set((rights), __VA_ARGS__, 0ULL)
void __cap_rights_set(cap_rights_t *rights, ...);
Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:
cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);
Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.
This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.
Sponsored by: The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
|
|
|
ar->k_ar.ar_arg_rights = *rightsp;
|
2011-07-18 12:58:18 +00:00
|
|
|
ARG_SET_VALID(ar, ARG_RIGHTS);
|
|
|
|
}
|
|
|
|
|
Merge Capsicum overhaul:
- Capability is no longer separate descriptor type. Now every descriptor
has set of its own capability rights.
- The cap_new(2) system call is left, but it is no longer documented and
should not be used in new code.
- The new syscall cap_rights_limit(2) should be used instead of
cap_new(2), which limits capability rights of the given descriptor
without creating a new one.
- The cap_getrights(2) syscall is renamed to cap_rights_get(2).
- If CAP_IOCTL capability right is present we can further reduce allowed
ioctls list with the new cap_ioctls_limit(2) syscall. List of allowed
ioctls can be retrived with cap_ioctls_get(2) syscall.
- If CAP_FCNTL capability right is present we can further reduce fcntls
that can be used with the new cap_fcntls_limit(2) syscall and retrive
them with cap_fcntls_get(2).
- To support ioctl and fcntl white-listing the filedesc structure was
heavly modified.
- The audit subsystem, kdump and procstat tools were updated to
recognize new syscalls.
- Capability rights were revised and eventhough I tried hard to provide
backward API and ABI compatibility there are some incompatible changes
that are described in detail below:
CAP_CREATE old behaviour:
- Allow for openat(2)+O_CREAT.
- Allow for linkat(2).
- Allow for symlinkat(2).
CAP_CREATE new behaviour:
- Allow for openat(2)+O_CREAT.
Added CAP_LINKAT:
- Allow for linkat(2). ABI: Reuses CAP_RMDIR bit.
- Allow to be target for renameat(2).
Added CAP_SYMLINKAT:
- Allow for symlinkat(2).
Removed CAP_DELETE. Old behaviour:
- Allow for unlinkat(2) when removing non-directory object.
- Allow to be source for renameat(2).
Removed CAP_RMDIR. Old behaviour:
- Allow for unlinkat(2) when removing directory.
Added CAP_RENAMEAT:
- Required for source directory for the renameat(2) syscall.
Added CAP_UNLINKAT (effectively it replaces CAP_DELETE and CAP_RMDIR):
- Allow for unlinkat(2) on any object.
- Required if target of renameat(2) exists and will be removed by this
call.
Removed CAP_MAPEXEC.
CAP_MMAP old behaviour:
- Allow for mmap(2) with any combination of PROT_NONE, PROT_READ and
PROT_WRITE.
CAP_MMAP new behaviour:
- Allow for mmap(2)+PROT_NONE.
Added CAP_MMAP_R:
- Allow for mmap(PROT_READ).
Added CAP_MMAP_W:
- Allow for mmap(PROT_WRITE).
Added CAP_MMAP_X:
- Allow for mmap(PROT_EXEC).
Added CAP_MMAP_RW:
- Allow for mmap(PROT_READ | PROT_WRITE).
Added CAP_MMAP_RX:
- Allow for mmap(PROT_READ | PROT_EXEC).
Added CAP_MMAP_WX:
- Allow for mmap(PROT_WRITE | PROT_EXEC).
Added CAP_MMAP_RWX:
- Allow for mmap(PROT_READ | PROT_WRITE | PROT_EXEC).
Renamed CAP_MKDIR to CAP_MKDIRAT.
Renamed CAP_MKFIFO to CAP_MKFIFOAT.
Renamed CAP_MKNODE to CAP_MKNODEAT.
CAP_READ old behaviour:
- Allow pread(2).
- Disallow read(2), readv(2) (if there is no CAP_SEEK).
CAP_READ new behaviour:
- Allow read(2), readv(2).
- Disallow pread(2) (CAP_SEEK was also required).
CAP_WRITE old behaviour:
- Allow pwrite(2).
- Disallow write(2), writev(2) (if there is no CAP_SEEK).
CAP_WRITE new behaviour:
- Allow write(2), writev(2).
- Disallow pwrite(2) (CAP_SEEK was also required).
Added convinient defines:
#define CAP_PREAD (CAP_SEEK | CAP_READ)
#define CAP_PWRITE (CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_R (CAP_MMAP | CAP_SEEK | CAP_READ)
#define CAP_MMAP_W (CAP_MMAP | CAP_SEEK | CAP_WRITE)
#define CAP_MMAP_X (CAP_MMAP | CAP_SEEK | 0x0000000000000008ULL)
#define CAP_MMAP_RW (CAP_MMAP_R | CAP_MMAP_W)
#define CAP_MMAP_RX (CAP_MMAP_R | CAP_MMAP_X)
#define CAP_MMAP_WX (CAP_MMAP_W | CAP_MMAP_X)
#define CAP_MMAP_RWX (CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X)
#define CAP_RECV CAP_READ
#define CAP_SEND CAP_WRITE
#define CAP_SOCK_CLIENT \
(CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \
CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN)
#define CAP_SOCK_SERVER \
(CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \
CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \
CAP_SETSOCKOPT | CAP_SHUTDOWN)
Added defines for backward API compatibility:
#define CAP_MAPEXEC CAP_MMAP_X
#define CAP_DELETE CAP_UNLINKAT
#define CAP_MKDIR CAP_MKDIRAT
#define CAP_RMDIR CAP_UNLINKAT
#define CAP_MKFIFO CAP_MKFIFOAT
#define CAP_MKNOD CAP_MKNODAT
#define CAP_SOCK_ALL (CAP_SOCK_CLIENT | CAP_SOCK_SERVER)
Sponsored by: The FreeBSD Foundation
Reviewed by: Christoph Mallon <christoph.mallon@gmx.de>
Many aspects discussed with: rwatson, benl, jonathan
ABI compatibility discussed with: kib
2013-03-02 00:53:12 +00:00
|
|
|
void
|
|
|
|
audit_arg_fcntl_rights(uint32_t fcntlrights)
|
|
|
|
{
|
|
|
|
struct kaudit_record *ar;
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ar->k_ar.ar_arg_fcntl_rights = fcntlrights;
|
|
|
|
ARG_SET_VALID(ar, ARG_FCNTL_RIGHTS);
|
|
|
|
}
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
/*
|
2006-03-19 17:34:00 +00:00
|
|
|
* The close() system call uses it's own audit call to capture the path/vnode
|
|
|
|
* information because those pieces are not easily obtained within the system
|
|
|
|
* call itself.
|
2006-02-01 20:01:18 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
audit_sysclose(struct thread *td, int fd)
|
|
|
|
{
|
2006-07-03 14:55:55 +00:00
|
|
|
struct kaudit_record *ar;
|
2006-02-01 20:01:18 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
struct file *fp;
|
|
|
|
|
2006-07-03 14:55:55 +00:00
|
|
|
KASSERT(td != NULL, ("audit_sysclose: td == NULL"));
|
|
|
|
|
|
|
|
ar = currecord();
|
|
|
|
if (ar == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-02-01 20:01:18 +00:00
|
|
|
audit_arg_fd(fd);
|
|
|
|
|
2011-08-11 12:30:23 +00:00
|
|
|
if (getvnode(td->td_proc->p_fd, fd, 0, &fp) != 0)
|
2006-02-01 20:01:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
vp = fp->f_vnode;
|
2008-11-04 22:31:04 +00:00
|
|
|
vn_lock(vp, LK_SHARED | LK_RETRY);
|
2009-07-28 21:52:24 +00:00
|
|
|
audit_arg_vnode1(vp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(vp, 0);
|
2006-02-01 20:01:18 +00:00
|
|
|
fdrop(fp, td);
|
2006-03-19 17:34:00 +00:00
|
|
|
}
|