freebsd-dev/sys/security/mac_seeotheruids/mac_seeotheruids.c
Robert Watson d8a7b7a3cd Introduce support for Mandatory Access Control and extensible
kernel access control.

Provide implementations of some sample operating system security
policy extensions.  These are not yet hooked up to the build as
other infrastructure is still being committed.  Most of these
work fairly well and are in daily use in our development and (limited)
production environments.  Some are not yet in their final form,
and a number of the labeled policies waste a lot of kernel memory
and will be fixed over the next month or so to be more conservative.
They do give good examples of the flexibility of the MAC framework
for implementing a variety of security policies.

mac_biba:	Implementation of fixed-label Biba integrity policy,
		similar to those found in a number of commercial
		trusted operating systems.  All subjects and objects
		are assigned integrity levels, and information flow
		is controlled based on a read-up, write-down
		policy.  Currently, purely hierarchal.

mac_bsdextended:	Implementation of a "file system firewall",
		which allows the administrator to specify a series
		of rules limiting access by users and groups to
		objects owned by other users and groups.  This
		policy is unlabeled, relying on existing system
		security labeling (file permissions/ownership,
		process credentials).

mac_ifoff:	Secure interface silencing.  Special-purpose module
		to limit inappropriate out-going network traffic
		for silent monitoring scenarios.  Prevents the
		various network stacks from generating any output
		despite an interface being live for reception.

mac_mls:	Implementation of fixed-label Multi-Level Security
		confidentiality policy, similar to those found in
		a number of commercial trusted operating systems.
		All subjects and objects are assigned confidentiality
		levels, and information flow is controlled based on
		a write-up, read-down policy.  Currently, purely
		hiearchal, although non-hierarchal support is in the
		works.

mac_none:	Policy module implementing all MAC policy entry
		points with empty stubs.  A good place to start if
		you want all the prototypes types in for you, and
		don't mind a bit of pruning.  Can be loaded, but
		has no access control impact.  Useful also for
		performance measurements.

mac_seeotheruids:	Policy module implementing a security service
		similar to security.bsd.seeotheruids, only a slightly
		more detailed policy involving exceptions for members
		of specific groups, etc.  This policy is unlabeled,
		relying on existing system security labeling
		(process credentials).

mac_test:	Policy module implementing basic sanity tests for
		label handling.  Attempts to ensure that labels are
		not freed multiple times, etc, etc.

Obtained from:	TrustedBSD Project
Sponsored by:	DARPA, NAI Labs
2002-07-31 18:07:45 +00:00

180 lines
5.5 KiB
C

/*-
* Copyright (c) 1999, 2000, 2001, 2002 Robert N. M. Watson
* Copyright (c) 2001, 2002 Networks Associates Technology, Inc.
* All rights reserved.
*
* This software was developed by Robert Watson for the TrustedBSD Project.
*
* This software was developed for the FreeBSD Project in part by NAI Labs,
* the Security Research Division of Network Associates, Inc. under
* DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA
* CHATS research program.
*
* 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.
* 3. The names of the authors may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* 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.
*
* $FreeBSD$
*/
/*
* Developed by the TrustedBSD Project.
* Prevent processes owned by a particular uid from seeing various transient
* kernel objects associated with other uids.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/mac.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
#include <sys/sysent.h>
#include <sys/vnode.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/sysctl.h>
#include <net/bpfdesc.h>
#include <net/if.h>
#include <net/if_types.h>
#include <net/if_var.h>
#include <vm/vm.h>
#include <sys/mac_policy.h>
SYSCTL_DECL(_security_mac);
SYSCTL_NODE(_security_mac, OID_AUTO, seeotheruids, CTLFLAG_RW, 0,
"TrustedBSD mac_seeotheruids policy controls");
static int mac_seeotheruids_enabled = 0;
SYSCTL_INT(_security_mac_seeotheruids, OID_AUTO, enabled, CTLFLAG_RW,
&mac_seeotheruids_enabled, 0, "Enforce seeotheruids policy");
/*
* Exception: allow credentials to be aware of other credentials with the
* same primary gid.
*/
static int primarygroup_enabled = 0;
SYSCTL_INT(_security_mac_seeotheruids, OID_AUTO, primarygroup_enabled,
CTLFLAG_RW, &primarygroup_enabled, 0, "Make an exception for credentials "
"with the same real primary group id");
/*
* Exception: allow processes with a specific gid to be exempt from the
* policy. One sysctl enables this functionality; the other sets the
* exempt gid.
*/
static int specificgid_enabled = 0;
SYSCTL_INT(_security_mac_seeotheruids, OID_AUTO, specificgid_enabled,
CTLFLAG_RW, &specificgid_enabled, 0, "Make an exception for credentials "
"with a specific gid as their real primary group id or group set");
static gid_t specificgid = 0;
SYSCTL_INT(_security_mac_seeotheruids, OID_AUTO, specificgid, CTLFLAG_RW,
&specificgid, 0, "Specific gid to be exempt from seeotheruids policy");
static int
mac_seeotheruids_check(struct ucred *u1, struct ucred *u2)
{
if (!mac_seeotheruids_enabled)
return (0);
if (primarygroup_enabled) {
if (u1->cr_rgid == u2->cr_rgid)
return (0);
}
if (specificgid_enabled) {
if (u1->cr_rgid == specificgid || groupmember(specificgid, u1))
return (0);
}
if (u1->cr_ruid == u2->cr_ruid)
return (0);
return (ESRCH);
}
static int
mac_seeotheruids_check_cred_visible(struct ucred *u1, struct ucred *u2)
{
return (mac_seeotheruids_check(u1, u2));
}
static int
mac_seeotheruids_check_proc_signal(struct ucred *cred, struct proc *proc,
int signum)
{
return (mac_seeotheruids_check(cred, proc->p_ucred));
}
static int
mac_seeotheruids_check_proc_sched(struct ucred *cred, struct proc *proc)
{
return (mac_seeotheruids_check(cred, proc->p_ucred));
}
static int
mac_seeotheruids_check_proc_debug(struct ucred *cred, struct proc *proc)
{
return (mac_seeotheruids_check(cred, proc->p_ucred));
}
static int
mac_seeotheruids_check_socket_visible(struct ucred *cred, struct socket *socket,
struct label *socketlabel)
{
return (mac_seeotheruids_check(cred, socket->so_cred));
}
static struct mac_policy_op_entry mac_seeotheruids_ops[] =
{
{ MAC_CHECK_CRED_VISIBLE,
(macop_t)mac_seeotheruids_check_cred_visible },
{ MAC_CHECK_PROC_DEBUG,
(macop_t)mac_seeotheruids_check_proc_debug },
{ MAC_CHECK_PROC_SCHED,
(macop_t)mac_seeotheruids_check_proc_sched },
{ MAC_CHECK_PROC_SIGNAL,
(macop_t)mac_seeotheruids_check_proc_signal },
{ MAC_CHECK_SOCKET_VISIBLE,
(macop_t)mac_seeotheruids_check_socket_visible },
{ MAC_OP_LAST, NULL }
};
MAC_POLICY_SET(mac_seeotheruids_ops, trustedbsd_mac_seeotheruids,
"TrustedBSD MAC/seeotheruids", MPC_LOADTIME_FLAG_UNLOADOK, NULL);