diff options
author | rwatson <rwatson@FreeBSD.org> | 2002-07-31 18:07:45 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2002-07-31 18:07:45 +0000 |
commit | 5529143578c655713fa2c3f6d900785571f22d95 (patch) | |
tree | 3737655ddb3f1f181d91eabcd4d14e4b87b0432d /sys | |
parent | 7ecedd74b3734a1bf7f80b376842fb65cfcf2242 (diff) | |
download | FreeBSD-src-5529143578c655713fa2c3f6d900785571f22d95.zip FreeBSD-src-5529143578c655713fa2c3f6d900785571f22d95.tar.gz |
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
Diffstat (limited to 'sys')
-rw-r--r-- | sys/security/mac_biba/mac_biba.c | 2226 | ||||
-rw-r--r-- | sys/security/mac_biba/mac_biba.h | 61 | ||||
-rw-r--r-- | sys/security/mac_bsdextended/mac_bsdextended.c | 749 | ||||
-rw-r--r-- | sys/security/mac_bsdextended/mac_bsdextended.h | 60 | ||||
-rw-r--r-- | sys/security/mac_ifoff/mac_ifoff.c | 173 | ||||
-rw-r--r-- | sys/security/mac_mls/mac_mls.c | 2177 | ||||
-rw-r--r-- | sys/security/mac_mls/mac_mls.h | 61 | ||||
-rw-r--r-- | sys/security/mac_none/mac_none.c | 1105 | ||||
-rw-r--r-- | sys/security/mac_seeotheruids/mac_seeotheruids.c | 179 | ||||
-rw-r--r-- | sys/security/mac_stub/mac_stub.c | 1105 | ||||
-rw-r--r-- | sys/security/mac_test/mac_test.c | 1311 |
11 files changed, 9207 insertions, 0 deletions
diff --git a/sys/security/mac_biba/mac_biba.c b/sys/security/mac_biba/mac_biba.c new file mode 100644 index 0000000..a7620b3 --- /dev/null +++ b/sys/security/mac_biba/mac_biba.c @@ -0,0 +1,2226 @@ +/*- + * 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. + * Biba fixed label mandatory integrity policy. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/acl.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/pipe.h> +#include <sys/sysctl.h> + +#include <fs/devfs/devfs.h> + +#include <net/bpfdesc.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/if_var.h> + +#include <netinet/in.h> +#include <netinet/ip_var.h> + +#include <vm/vm.h> + +#include <sys/mac_policy.h> + +#include <security/mac_biba/mac_biba.h> + +SYSCTL_DECL(_security_mac); + +SYSCTL_NODE(_security_mac, OID_AUTO, biba, CTLFLAG_RW, 0, + "TrustedBSD mac_biba policy controls"); + +static int mac_biba_enabled = 0; +SYSCTL_INT(_security_mac_biba, OID_AUTO, enabled, CTLFLAG_RW, + &mac_biba_enabled, 0, "Enforce MAC/Biba policy"); + +static int destroyed_not_inited; +SYSCTL_INT(_security_mac_biba, OID_AUTO, destroyed_not_inited, CTLFLAG_RD, + &destroyed_not_inited, 0, "Count of labels destroyed but not inited"); + +static int trust_all_interfaces = 0; +SYSCTL_INT(_security_mac_biba, OID_AUTO, trust_all_interfaces, CTLFLAG_RD, + &trust_all_interfaces, 0, "Consider all interfaces 'trusted' by MAC/Biba"); +TUNABLE_INT("security.mac.biba.trust_all_interfaces", &trust_all_interfaces); + +static char trusted_interfaces[128]; +SYSCTL_STRING(_security_mac_biba, OID_AUTO, trusted_interfaces, CTLFLAG_RD, + trusted_interfaces, 0, "Interfaces considered 'trusted' by MAC/Biba"); +TUNABLE_STR("security.mac.biba.trusted_interfaces", trusted_interfaces, + sizeof(trusted_interfaces)); + +static int mac_biba_revocation_enabled = 0; +SYSCTL_INT(_security_mac_biba, OID_AUTO, revocation_enabled, CTLFLAG_RW, + &mac_biba_revocation_enabled, 0, "Revoke access to objects on relabel"); +TUNABLE_INT("security.mac.biba.revocation_enabled", + &mac_biba_revocation_enabled); + +static int mac_biba_slot; +#define SLOT(l) ((struct mac_biba *)LABEL_TO_SLOT((l), mac_biba_slot).l_ptr) + +MALLOC_DEFINE(M_MACBIBA, "biba label", "MAC/Biba labels"); + +static int mac_biba_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, mode_t acc_mode); + +static struct mac_biba * +biba_alloc(int how) +{ + struct mac_biba *mac_biba; + + mac_biba = malloc(sizeof(struct mac_biba), M_MACBIBA, M_ZERO | how); + + return (mac_biba); +} + +static void +biba_free(struct mac_biba *mac_biba) +{ + + if (mac_biba != NULL) + free(mac_biba, M_MACBIBA); + else + atomic_add_int(&destroyed_not_inited, 1); +} + +static int +mac_biba_dominate_element(struct mac_biba_element *a, + struct mac_biba_element *b) +{ + + switch(a->mbe_type) { + case MAC_BIBA_TYPE_EQUAL: + case MAC_BIBA_TYPE_HIGH: + return (1); + + case MAC_BIBA_TYPE_LOW: + switch (b->mbe_type) { + case MAC_BIBA_TYPE_GRADE: + case MAC_BIBA_TYPE_HIGH: + return (0); + + case MAC_BIBA_TYPE_EQUAL: + case MAC_BIBA_TYPE_LOW: + return (1); + + default: + panic("mac_biba_dominate_element: b->mbe_type invalid"); + } + + case MAC_BIBA_TYPE_GRADE: + switch (b->mbe_type) { + case MAC_BIBA_TYPE_EQUAL: + case MAC_BIBA_TYPE_LOW: + return (1); + + case MAC_BIBA_TYPE_HIGH: + return (0); + + case MAC_BIBA_TYPE_GRADE: + return (a->mbe_grade >= b->mbe_grade); + + default: + panic("mac_biba_dominate_element: b->mbe_type invalid"); + } + + default: + panic("mac_biba_dominate_element: a->mbe_type invalid"); + } + + return (0); +} + +static int +mac_biba_range_in_range(struct mac_biba *rangea, struct mac_biba *rangeb) +{ + + return (mac_biba_dominate_element(&rangeb->mb_rangehigh, + &rangea->mb_rangehigh) && + mac_biba_dominate_element(&rangea->mb_rangelow, + &rangeb->mb_rangelow)); +} + +static int +mac_biba_single_in_range(struct mac_biba *single, struct mac_biba *range) +{ + + KASSERT((single->mb_flag & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_single_in_range: a not single")); + KASSERT((range->mb_flag & MAC_BIBA_FLAG_RANGE) != 0, + ("mac_biba_single_in_range: b not range")); + + return (mac_biba_dominate_element(&range->mb_rangehigh, + &single->mb_single) && + mac_biba_dominate_element(&single->mb_single, + &range->mb_rangelow)); + + return (1); +} + +static int +mac_biba_dominate_single(struct mac_biba *a, struct mac_biba *b) +{ + KASSERT((a->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_dominate_single: a not single")); + KASSERT((b->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_dominate_single: b not single")); + + return (mac_biba_dominate_element(&a->mb_single, &b->mb_single)); +} + +static int +mac_biba_equal_element(struct mac_biba_element *a, struct mac_biba_element *b) +{ + + if (a->mbe_type == MAC_BIBA_TYPE_EQUAL || + b->mbe_type == MAC_BIBA_TYPE_EQUAL) + return (1); + + return (a->mbe_type == b->mbe_type && a->mbe_grade == b->mbe_grade); +} + +static int +mac_biba_equal_range(struct mac_biba *a, struct mac_biba *b) +{ + + KASSERT((a->mb_flags & MAC_BIBA_FLAG_RANGE) != 0, + ("mac_biba_equal_range: a not range")); + KASSERT((b->mb_flags & MAC_BIBA_FLAG_RANGE) != 0, + ("mac_biba_equal_range: b not range")); + + return (mac_biba_equal_element(&a->mb_rangelow, &b->mb_rangelow) && + mac_biba_equal_element(&a->mb_rangehigh, &b->mb_rangehigh)); +} + +static int +mac_biba_equal_single(struct mac_biba *a, struct mac_biba *b) +{ + + KASSERT((a->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_equal_single: a not single")); + KASSERT((b->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_equal_single: b not single")); + + return (mac_biba_equal_element(&a->mb_single, &b->mb_single)); +} + +static int +mac_biba_high_single(struct mac_biba *mac_biba) +{ + + return (mac_biba->mb_single.mbe_type == MAC_BIBA_TYPE_HIGH); +} + +static int +mac_biba_valid(struct mac_biba *mac_biba) +{ + + if (mac_biba->mb_flags & MAC_BIBA_FLAG_SINGLE) { + switch (mac_biba->mb_single.mbe_type) { + case MAC_BIBA_TYPE_GRADE: + break; + + case MAC_BIBA_TYPE_EQUAL: + case MAC_BIBA_TYPE_HIGH: + case MAC_BIBA_TYPE_LOW: + if (mac_biba->mb_single.mbe_grade != 0) + return (EINVAL); + break; + + default: + return (EINVAL); + } + } else { + if (mac_biba->mb_single.mbe_type != MAC_BIBA_TYPE_UNDEF) + return (EINVAL); + } + + if (mac_biba->mb_flags & MAC_BIBA_FLAG_RANGE) { + switch (mac_biba->mb_rangelow.mbe_type) { + case MAC_BIBA_TYPE_GRADE: + break; + + case MAC_BIBA_TYPE_EQUAL: + case MAC_BIBA_TYPE_HIGH: + case MAC_BIBA_TYPE_LOW: + if (mac_biba->mb_rangelow.mbe_grade != 0) + return (EINVAL); + break; + + default: + return (EINVAL); + } + + switch (mac_biba->mb_rangehigh.mbe_type) { + case MAC_BIBA_TYPE_GRADE: + break; + + case MAC_BIBA_TYPE_EQUAL: + case MAC_BIBA_TYPE_HIGH: + case MAC_BIBA_TYPE_LOW: + if (mac_biba->mb_rangehigh.mbe_grade != 0) + return (EINVAL); + break; + + default: + return (EINVAL); + } + if (!mac_biba_dominate_element(&mac_biba->mb_rangehigh, + &mac_biba->mb_rangelow)) + return (EINVAL); + } else { + if (mac_biba->mb_rangelow.mbe_type != MAC_BIBA_TYPE_UNDEF || + mac_biba->mb_rangehigh.mbe_type != MAC_BIBA_TYPE_UNDEF) + return (EINVAL); + } + + return (0); +} + +static void +mac_biba_set_range(struct mac_biba *mac_biba, u_short typelow, + u_short gradelow, u_short typehigh, u_short gradehigh) +{ + + mac_biba->mb_rangelow.mbe_type = typelow; + mac_biba->mb_rangelow.mbe_grade = gradelow; + mac_biba->mb_rangehigh.mbe_type = typehigh; + mac_biba->mb_rangehigh.mbe_grade = gradehigh; + mac_biba->mb_flags |= MAC_BIBA_FLAG_RANGE; +} + +static void +mac_biba_set_single(struct mac_biba *mac_biba, u_short type, u_short grade) +{ + + mac_biba->mb_single.mbe_type = type; + mac_biba->mb_single.mbe_grade = grade; + mac_biba->mb_flags |= MAC_BIBA_FLAG_SINGLE; +} + +static void +mac_biba_copy_range(struct mac_biba *labelfrom, struct mac_biba *labelto) +{ + KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_RANGE) != 0, + ("mac_biba_copy_range: labelfrom not range")); + + labelto->mb_rangelow = labelfrom->mb_rangelow; + labelto->mb_rangehigh = labelfrom->mb_rangehigh; + labelto->mb_flags |= MAC_BIBA_FLAG_RANGE; +} + +static void +mac_biba_copy_single(struct mac_biba *labelfrom, struct mac_biba *labelto) +{ + + KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_copy_single: labelfrom not single")); + + labelto->mb_single = labelfrom->mb_single; + labelto->mb_flags |= MAC_BIBA_FLAG_SINGLE; +} + +static void +mac_biba_copy_single_to_range(struct mac_biba *labelfrom, + struct mac_biba *labelto) +{ + + KASSERT((labelfrom->mb_flags & MAC_BIBA_FLAG_SINGLE) != 0, + ("mac_biba_copy_single_to_range: labelfrom not single")); + + labelto->mb_rangelow = labelfrom->mb_single; + labelto->mb_rangehigh = labelfrom->mb_single; + labelto->mb_flags |= MAC_BIBA_FLAG_RANGE; +} + +/* + * Policy module operations. + */ +static void +mac_biba_destroy(struct mac_policy_conf *conf) +{ + +} + +static void +mac_biba_init(struct mac_policy_conf *conf) +{ + +} + +/* + * Label operations. + */ +static void +mac_biba_init_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_cred(struct ucred *ucred, struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_ifnet(struct ifnet *ifnet, struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_ipq(struct ipq *ipq, struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static int +mac_biba_init_mbuf(struct mbuf *mbuf, int how, struct label *label) +{ + + SLOT(label) = biba_alloc(how); + if (SLOT(label) == NULL) + return (ENOMEM); + + return (0); +} + +static void +mac_biba_init_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + + SLOT(mntlabel) = biba_alloc(M_WAITOK); + SLOT(fslabel) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + + SLOT(label) = biba_alloc(M_WAITOK); + SLOT(peerlabel) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_pipe(struct pipe *pipe, struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_temp(struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_init_vnode(struct vnode *vp, struct label *label) +{ + + SLOT(label) = biba_alloc(M_WAITOK); +} + +static void +mac_biba_destroy_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_cred(struct ucred *ucred, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_ifnet(struct ifnet *ifnet, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_ipq(struct ipq *ipq, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_mbuf(struct mbuf *mbuf, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + + biba_free(SLOT(mntlabel)); + SLOT(mntlabel) = NULL; + biba_free(SLOT(fslabel)); + SLOT(fslabel) = NULL; +} + +static void +mac_biba_destroy_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; + biba_free(SLOT(peerlabel)); + SLOT(peerlabel) = NULL; +} + +static void +mac_biba_destroy_pipe(struct pipe *pipe, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_temp(struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_biba_destroy_vnode(struct vnode *vp, struct label *label) +{ + + biba_free(SLOT(label)); + SLOT(label) = NULL; +} + +static int +mac_biba_externalize(struct label *label, struct mac *extmac) +{ + struct mac_biba *mac_biba; + + mac_biba = SLOT(label); + + if (mac_biba == NULL) { + printf("mac_biba_externalize: NULL pointer\n"); + return (0); + } + + extmac->m_biba = *mac_biba; + + return (0); +} + +static int +mac_biba_internalize(struct label *label, struct mac *extmac) +{ + struct mac_biba *mac_biba; + int error; + + mac_biba = SLOT(label); + + error = mac_biba_valid(mac_biba); + if (error) + return (error); + + *mac_biba = extmac->m_biba; + + return (0); +} + +/* + * Labeling event operations: file system objects, and things that look + * a lot like file system objects. + */ +static void +mac_biba_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent, + struct label *label) +{ + struct mac_biba *mac_biba; + int biba_type; + + mac_biba = SLOT(label); + if (strcmp(dev->si_name, "null") == 0 || + strcmp(dev->si_name, "zero") == 0 || + strcmp(dev->si_name, "random") == 0 || + strncmp(dev->si_name, "fd/", strlen("fd/")) == 0) + biba_type = MAC_BIBA_TYPE_EQUAL; + else + biba_type = MAC_BIBA_TYPE_HIGH; + mac_biba_set_single(mac_biba, biba_type, 0); +} + +static void +mac_biba_create_devfs_directory(char *dirname, int dirnamelen, + struct devfs_dirent *devfs_dirent, struct label *label) +{ + struct mac_biba *mac_biba; + + mac_biba = SLOT(label); + mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0); +} + +static void +mac_biba_create_devfs_vnode(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(direntlabel); + dest = SLOT(vnodelabel); + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_vnode(struct ucred *cred, struct vnode *parent, + struct label *parentlabel, struct vnode *child, struct label *childlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(childlabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(mntlabel); + mac_biba_copy_single(source, dest); + dest = SLOT(fslabel); + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_root_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + struct mac_biba *mac_biba; + + /* Always mount root as high integrity. */ + mac_biba = SLOT(fslabel); + mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0); + mac_biba = SLOT(mntlabel); + mac_biba_set_single(mac_biba, MAC_BIBA_TYPE_HIGH, 0); +} + +static void +mac_biba_relabel_vnode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *label) +{ + struct mac_biba *source, *dest; + + source = SLOT(label); + dest = SLOT(vnodelabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_update_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(vnodelabel); + dest = SLOT(direntlabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_update_procfsvnode(struct vnode *vp, struct label *vnodelabel, + struct ucred *cred) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(vnodelabel); + + /* + * Only copy the single, not the range, since vnodes only have + * a single. + */ + mac_biba_copy_single(source, dest); +} + +static int +mac_biba_update_vnode_from_externalized(struct vnode *vp, + struct label *vnodelabel, struct mac *extmac) +{ + struct mac_biba *source, *dest; + int error; + + source = &extmac->m_biba; + dest = SLOT(vnodelabel); + + error = mac_biba_valid(source); + if (error) + return (error); + + if ((source->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE) + return (EINVAL); + + mac_biba_copy_single(source, dest); + + return (0); +} + +static void +mac_biba_update_vnode_from_mount(struct vnode *vp, struct label *vnodelabel, + struct mount *mp, struct label *fslabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(fslabel); + dest = SLOT(vnodelabel); + + mac_biba_copy_single(source, dest); +} + +/* + * Labeling event operations: IPC object. + */ +static void +mac_biba_create_mbuf_from_socket(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(socketlabel); + dest = SLOT(mbuflabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(socketlabel); + + mac_biba_copy_single(source, dest); + mac_biba_copy_single_to_range(source, dest); +} + +static void +mac_biba_create_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(pipelabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_socket_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(oldsocketlabel); + dest = SLOT(newsocketlabel); + + mac_biba_copy_single(source, dest); + mac_biba_copy_range(source, dest); +} + +static void +mac_biba_relabel_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(socketlabel); + + mac_biba_copy_single(source, dest); + mac_biba_copy_range(source, dest); +} + +static void +mac_biba_relabel_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(pipelabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, + struct socket *socket, struct label *socketpeerlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(mbuflabel); + dest = SLOT(socketpeerlabel); + + mac_biba_copy_single(source, dest); +} + +/* + * Labeling event operations: network objects. + */ +static void +mac_biba_set_socket_peer_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketpeerlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(oldsocketlabel); + dest = SLOT(newsocketpeerlabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d, + struct label *bpflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(bpflabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel) +{ + char tifname[IFNAMSIZ], ifname[IFNAMSIZ], *p, *q; + char tiflist[sizeof(trusted_interfaces)]; + struct mac_biba *dest; + int len, grade; + + dest = SLOT(ifnetlabel); + + if (ifnet->if_type == IFT_LOOP) { + grade = MAC_BIBA_TYPE_EQUAL; + goto set; + } + + if (trust_all_interfaces) { + grade = MAC_BIBA_TYPE_HIGH; + goto set; + } + + grade = MAC_BIBA_TYPE_LOW; + + if (trusted_interfaces[0] == '\0' || + !strvalid(trusted_interfaces, sizeof(trusted_interfaces))) + goto set; + + for (p = trusted_interfaces, q = tiflist; *p != '\0'; p++, q++) + if(*p != ' ' && *p != '\t') + *q = *p; + + snprintf(ifname, IFNAMSIZ, "%s%d", ifnet->if_name, ifnet->if_unit); + + for (p = q = tiflist;; p++) { + if (*p == ',' || *p == '\0') { + len = p - q; + if (len < IFNAMSIZ) { + bzero(tifname, sizeof(tifname)); + bcopy(q, tifname, len); + if (strcmp(tifname, ifname) == 0) { + grade = MAC_BIBA_TYPE_HIGH; + break; + } + } + if (*p == '\0') + break; + q = p + 1; + } + } +set: + mac_biba_set_single(dest, grade, 0); + mac_biba_set_range(dest, grade, 0, grade, 0); +} + +static void +mac_biba_create_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(fragmentlabel); + dest = SLOT(ipqlabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel, + struct mbuf *datagram, struct label *datagramlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(ipqlabel); + dest = SLOT(datagramlabel); + + /* Just use the head, since we require them all to match. */ + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_fragment(struct mbuf *datagram, struct label *datagramlabel, + struct mbuf *fragment, struct label *fragmentlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(datagramlabel); + dest = SLOT(fragmentlabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_mbuf_from_mbuf(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(oldmbuflabel); + dest = SLOT(newmbuflabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + struct mac_biba *dest; + + dest = SLOT(mbuflabel); + + mac_biba_set_single(dest, MAC_BIBA_TYPE_EQUAL, 0); +} + +static void +mac_biba_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(bpflabel); + dest = SLOT(mbuflabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(ifnetlabel); + dest = SLOT(mbuflabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_mbuf_multicast_encap(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(oldmbuflabel); + dest = SLOT(newmbuflabel); + + mac_biba_copy_single(source, dest); +} + +static void +mac_biba_create_mbuf_netlayer(struct mbuf *oldmbuf, struct label *oldmbuflabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(oldmbuflabel); + dest = SLOT(newmbuflabel); + + mac_biba_copy_single(source, dest); +} + +static int +mac_biba_fragment_match(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + struct mac_biba *a, *b; + + a = SLOT(ipqlabel); + b = SLOT(fragmentlabel); + + return (mac_biba_equal_single(a, b)); +} + +static void +mac_biba_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(ifnetlabel); + + mac_biba_copy_single(source, dest); + mac_biba_copy_range(source, dest); +} + +static void +mac_biba_update_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + + /* NOOP: we only accept matching labels, so no need to update */ +} + +/* + * Labeling event operations: processes. + */ +static void +mac_biba_create_cred(struct ucred *cred_parent, struct ucred *cred_child) +{ + struct mac_biba *source, *dest; + + source = SLOT(&cred_parent->cr_label); + dest = SLOT(&cred_child->cr_label); + + mac_biba_copy_single(source, dest); + mac_biba_copy_range(source, dest); +} + +static void +mac_biba_execve_transition(struct ucred *old, struct ucred *new, + struct vnode *vp, struct mac *vnodelabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(&old->cr_label); + dest = SLOT(&new->cr_label); + + mac_biba_copy_single(source, dest); + mac_biba_copy_range(source, dest); +} + +static int +mac_biba_execve_will_transition(struct ucred *old, struct vnode *vp, + struct mac *vnodelabel) +{ + + return (0); +} + +static void +mac_biba_create_proc0(struct ucred *cred) +{ + struct mac_biba *dest; + + dest = SLOT(&cred->cr_label); + + mac_biba_set_single(dest, MAC_BIBA_TYPE_EQUAL, 0); + mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, MAC_BIBA_TYPE_HIGH, 0); +} + +static void +mac_biba_create_proc1(struct ucred *cred) +{ + struct mac_biba *dest; + + dest = SLOT(&cred->cr_label); + + mac_biba_set_single(dest, MAC_BIBA_TYPE_HIGH, 0); + mac_biba_set_range(dest, MAC_BIBA_TYPE_LOW, 0, MAC_BIBA_TYPE_HIGH, 0); +} + +static void +mac_biba_relabel_cred(struct ucred *cred, struct label *newlabel) +{ + struct mac_biba *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(&cred->cr_label); + + mac_biba_copy_single(source, dest); + mac_biba_copy_range(source, dest); +} + +/* + * Access control checks. + */ +static int +mac_biba_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, + struct ifnet *ifnet, struct label *ifnetlabel) +{ + struct mac_biba *a, *b; + + if (!mac_biba_enabled) + return (0); + + a = SLOT(bpflabel); + b = SLOT(ifnetlabel); + + if (mac_biba_equal_single(a, b)) + return (0); + return (EACCES); +} + +static int +mac_biba_check_cred_relabel(struct ucred *cred, struct label *newlabel) +{ + struct mac_biba *subj, *new; + + subj = SLOT(&cred->cr_label); + new = SLOT(newlabel); + + if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAGS_BOTH) + return (EINVAL); + + /* + * XXX: Allow processes with root privilege to set labels outside + * their range, so suid things like "su" work. This WILL go away + * when we figure out the 'correct' solution... + */ + if (!suser_cred(cred, 0)) + return (0); + + /* + * The new single must be in the old range. + */ + if (!mac_biba_single_in_range(new, subj)) + return (EPERM); + + /* + * The new range must be in the old range. + */ + if (!mac_biba_range_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (0); +} + +static int +mac_biba_check_cred_visible(struct ucred *u1, struct ucred *u2) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&u1->cr_label); + obj = SLOT(&u2->cr_label); + + /* XXX: range */ + if (!mac_biba_dominate_single(obj, subj)) + return (ESRCH); + + return (0); +} + +static int +mac_biba_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + struct mac_biba *subj, *new; + + subj = SLOT(&cred->cr_label); + new = SLOT(newlabel); + + if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAGS_BOTH) + return (EINVAL); + + /* + * XXX: Only Biba HIGH subjects may relabel interfaces. */ + if (!mac_biba_high_single(subj)) + return (EPERM); + + return (suser_cred(cred, 0)); +} + +static int +mac_biba_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_biba *p, *i; + + if (!mac_biba_enabled) + return (0); + + p = SLOT(mbuflabel); + i = SLOT(ifnetlabel); + + return (mac_biba_single_in_range(p, i) ? 0 : EACCES); +} + +static int +mac_biba_check_mount_stat(struct ucred *cred, struct mount *mp, + struct label *mntlabel) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(mntlabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) +{ + + if(!mac_biba_enabled) + return (0); + + /* XXX: This will be implemented soon... */ + + return (0); +} + +static int +mac_biba_check_pipe_op(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, int op) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT((pipelabel)); + + switch(op) { + case MAC_OP_PIPE_READ: + case MAC_OP_PIPE_STAT: + case MAC_OP_PIPE_POLL: + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + break; + case MAC_OP_PIPE_WRITE: + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + break; + default: + panic("mac_biba_check_pipe_op: invalid pipe operation"); + } + + return (0); +} + +static int +mac_biba_check_pipe_relabel(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + struct mac_biba *subj, *obj, *new; + + new = SLOT(newlabel); + subj = SLOT(&cred->cr_label); + obj = SLOT(pipelabel); + + if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE) + return (EINVAL); + + /* + * To relabel a pipe, the old pipe label must be in the subject + * range. + */ + if (!mac_biba_single_in_range(obj, subj)) + return (EPERM); + + /* + * To relabel a pipe, the new pipe label must be in the subject + * range. + */ + if (!mac_biba_single_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (0); +} + +static int +mac_biba_check_proc_debug(struct ucred *cred, struct proc *proc) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(&proc->p_ucred->cr_label); + + /* XXX: range checks */ + if (!mac_biba_dominate_single(obj, subj)) + return (ESRCH); + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_proc_sched(struct ucred *cred, struct proc *proc) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(&proc->p_ucred->cr_label); + + /* XXX: range checks */ + if (!mac_biba_dominate_single(obj, subj)) + return (ESRCH); + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_proc_signal(struct ucred *cred, struct proc *proc, int signum) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(&proc->p_ucred->cr_label); + + /* XXX: range checks */ + if (!mac_biba_dominate_single(obj, subj)) + return (ESRCH); + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_socket_receive(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_biba *p, *s; + + if (!mac_biba_enabled) + return (0); + + p = SLOT(mbuflabel); + s = SLOT(socketlabel); + + return (mac_biba_equal_single(p, s) ? 0 : EACCES); +} + +static int +mac_biba_check_socket_relabel(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + struct mac_biba *subj, *obj, *new; + + new = SLOT(newlabel); + subj = SLOT(&cred->cr_label); + obj = SLOT(socketlabel); + + if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE) + return (EINVAL); + + /* + * To relabel a socket, the old socket label must be in the subject + * range. + */ + if (!mac_biba_single_in_range(obj, subj)) + return (EPERM); + + /* + * To relabel a socket, the new socket label must be in the subject + * range. + */ + if (!mac_biba_single_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (0); +} + +static int +mac_biba_check_socket_visible(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + struct mac_biba *subj, *obj; + + subj = SLOT(&cred->cr_label); + obj = SLOT(socketlabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (ENOENT); + + return (0); +} + +static int +mac_biba_check_vnode_access(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t flags) +{ + + return (mac_biba_check_vnode_open(cred, vp, label, flags)); +} + +static int +mac_biba_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_create(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp, struct vattr *vap) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + obj = SLOT(label); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, mode_t acc_mode) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + /* XXX privilege override for admin? */ + if (acc_mode & (VREAD | VEXEC | VSTAT)) { + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + } + if (acc_mode & (VWRITE | VAPPEND | VADMIN)) { + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + } + + return (0); +} + +static int +mac_biba_check_vnode_readdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_readlink(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_relabel(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *newlabel) +{ + struct mac_biba *old, *new, *subj; + + old = SLOT(vnodelabel); + new = SLOT(newlabel); + subj = SLOT(&cred->cr_label); + + if ((new->mb_flags & MAC_BIBA_FLAGS_BOTH) != MAC_BIBA_FLAG_SINGLE) + return (EINVAL); + + /* + * To relabel a vnode, the old vnode label must be in the subject + * range. + */ + if (!mac_biba_single_in_range(old, subj)) + return (EPERM); + + /* + * To relabel a vnode, the new vnode label must be in the subject + * range. + */ + if (!mac_biba_single_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (suser_cred(cred, 0)); +} + +static int +mac_biba_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + obj = SLOT(label); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, int samedir, + struct componentname *cnp) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + if (vp != NULL) { + obj = SLOT(label); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + } + + return (0); +} + +static int +mac_biba_check_vnode_revoke(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_setacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type, struct acl *acl) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, int attrnamespace, const char *name, + struct uio *uio) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + /* XXX: protect the MAC EA in a special way? */ + + return (0); +} + +static int +mac_biba_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, u_long flags) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, mode_t mode) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, uid_t uid, gid_t gid) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct timespec atime, struct timespec mtime) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_biba_check_vnode_stat(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static vm_prot_t +mac_biba_check_vnode_mmap_perms(struct ucred *cred, struct vnode *vp, + struct label *label, int newmapping) +{ + struct mac_biba *subj, *obj; + vm_prot_t prot = 0; + + if (!mac_biba_enabled || (!mac_biba_revocation_enabled && !newmapping)) + return (VM_PROT_ALL); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (mac_biba_dominate_single(obj, subj)) + prot |= VM_PROT_READ | VM_PROT_EXECUTE; + if (mac_biba_dominate_single(subj, obj)) + prot |= VM_PROT_WRITE; + return (prot); +} + +static int +mac_biba_check_vnode_op(struct ucred *cred, struct vnode *vp, + struct label *label, int op) +{ + struct mac_biba *subj, *obj; + + if (!mac_biba_enabled || !mac_biba_revocation_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + switch (op) { + case MAC_OP_VNODE_POLL: + case MAC_OP_VNODE_READ: + if (!mac_biba_dominate_single(obj, subj)) + return (EACCES); + return (0); + + case MAC_OP_VNODE_WRITE: + if (!mac_biba_dominate_single(subj, obj)) + return (EACCES); + return (0); + + default: + printf("mac_biba_check_vnode_op: unknown operation %d\n", op); + return (EINVAL); + } +} + +static struct mac_policy_op_entry mac_biba_ops[] = +{ + { MAC_DESTROY, + (macop_t)mac_biba_destroy }, + { MAC_INIT, + (macop_t)mac_biba_init }, + { MAC_INIT_BPFDESC, + (macop_t)mac_biba_init_bpfdesc }, + { MAC_INIT_CRED, + (macop_t)mac_biba_init_cred }, + { MAC_INIT_DEVFSDIRENT, + (macop_t)mac_biba_init_devfsdirent }, + { MAC_INIT_IFNET, + (macop_t)mac_biba_init_ifnet }, + { MAC_INIT_IPQ, + (macop_t)mac_biba_init_ipq }, + { MAC_INIT_MBUF, + (macop_t)mac_biba_init_mbuf }, + { MAC_INIT_MOUNT, + (macop_t)mac_biba_init_mount }, + { MAC_INIT_PIPE, + (macop_t)mac_biba_init_pipe }, + { MAC_INIT_SOCKET, + (macop_t)mac_biba_init_socket }, + { MAC_INIT_TEMP, + (macop_t)mac_biba_init_temp }, + { MAC_INIT_VNODE, + (macop_t)mac_biba_init_vnode }, + { MAC_DESTROY_BPFDESC, + (macop_t)mac_biba_destroy_bpfdesc }, + { MAC_DESTROY_CRED, + (macop_t)mac_biba_destroy_cred }, + { MAC_DESTROY_DEVFSDIRENT, + (macop_t)mac_biba_destroy_devfsdirent }, + { MAC_DESTROY_IFNET, + (macop_t)mac_biba_destroy_ifnet }, + { MAC_DESTROY_IPQ, + (macop_t)mac_biba_destroy_ipq }, + { MAC_DESTROY_MBUF, + (macop_t)mac_biba_destroy_mbuf }, + { MAC_DESTROY_MOUNT, + (macop_t)mac_biba_destroy_mount }, + { MAC_DESTROY_PIPE, + (macop_t)mac_biba_destroy_pipe }, + { MAC_DESTROY_SOCKET, + (macop_t)mac_biba_destroy_socket }, + { MAC_DESTROY_TEMP, + (macop_t)mac_biba_destroy_temp }, + { MAC_DESTROY_VNODE, + (macop_t)mac_biba_destroy_vnode }, + { MAC_EXTERNALIZE, + (macop_t)mac_biba_externalize }, + { MAC_INTERNALIZE, + (macop_t)mac_biba_internalize }, + { MAC_CREATE_DEVFS_DEVICE, + (macop_t)mac_biba_create_devfs_device }, + { MAC_CREATE_DEVFS_DIRECTORY, + (macop_t)mac_biba_create_devfs_directory }, + { MAC_CREATE_DEVFS_VNODE, + (macop_t)mac_biba_create_devfs_vnode }, + { MAC_CREATE_VNODE, + (macop_t)mac_biba_create_vnode }, + { MAC_CREATE_MOUNT, + (macop_t)mac_biba_create_mount }, + { MAC_CREATE_ROOT_MOUNT, + (macop_t)mac_biba_create_root_mount }, + { MAC_RELABEL_VNODE, + (macop_t)mac_biba_relabel_vnode }, + { MAC_UPDATE_DEVFSDIRENT, + (macop_t)mac_biba_update_devfsdirent }, + { MAC_UPDATE_PROCFSVNODE, + (macop_t)mac_biba_update_procfsvnode }, + { MAC_UPDATE_VNODE_FROM_EXTERNALIZED, + (macop_t)mac_biba_update_vnode_from_externalized }, + { MAC_UPDATE_VNODE_FROM_MOUNT, + (macop_t)mac_biba_update_vnode_from_mount }, + { MAC_CREATE_MBUF_FROM_SOCKET, + (macop_t)mac_biba_create_mbuf_from_socket }, + { MAC_CREATE_PIPE, + (macop_t)mac_biba_create_pipe }, + { MAC_CREATE_SOCKET, + (macop_t)mac_biba_create_socket }, + { MAC_CREATE_SOCKET_FROM_SOCKET, + (macop_t)mac_biba_create_socket_from_socket }, + { MAC_RELABEL_PIPE, + (macop_t)mac_biba_relabel_pipe }, + { MAC_RELABEL_SOCKET, + (macop_t)mac_biba_relabel_socket }, + { MAC_SET_SOCKET_PEER_FROM_MBUF, + (macop_t)mac_biba_set_socket_peer_from_mbuf }, + { MAC_SET_SOCKET_PEER_FROM_SOCKET, + (macop_t)mac_biba_set_socket_peer_from_socket }, + { MAC_CREATE_BPFDESC, + (macop_t)mac_biba_create_bpfdesc }, + { MAC_CREATE_DATAGRAM_FROM_IPQ, + (macop_t)mac_biba_create_datagram_from_ipq }, + { MAC_CREATE_FRAGMENT, + (macop_t)mac_biba_create_fragment }, + { MAC_CREATE_IFNET, + (macop_t)mac_biba_create_ifnet }, + { MAC_CREATE_IPQ, + (macop_t)mac_biba_create_ipq }, + { MAC_CREATE_MBUF_FROM_MBUF, + (macop_t)mac_biba_create_mbuf_from_mbuf }, + { MAC_CREATE_MBUF_LINKLAYER, + (macop_t)mac_biba_create_mbuf_linklayer }, + { MAC_CREATE_MBUF_FROM_BPFDESC, + (macop_t)mac_biba_create_mbuf_from_bpfdesc }, + { MAC_CREATE_MBUF_FROM_IFNET, + (macop_t)mac_biba_create_mbuf_from_ifnet }, + { MAC_CREATE_MBUF_MULTICAST_ENCAP, + (macop_t)mac_biba_create_mbuf_multicast_encap }, + { MAC_CREATE_MBUF_NETLAYER, + (macop_t)mac_biba_create_mbuf_netlayer }, + { MAC_FRAGMENT_MATCH, + (macop_t)mac_biba_fragment_match }, + { MAC_RELABEL_IFNET, + (macop_t)mac_biba_relabel_ifnet }, + { MAC_UPDATE_IPQ, + (macop_t)mac_biba_update_ipq }, + { MAC_CREATE_CRED, + (macop_t)mac_biba_create_cred }, + { MAC_EXECVE_TRANSITION, + (macop_t)mac_biba_execve_transition }, + { MAC_EXECVE_WILL_TRANSITION, + (macop_t)mac_biba_execve_will_transition }, + { MAC_CREATE_PROC0, + (macop_t)mac_biba_create_proc0 }, + { MAC_CREATE_PROC1, + (macop_t)mac_biba_create_proc1 }, + { MAC_RELABEL_CRED, + (macop_t)mac_biba_relabel_cred }, + { MAC_CHECK_BPFDESC_RECEIVE, + (macop_t)mac_biba_check_bpfdesc_receive }, + { MAC_CHECK_CRED_RELABEL, + (macop_t)mac_biba_check_cred_relabel }, + { MAC_CHECK_CRED_VISIBLE, + (macop_t)mac_biba_check_cred_visible }, + { MAC_CHECK_IFNET_RELABEL, + (macop_t)mac_biba_check_ifnet_relabel }, + { MAC_CHECK_IFNET_TRANSMIT, + (macop_t)mac_biba_check_ifnet_transmit }, + { MAC_CHECK_MOUNT_STAT, + (macop_t)mac_biba_check_mount_stat }, + { MAC_CHECK_PIPE_IOCTL, + (macop_t)mac_biba_check_pipe_ioctl }, + { MAC_CHECK_PIPE_OP, + (macop_t)mac_biba_check_pipe_op }, + { MAC_CHECK_PIPE_RELABEL, + (macop_t)mac_biba_check_pipe_relabel }, + { MAC_CHECK_PROC_DEBUG, + (macop_t)mac_biba_check_proc_debug }, + { MAC_CHECK_PROC_SCHED, + (macop_t)mac_biba_check_proc_sched }, + { MAC_CHECK_PROC_SIGNAL, + (macop_t)mac_biba_check_proc_signal }, + { MAC_CHECK_SOCKET_RECEIVE, + (macop_t)mac_biba_check_socket_receive }, + { MAC_CHECK_SOCKET_RELABEL, + (macop_t)mac_biba_check_socket_relabel }, + { MAC_CHECK_SOCKET_VISIBLE, + (macop_t)mac_biba_check_socket_visible }, + { MAC_CHECK_VNODE_ACCESS, + (macop_t)mac_biba_check_vnode_access }, + { MAC_CHECK_VNODE_CHDIR, + (macop_t)mac_biba_check_vnode_chdir }, + { MAC_CHECK_VNODE_CHROOT, + (macop_t)mac_biba_check_vnode_chroot }, + { MAC_CHECK_VNODE_CREATE, + (macop_t)mac_biba_check_vnode_create }, + { MAC_CHECK_VNODE_DELETE, + (macop_t)mac_biba_check_vnode_delete }, + { MAC_CHECK_VNODE_DELETEACL, + (macop_t)mac_biba_check_vnode_deleteacl }, + { MAC_CHECK_VNODE_EXEC, + (macop_t)mac_biba_check_vnode_exec }, + { MAC_CHECK_VNODE_GETACL, + (macop_t)mac_biba_check_vnode_getacl }, + { MAC_CHECK_VNODE_GETEXTATTR, + (macop_t)mac_biba_check_vnode_getextattr }, + { MAC_CHECK_VNODE_LOOKUP, + (macop_t)mac_biba_check_vnode_lookup }, + { MAC_CHECK_VNODE_OPEN, + (macop_t)mac_biba_check_vnode_open }, + { MAC_CHECK_VNODE_READDIR, + (macop_t)mac_biba_check_vnode_readdir }, + { MAC_CHECK_VNODE_READLINK, + (macop_t)mac_biba_check_vnode_readlink }, + { MAC_CHECK_VNODE_RELABEL, + (macop_t)mac_biba_check_vnode_relabel }, + { MAC_CHECK_VNODE_RENAME_FROM, + (macop_t)mac_biba_check_vnode_rename_from }, + { MAC_CHECK_VNODE_RENAME_TO, + (macop_t)mac_biba_check_vnode_rename_to }, + { MAC_CHECK_VNODE_REVOKE, + (macop_t)mac_biba_check_vnode_revoke }, + { MAC_CHECK_VNODE_SETACL, + (macop_t)mac_biba_check_vnode_setacl }, + { MAC_CHECK_VNODE_SETEXTATTR, + (macop_t)mac_biba_check_vnode_setextattr }, + { MAC_CHECK_VNODE_SETFLAGS, + (macop_t)mac_biba_check_vnode_setflags }, + { MAC_CHECK_VNODE_SETMODE, + (macop_t)mac_biba_check_vnode_setmode }, + { MAC_CHECK_VNODE_SETOWNER, + (macop_t)mac_biba_check_vnode_setowner }, + { MAC_CHECK_VNODE_SETUTIMES, + (macop_t)mac_biba_check_vnode_setutimes }, + { MAC_CHECK_VNODE_STAT, + (macop_t)mac_biba_check_vnode_stat }, + { MAC_CHECK_VNODE_MMAP_PERMS, + (macop_t)mac_biba_check_vnode_mmap_perms }, + { MAC_CHECK_VNODE_OP, + (macop_t)mac_biba_check_vnode_op }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_biba_ops, trustedbsd_mac_biba, "TrustedBSD MAC/Biba", + MPC_LOADTIME_FLAG_NOTLATE, &mac_biba_slot); diff --git a/sys/security/mac_biba/mac_biba.h b/sys/security/mac_biba/mac_biba.h new file mode 100644 index 0000000..aa42344 --- /dev/null +++ b/sys/security/mac_biba/mac_biba.h @@ -0,0 +1,61 @@ +/*- + * 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$ + */ +/* + * Definitions for the TrustedBSD Biba integrity policy module. + */ +#ifndef _SYS_SECURITY_MAC_BIBA_H +#define _SYS_SECURITY_MAC_BIBA_H + +#define MAC_BIBA_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define MAC_BIBA_EXTATTR_NAME "mac_biba" + +#define MAC_BIBA_FLAG_SINGLE 0x00000001 /* mb_single initialized */ +#define MAC_BIBA_FLAG_RANGE 0x00000002 /* mb_range* initialized */ +#define MAC_BIBA_FLAGS_BOTH (MAC_BIBA_FLAG_SINGLE | MAC_BIBA_FLAG_RANGE) + +#define MAC_BIBA_TYPE_UNDEF 0 /* Undefined */ +#define MAC_BIBA_TYPE_GRADE 1 /* Hierarchal grade with mb_grade. */ +#define MAC_BIBA_TYPE_LOW 2 /* Dominated by any + * MAC_BIBA_TYPE_LABEL. */ +#define MAC_BIBA_TYPE_HIGH 3 /* Dominates any + * MAC_BIBA_TYPE_LABEL. */ +#define MAC_BIBA_TYPE_EQUAL 4 /* Equivilent to any + * MAC_BIBA_TYPE_LABEL. */ + +#endif /* !_SYS_SECURITY_MAC_BIBA_H */ diff --git a/sys/security/mac_bsdextended/mac_bsdextended.c b/sys/security/mac_bsdextended/mac_bsdextended.c new file mode 100644 index 0000000..f0f6cee --- /dev/null +++ b/sys/security/mac_bsdextended/mac_bsdextended.c @@ -0,0 +1,749 @@ +/*- + * 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. + * "BSD Extended" MAC policy, allowing the administrator to impose + * mandatory rules regarding users and some system objects. + * + * XXX: Much locking support required here. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/acl.h> +#include <sys/conf.h> +#include <sys/kernel.h> +#include <sys/mac.h> +#include <sys/malloc.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> + +#include <security/mac_bsdextended/mac_bsdextended.h> + +SYSCTL_DECL(_security_mac); + +SYSCTL_NODE(_security_mac, OID_AUTO, bsdextended, CTLFLAG_RW, 0, + "TrustedBSD extended BSD MAC policy controls"); + +static int mac_bsdextended_enabled = 1; +SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, enabled, CTLFLAG_RW, + &mac_bsdextended_enabled, 0, "Enforce extended BSD policy"); +TUNABLE_INT("security.mac.bsdextended.enabled", &mac_bsdextended_enabled); + +MALLOC_DEFINE(M_MACBSDEXTENDED, "mac_bsdextended", "BSD Extended MAC rule"); + +#define MAC_BSDEXTENDED_MAXRULES 250 +static struct mac_bsdextended_rule *rules[MAC_BSDEXTENDED_MAXRULES]; +static int rule_count = 0; +static int rule_slots = 0; + +SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_count, CTLFLAG_RD, + &rule_count, 0, "Number of defined rules\n"); +SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, rule_slots, CTLFLAG_RD, + &rule_slots, 0, "Number of used rule slots\n"); + +static int mac_bsdextended_debugging; +SYSCTL_INT(_security_mac_bsdextended, OID_AUTO, debugging, CTLFLAG_RW, + &mac_bsdextended_debugging, 0, "Enable debugging on failure"); + +static int +mac_bsdextended_rule_valid(struct mac_bsdextended_rule *rule) +{ + + if ((rule->mbr_subject.mbi_flags | MBI_BITS) != MBI_BITS) + return (EINVAL); + + if ((rule->mbr_object.mbi_flags | MBI_BITS) != MBI_BITS) + return (EINVAL); + + if ((rule->mbr_mode | VALLPERM) != VALLPERM) + return (EINVAL); + + return (0); +} + +static int +sysctl_rule(SYSCTL_HANDLER_ARGS) +{ + struct mac_bsdextended_rule temprule, *ruleptr; + u_int namelen; + int error, index, *name; + + name = (int *)arg1; + namelen = arg2; + + /* printf("bsdextended sysctl handler (namelen %d)\n", namelen); */ + + if (namelen != 1) + return (EINVAL); + + index = name[0]; + if (index < 0 || index > rule_slots + 1) + return (ENOENT); + if (rule_slots >= MAC_BSDEXTENDED_MAXRULES) + return (ENOENT); + + if (req->oldptr) { + if (rules[index] == NULL) + return (ENOENT); + + error = SYSCTL_OUT(req, rules[index], sizeof(*rules[index])); + if (error) + return (error); + } + + if (req->newptr) { + if (req->newlen == 0) { + /* printf("deletion\n"); */ + ruleptr = rules[index]; + if (ruleptr == NULL) + return (ENOENT); + rule_count--; + rules[index] = NULL; + FREE(ruleptr, M_MACBSDEXTENDED); + return(0); + } + error = SYSCTL_IN(req, &temprule, sizeof(temprule)); + if (error) + return (error); + + error = mac_bsdextended_rule_valid(&temprule); + if (error) + return (error); + + if (rules[index] == NULL) { + /* printf("addition\n"); */ + MALLOC(ruleptr, struct mac_bsdextended_rule *, + sizeof(*ruleptr), M_MACBSDEXTENDED, M_WAITOK | + M_ZERO); + *ruleptr = temprule; + rules[index] = ruleptr; + if (index+1 > rule_slots) + rule_slots = index+1; + rule_count++; + } else { + /* printf("replacement\n"); */ + *rules[index] = temprule; + } + } + + return (0); +} + +SYSCTL_NODE(_security_mac_bsdextended, OID_AUTO, rules, + CTLFLAG_RW, sysctl_rule, "BSD extended MAC rules"); + +static void +mac_bsdextended_init(struct mac_policy_conf *mpc) +{ + + /* Initialize ruleset lock. */ + /* Register dynamic sysctl's for rules. */ +} + +static void +mac_bsdextended_destroy(struct mac_policy_conf *mpc) +{ + + /* Tear down sysctls. */ + /* Destroy ruleset lock. */ +} + +static int +mac_bsdextended_rulecheck(struct mac_bsdextended_rule *rule, + struct ucred *cred, uid_t object_uid, gid_t object_gid, mode_t acc_mode) +{ + int match; + + /* + * Is there a subject match? + */ + if (rule->mbr_subject.mbi_flags & MBI_UID_DEFINED) { + match = (rule->mbr_subject.mbi_uid == cred->cr_uid || + rule->mbr_subject.mbi_uid == cred->cr_ruid || + rule->mbr_subject.mbi_uid == cred->cr_svuid); + + if (rule->mbr_subject.mbi_flags & MBI_NEGATED) + match = !match; + + if (!match) + return (0); + } + + if (rule->mbr_subject.mbi_flags & MBI_GID_DEFINED) { + match = (groupmember(rule->mbr_subject.mbi_gid, cred) || + rule->mbr_subject.mbi_gid == cred->cr_rgid || + rule->mbr_subject.mbi_gid == cred->cr_svgid); + + if (rule->mbr_subject.mbi_flags & MBI_NEGATED) + match = !match; + + if (!match) + return (0); + } + + /* + * Is there an object match? + */ + if (rule->mbr_object.mbi_flags & MBI_UID_DEFINED) { + match = (rule->mbr_object.mbi_uid == object_uid); + + if (rule->mbr_object.mbi_flags & MBI_NEGATED) + match = !match; + + if (!match) + return (0); + } + + if (rule->mbr_object.mbi_flags & MBI_GID_DEFINED) { + match = (rule->mbr_object.mbi_gid == object_gid); + + if (rule->mbr_object.mbi_flags & MBI_NEGATED) + match = !match; + + if (!match) + return (0); + } + + /* + * Is the access permitted? + */ + if ((rule->mbr_mode & acc_mode) != acc_mode) { + if (mac_bsdextended_debugging) + printf("mac_bsdextended: %d:%d request %d on %d:%d" + " fails\n", cred->cr_ruid, cred->cr_rgid, + acc_mode, object_uid, object_gid); + return (EACCES); + } + + return (0); +} + +static int +mac_bsdextended_check(struct ucred *cred, uid_t object_uid, gid_t object_gid, + mode_t acc_mode) +{ + int error, i; + + for (i = 0; i < rule_slots; i++) { + if (rules[i] == NULL) + continue; + + error = mac_bsdextended_rulecheck(rules[i], cred, object_uid, + object_gid, acc_mode); + if (error) + return (error); + } + + return (0); +} + +static int +mac_bsdextended_check_vnode_access(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t flags) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, flags)); +} + +static int +mac_bsdextended_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VEXEC)); +} + +static int +mac_bsdextended_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VEXEC)); +} + +static int +mac_bsdextended_check_create_vnode(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp, struct vattr *vap) +{ + struct vattr dvap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &dvap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, dvap.va_uid, dvap.va_gid, VWRITE)); +} + +static int +mac_bsdextended_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + error = mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VWRITE); + if (error) + return (error); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VWRITE)); +} + +static int +mac_bsdextended_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, + VREAD|VEXEC)); +} + +static int +mac_bsdextended_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VSTAT)); +} + +static int +mac_bsdextended_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VREAD)); +} + +static int +mac_bsdextended_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VEXEC)); +} + +static int +mac_bsdextended_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *filelabel, mode_t acc_mode) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, acc_mode)); +} + +static int +mac_bsdextended_check_vnode_readdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VREAD)); +} + +static int +mac_bsdextended_check_vnode_readdlink(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VREAD)); +} + +static int +mac_bsdextended_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + error = mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VWRITE); + if (error) + return (error); + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + error = mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VWRITE); + + return (error); +} + +static int +mac_bsdextended_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, int samedir, + struct componentname *cnp) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(dvp, &vap, cred, curthread); + if (error) + return (error); + error = mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VWRITE); + if (error) + return (error); + + if (vp != NULL) { + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + error = mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, + VWRITE); + } + + return (error); +} + +static int +mac_bsdextended_check_vnode_revoke(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_setacl_vnode(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type, struct acl *acl) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VWRITE)); +} + +static int +mac_bsdextended_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + struct label *label, u_long flags) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t mode) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + struct label *label, uid_t uid, gid_t gid) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct label *label, struct timespec atime, struct timespec utime) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VADMIN)); +} + +static int +mac_bsdextended_check_vnode_stat(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct vattr vap; + int error; + + if (!mac_bsdextended_enabled) + return (0); + + error = VOP_GETATTR(vp, &vap, cred, curthread); + if (error) + return (error); + return (mac_bsdextended_check(cred, vap.va_uid, vap.va_gid, VSTAT)); +} + +static struct mac_policy_op_entry mac_bsdextended_ops[] = +{ + { MAC_DESTROY, + (macop_t)mac_bsdextended_destroy }, + { MAC_INIT, + (macop_t)mac_bsdextended_init }, + { MAC_CHECK_VNODE_ACCESS, + (macop_t)mac_bsdextended_check_vnode_access }, + { MAC_CHECK_VNODE_CHDIR, + (macop_t)mac_bsdextended_check_vnode_chdir }, + { MAC_CHECK_VNODE_CHROOT, + (macop_t)mac_bsdextended_check_vnode_chroot }, + { MAC_CHECK_VNODE_CREATE, + (macop_t)mac_bsdextended_check_create_vnode }, + { MAC_CHECK_VNODE_DELETE, + (macop_t)mac_bsdextended_check_vnode_delete }, + { MAC_CHECK_VNODE_DELETEACL, + (macop_t)mac_bsdextended_check_vnode_deleteacl }, + { MAC_CHECK_VNODE_EXEC, + (macop_t)mac_bsdextended_check_vnode_exec }, + { MAC_CHECK_VNODE_GETACL, + (macop_t)mac_bsdextended_check_vnode_getacl }, + { MAC_CHECK_VNODE_GETEXTATTR, + (macop_t)mac_bsdextended_check_vnode_getextattr }, + { MAC_CHECK_VNODE_LOOKUP, + (macop_t)mac_bsdextended_check_vnode_lookup }, + { MAC_CHECK_VNODE_OPEN, + (macop_t)mac_bsdextended_check_vnode_open }, + { MAC_CHECK_VNODE_READDIR, + (macop_t)mac_bsdextended_check_vnode_readdir }, + { MAC_CHECK_VNODE_READLINK, + (macop_t)mac_bsdextended_check_vnode_readdlink }, + { MAC_CHECK_VNODE_RENAME_FROM, + (macop_t)mac_bsdextended_check_vnode_rename_from }, + { MAC_CHECK_VNODE_RENAME_TO, + (macop_t)mac_bsdextended_check_vnode_rename_to }, + { MAC_CHECK_VNODE_REVOKE, + (macop_t)mac_bsdextended_check_vnode_revoke }, + { MAC_CHECK_VNODE_SETACL, + (macop_t)mac_bsdextended_check_setacl_vnode }, + { MAC_CHECK_VNODE_SETEXTATTR, + (macop_t)mac_bsdextended_check_vnode_setextattr }, + { MAC_CHECK_VNODE_SETFLAGS, + (macop_t)mac_bsdextended_check_vnode_setflags }, + { MAC_CHECK_VNODE_SETMODE, + (macop_t)mac_bsdextended_check_vnode_setmode }, + { MAC_CHECK_VNODE_SETOWNER, + (macop_t)mac_bsdextended_check_vnode_setowner }, + { MAC_CHECK_VNODE_SETUTIMES, + (macop_t)mac_bsdextended_check_vnode_setutimes }, + { MAC_CHECK_VNODE_STAT, + (macop_t)mac_bsdextended_check_vnode_stat }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_bsdextended_ops, trustedbsd_mac_bsdextended, + "TrustedBSD MAC/BSD Extended", MPC_LOADTIME_FLAG_UNLOADOK, NULL); diff --git a/sys/security/mac_bsdextended/mac_bsdextended.h b/sys/security/mac_bsdextended/mac_bsdextended.h new file mode 100644 index 0000000..ae9ca24 --- /dev/null +++ b/sys/security/mac_bsdextended/mac_bsdextended.h @@ -0,0 +1,60 @@ +/*- + * 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$ + */ + +#ifndef _SYS_SECURITY_MAC_BSDEXTENDED_H +#define _SYS_SECURITY_MAC_BSDEXTENDED_H + +#define MBI_UID_DEFINED 0x00000001 /* uid field should be used */ +#define MBI_GID_DEFINED 0x00000002 /* gid field should be used */ +#define MBI_NEGATED 0x00000004 /* negate uid/gid matches */ +#define MBI_BITS (MBI_UID_DEFINED | MBI_GID_DEFINED | MBI_NEGATED) + +struct mac_bsdextended_identity { + int mbi_flags; + uid_t mbi_uid; + gid_t mbi_gid; +}; + +struct mac_bsdextended_rule { + struct mac_bsdextended_identity mbr_subject; + struct mac_bsdextended_identity mbr_object; + mode_t mbr_mode; /* maximum access */ +}; + +#endif /* _SYS_SECURITY_MAC_BSDEXTENDED_H */ diff --git a/sys/security/mac_ifoff/mac_ifoff.c b/sys/security/mac_ifoff/mac_ifoff.c new file mode 100644 index 0000000..b43bb1a --- /dev/null +++ b/sys/security/mac_ifoff/mac_ifoff.c @@ -0,0 +1,173 @@ +/*- + * 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. + * Limit access to interfaces until they are specifically administratively + * enabled. Prevents protocol stack-driven packet leakage in unsafe + * environments. + */ + +#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, ifoff, CTLFLAG_RW, 0, + "TrustedBSD mac_ifoff policy controls"); + +static int mac_ifoff_enabled = 1; +SYSCTL_INT(_security_mac_ifoff, OID_AUTO, enabled, CTLFLAG_RW, + &mac_ifoff_enabled, 0, "Enforce ifoff policy"); +TUNABLE_INT("security.mac.ifoff.enabled", &mac_ifoff_enabled); + +static int mac_ifoff_lo_enabled = 1; +SYSCTL_INT(_security_mac_ifoff, OID_AUTO, lo_enabled, CTLFLAG_RW, + &mac_ifoff_lo_enabled, 0, "Enable loopback interfaces"); +TUNABLE_INT("security.mac.ifoff.lo_enabled", &mac_ifoff_lo_enabled); + +static int mac_ifoff_other_enabled = 0; +SYSCTL_INT(_security_mac_ifoff, OID_AUTO, other_enabled, CTLFLAG_RW, + &mac_ifoff_other_enabled, 0, "Enable other interfaces"); +TUNABLE_INT("security.mac.ifoff.other_enabled", &mac_ifoff_other_enabled); + +static int mac_ifoff_bpfrecv_enabled = 0; +SYSCTL_INT(_security_mac_ifoff, OID_AUTO, bpfrecv_enabled, CTLFLAG_RW, + &mac_ifoff_bpfrecv_enabled, 0, "Enable BPF reception even when interface " + "is disabled"); +TUNABLE_INT("security.mac.ifoff.bpfrecv.enabled", &mac_ifoff_bpfrecv_enabled); + +static int +check_ifnet_outgoing(struct ifnet *ifnet) +{ + + if (!mac_ifoff_enabled) + return (0); + + if (mac_ifoff_lo_enabled && ifnet->if_type == IFT_LOOP) + return (0); + + if (mac_ifoff_other_enabled && ifnet->if_type != IFT_LOOP) + return (0); + + return (EPERM); +} + +static int +check_ifnet_incoming(struct ifnet *ifnet, int viabpf) +{ + if (!mac_ifoff_enabled) + return (0); + + if (mac_ifoff_lo_enabled && ifnet->if_type == IFT_LOOP) + return (0); + + if (mac_ifoff_other_enabled && ifnet->if_type != IFT_LOOP) + return (0); + + if (viabpf && mac_ifoff_bpfrecv_enabled) + return (0); + + return (EPERM); +} + +static int +mac_ifoff_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, + struct ifnet *ifnet, struct label *ifnetlabel) +{ + + return (check_ifnet_incoming(ifnet, 1)); +} + +static int +mac_ifoff_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (check_ifnet_outgoing(ifnet)); +} + +static int +mac_ifoff_check_socket_receive(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + if (m->m_flags & M_PKTHDR) { + if (m->m_pkthdr.rcvif != NULL) + return (check_ifnet_incoming(m->m_pkthdr.rcvif, 0)); + } + + return (0); +} + +static struct mac_policy_op_entry mac_ifoff_ops[] = +{ + { MAC_CHECK_BPFDESC_RECEIVE, + (macop_t)mac_ifoff_check_bpfdesc_receive }, + { MAC_CHECK_IFNET_TRANSMIT, + (macop_t)mac_ifoff_check_ifnet_transmit }, + { MAC_CHECK_SOCKET_RECEIVE, + (macop_t)mac_ifoff_check_socket_receive }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_ifoff_ops, trustedbsd_mac_ifoff, "TrustedBSD MAC/ifoff", + MPC_LOADTIME_FLAG_UNLOADOK, NULL); diff --git a/sys/security/mac_mls/mac_mls.c b/sys/security/mac_mls/mac_mls.c new file mode 100644 index 0000000..a4b1e1f --- /dev/null +++ b/sys/security/mac_mls/mac_mls.c @@ -0,0 +1,2177 @@ +/*- + * 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. + * MLS fixed label mandatory confidentiality policy. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/acl.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/pipe.h> +#include <sys/sysctl.h> + +#include <fs/devfs/devfs.h> + +#include <net/bpfdesc.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/if_var.h> + +#include <netinet/in.h> +#include <netinet/ip_var.h> + +#include <vm/vm.h> + +#include <sys/mac_policy.h> + +#include <security/mac_mls/mac_mls.h> + +SYSCTL_DECL(_security_mac); + +SYSCTL_NODE(_security_mac, OID_AUTO, mls, CTLFLAG_RW, 0, + "TrustedBSD mac_mls policy controls"); + +static int mac_mls_enabled = 0; +SYSCTL_INT(_security_mac_mls, OID_AUTO, enabled, CTLFLAG_RW, + &mac_mls_enabled, 0, "Enforce MAC/MLS policy"); + +static int destroyed_not_inited; +SYSCTL_INT(_security_mac_mls, OID_AUTO, destroyed_not_inited, CTLFLAG_RD, + &destroyed_not_inited, 0, "Count of labels destroyed but not inited"); + +static int mac_mls_revocation_enabled = 0; +SYSCTL_INT(_security_mac_mls, OID_AUTO, revocation_enabled, CTLFLAG_RW, + &mac_mls_revocation_enabled, 0, "Revoke access to objects on relabel"); +TUNABLE_INT("security.mac.mls.revocation_enabled", + &mac_mls_revocation_enabled); + +static int mac_mls_slot; +#define SLOT(l) ((struct mac_mls *)LABEL_TO_SLOT((l), mac_mls_slot).l_ptr) + +MALLOC_DEFINE(M_MACMLS, "mls label", "MAC/MLS labels"); + +static int mac_mls_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, mode_t acc_mode); + +static struct mac_mls * +mls_alloc(int how) +{ + struct mac_mls *mac_mls; + + mac_mls = malloc(sizeof(struct mac_mls), M_MACMLS, M_ZERO | how); + + return (mac_mls); +} + +static void +mls_free(struct mac_mls *mac_mls) +{ + + if (mac_mls != NULL) + free(mac_mls, M_MACMLS); + else + atomic_add_int(&destroyed_not_inited, 1); +} + +static int +mac_mls_dominate_element(struct mac_mls_element *a, + struct mac_mls_element *b) +{ + + switch(a->mme_type) { + case MAC_MLS_TYPE_EQUAL: + case MAC_MLS_TYPE_HIGH: + return (1); + + case MAC_MLS_TYPE_LOW: + switch (b->mme_type) { + case MAC_MLS_TYPE_LEVEL: + case MAC_MLS_TYPE_HIGH: + return (0); + + case MAC_MLS_TYPE_EQUAL: + case MAC_MLS_TYPE_LOW: + return (1); + + default: + panic("mac_mls_dominate_element: b->mme_type invalid"); + } + + case MAC_MLS_TYPE_LEVEL: + switch (b->mme_type) { + case MAC_MLS_TYPE_EQUAL: + case MAC_MLS_TYPE_LOW: + return (1); + + case MAC_MLS_TYPE_HIGH: + return (0); + + case MAC_MLS_TYPE_LEVEL: + return (a->mme_level >= b->mme_level); + + default: + panic("mac_mls_dominate_element: b->mme_type invalid"); + } + + default: + panic("mac_mls_dominate_element: a->mme_type invalid"); + } + + return (0); +} + +static int +mac_mls_range_in_range(struct mac_mls *rangea, struct mac_mls *rangeb) +{ + + return (mac_mls_dominate_element(&rangeb->mm_rangehigh, + &rangea->mm_rangehigh) && + mac_mls_dominate_element(&rangea->mm_rangelow, + &rangeb->mm_rangelow)); +} + +static int +mac_mls_single_in_range(struct mac_mls *single, struct mac_mls *range) +{ + + KASSERT((single->mm_flag & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_single_in_range: a not single")); + KASSERT((range->mm_flag & MAC_MLS_FLAG_RANGE) != 0, + ("mac_mls_single_in_range: b not range")); + + return (mac_mls_dominate_element(&range->mm_rangehigh, + &single->mm_single) && + mac_mls_dominate_element(&single->mm_single, + &range->mm_rangelow)); + + return (1); +} + +static int +mac_mls_dominate_single(struct mac_mls *a, struct mac_mls *b) +{ + KASSERT((a->mm_flags & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_dominate_single: a not single")); + KASSERT((b->mm_flags & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_dominate_single: b not single")); + + return (mac_mls_dominate_element(&a->mm_single, &b->mm_single)); +} + +static int +mac_mls_equal_element(struct mac_mls_element *a, struct mac_mls_element *b) +{ + + if (a->mme_type == MAC_MLS_TYPE_EQUAL || + b->mme_type == MAC_MLS_TYPE_EQUAL) + return (1); + + return (a->mme_type == b->mme_type && a->mme_level == b->mme_level); +} + +static int +mac_mls_equal_range(struct mac_mls *a, struct mac_mls *b) +{ + + KASSERT((a->mm_flags & MAC_MLS_FLAG_RANGE) != 0, + ("mac_mls_equal_range: a not range")); + KASSERT((b->mm_flags & MAC_MLS_FLAG_RANGE) != 0, + ("mac_mls_equal_range: b not range")); + + return (mac_mls_equal_element(&a->mm_rangelow, &b->mm_rangelow) && + mac_mls_equal_element(&a->mm_rangehigh, &b->mm_rangehigh)); +} + +static int +mac_mls_equal_single(struct mac_mls *a, struct mac_mls *b) +{ + + KASSERT((a->mm_flags & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_equal_single: a not single")); + KASSERT((b->mm_flags & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_equal_single: b not single")); + + return (mac_mls_equal_element(&a->mm_single, &b->mm_single)); +} + +static int +mac_mls_valid(struct mac_mls *mac_mls) +{ + + if (mac_mls->mm_flags & MAC_MLS_FLAG_SINGLE) { + switch (mac_mls->mm_single.mme_type) { + case MAC_MLS_TYPE_LEVEL: + break; + + case MAC_MLS_TYPE_EQUAL: + case MAC_MLS_TYPE_HIGH: + case MAC_MLS_TYPE_LOW: + if (mac_mls->mm_single.mme_level != 0) + return (EINVAL); + break; + + default: + return (EINVAL); + } + } else { + if (mac_mls->mm_single.mme_type != MAC_MLS_TYPE_UNDEF) + return (EINVAL); + } + + if (mac_mls->mm_flags & MAC_MLS_FLAG_RANGE) { + switch (mac_mls->mm_rangelow.mme_type) { + case MAC_MLS_TYPE_LEVEL: + break; + + case MAC_MLS_TYPE_EQUAL: + case MAC_MLS_TYPE_HIGH: + case MAC_MLS_TYPE_LOW: + if (mac_mls->mm_rangelow.mme_level != 0) + return (EINVAL); + break; + + default: + return (EINVAL); + } + + switch (mac_mls->mm_rangehigh.mme_type) { + case MAC_MLS_TYPE_LEVEL: + break; + + case MAC_MLS_TYPE_EQUAL: + case MAC_MLS_TYPE_HIGH: + case MAC_MLS_TYPE_LOW: + if (mac_mls->mm_rangehigh.mme_level != 0) + return (EINVAL); + break; + + default: + return (EINVAL); + } + if (!mac_mls_dominate_element(&mac_mls->mm_rangehigh, + &mac_mls->mm_rangelow)) + return (EINVAL); + } else { + if (mac_mls->mm_rangelow.mme_type != MAC_MLS_TYPE_UNDEF || + mac_mls->mm_rangehigh.mme_type != MAC_MLS_TYPE_UNDEF) + return (EINVAL); + } + + return (0); +} + +static void +mac_mls_set_range(struct mac_mls *mac_mls, u_short typelow, + u_short levellow, u_short typehigh, u_short levelhigh) +{ + + mac_mls->mm_rangelow.mme_type = typelow; + mac_mls->mm_rangelow.mme_level = levellow; + mac_mls->mm_rangehigh.mme_type = typehigh; + mac_mls->mm_rangehigh.mme_level = levelhigh; + mac_mls->mm_flags |= MAC_MLS_FLAG_RANGE; +} + +static void +mac_mls_set_single(struct mac_mls *mac_mls, u_short type, u_short level) +{ + + mac_mls->mm_single.mme_type = type; + mac_mls->mm_single.mme_level = level; + mac_mls->mm_flags |= MAC_MLS_FLAG_SINGLE; +} + +static void +mac_mls_copy_range(struct mac_mls *labelfrom, struct mac_mls *labelto) +{ + KASSERT((labelfrom->mm_flags & MAC_MLS_FLAG_RANGE) != 0, + ("mac_mls_copy_range: labelfrom not range")); + + labelto->mm_rangelow = labelfrom->mm_rangelow; + labelto->mm_rangehigh = labelfrom->mm_rangehigh; + labelto->mm_flags |= MAC_MLS_FLAG_RANGE; +} + +static void +mac_mls_copy_single(struct mac_mls *labelfrom, struct mac_mls *labelto) +{ + + KASSERT((labelfrom->mm_flags & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_copy_single: labelfrom not single")); + + labelto->mm_single = labelfrom->mm_single; + labelto->mm_flags |= MAC_MLS_FLAG_SINGLE; +} + +static void +mac_mls_copy_single_to_range(struct mac_mls *labelfrom, + struct mac_mls *labelto) +{ + + KASSERT((labelfrom->mm_flags & MAC_MLS_FLAG_SINGLE) != 0, + ("mac_mls_copy_single_to_range: labelfrom not single")); + + labelto->mm_rangelow = labelfrom->mm_single; + labelto->mm_rangehigh = labelfrom->mm_single; + labelto->mm_flags |= MAC_MLS_FLAG_RANGE; +} + +/* + * Policy module operations. + */ +static void +mac_mls_destroy(struct mac_policy_conf *conf) +{ + +} + +static void +mac_mls_init(struct mac_policy_conf *conf) +{ + +} + +/* + * Label operations. + */ +static void +mac_mls_init_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_cred(struct ucred *ucred, struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_ifnet(struct ifnet *ifnet, struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_ipq(struct ipq *ipq, struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static int +mac_mls_init_mbuf(struct mbuf *mbuf, int how, struct label *label) +{ + + SLOT(label) = mls_alloc(how); + if (SLOT(label) == NULL) + return (ENOMEM); + + return (0); +} + +static void +mac_mls_init_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + + SLOT(mntlabel) = mls_alloc(M_WAITOK); + SLOT(fslabel) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + + SLOT(label) = mls_alloc(M_WAITOK); + SLOT(peerlabel) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_pipe(struct pipe *pipe, struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_temp(struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_init_vnode(struct vnode *vp, struct label *label) +{ + + SLOT(label) = mls_alloc(M_WAITOK); +} + +static void +mac_mls_destroy_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_cred(struct ucred *ucred, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_ifnet(struct ifnet *ifnet, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_ipq(struct ipq *ipq, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_mbuf(struct mbuf *mbuf, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + + mls_free(SLOT(mntlabel)); + SLOT(mntlabel) = NULL; + mls_free(SLOT(fslabel)); + SLOT(fslabel) = NULL; +} + +static void +mac_mls_destroy_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; + mls_free(SLOT(peerlabel)); + SLOT(peerlabel) = NULL; +} + +static void +mac_mls_destroy_pipe(struct pipe *pipe, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_temp(struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static void +mac_mls_destroy_vnode(struct vnode *vp, struct label *label) +{ + + mls_free(SLOT(label)); + SLOT(label) = NULL; +} + +static int +mac_mls_externalize(struct label *label, struct mac *extmac) +{ + struct mac_mls *mac_mls; + + mac_mls = SLOT(label); + + if (mac_mls == NULL) { + printf("mac_mls_externalize: NULL pointer\n"); + return (0); + } + + extmac->m_mls = *mac_mls; + + return (0); +} + +static int +mac_mls_internalize(struct label *label, struct mac *extmac) +{ + struct mac_mls *mac_mls; + int error; + + mac_mls = SLOT(label); + + error = mac_mls_valid(mac_mls); + if (error) + return (error); + + *mac_mls = extmac->m_mls; + + return (0); +} + +/* + * Labeling event operations: file system objects, and things that look + * a lot like file system objects. + */ +static void +mac_mls_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent, + struct label *label) +{ + struct mac_mls *mac_mls; + int mls_type; + + mac_mls = SLOT(label); + if (strcmp(dev->si_name, "null") == 0 || + strcmp(dev->si_name, "zero") == 0 || + strcmp(dev->si_name, "random") == 0 || + strncmp(dev->si_name, "fd/", strlen("fd/")) == 0) + mls_type = MAC_MLS_TYPE_EQUAL; + else if (strcmp(dev->si_name, "kmem") == 0 || + strcmp(dev->si_name, "mem") == 0) + mls_type = MAC_MLS_TYPE_HIGH; + else + mls_type = MAC_MLS_TYPE_LOW; + mac_mls_set_single(mac_mls, mls_type, 0); +} + +static void +mac_mls_create_devfs_directory(char *dirname, int dirnamelen, + struct devfs_dirent *devfs_dirent, struct label *label) +{ + struct mac_mls *mac_mls; + + mac_mls = SLOT(label); + mac_mls_set_single(mac_mls, MAC_MLS_TYPE_LOW, 0); +} + +static void +mac_mls_create_devfs_vnode(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(direntlabel); + dest = SLOT(vnodelabel); + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_vnode(struct ucred *cred, struct vnode *parent, + struct label *parentlabel, struct vnode *child, struct label *childlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(childlabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(mntlabel); + mac_mls_copy_single(source, dest); + dest = SLOT(fslabel); + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_root_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + struct mac_mls *mac_mls; + + /* Always mount root as high integrity. */ + mac_mls = SLOT(fslabel); + mac_mls_set_single(mac_mls, MAC_MLS_TYPE_LOW, 0); + mac_mls = SLOT(mntlabel); + mac_mls_set_single(mac_mls, MAC_MLS_TYPE_LOW, 0); +} + +static void +mac_mls_relabel_vnode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *label) +{ + struct mac_mls *source, *dest; + + source = SLOT(label); + dest = SLOT(vnodelabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_update_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(vnodelabel); + dest = SLOT(direntlabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_update_procfsvnode(struct vnode *vp, struct label *vnodelabel, + struct ucred *cred) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(vnodelabel); + + /* + * Only copy the single, not the range, since vnodes only have + * a single. + */ + mac_mls_copy_single(source, dest); +} + +static int +mac_mls_update_vnode_from_externalized(struct vnode *vp, + struct label *vnodelabel, struct mac *extmac) +{ + struct mac_mls *source, *dest; + int error; + + source = &extmac->m_mls; + dest = SLOT(vnodelabel); + + error = mac_mls_valid(source); + if (error) + return (error); + + if ((source->mm_flags & MAC_MLS_FLAGS_BOTH) != MAC_MLS_FLAG_SINGLE) + return (EINVAL); + + mac_mls_copy_single(source, dest); + + return (0); +} + +static void +mac_mls_update_vnode_from_mount(struct vnode *vp, struct label *vnodelabel, + struct mount *mp, struct label *fslabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(fslabel); + dest = SLOT(vnodelabel); + + mac_mls_copy_single(source, dest); +} + +/* + * Labeling event operations: IPC object. + */ +static void +mac_mls_create_mbuf_from_socket(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(socketlabel); + dest = SLOT(mbuflabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(socketlabel); + + mac_mls_copy_single(source, dest); + mac_mls_copy_single_to_range(source, dest); +} + +static void +mac_mls_create_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(pipelabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_socket_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(oldsocketlabel); + dest = SLOT(newsocketlabel); + + mac_mls_copy_single(source, dest); + mac_mls_copy_range(source, dest); +} + +static void +mac_mls_relabel_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(socketlabel); + + mac_mls_copy_single(source, dest); + mac_mls_copy_range(source, dest); +} + +static void +mac_mls_relabel_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(pipelabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, + struct socket *socket, struct label *socketpeerlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(mbuflabel); + dest = SLOT(socketpeerlabel); + + mac_mls_copy_single(source, dest); +} + +/* + * Labeling event operations: network objects. + */ +static void +mac_mls_set_socket_peer_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketpeerlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(oldsocketlabel); + dest = SLOT(newsocketpeerlabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d, + struct label *bpflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred->cr_label); + dest = SLOT(bpflabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel) +{ + struct mac_mls *dest; + int level; + + dest = SLOT(ifnetlabel); + + if (ifnet->if_type == IFT_LOOP) + level = MAC_MLS_TYPE_EQUAL; + else + level = MAC_MLS_TYPE_LOW; + + mac_mls_set_single(dest, level, 0); + mac_mls_set_range(dest, level, 0, level, 0); +} + +static void +mac_mls_create_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(fragmentlabel); + dest = SLOT(ipqlabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel, + struct mbuf *datagram, struct label *datagramlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(ipqlabel); + dest = SLOT(datagramlabel); + + /* Just use the head, since we require them all to match. */ + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_fragment(struct mbuf *datagram, struct label *datagramlabel, + struct mbuf *fragment, struct label *fragmentlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(datagramlabel); + dest = SLOT(fragmentlabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_mbuf_from_mbuf(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(oldmbuflabel); + dest = SLOT(newmbuflabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + struct mac_mls *dest; + + dest = SLOT(mbuflabel); + + mac_mls_set_single(dest, MAC_MLS_TYPE_EQUAL, 0); +} + +static void +mac_mls_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(bpflabel); + dest = SLOT(mbuflabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(ifnetlabel); + dest = SLOT(mbuflabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_mbuf_multicast_encap(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(oldmbuflabel); + dest = SLOT(newmbuflabel); + + mac_mls_copy_single(source, dest); +} + +static void +mac_mls_create_mbuf_netlayer(struct mbuf *oldmbuf, struct label *oldmbuflabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(oldmbuflabel); + dest = SLOT(newmbuflabel); + + mac_mls_copy_single(source, dest); +} + +static int +mac_mls_fragment_match(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + struct mac_mls *a, *b; + + a = SLOT(ipqlabel); + b = SLOT(fragmentlabel); + + return (mac_mls_equal_single(a, b)); +} + +static void +mac_mls_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(ifnetlabel); + + mac_mls_copy_single(source, dest); + mac_mls_copy_range(source, dest); +} + +static void +mac_mls_update_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + + /* NOOP: we only accept matching labels, so no need to update */ +} + +/* + * Labeling event operations: processes. + */ +static void +mac_mls_create_cred(struct ucred *cred_parent, struct ucred *cred_child) +{ + struct mac_mls *source, *dest; + + source = SLOT(&cred_parent->cr_label); + dest = SLOT(&cred_child->cr_label); + + mac_mls_copy_single(source, dest); + mac_mls_copy_range(source, dest); +} + +static void +mac_mls_execve_transition(struct ucred *old, struct ucred *new, + struct vnode *vp, struct mac *vnodelabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(&old->cr_label); + dest = SLOT(&new->cr_label); + + mac_mls_copy_single(source, dest); + mac_mls_copy_range(source, dest); +} + +static int +mac_mls_execve_will_transition(struct ucred *old, struct vnode *vp, + struct mac *vnodelabel) +{ + + return (0); +} + +static void +mac_mls_create_proc0(struct ucred *cred) +{ + struct mac_mls *dest; + + dest = SLOT(&cred->cr_label); + + mac_mls_set_single(dest, MAC_MLS_TYPE_EQUAL, 0); + mac_mls_set_range(dest, MAC_MLS_TYPE_LOW, 0, MAC_MLS_TYPE_HIGH, 0); +} + +static void +mac_mls_create_proc1(struct ucred *cred) +{ + struct mac_mls *dest; + + dest = SLOT(&cred->cr_label); + + mac_mls_set_single(dest, MAC_MLS_TYPE_LOW, 0); + mac_mls_set_range(dest, MAC_MLS_TYPE_LOW, 0, MAC_MLS_TYPE_HIGH, 0); +} + +static void +mac_mls_relabel_cred(struct ucred *cred, struct label *newlabel) +{ + struct mac_mls *source, *dest; + + source = SLOT(newlabel); + dest = SLOT(&cred->cr_label); + + mac_mls_copy_single(source, dest); + mac_mls_copy_range(source, dest); +} + +/* + * Access control checks. + */ +static int +mac_mls_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, + struct ifnet *ifnet, struct label *ifnetlabel) +{ + struct mac_mls *a, *b; + + if (!mac_mls_enabled) + return (0); + + a = SLOT(bpflabel); + b = SLOT(ifnetlabel); + + if (mac_mls_equal_single(a, b)) + return (0); + return (EACCES); +} + +static int +mac_mls_check_cred_relabel(struct ucred *cred, struct label *newlabel) +{ + struct mac_mls *subj, *new; + + subj = SLOT(&cred->cr_label); + new = SLOT(newlabel); + + if ((new->mm_flags & MAC_MLS_FLAGS_BOTH) != MAC_MLS_FLAGS_BOTH) + return (EINVAL); + + /* + * XXX: Allow processes with root privilege to set labels outside + * their range, so suid things like "su" work. This WILL go away + * when we figure out the 'correct' solution... + */ + if (!suser_cred(cred, 0)) + return (0); + + /* + * The new single must be in the old range. + */ + if (!mac_mls_single_in_range(new, subj)) + return (EPERM); + + /* + * The new range must be in the old range. + */ + if (!mac_mls_range_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (0); +} + + +static int +mac_mls_check_cred_visible(struct ucred *u1, struct ucred *u2) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&u1->cr_label); + obj = SLOT(&u2->cr_label); + + /* XXX: range */ + if (!mac_mls_dominate_single(subj, obj)) + return (ESRCH); + + return (0); +} + +static int +mac_mls_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + struct mac_mls *subj, *new; + + subj = SLOT(&cred->cr_label); + new = SLOT(newlabel); + + if ((new->mm_flags & MAC_MLS_FLAGS_BOTH) != MAC_MLS_FLAGS_BOTH) + return (EINVAL); + + /* XXX: privilege model here? */ + + return (suser_cred(cred, 0)); +} + +static int +mac_mls_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_mls *p, *i; + + if (!mac_mls_enabled) + return (0); + + p = SLOT(mbuflabel); + i = SLOT(ifnetlabel); + + return (mac_mls_single_in_range(p, i) ? 0 : EACCES); +} + +static int +mac_mls_check_mount_stat(struct ucred *cred, struct mount *mp, + struct label *mntlabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(mntlabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) +{ + + if(!mac_mls_enabled) + return (0); + + /* XXX: This will be implemented soon... */ + + return (0); +} + +static int +mac_mls_check_pipe_op(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, int op) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT((pipelabel)); + + switch(op) { + case MAC_OP_PIPE_READ: + case MAC_OP_PIPE_STAT: + case MAC_OP_PIPE_POLL: + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + break; + case MAC_OP_PIPE_WRITE: + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + break; + default: + panic("mac_mls_check_pipe_op: invalid pipe operation"); + } + + return (0); +} + +static int +mac_mls_check_pipe_relabel(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + struct mac_mls *subj, *obj, *new; + + new = SLOT(newlabel); + subj = SLOT(&cred->cr_label); + obj = SLOT(pipelabel); + + if ((new->mm_flags & MAC_MLS_FLAGS_BOTH) != MAC_MLS_FLAG_SINGLE) + return (EINVAL); + + /* + * To relabel a pipe, the old pipe label must be in the subject + * range. + */ + if (!mac_mls_single_in_range(obj, subj)) + return (EPERM); + + /* + * To relabel a pipe, the new pipe label must be in the subject + * range. + */ + if (!mac_mls_single_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (0); +} + +static int +mac_mls_check_proc_debug(struct ucred *cred, struct proc *proc) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(&proc->p_ucred->cr_label); + + /* XXX: range checks */ + if (!mac_mls_dominate_single(subj, obj)) + return (ESRCH); + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_proc_sched(struct ucred *cred, struct proc *proc) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(&proc->p_ucred->cr_label); + + /* XXX: range checks */ + if (!mac_mls_dominate_single(subj, obj)) + return (ESRCH); + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_proc_signal(struct ucred *cred, struct proc *proc, int signum) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(&proc->p_ucred->cr_label); + + /* XXX: range checks */ + if (!mac_mls_dominate_single(subj, obj)) + return (ESRCH); + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_socket_receive(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + struct mac_mls *p, *s; + + if (!mac_mls_enabled) + return (0); + + p = SLOT(mbuflabel); + s = SLOT(socketlabel); + + return (mac_mls_equal_single(p, s) ? 0 : EACCES); +} + +static int +mac_mls_check_socket_relabel(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + struct mac_mls *subj, *obj, *new; + + new = SLOT(newlabel); + subj = SLOT(&cred->cr_label); + obj = SLOT(socketlabel); + + if ((new->mm_flags & MAC_MLS_FLAGS_BOTH) != MAC_MLS_FLAG_SINGLE) + return (EINVAL); + + /* + * To relabel a socket, the old socket label must be in the subject + * range. + */ + if (!mac_mls_single_in_range(obj, subj)) + return (EPERM); + + /* + * To relabel a socket, the new socket label must be in the subject + * range. + */ + if (!mac_mls_single_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (0); +} + +static int +mac_mls_check_socket_visible(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(socketlabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (ENOENT); + + return (0); +} + +static int +mac_mls_check_vnode_access(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t flags) +{ + + return (mac_mls_check_vnode_open(cred, vp, label, flags)); +} + +static int +mac_mls_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_create(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp, struct vattr *vap) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + obj = SLOT(label); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, mode_t acc_mode) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + /* XXX privilege override for admin? */ + if (acc_mode & (VREAD | VEXEC | VSTAT)) { + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + } + if (acc_mode & (VWRITE | VAPPEND | VADMIN)) { + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + } + + return (0); +} + +static int +mac_mls_check_vnode_readdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_readlink(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_relabel(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *newlabel) +{ + struct mac_mls *old, *new, *subj; + + old = SLOT(vnodelabel); + new = SLOT(newlabel); + subj = SLOT(&cred->cr_label); + + if ((new->mm_flags & MAC_MLS_FLAGS_BOTH) != MAC_MLS_FLAG_SINGLE) + return (EINVAL); + + /* + * To relabel a vnode, the old vnode label must be in the subject + * range. + */ + if (!mac_mls_single_in_range(old, subj)) + return (EPERM); + + /* + * To relabel a vnode, the new vnode label must be in the subject + * range. + */ + if (!mac_mls_single_in_range(new, subj)) + return (EPERM); + + /* + * XXX: Don't permit EQUAL in a label unless the subject has EQUAL. + */ + + return (suser_cred(cred, 0)); +} + + +static int +mac_mls_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + obj = SLOT(label); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, int samedir, + struct componentname *cnp) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(dlabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + if (vp != NULL) { + obj = SLOT(label); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + } + + return (0); +} + +static int +mac_mls_check_vnode_revoke(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_setacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type, struct acl *acl) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, int attrnamespace, const char *name, + struct uio *uio) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + /* XXX: protect the MAC EA in a special way? */ + + return (0); +} + +static int +mac_mls_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, u_long flags) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, mode_t mode) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, uid_t uid, gid_t gid) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct timespec atime, struct timespec mtime) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + + return (0); +} + +static int +mac_mls_check_vnode_stat(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(vnodelabel); + + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + + return (0); +} + +static vm_prot_t +mac_mls_check_vnode_mmap_perms(struct ucred *cred, struct vnode *vp, + struct label *label, int newmapping) +{ + struct mac_mls *subj, *obj; + vm_prot_t prot = 0; + + if (!mac_mls_enabled || (!mac_mls_revocation_enabled && !newmapping)) + return (VM_PROT_ALL); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + if (mac_mls_dominate_single(subj, obj)) + prot |= VM_PROT_READ | VM_PROT_EXECUTE; + if (mac_mls_dominate_single(obj, subj)) + prot |= VM_PROT_WRITE; + return (prot); +} + +static int +mac_mls_check_vnode_op(struct ucred *cred, struct vnode *vp, + struct label *label, int op) +{ + struct mac_mls *subj, *obj; + + if (!mac_mls_enabled || !mac_mls_revocation_enabled) + return (0); + + subj = SLOT(&cred->cr_label); + obj = SLOT(label); + + switch (op) { + case MAC_OP_VNODE_POLL: + case MAC_OP_VNODE_READ: + if (!mac_mls_dominate_single(subj, obj)) + return (EACCES); + return (0); + + case MAC_OP_VNODE_WRITE: + if (!mac_mls_dominate_single(obj, subj)) + return (EACCES); + return (0); + + default: + printf("mac_mls_check_vnode_op: unknown operation %d\n", op); + return (EINVAL); + } +} + +static struct mac_policy_op_entry mac_mls_ops[] = +{ + { MAC_DESTROY, + (macop_t)mac_mls_destroy }, + { MAC_INIT, + (macop_t)mac_mls_init }, + { MAC_INIT_BPFDESC, + (macop_t)mac_mls_init_bpfdesc }, + { MAC_INIT_CRED, + (macop_t)mac_mls_init_cred }, + { MAC_INIT_DEVFSDIRENT, + (macop_t)mac_mls_init_devfsdirent }, + { MAC_INIT_IFNET, + (macop_t)mac_mls_init_ifnet }, + { MAC_INIT_IPQ, + (macop_t)mac_mls_init_ipq }, + { MAC_INIT_MBUF, + (macop_t)mac_mls_init_mbuf }, + { MAC_INIT_MOUNT, + (macop_t)mac_mls_init_mount }, + { MAC_INIT_PIPE, + (macop_t)mac_mls_init_pipe }, + { MAC_INIT_SOCKET, + (macop_t)mac_mls_init_socket }, + { MAC_INIT_TEMP, + (macop_t)mac_mls_init_temp }, + { MAC_INIT_VNODE, + (macop_t)mac_mls_init_vnode }, + { MAC_DESTROY_BPFDESC, + (macop_t)mac_mls_destroy_bpfdesc }, + { MAC_DESTROY_CRED, + (macop_t)mac_mls_destroy_cred }, + { MAC_DESTROY_DEVFSDIRENT, + (macop_t)mac_mls_destroy_devfsdirent }, + { MAC_DESTROY_IFNET, + (macop_t)mac_mls_destroy_ifnet }, + { MAC_DESTROY_IPQ, + (macop_t)mac_mls_destroy_ipq }, + { MAC_DESTROY_MBUF, + (macop_t)mac_mls_destroy_mbuf }, + { MAC_DESTROY_MOUNT, + (macop_t)mac_mls_destroy_mount }, + { MAC_DESTROY_PIPE, + (macop_t)mac_mls_destroy_pipe }, + { MAC_DESTROY_SOCKET, + (macop_t)mac_mls_destroy_socket }, + { MAC_DESTROY_TEMP, + (macop_t)mac_mls_destroy_temp }, + { MAC_DESTROY_VNODE, + (macop_t)mac_mls_destroy_vnode }, + { MAC_EXTERNALIZE, + (macop_t)mac_mls_externalize }, + { MAC_INTERNALIZE, + (macop_t)mac_mls_internalize }, + { MAC_CREATE_DEVFS_DEVICE, + (macop_t)mac_mls_create_devfs_device }, + { MAC_CREATE_DEVFS_DIRECTORY, + (macop_t)mac_mls_create_devfs_directory }, + { MAC_CREATE_DEVFS_VNODE, + (macop_t)mac_mls_create_devfs_vnode }, + { MAC_CREATE_VNODE, + (macop_t)mac_mls_create_vnode }, + { MAC_CREATE_MOUNT, + (macop_t)mac_mls_create_mount }, + { MAC_CREATE_ROOT_MOUNT, + (macop_t)mac_mls_create_root_mount }, + { MAC_RELABEL_VNODE, + (macop_t)mac_mls_relabel_vnode }, + { MAC_UPDATE_DEVFSDIRENT, + (macop_t)mac_mls_update_devfsdirent }, + { MAC_UPDATE_PROCFSVNODE, + (macop_t)mac_mls_update_procfsvnode }, + { MAC_UPDATE_VNODE_FROM_EXTERNALIZED, + (macop_t)mac_mls_update_vnode_from_externalized }, + { MAC_UPDATE_VNODE_FROM_MOUNT, + (macop_t)mac_mls_update_vnode_from_mount }, + { MAC_CREATE_MBUF_FROM_SOCKET, + (macop_t)mac_mls_create_mbuf_from_socket }, + { MAC_CREATE_PIPE, + (macop_t)mac_mls_create_pipe }, + { MAC_CREATE_SOCKET, + (macop_t)mac_mls_create_socket }, + { MAC_CREATE_SOCKET_FROM_SOCKET, + (macop_t)mac_mls_create_socket_from_socket }, + { MAC_RELABEL_PIPE, + (macop_t)mac_mls_relabel_pipe }, + { MAC_RELABEL_SOCKET, + (macop_t)mac_mls_relabel_socket }, + { MAC_SET_SOCKET_PEER_FROM_MBUF, + (macop_t)mac_mls_set_socket_peer_from_mbuf }, + { MAC_SET_SOCKET_PEER_FROM_SOCKET, + (macop_t)mac_mls_set_socket_peer_from_socket }, + { MAC_CREATE_BPFDESC, + (macop_t)mac_mls_create_bpfdesc }, + { MAC_CREATE_DATAGRAM_FROM_IPQ, + (macop_t)mac_mls_create_datagram_from_ipq }, + { MAC_CREATE_FRAGMENT, + (macop_t)mac_mls_create_fragment }, + { MAC_CREATE_IFNET, + (macop_t)mac_mls_create_ifnet }, + { MAC_CREATE_IPQ, + (macop_t)mac_mls_create_ipq }, + { MAC_CREATE_MBUF_FROM_MBUF, + (macop_t)mac_mls_create_mbuf_from_mbuf }, + { MAC_CREATE_MBUF_LINKLAYER, + (macop_t)mac_mls_create_mbuf_linklayer }, + { MAC_CREATE_MBUF_FROM_BPFDESC, + (macop_t)mac_mls_create_mbuf_from_bpfdesc }, + { MAC_CREATE_MBUF_FROM_IFNET, + (macop_t)mac_mls_create_mbuf_from_ifnet }, + { MAC_CREATE_MBUF_MULTICAST_ENCAP, + (macop_t)mac_mls_create_mbuf_multicast_encap }, + { MAC_CREATE_MBUF_NETLAYER, + (macop_t)mac_mls_create_mbuf_netlayer }, + { MAC_FRAGMENT_MATCH, + (macop_t)mac_mls_fragment_match }, + { MAC_RELABEL_IFNET, + (macop_t)mac_mls_relabel_ifnet }, + { MAC_UPDATE_IPQ, + (macop_t)mac_mls_update_ipq }, + { MAC_CREATE_CRED, + (macop_t)mac_mls_create_cred }, + { MAC_EXECVE_TRANSITION, + (macop_t)mac_mls_execve_transition }, + { MAC_EXECVE_WILL_TRANSITION, + (macop_t)mac_mls_execve_will_transition }, + { MAC_CREATE_PROC0, + (macop_t)mac_mls_create_proc0 }, + { MAC_CREATE_PROC1, + (macop_t)mac_mls_create_proc1 }, + { MAC_RELABEL_CRED, + (macop_t)mac_mls_relabel_cred }, + { MAC_CHECK_BPFDESC_RECEIVE, + (macop_t)mac_mls_check_bpfdesc_receive }, + { MAC_CHECK_CRED_RELABEL, + (macop_t)mac_mls_check_cred_relabel }, + { MAC_CHECK_CRED_VISIBLE, + (macop_t)mac_mls_check_cred_visible }, + { MAC_CHECK_IFNET_RELABEL, + (macop_t)mac_mls_check_ifnet_relabel }, + { MAC_CHECK_IFNET_TRANSMIT, + (macop_t)mac_mls_check_ifnet_transmit }, + { MAC_CHECK_MOUNT_STAT, + (macop_t)mac_mls_check_mount_stat }, + { MAC_CHECK_PIPE_IOCTL, + (macop_t)mac_mls_check_pipe_ioctl }, + { MAC_CHECK_PIPE_OP, + (macop_t)mac_mls_check_pipe_op }, + { MAC_CHECK_PIPE_RELABEL, + (macop_t)mac_mls_check_pipe_relabel }, + { MAC_CHECK_PROC_DEBUG, + (macop_t)mac_mls_check_proc_debug }, + { MAC_CHECK_PROC_SCHED, + (macop_t)mac_mls_check_proc_sched }, + { MAC_CHECK_PROC_SIGNAL, + (macop_t)mac_mls_check_proc_signal }, + { MAC_CHECK_SOCKET_RECEIVE, + (macop_t)mac_mls_check_socket_receive }, + { MAC_CHECK_SOCKET_RELABEL, + (macop_t)mac_mls_check_socket_relabel }, + { MAC_CHECK_SOCKET_VISIBLE, + (macop_t)mac_mls_check_socket_visible }, + { MAC_CHECK_VNODE_ACCESS, + (macop_t)mac_mls_check_vnode_access }, + { MAC_CHECK_VNODE_CHDIR, + (macop_t)mac_mls_check_vnode_chdir }, + { MAC_CHECK_VNODE_CHROOT, + (macop_t)mac_mls_check_vnode_chroot }, + { MAC_CHECK_VNODE_CREATE, + (macop_t)mac_mls_check_vnode_create }, + { MAC_CHECK_VNODE_DELETE, + (macop_t)mac_mls_check_vnode_delete }, + { MAC_CHECK_VNODE_DELETEACL, + (macop_t)mac_mls_check_vnode_deleteacl }, + { MAC_CHECK_VNODE_EXEC, + (macop_t)mac_mls_check_vnode_exec }, + { MAC_CHECK_VNODE_GETACL, + (macop_t)mac_mls_check_vnode_getacl }, + { MAC_CHECK_VNODE_GETEXTATTR, + (macop_t)mac_mls_check_vnode_getextattr }, + { MAC_CHECK_VNODE_LOOKUP, + (macop_t)mac_mls_check_vnode_lookup }, + { MAC_CHECK_VNODE_OPEN, + (macop_t)mac_mls_check_vnode_open }, + { MAC_CHECK_VNODE_READDIR, + (macop_t)mac_mls_check_vnode_readdir }, + { MAC_CHECK_VNODE_READLINK, + (macop_t)mac_mls_check_vnode_readlink }, + { MAC_CHECK_VNODE_RELABEL, + (macop_t)mac_mls_check_vnode_relabel }, + { MAC_CHECK_VNODE_RENAME_FROM, + (macop_t)mac_mls_check_vnode_rename_from }, + { MAC_CHECK_VNODE_RENAME_TO, + (macop_t)mac_mls_check_vnode_rename_to }, + { MAC_CHECK_VNODE_REVOKE, + (macop_t)mac_mls_check_vnode_revoke }, + { MAC_CHECK_VNODE_SETACL, + (macop_t)mac_mls_check_vnode_setacl }, + { MAC_CHECK_VNODE_SETEXTATTR, + (macop_t)mac_mls_check_vnode_setextattr }, + { MAC_CHECK_VNODE_SETFLAGS, + (macop_t)mac_mls_check_vnode_setflags }, + { MAC_CHECK_VNODE_SETMODE, + (macop_t)mac_mls_check_vnode_setmode }, + { MAC_CHECK_VNODE_SETOWNER, + (macop_t)mac_mls_check_vnode_setowner }, + { MAC_CHECK_VNODE_SETUTIMES, + (macop_t)mac_mls_check_vnode_setutimes }, + { MAC_CHECK_VNODE_STAT, + (macop_t)mac_mls_check_vnode_stat }, + { MAC_CHECK_VNODE_MMAP_PERMS, + (macop_t)mac_mls_check_vnode_mmap_perms }, + { MAC_CHECK_VNODE_OP, + (macop_t)mac_mls_check_vnode_op }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_mls_ops, trustedbsd_mac_mls, "TrustedBSD MAC/MLS", + MPC_LOADTIME_FLAG_NOTLATE, &mac_mls_slot); diff --git a/sys/security/mac_mls/mac_mls.h b/sys/security/mac_mls/mac_mls.h new file mode 100644 index 0000000..bb99a36 --- /dev/null +++ b/sys/security/mac_mls/mac_mls.h @@ -0,0 +1,61 @@ +/*- + * 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$ + */ +/* + * Definitions for the TrustedBSD MLS confidentiality policy module. + */ +#ifndef _SYS_SECURITY_MAC_MLS_H +#define _SYS_SECURITY_MAC_MLS_H + +#define MAC_MLS_EXTATTR_NAMESPACE EXTATTR_NAMESPACE_SYSTEM +#define MAC_MLS_EXTATTR_NAME "mac_biba" + +#define MAC_MLS_FLAG_SINGLE 0x00000001 /* mm_single initialized */ +#define MAC_MLS_FLAG_RANGE 0x00000002 /* mm_range* initialized */ +#define MAC_MLS_FLAGS_BOTH (MAC_MLS_FLAG_SINGLE | MAC_MLS_FLAG_RANGE) + +#define MAC_MLS_TYPE_UNDEF 0 /* Undefined */ +#define MAC_MLS_TYPE_LEVEL 1 /* Hierarchal level with mm_level. */ +#define MAC_MLS_TYPE_LOW 2 /* Dominated by any + * MAC_MLS_TYPE_LABEL. */ +#define MAC_MLS_TYPE_HIGH 3 /* Dominates any + * MAC_MLS_TYPE_LABEL. */ +#define MAC_MLS_TYPE_EQUAL 4 /* Equivilent to any + * MAC_MLS_TYPE_LABEL. */ + +#endif /* !_SYS_SECURITY_MAC_MLS_H */ diff --git a/sys/security/mac_none/mac_none.c b/sys/security/mac_none/mac_none.c new file mode 100644 index 0000000..8174c2a --- /dev/null +++ b/sys/security/mac_none/mac_none.c @@ -0,0 +1,1105 @@ +/*- + * 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. + * Generic mandatory access module that does nothing. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/acl.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/pipe.h> +#include <sys/sysctl.h> + +#include <fs/devfs/devfs.h> + +#include <net/bpfdesc.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/if_var.h> + +#include <netinet/in.h> +#include <netinet/ip_var.h> + +#include <vm/vm.h> + +#include <sys/mac_policy.h> + +SYSCTL_DECL(_security_mac); + +SYSCTL_NODE(_security_mac, OID_AUTO, none, CTLFLAG_RW, 0, + "TrustedBSD mac_none policy controls"); + +static int mac_none_enabled = 0; +SYSCTL_INT(_security_mac_none, OID_AUTO, enabled, CTLFLAG_RW, + &mac_none_enabled, 0, "Enforce none policy"); + +/* + * Policy module operations. + */ +static void +mac_none_destroy(struct mac_policy_conf *conf) +{ + +} + +static void +mac_none_init(struct mac_policy_conf *conf) +{ + +} + +/* + * Label operations. + */ +static void +mac_none_init_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + +} + +static void +mac_none_init_cred(struct ucred *ucred, struct label *label) +{ + +} + +static void +mac_none_init_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_none_init_ifnet(struct ifnet *ifnet, struct label *label) +{ + +} + +static void +mac_none_init_ipq(struct ipq *ipq, struct label *ipqlabel) +{ + +} + +static int +mac_none_init_mbuf(struct mbuf *mbuf, int how, struct label *label) +{ + + return (0); +} + +static void +mac_none_init_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + +} + +static void +mac_none_init_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + +} + +static void +mac_none_init_pipe(struct pipe *pipe, struct label *label) +{ + +} + +static void +mac_none_init_temp(struct label *label) +{ + +} + +static void +mac_none_init_vnode(struct vnode *vp, struct label *label) +{ + +} + +static void +mac_none_destroy_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + +} + +static void +mac_none_destroy_cred(struct ucred *ucred, struct label *label) +{ + +} + +static void +mac_none_destroy_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_none_destroy_ifnet(struct ifnet *ifnet, struct label *label) +{ + +} + +static void +mac_none_destroy_ipq(struct ipq *ipq, struct label *label) +{ + +} + +static void +mac_none_destroy_mbuf(struct mbuf *mbuf, struct label *label) +{ + +} + +static void +mac_none_destroy_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + +} + +static void +mac_none_destroy_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + +} + +static void +mac_none_destroy_pipe(struct pipe *pipe, struct label *label) +{ + +} + +static void +mac_none_destroy_temp(struct label *label) +{ + +} + +static void +mac_none_destroy_vnode(struct vnode *vp, struct label *label) +{ + +} + +static int +mac_none_externalize(struct label *label, struct mac *extmac) +{ + + return (0); +} + +static int +mac_none_internalize(struct label *label, struct mac *extmac) +{ + + return (0); +} + +/* + * Labeling event operations: file system objects, and things that look + * a lot like file system objects. + */ +static void +mac_none_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_none_create_devfs_directory(char *dirname, int dirnamelen, + struct devfs_dirent *devfs_dirent, struct label *label) +{ + +} + +static void +mac_none_create_devfs_vnode(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + +} + +static void +mac_none_create_vnode(struct ucred *cred, struct vnode *parent, + struct label *parentlabel, struct vnode *child, + struct label *childlabel) +{ + +} + +static void +mac_none_create_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + +} + +static void +mac_none_create_root_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + +} + +static void +mac_none_relabel_vnode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *label) +{ + +} + +static void +mac_none_update_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + +} + +static void +mac_none_update_procfsvnode(struct vnode *vp, struct label *vnodelabel, + struct ucred *cred) +{ + +} + +static int +mac_none_update_vnode_from_externalized(struct vnode *vp, + struct label *vnodelabel, struct mac *extmac) +{ + + return (0); +} + +static void +mac_none_update_vnode_from_mount(struct vnode *vp, struct label *vnodelabel, + struct mount *mp, struct label *fslabel) +{ + +} + +/* + * Labeling event operations: IPC object. + */ +static void +mac_none_create_mbuf_from_socket(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + +} + +static void +mac_none_create_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel) +{ + +} + +static void +mac_none_create_socket_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketlabel) +{ + +} + +static void +mac_none_relabel_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + +} + +static void +mac_none_relabel_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + +} + +static void +mac_none_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, + struct socket *socket, struct label *socketpeerlabel) +{ + +} + +static void +mac_none_set_socket_peer_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketpeerlabel) +{ + +} + +/* + * Labeling event operations: network objects. + */ +static void +mac_none_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d, + struct label *bpflabel) +{ + +} + +static void +mac_none_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel, + struct mbuf *datagram, struct label *datagramlabel) +{ + +} + +static void +mac_none_create_fragment(struct mbuf *datagram, struct label *datagramlabel, + struct mbuf *fragment, struct label *fragmentlabel) +{ + +} + +static void +mac_none_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel) +{ + +} + +static void +mac_none_create_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + +} + +static void +mac_none_create_mbuf_from_mbuf(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel) +{ + +} + +static void +mac_none_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_mbuf_multicast_encap(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + +} + +static void +mac_none_create_mbuf_netlayer(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, struct label *newmbuflabel) +{ + +} + +static int +mac_none_fragment_match(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + + return (1); +} + +static void +mac_none_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + +} + +static void +mac_none_update_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + +} + +/* + * Labeling event operations: processes. + */ +static void +mac_none_create_cred(struct ucred *cred_parent, struct ucred *cred_child) +{ + +} + +static void +mac_none_execve_transition(struct ucred *old, struct ucred *new, + struct vnode *vp, struct label *vnodelabel) +{ + +} + +static int +mac_none_execve_will_transition(struct ucred *old, struct vnode *vp, + struct label *vnodelabel) +{ + + return (0); +} + +static void +mac_none_create_proc0(struct ucred *cred) +{ + +} + +static void +mac_none_create_proc1(struct ucred *cred) +{ + +} + +static void +mac_none_relabel_cred(struct ucred *cred, struct label *newlabel) +{ + +} + +/* + * Access control checks. + */ +static int +mac_none_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, + struct ifnet *ifnet, struct label *ifnet_label) +{ + + return (0); +} + +static int +mac_none_check_cred_relabel(struct ucred *cred, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_cred_visible(struct ucred *u1, struct ucred *u2) +{ + + return (0); +} + +static int +mac_none_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, + struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (0); +} + +static int +mac_none_check_mount_stat(struct ucred *cred, struct mount *mp, + struct label *mntlabel) +{ + + return (0); +} + +static int +mac_none_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) +{ + + return (0); +} + +static int +mac_none_check_pipe_op(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, int op) +{ + + return (0); +} + +static int +mac_none_check_pipe_relabel(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_proc_debug(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_none_check_proc_sched(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_none_check_proc_signal(struct ucred *cred, struct proc *proc, int signum) +{ + + return (0); +} + +static int +mac_none_check_socket_bind(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_none_check_socket_connect(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_none_check_socket_listen(struct ucred *cred, struct vnode *vp, + struct label *socketlabel) +{ + + return (0); +} + +static int +mac_none_check_socket_receive(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (0); +} + +static int +mac_none_check_socket_relabel(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_socket_visible(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_access(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t flags) +{ + + return (0); +} + +static int +mac_none_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_create(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp, struct vattr *vap) +{ + + return (0); +} + +static int +mac_none_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + + return (0); +} + +static int +mac_none_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static int +mac_none_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + + return (0); +} + +static int +mac_none_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + + return (0); +} + +static int +mac_none_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *filelabel, mode_t acc_mode) +{ + + return (0); +} + +static int +mac_none_check_vnode_readdir(struct ucred *cred, struct vnode *vp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_readlink(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_relabel(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, int samedir, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_revoke(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static int +mac_none_check_vnode_setacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type, struct acl *acl) +{ + + return (0); +} + +static int +mac_none_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + + return (0); +} + +static int +mac_none_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + struct label *label, u_long flags) +{ + + return (0); +} + +static int +mac_none_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t mode) +{ + + return (0); +} + +static int +mac_none_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + struct label *label, uid_t uid, gid_t gid) +{ + + return (0); +} + +static int +mac_none_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct label *label, struct timespec atime, struct timespec mtime) +{ + + return (0); +} + +static int +mac_none_check_vnode_stat(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static struct mac_policy_op_entry mac_none_ops[] = +{ + { MAC_DESTROY, + (macop_t)mac_none_destroy }, + { MAC_INIT, + (macop_t)mac_none_init }, + { MAC_INIT_BPFDESC, + (macop_t)mac_none_init_bpfdesc }, + { MAC_INIT_CRED, + (macop_t)mac_none_init_cred }, + { MAC_INIT_DEVFSDIRENT, + (macop_t)mac_none_init_devfsdirent }, + { MAC_INIT_IFNET, + (macop_t)mac_none_init_ifnet }, + { MAC_INIT_IPQ, + (macop_t)mac_none_init_ipq }, + { MAC_INIT_MBUF, + (macop_t)mac_none_init_mbuf }, + { MAC_INIT_MOUNT, + (macop_t)mac_none_init_mount }, + { MAC_INIT_PIPE, + (macop_t)mac_none_init_pipe }, + { MAC_INIT_SOCKET, + (macop_t)mac_none_init_socket }, + { MAC_INIT_TEMP, + (macop_t)mac_none_init_temp }, + { MAC_INIT_VNODE, + (macop_t)mac_none_init_vnode }, + { MAC_DESTROY_BPFDESC, + (macop_t)mac_none_destroy_bpfdesc }, + { MAC_DESTROY_CRED, + (macop_t)mac_none_destroy_cred }, + { MAC_DESTROY_DEVFSDIRENT, + (macop_t)mac_none_destroy_devfsdirent }, + { MAC_DESTROY_IFNET, + (macop_t)mac_none_destroy_ifnet }, + { MAC_DESTROY_IPQ, + (macop_t)mac_none_destroy_ipq }, + { MAC_DESTROY_MBUF, + (macop_t)mac_none_destroy_mbuf }, + { MAC_DESTROY_MOUNT, + (macop_t)mac_none_destroy_mount }, + { MAC_DESTROY_PIPE, + (macop_t)mac_none_destroy_pipe }, + { MAC_DESTROY_SOCKET, + (macop_t)mac_none_destroy_socket }, + { MAC_DESTROY_TEMP, + (macop_t)mac_none_destroy_temp }, + { MAC_DESTROY_VNODE, + (macop_t)mac_none_destroy_vnode }, + { MAC_EXTERNALIZE, + (macop_t)mac_none_externalize }, + { MAC_INTERNALIZE, + (macop_t)mac_none_internalize }, + { MAC_CREATE_DEVFS_DEVICE, + (macop_t)mac_none_create_devfs_device }, + { MAC_CREATE_DEVFS_DIRECTORY, + (macop_t)mac_none_create_devfs_directory }, + { MAC_CREATE_DEVFS_VNODE, + (macop_t)mac_none_create_devfs_vnode }, + { MAC_CREATE_VNODE, + (macop_t)mac_none_create_vnode }, + { MAC_CREATE_MOUNT, + (macop_t)mac_none_create_mount }, + { MAC_CREATE_ROOT_MOUNT, + (macop_t)mac_none_create_root_mount }, + { MAC_RELABEL_VNODE, + (macop_t)mac_none_relabel_vnode }, + { MAC_UPDATE_DEVFSDIRENT, + (macop_t)mac_none_update_devfsdirent }, + { MAC_UPDATE_PROCFSVNODE, + (macop_t)mac_none_update_procfsvnode }, + { MAC_UPDATE_VNODE_FROM_EXTERNALIZED, + (macop_t)mac_none_update_vnode_from_externalized }, + { MAC_UPDATE_VNODE_FROM_MOUNT, + (macop_t)mac_none_update_vnode_from_mount }, + { MAC_CREATE_MBUF_FROM_SOCKET, + (macop_t)mac_none_create_mbuf_from_socket }, + { MAC_CREATE_PIPE, + (macop_t)mac_none_create_pipe }, + { MAC_CREATE_SOCKET, + (macop_t)mac_none_create_socket }, + { MAC_CREATE_SOCKET_FROM_SOCKET, + (macop_t)mac_none_create_socket_from_socket }, + { MAC_RELABEL_PIPE, + (macop_t)mac_none_relabel_pipe }, + { MAC_RELABEL_SOCKET, + (macop_t)mac_none_relabel_socket }, + { MAC_SET_SOCKET_PEER_FROM_MBUF, + (macop_t)mac_none_set_socket_peer_from_mbuf }, + { MAC_SET_SOCKET_PEER_FROM_SOCKET, + (macop_t)mac_none_set_socket_peer_from_socket }, + { MAC_CREATE_BPFDESC, + (macop_t)mac_none_create_bpfdesc }, + { MAC_CREATE_IFNET, + (macop_t)mac_none_create_ifnet }, + { MAC_CREATE_IPQ, + (macop_t)mac_none_create_ipq }, + { MAC_CREATE_DATAGRAM_FROM_IPQ, + (macop_t)mac_none_create_datagram_from_ipq }, + { MAC_CREATE_FRAGMENT, + (macop_t)mac_none_create_fragment }, + { MAC_CREATE_IPQ, + (macop_t)mac_none_create_ipq }, + { MAC_CREATE_MBUF_FROM_MBUF, + (macop_t)mac_none_create_mbuf_from_mbuf }, + { MAC_CREATE_MBUF_LINKLAYER, + (macop_t)mac_none_create_mbuf_linklayer }, + { MAC_CREATE_MBUF_FROM_BPFDESC, + (macop_t)mac_none_create_mbuf_from_bpfdesc }, + { MAC_CREATE_MBUF_FROM_IFNET, + (macop_t)mac_none_create_mbuf_from_ifnet }, + { MAC_CREATE_MBUF_MULTICAST_ENCAP, + (macop_t)mac_none_create_mbuf_multicast_encap }, + { MAC_CREATE_MBUF_NETLAYER, + (macop_t)mac_none_create_mbuf_netlayer }, + { MAC_FRAGMENT_MATCH, + (macop_t)mac_none_fragment_match }, + { MAC_RELABEL_IFNET, + (macop_t)mac_none_relabel_ifnet }, + { MAC_UPDATE_IPQ, + (macop_t)mac_none_update_ipq }, + { MAC_CREATE_CRED, + (macop_t)mac_none_create_cred }, + { MAC_EXECVE_TRANSITION, + (macop_t)mac_none_execve_transition }, + { MAC_EXECVE_WILL_TRANSITION, + (macop_t)mac_none_execve_will_transition }, + { MAC_CREATE_PROC0, + (macop_t)mac_none_create_proc0 }, + { MAC_CREATE_PROC1, + (macop_t)mac_none_create_proc1 }, + { MAC_RELABEL_CRED, + (macop_t)mac_none_relabel_cred }, + { MAC_CHECK_BPFDESC_RECEIVE, + (macop_t)mac_none_check_bpfdesc_receive }, + { MAC_CHECK_CRED_RELABEL, + (macop_t)mac_none_check_cred_relabel }, + { MAC_CHECK_CRED_VISIBLE, + (macop_t)mac_none_check_cred_visible }, + { MAC_CHECK_IFNET_RELABEL, + (macop_t)mac_none_check_ifnet_relabel }, + { MAC_CHECK_IFNET_TRANSMIT, + (macop_t)mac_none_check_ifnet_transmit }, + { MAC_CHECK_MOUNT_STAT, + (macop_t)mac_none_check_mount_stat }, + { MAC_CHECK_PIPE_IOCTL, + (macop_t)mac_none_check_pipe_ioctl }, + { MAC_CHECK_PIPE_OP, + (macop_t)mac_none_check_pipe_op }, + { MAC_CHECK_PIPE_RELABEL, + (macop_t)mac_none_check_pipe_relabel }, + { MAC_CHECK_PROC_DEBUG, + (macop_t)mac_none_check_proc_debug }, + { MAC_CHECK_PROC_SCHED, + (macop_t)mac_none_check_proc_sched }, + { MAC_CHECK_PROC_SIGNAL, + (macop_t)mac_none_check_proc_signal }, + { MAC_CHECK_SOCKET_BIND, + (macop_t)mac_none_check_socket_bind }, + { MAC_CHECK_SOCKET_CONNECT, + (macop_t)mac_none_check_socket_connect }, + { MAC_CHECK_SOCKET_LISTEN, + (macop_t)mac_none_check_socket_listen }, + { MAC_CHECK_SOCKET_RECEIVE, + (macop_t)mac_none_check_socket_receive }, + { MAC_CHECK_SOCKET_RELABEL, + (macop_t)mac_none_check_socket_relabel }, + { MAC_CHECK_SOCKET_VISIBLE, + (macop_t)mac_none_check_socket_visible }, + { MAC_CHECK_VNODE_ACCESS, + (macop_t)mac_none_check_vnode_access }, + { MAC_CHECK_VNODE_CHDIR, + (macop_t)mac_none_check_vnode_chdir }, + { MAC_CHECK_VNODE_CHROOT, + (macop_t)mac_none_check_vnode_chroot }, + { MAC_CHECK_VNODE_CREATE, + (macop_t)mac_none_check_vnode_create }, + { MAC_CHECK_VNODE_DELETE, + (macop_t)mac_none_check_vnode_delete }, + { MAC_CHECK_VNODE_DELETEACL, + (macop_t)mac_none_check_vnode_deleteacl }, + { MAC_CHECK_VNODE_EXEC, + (macop_t)mac_none_check_vnode_exec }, + { MAC_CHECK_VNODE_GETACL, + (macop_t)mac_none_check_vnode_getacl }, + { MAC_CHECK_VNODE_GETEXTATTR, + (macop_t)mac_none_check_vnode_getextattr }, + { MAC_CHECK_VNODE_LOOKUP, + (macop_t)mac_none_check_vnode_lookup }, + { MAC_CHECK_VNODE_OPEN, + (macop_t)mac_none_check_vnode_open }, + { MAC_CHECK_VNODE_READDIR, + (macop_t)mac_none_check_vnode_readdir }, + { MAC_CHECK_VNODE_READLINK, + (macop_t)mac_none_check_vnode_readlink }, + { MAC_CHECK_VNODE_RELABEL, + (macop_t)mac_none_check_vnode_relabel }, + { MAC_CHECK_VNODE_RENAME_FROM, + (macop_t)mac_none_check_vnode_rename_from }, + { MAC_CHECK_VNODE_RENAME_TO, + (macop_t)mac_none_check_vnode_rename_to }, + { MAC_CHECK_VNODE_REVOKE, + (macop_t)mac_none_check_vnode_revoke }, + { MAC_CHECK_VNODE_SETACL, + (macop_t)mac_none_check_vnode_setacl }, + { MAC_CHECK_VNODE_SETEXTATTR, + (macop_t)mac_none_check_vnode_setextattr }, + { MAC_CHECK_VNODE_SETFLAGS, + (macop_t)mac_none_check_vnode_setflags }, + { MAC_CHECK_VNODE_SETMODE, + (macop_t)mac_none_check_vnode_setmode }, + { MAC_CHECK_VNODE_SETOWNER, + (macop_t)mac_none_check_vnode_setowner }, + { MAC_CHECK_VNODE_SETUTIMES, + (macop_t)mac_none_check_vnode_setutimes }, + { MAC_CHECK_VNODE_STAT, + (macop_t)mac_none_check_vnode_stat }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_none_ops, trustedbsd_mac_none, "TrustedBSD MAC/None", + MPC_LOADTIME_FLAG_UNLOADOK, 0); diff --git a/sys/security/mac_seeotheruids/mac_seeotheruids.c b/sys/security/mac_seeotheruids/mac_seeotheruids.c new file mode 100644 index 0000000..8233724 --- /dev/null +++ b/sys/security/mac_seeotheruids/mac_seeotheruids.c @@ -0,0 +1,179 @@ +/*- + * 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); diff --git a/sys/security/mac_stub/mac_stub.c b/sys/security/mac_stub/mac_stub.c new file mode 100644 index 0000000..8174c2a --- /dev/null +++ b/sys/security/mac_stub/mac_stub.c @@ -0,0 +1,1105 @@ +/*- + * 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. + * Generic mandatory access module that does nothing. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/acl.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/pipe.h> +#include <sys/sysctl.h> + +#include <fs/devfs/devfs.h> + +#include <net/bpfdesc.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/if_var.h> + +#include <netinet/in.h> +#include <netinet/ip_var.h> + +#include <vm/vm.h> + +#include <sys/mac_policy.h> + +SYSCTL_DECL(_security_mac); + +SYSCTL_NODE(_security_mac, OID_AUTO, none, CTLFLAG_RW, 0, + "TrustedBSD mac_none policy controls"); + +static int mac_none_enabled = 0; +SYSCTL_INT(_security_mac_none, OID_AUTO, enabled, CTLFLAG_RW, + &mac_none_enabled, 0, "Enforce none policy"); + +/* + * Policy module operations. + */ +static void +mac_none_destroy(struct mac_policy_conf *conf) +{ + +} + +static void +mac_none_init(struct mac_policy_conf *conf) +{ + +} + +/* + * Label operations. + */ +static void +mac_none_init_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + +} + +static void +mac_none_init_cred(struct ucred *ucred, struct label *label) +{ + +} + +static void +mac_none_init_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_none_init_ifnet(struct ifnet *ifnet, struct label *label) +{ + +} + +static void +mac_none_init_ipq(struct ipq *ipq, struct label *ipqlabel) +{ + +} + +static int +mac_none_init_mbuf(struct mbuf *mbuf, int how, struct label *label) +{ + + return (0); +} + +static void +mac_none_init_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + +} + +static void +mac_none_init_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + +} + +static void +mac_none_init_pipe(struct pipe *pipe, struct label *label) +{ + +} + +static void +mac_none_init_temp(struct label *label) +{ + +} + +static void +mac_none_init_vnode(struct vnode *vp, struct label *label) +{ + +} + +static void +mac_none_destroy_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + +} + +static void +mac_none_destroy_cred(struct ucred *ucred, struct label *label) +{ + +} + +static void +mac_none_destroy_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_none_destroy_ifnet(struct ifnet *ifnet, struct label *label) +{ + +} + +static void +mac_none_destroy_ipq(struct ipq *ipq, struct label *label) +{ + +} + +static void +mac_none_destroy_mbuf(struct mbuf *mbuf, struct label *label) +{ + +} + +static void +mac_none_destroy_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + +} + +static void +mac_none_destroy_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + +} + +static void +mac_none_destroy_pipe(struct pipe *pipe, struct label *label) +{ + +} + +static void +mac_none_destroy_temp(struct label *label) +{ + +} + +static void +mac_none_destroy_vnode(struct vnode *vp, struct label *label) +{ + +} + +static int +mac_none_externalize(struct label *label, struct mac *extmac) +{ + + return (0); +} + +static int +mac_none_internalize(struct label *label, struct mac *extmac) +{ + + return (0); +} + +/* + * Labeling event operations: file system objects, and things that look + * a lot like file system objects. + */ +static void +mac_none_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_none_create_devfs_directory(char *dirname, int dirnamelen, + struct devfs_dirent *devfs_dirent, struct label *label) +{ + +} + +static void +mac_none_create_devfs_vnode(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + +} + +static void +mac_none_create_vnode(struct ucred *cred, struct vnode *parent, + struct label *parentlabel, struct vnode *child, + struct label *childlabel) +{ + +} + +static void +mac_none_create_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + +} + +static void +mac_none_create_root_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + +} + +static void +mac_none_relabel_vnode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *label) +{ + +} + +static void +mac_none_update_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + +} + +static void +mac_none_update_procfsvnode(struct vnode *vp, struct label *vnodelabel, + struct ucred *cred) +{ + +} + +static int +mac_none_update_vnode_from_externalized(struct vnode *vp, + struct label *vnodelabel, struct mac *extmac) +{ + + return (0); +} + +static void +mac_none_update_vnode_from_mount(struct vnode *vp, struct label *vnodelabel, + struct mount *mp, struct label *fslabel) +{ + +} + +/* + * Labeling event operations: IPC object. + */ +static void +mac_none_create_mbuf_from_socket(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + +} + +static void +mac_none_create_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel) +{ + +} + +static void +mac_none_create_socket_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketlabel) +{ + +} + +static void +mac_none_relabel_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + +} + +static void +mac_none_relabel_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + +} + +static void +mac_none_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, + struct socket *socket, struct label *socketpeerlabel) +{ + +} + +static void +mac_none_set_socket_peer_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketpeerlabel) +{ + +} + +/* + * Labeling event operations: network objects. + */ +static void +mac_none_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d, + struct label *bpflabel) +{ + +} + +static void +mac_none_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel, + struct mbuf *datagram, struct label *datagramlabel) +{ + +} + +static void +mac_none_create_fragment(struct mbuf *datagram, struct label *datagramlabel, + struct mbuf *fragment, struct label *fragmentlabel) +{ + +} + +static void +mac_none_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel) +{ + +} + +static void +mac_none_create_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + +} + +static void +mac_none_create_mbuf_from_mbuf(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel) +{ + +} + +static void +mac_none_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + +} + +static void +mac_none_create_mbuf_multicast_encap(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + +} + +static void +mac_none_create_mbuf_netlayer(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, struct label *newmbuflabel) +{ + +} + +static int +mac_none_fragment_match(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + + return (1); +} + +static void +mac_none_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + +} + +static void +mac_none_update_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + +} + +/* + * Labeling event operations: processes. + */ +static void +mac_none_create_cred(struct ucred *cred_parent, struct ucred *cred_child) +{ + +} + +static void +mac_none_execve_transition(struct ucred *old, struct ucred *new, + struct vnode *vp, struct label *vnodelabel) +{ + +} + +static int +mac_none_execve_will_transition(struct ucred *old, struct vnode *vp, + struct label *vnodelabel) +{ + + return (0); +} + +static void +mac_none_create_proc0(struct ucred *cred) +{ + +} + +static void +mac_none_create_proc1(struct ucred *cred) +{ + +} + +static void +mac_none_relabel_cred(struct ucred *cred, struct label *newlabel) +{ + +} + +/* + * Access control checks. + */ +static int +mac_none_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, + struct ifnet *ifnet, struct label *ifnet_label) +{ + + return (0); +} + +static int +mac_none_check_cred_relabel(struct ucred *cred, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_cred_visible(struct ucred *u1, struct ucred *u2) +{ + + return (0); +} + +static int +mac_none_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, + struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (0); +} + +static int +mac_none_check_mount_stat(struct ucred *cred, struct mount *mp, + struct label *mntlabel) +{ + + return (0); +} + +static int +mac_none_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) +{ + + return (0); +} + +static int +mac_none_check_pipe_op(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, int op) +{ + + return (0); +} + +static int +mac_none_check_pipe_relabel(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_proc_debug(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_none_check_proc_sched(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_none_check_proc_signal(struct ucred *cred, struct proc *proc, int signum) +{ + + return (0); +} + +static int +mac_none_check_socket_bind(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_none_check_socket_connect(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_none_check_socket_listen(struct ucred *cred, struct vnode *vp, + struct label *socketlabel) +{ + + return (0); +} + +static int +mac_none_check_socket_receive(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (0); +} + +static int +mac_none_check_socket_relabel(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_socket_visible(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_access(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t flags) +{ + + return (0); +} + +static int +mac_none_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_create(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp, struct vattr *vap) +{ + + return (0); +} + +static int +mac_none_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + + return (0); +} + +static int +mac_none_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static int +mac_none_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + + return (0); +} + +static int +mac_none_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + + return (0); +} + +static int +mac_none_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *filelabel, mode_t acc_mode) +{ + + return (0); +} + +static int +mac_none_check_vnode_readdir(struct ucred *cred, struct vnode *vp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_readlink(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_relabel(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_none_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, int samedir, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_none_check_vnode_revoke(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static int +mac_none_check_vnode_setacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type, struct acl *acl) +{ + + return (0); +} + +static int +mac_none_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + + return (0); +} + +static int +mac_none_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + struct label *label, u_long flags) +{ + + return (0); +} + +static int +mac_none_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t mode) +{ + + return (0); +} + +static int +mac_none_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + struct label *label, uid_t uid, gid_t gid) +{ + + return (0); +} + +static int +mac_none_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct label *label, struct timespec atime, struct timespec mtime) +{ + + return (0); +} + +static int +mac_none_check_vnode_stat(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static struct mac_policy_op_entry mac_none_ops[] = +{ + { MAC_DESTROY, + (macop_t)mac_none_destroy }, + { MAC_INIT, + (macop_t)mac_none_init }, + { MAC_INIT_BPFDESC, + (macop_t)mac_none_init_bpfdesc }, + { MAC_INIT_CRED, + (macop_t)mac_none_init_cred }, + { MAC_INIT_DEVFSDIRENT, + (macop_t)mac_none_init_devfsdirent }, + { MAC_INIT_IFNET, + (macop_t)mac_none_init_ifnet }, + { MAC_INIT_IPQ, + (macop_t)mac_none_init_ipq }, + { MAC_INIT_MBUF, + (macop_t)mac_none_init_mbuf }, + { MAC_INIT_MOUNT, + (macop_t)mac_none_init_mount }, + { MAC_INIT_PIPE, + (macop_t)mac_none_init_pipe }, + { MAC_INIT_SOCKET, + (macop_t)mac_none_init_socket }, + { MAC_INIT_TEMP, + (macop_t)mac_none_init_temp }, + { MAC_INIT_VNODE, + (macop_t)mac_none_init_vnode }, + { MAC_DESTROY_BPFDESC, + (macop_t)mac_none_destroy_bpfdesc }, + { MAC_DESTROY_CRED, + (macop_t)mac_none_destroy_cred }, + { MAC_DESTROY_DEVFSDIRENT, + (macop_t)mac_none_destroy_devfsdirent }, + { MAC_DESTROY_IFNET, + (macop_t)mac_none_destroy_ifnet }, + { MAC_DESTROY_IPQ, + (macop_t)mac_none_destroy_ipq }, + { MAC_DESTROY_MBUF, + (macop_t)mac_none_destroy_mbuf }, + { MAC_DESTROY_MOUNT, + (macop_t)mac_none_destroy_mount }, + { MAC_DESTROY_PIPE, + (macop_t)mac_none_destroy_pipe }, + { MAC_DESTROY_SOCKET, + (macop_t)mac_none_destroy_socket }, + { MAC_DESTROY_TEMP, + (macop_t)mac_none_destroy_temp }, + { MAC_DESTROY_VNODE, + (macop_t)mac_none_destroy_vnode }, + { MAC_EXTERNALIZE, + (macop_t)mac_none_externalize }, + { MAC_INTERNALIZE, + (macop_t)mac_none_internalize }, + { MAC_CREATE_DEVFS_DEVICE, + (macop_t)mac_none_create_devfs_device }, + { MAC_CREATE_DEVFS_DIRECTORY, + (macop_t)mac_none_create_devfs_directory }, + { MAC_CREATE_DEVFS_VNODE, + (macop_t)mac_none_create_devfs_vnode }, + { MAC_CREATE_VNODE, + (macop_t)mac_none_create_vnode }, + { MAC_CREATE_MOUNT, + (macop_t)mac_none_create_mount }, + { MAC_CREATE_ROOT_MOUNT, + (macop_t)mac_none_create_root_mount }, + { MAC_RELABEL_VNODE, + (macop_t)mac_none_relabel_vnode }, + { MAC_UPDATE_DEVFSDIRENT, + (macop_t)mac_none_update_devfsdirent }, + { MAC_UPDATE_PROCFSVNODE, + (macop_t)mac_none_update_procfsvnode }, + { MAC_UPDATE_VNODE_FROM_EXTERNALIZED, + (macop_t)mac_none_update_vnode_from_externalized }, + { MAC_UPDATE_VNODE_FROM_MOUNT, + (macop_t)mac_none_update_vnode_from_mount }, + { MAC_CREATE_MBUF_FROM_SOCKET, + (macop_t)mac_none_create_mbuf_from_socket }, + { MAC_CREATE_PIPE, + (macop_t)mac_none_create_pipe }, + { MAC_CREATE_SOCKET, + (macop_t)mac_none_create_socket }, + { MAC_CREATE_SOCKET_FROM_SOCKET, + (macop_t)mac_none_create_socket_from_socket }, + { MAC_RELABEL_PIPE, + (macop_t)mac_none_relabel_pipe }, + { MAC_RELABEL_SOCKET, + (macop_t)mac_none_relabel_socket }, + { MAC_SET_SOCKET_PEER_FROM_MBUF, + (macop_t)mac_none_set_socket_peer_from_mbuf }, + { MAC_SET_SOCKET_PEER_FROM_SOCKET, + (macop_t)mac_none_set_socket_peer_from_socket }, + { MAC_CREATE_BPFDESC, + (macop_t)mac_none_create_bpfdesc }, + { MAC_CREATE_IFNET, + (macop_t)mac_none_create_ifnet }, + { MAC_CREATE_IPQ, + (macop_t)mac_none_create_ipq }, + { MAC_CREATE_DATAGRAM_FROM_IPQ, + (macop_t)mac_none_create_datagram_from_ipq }, + { MAC_CREATE_FRAGMENT, + (macop_t)mac_none_create_fragment }, + { MAC_CREATE_IPQ, + (macop_t)mac_none_create_ipq }, + { MAC_CREATE_MBUF_FROM_MBUF, + (macop_t)mac_none_create_mbuf_from_mbuf }, + { MAC_CREATE_MBUF_LINKLAYER, + (macop_t)mac_none_create_mbuf_linklayer }, + { MAC_CREATE_MBUF_FROM_BPFDESC, + (macop_t)mac_none_create_mbuf_from_bpfdesc }, + { MAC_CREATE_MBUF_FROM_IFNET, + (macop_t)mac_none_create_mbuf_from_ifnet }, + { MAC_CREATE_MBUF_MULTICAST_ENCAP, + (macop_t)mac_none_create_mbuf_multicast_encap }, + { MAC_CREATE_MBUF_NETLAYER, + (macop_t)mac_none_create_mbuf_netlayer }, + { MAC_FRAGMENT_MATCH, + (macop_t)mac_none_fragment_match }, + { MAC_RELABEL_IFNET, + (macop_t)mac_none_relabel_ifnet }, + { MAC_UPDATE_IPQ, + (macop_t)mac_none_update_ipq }, + { MAC_CREATE_CRED, + (macop_t)mac_none_create_cred }, + { MAC_EXECVE_TRANSITION, + (macop_t)mac_none_execve_transition }, + { MAC_EXECVE_WILL_TRANSITION, + (macop_t)mac_none_execve_will_transition }, + { MAC_CREATE_PROC0, + (macop_t)mac_none_create_proc0 }, + { MAC_CREATE_PROC1, + (macop_t)mac_none_create_proc1 }, + { MAC_RELABEL_CRED, + (macop_t)mac_none_relabel_cred }, + { MAC_CHECK_BPFDESC_RECEIVE, + (macop_t)mac_none_check_bpfdesc_receive }, + { MAC_CHECK_CRED_RELABEL, + (macop_t)mac_none_check_cred_relabel }, + { MAC_CHECK_CRED_VISIBLE, + (macop_t)mac_none_check_cred_visible }, + { MAC_CHECK_IFNET_RELABEL, + (macop_t)mac_none_check_ifnet_relabel }, + { MAC_CHECK_IFNET_TRANSMIT, + (macop_t)mac_none_check_ifnet_transmit }, + { MAC_CHECK_MOUNT_STAT, + (macop_t)mac_none_check_mount_stat }, + { MAC_CHECK_PIPE_IOCTL, + (macop_t)mac_none_check_pipe_ioctl }, + { MAC_CHECK_PIPE_OP, + (macop_t)mac_none_check_pipe_op }, + { MAC_CHECK_PIPE_RELABEL, + (macop_t)mac_none_check_pipe_relabel }, + { MAC_CHECK_PROC_DEBUG, + (macop_t)mac_none_check_proc_debug }, + { MAC_CHECK_PROC_SCHED, + (macop_t)mac_none_check_proc_sched }, + { MAC_CHECK_PROC_SIGNAL, + (macop_t)mac_none_check_proc_signal }, + { MAC_CHECK_SOCKET_BIND, + (macop_t)mac_none_check_socket_bind }, + { MAC_CHECK_SOCKET_CONNECT, + (macop_t)mac_none_check_socket_connect }, + { MAC_CHECK_SOCKET_LISTEN, + (macop_t)mac_none_check_socket_listen }, + { MAC_CHECK_SOCKET_RECEIVE, + (macop_t)mac_none_check_socket_receive }, + { MAC_CHECK_SOCKET_RELABEL, + (macop_t)mac_none_check_socket_relabel }, + { MAC_CHECK_SOCKET_VISIBLE, + (macop_t)mac_none_check_socket_visible }, + { MAC_CHECK_VNODE_ACCESS, + (macop_t)mac_none_check_vnode_access }, + { MAC_CHECK_VNODE_CHDIR, + (macop_t)mac_none_check_vnode_chdir }, + { MAC_CHECK_VNODE_CHROOT, + (macop_t)mac_none_check_vnode_chroot }, + { MAC_CHECK_VNODE_CREATE, + (macop_t)mac_none_check_vnode_create }, + { MAC_CHECK_VNODE_DELETE, + (macop_t)mac_none_check_vnode_delete }, + { MAC_CHECK_VNODE_DELETEACL, + (macop_t)mac_none_check_vnode_deleteacl }, + { MAC_CHECK_VNODE_EXEC, + (macop_t)mac_none_check_vnode_exec }, + { MAC_CHECK_VNODE_GETACL, + (macop_t)mac_none_check_vnode_getacl }, + { MAC_CHECK_VNODE_GETEXTATTR, + (macop_t)mac_none_check_vnode_getextattr }, + { MAC_CHECK_VNODE_LOOKUP, + (macop_t)mac_none_check_vnode_lookup }, + { MAC_CHECK_VNODE_OPEN, + (macop_t)mac_none_check_vnode_open }, + { MAC_CHECK_VNODE_READDIR, + (macop_t)mac_none_check_vnode_readdir }, + { MAC_CHECK_VNODE_READLINK, + (macop_t)mac_none_check_vnode_readlink }, + { MAC_CHECK_VNODE_RELABEL, + (macop_t)mac_none_check_vnode_relabel }, + { MAC_CHECK_VNODE_RENAME_FROM, + (macop_t)mac_none_check_vnode_rename_from }, + { MAC_CHECK_VNODE_RENAME_TO, + (macop_t)mac_none_check_vnode_rename_to }, + { MAC_CHECK_VNODE_REVOKE, + (macop_t)mac_none_check_vnode_revoke }, + { MAC_CHECK_VNODE_SETACL, + (macop_t)mac_none_check_vnode_setacl }, + { MAC_CHECK_VNODE_SETEXTATTR, + (macop_t)mac_none_check_vnode_setextattr }, + { MAC_CHECK_VNODE_SETFLAGS, + (macop_t)mac_none_check_vnode_setflags }, + { MAC_CHECK_VNODE_SETMODE, + (macop_t)mac_none_check_vnode_setmode }, + { MAC_CHECK_VNODE_SETOWNER, + (macop_t)mac_none_check_vnode_setowner }, + { MAC_CHECK_VNODE_SETUTIMES, + (macop_t)mac_none_check_vnode_setutimes }, + { MAC_CHECK_VNODE_STAT, + (macop_t)mac_none_check_vnode_stat }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_none_ops, trustedbsd_mac_none, "TrustedBSD MAC/None", + MPC_LOADTIME_FLAG_UNLOADOK, 0); diff --git a/sys/security/mac_test/mac_test.c b/sys/security/mac_test/mac_test.c new file mode 100644 index 0000000..c3050d2 --- /dev/null +++ b/sys/security/mac_test/mac_test.c @@ -0,0 +1,1311 @@ +/*- + * 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. + * Generic mandatory access module that does nothing. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/acl.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 <fs/devfs/devfs.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, test, CTLFLAG_RW, 0, + "TrustedBSD mac_test policy controls"); + +static int mac_test_enabled = 0; +SYSCTL_INT(_security_mac_test, OID_AUTO, enabled, CTLFLAG_RW, + &mac_test_enabled, 0, "Enforce test policy"); + +#define BPFMAGIC 0xfe1ad1b6 +#define DEVFSMAGIC 0x9ee79c32 +#define IFNETMAGIC 0xc218b120 +#define IPQMAGIC 0x206188ef +#define MBUFMAGIC 0xbbefa5bb +#define MOUNTMAGIC 0xc7c46e47 +#define SOCKETMAGIC 0x9199c6cd +#define PIPEMAGIC 0xdc6c9919 +#define CREDMAGIC 0x9a5a4987 +#define TEMPMAGIC 0x70336678 +#define VNODEMAGIC 0x1a67a45c +#define EXMAGIC 0x849ba1fd + +#define SLOT(x) LABEL_TO_SLOT((x), test_slot).l_long +static int test_slot; +SYSCTL_INT(_security_mac_test, OID_AUTO, slot, CTLFLAG_RD, + &test_slot, 0, "Slot allocated by framework"); + +static int init_count_bpfdesc; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_bpfdesc, CTLFLAG_RD, + &init_count_bpfdesc, 0, "bpfdesc init calls"); +static int init_count_cred; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_cred, CTLFLAG_RD, + &init_count_cred, 0, "cred init calls"); +static int init_count_devfsdirent; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_devfsdirent, CTLFLAG_RD, + &init_count_devfsdirent, 0, "devfsdirent init calls"); +static int init_count_ifnet; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_ifnet, CTLFLAG_RD, + &init_count_ifnet, 0, "ifnet init calls"); +static int init_count_ipq; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_ipq, CTLFLAG_RD, + &init_count_ipq, 0, "ipq init calls"); +static int init_count_mbuf; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_mbuf, CTLFLAG_RD, + &init_count_mbuf, 0, "mbuf init calls"); +static int init_count_mount; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_mount, CTLFLAG_RD, + &init_count_mount, 0, "mount init calls"); +static int init_count_socket; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_socket, CTLFLAG_RD, + &init_count_socket, 0, "socket init calls"); +static int init_count_pipe; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_pipe, CTLFLAG_RD, + &init_count_pipe, 0, "pipe init calls"); +static int init_count_temp; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_temp, CTLFLAG_RD, + &init_count_temp, 0, "temp init calls"); +static int init_count_vnode; +SYSCTL_INT(_security_mac_test, OID_AUTO, init_count_vnode, CTLFLAG_RD, + &init_count_vnode, 0, "vnode init calls"); + +static int destroy_count_bpfdesc; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_bpfdesc, CTLFLAG_RD, + &destroy_count_bpfdesc, 0, "bpfdesc destroy calls"); +static int destroy_count_cred; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_cred, CTLFLAG_RD, + &destroy_count_cred, 0, "cred destroy calls"); +static int destroy_count_devfsdirent; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_devfsdirent, CTLFLAG_RD, + &destroy_count_devfsdirent, 0, "devfsdirent destroy calls"); +static int destroy_count_ifnet; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_ifnet, CTLFLAG_RD, + &destroy_count_ifnet, 0, "ifnet destroy calls"); +static int destroy_count_ipq; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_ipq, CTLFLAG_RD, + &destroy_count_ipq, 0, "ipq destroy calls"); +static int destroy_count_mbuf; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_mbuf, CTLFLAG_RD, + &destroy_count_mbuf, 0, "mbuf destroy calls"); +static int destroy_count_mount; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_mount, CTLFLAG_RD, + &destroy_count_mount, 0, "mount destroy calls"); +static int destroy_count_socket; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_socket, CTLFLAG_RD, + &destroy_count_socket, 0, "socket destroy calls"); +static int destroy_count_pipe; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_pipe, CTLFLAG_RD, + &destroy_count_pipe, 0, "pipe destroy calls"); +static int destroy_count_temp; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_temp, CTLFLAG_RD, + &destroy_count_temp, 0, "temp destroy calls"); +static int destroy_count_vnode; +SYSCTL_INT(_security_mac_test, OID_AUTO, destroy_count_vnode, CTLFLAG_RD, + &destroy_count_vnode, 0, "vnode destroy calls"); + +static int externalize_count; +SYSCTL_INT(_security_mac_test, OID_AUTO, externalize_count, CTLFLAG_RD, + &externalize_count, 0, "Subject/object externalize calls"); +static int internalize_count; +SYSCTL_INT(_security_mac_test, OID_AUTO, internalize_count, CTLFLAG_RD, + &internalize_count, 0, "Subject/object internalize calls"); + +/* + * Policy module operations. + */ +static void +mac_test_destroy(struct mac_policy_conf *conf) +{ + +} + +static void +mac_test_init(struct mac_policy_conf *conf) +{ + +} + +/* + * Label operations. + */ +static void +mac_test_init_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + + SLOT(label) = BPFMAGIC; + atomic_add_int(&init_count_bpfdesc, 1); +} + +static void +mac_test_init_cred(struct ucred *ucred, struct label *label) +{ + + SLOT(label) = CREDMAGIC; + atomic_add_int(&init_count_cred, 1); +} + +static void +mac_test_init_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + + SLOT(label) = DEVFSMAGIC; + atomic_add_int(&init_count_devfsdirent, 1); +} + +static void +mac_test_init_ifnet(struct ifnet *ifnet, struct label *label) +{ + + SLOT(label) = IFNETMAGIC; + atomic_add_int(&init_count_ifnet, 1); +} + +static void +mac_test_init_ipq(struct ipq *ipq, struct label *label) +{ + + SLOT(label) = IPQMAGIC; + atomic_add_int(&init_count_ipq, 1); +} + +static int +mac_test_init_mbuf(struct mbuf *mbuf, int how, struct label *label) +{ + + SLOT(label) = MBUFMAGIC; + atomic_add_int(&init_count_mbuf, 1); + return (0); +} + +static void +mac_test_init_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + + SLOT(mntlabel) = MOUNTMAGIC; + SLOT(fslabel) = MOUNTMAGIC; + atomic_add_int(&init_count_mount, 1); +} + +static void +mac_test_init_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + + SLOT(label) = SOCKETMAGIC; + SLOT(peerlabel) = SOCKETMAGIC; + atomic_add_int(&init_count_socket, 1); +} + +static void +mac_test_init_pipe(struct pipe *pipe, struct label *label) +{ + + SLOT(label) = PIPEMAGIC; + atomic_add_int(&init_count_pipe, 1); +} + +static void +mac_test_init_temp(struct label *label) +{ + + SLOT(label) = TEMPMAGIC; + atomic_add_int(&init_count_temp, 1); +} + +static void +mac_test_init_vnode(struct vnode *vp, struct label *label) +{ + + SLOT(label) = VNODEMAGIC; + atomic_add_int(&init_count_vnode, 1); +} + +static void +mac_test_destroy_bpfdesc(struct bpf_d *bpf_d, struct label *label) +{ + + if (SLOT(label) == BPFMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_bpfdesc, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_bpfdesc: dup destroy"); + } else { + Debugger("mac_test_destroy_bpfdesc: corrupted label"); + } +} + +static void +mac_test_destroy_cred(struct ucred *ucred, struct label *label) +{ + + if (SLOT(label) == CREDMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_cred, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_cred: dup destroy"); + } else { + Debugger("mac_test_destroy_cred: corrupted label"); + } +} + +static void +mac_test_destroy_devfsdirent(struct devfs_dirent *devfs_dirent, + struct label *label) +{ + + if (SLOT(label) == DEVFSMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_devfsdirent, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_devfsdirent: dup destroy"); + } else { + Debugger("mac_test_destroy_devfsdirent: corrupted label"); + } +} + +static void +mac_test_destroy_ifnet(struct ifnet *ifnet, struct label *label) +{ + + if (SLOT(label) == IFNETMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_ifnet, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_ifnet: dup destroy"); + } else { + Debugger("mac_test_destroy_ifnet: corrupted label"); + } +} + +static void +mac_test_destroy_ipq(struct ipq *ipq, struct label *label) +{ + + if (SLOT(label) == IPQMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_ipq, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_ipq: dup destroy"); + } else { + Debugger("mac_test_destroy_ipq: corrupted label"); + } +} + +static void +mac_test_destroy_mbuf(struct mbuf *mbuf, struct label *label) +{ + + if (SLOT(label) == MBUFMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_mbuf, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_mbuf: dup destroy"); + } else { + Debugger("mac_test_destroy_mbuf: corrupted label"); + } +} + +static void +mac_test_destroy_mount(struct mount *mount, struct label *mntlabel, + struct label *fslabel) +{ + + if ((SLOT(mntlabel) == MOUNTMAGIC || SLOT(mntlabel) == 0) && + (SLOT(fslabel) == MOUNTMAGIC || SLOT(fslabel) == 0)) { + atomic_add_int(&destroy_count_mount, 1); + SLOT(mntlabel) = EXMAGIC; + SLOT(fslabel) = EXMAGIC; + } else if (SLOT(mntlabel) == EXMAGIC || SLOT(fslabel) == EXMAGIC) { + Debugger("mac_test_destroy_mount: dup destroy"); + } else { + Debugger("mac_test_destroy_mount: corrupted label"); + } +} + +static void +mac_test_destroy_socket(struct socket *socket, struct label *label, + struct label *peerlabel) +{ + + if ((SLOT(label) == SOCKETMAGIC || SLOT(label) == 0) && + (SLOT(peerlabel) == SOCKETMAGIC || SLOT(peerlabel) == 0)) { + atomic_add_int(&destroy_count_socket, 1); + SLOT(label) = EXMAGIC; + SLOT(peerlabel) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC || SLOT(peerlabel) == EXMAGIC) { + Debugger("mac_test_destroy_socket: dup destroy"); + } else { + Debugger("mac_test_destroy_socket: corrupted label"); + } +} +static void +mac_test_destroy_pipe(struct pipe *pipe, struct label *label) +{ + + if ((SLOT(label) == PIPEMAGIC || SLOT(label) == 0)) { + atomic_add_int(&destroy_count_pipe, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_pipe: dup destroy"); + } else { + Debugger("mac_test_destroy_pipe: corrupted label"); + } +} + +static void +mac_test_destroy_temp(struct label *label) +{ + + if (SLOT(label) == TEMPMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_temp, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_temp: dup destroy"); + } else { + Debugger("mac_test_destroy_temp: corrupted label"); + } +} + +static void +mac_test_destroy_vnode(struct vnode *vp, struct label *label) +{ + + if (SLOT(label) == VNODEMAGIC || SLOT(label) == 0) { + atomic_add_int(&destroy_count_vnode, 1); + SLOT(label) = EXMAGIC; + } else if (SLOT(label) == EXMAGIC) { + Debugger("mac_test_destroy_vnode: dup destroy"); + } else { + Debugger("mac_test_destroy_vnode: corrupted label"); + } +} + +static int +mac_test_externalize(struct label *label, struct mac *extmac) +{ + + atomic_add_int(&externalize_count, 1); + + return (0); +} + +static int +mac_test_internalize(struct label *label, struct mac *extmac) +{ + + atomic_add_int(&internalize_count, 1); + + return (0); +} + +/* + * Labeling event operations: file system objects, and things that look + * a lot like file system objects. + */ +static void +mac_test_create_devfs_device(dev_t dev, struct devfs_dirent *devfs_dirent, + struct label *label) +{ + +} + +static void +mac_test_create_devfs_directory(char *dirname, int dirnamelen, + struct devfs_dirent *devfs_dirent, struct label *label) +{ + +} + +static void +mac_test_create_devfs_vnode(struct devfs_dirent *devfs_dirent, + struct label *direntlabel, struct vnode *vp, struct label *vnodelabel) +{ + +} + +static void +mac_test_create_vnode(struct ucred *cred, struct vnode *parent, + struct label *parentlabel, struct vnode *child, struct label *childlabel) +{ + +} + +static void +mac_test_create_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + +} + +static void +mac_test_create_root_mount(struct ucred *cred, struct mount *mp, + struct label *mntlabel, struct label *fslabel) +{ + +} + +static void +mac_test_relabel_vnode(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *label) +{ + +} + +static void +mac_test_update_devfsdirent(struct devfs_dirent *devfs_dirent, + struct vnode *vp) +{ + +} + +static void +mac_test_update_procfsvnode(struct vnode *vp, struct label *vnodelabel, + struct ucred *cred) +{ + +} + +static int +mac_test_update_vnode_from_externalized(struct vnode *vp, + struct label *vnodelabel, struct mac *extmac) +{ + + return (0); +} + +static void +mac_test_update_vnode_from_mount(struct vnode *vp, struct label *vnodelabel, + struct mount *mp, struct label *fslabel) +{ + +} + +/* + * Labeling event operations: IPC object. + */ +static void +mac_test_create_mbuf_from_socket(struct socket *so, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + +} + +static void +mac_test_create_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + +} + +static void +mac_test_create_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel) +{ + +} + +static void +mac_test_create_socket_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketlabel) +{ + +} + +static void +mac_test_relabel_socket(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + +} + +static void +mac_test_relabel_pipe(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + +} + +static void +mac_test_set_socket_peer_from_mbuf(struct mbuf *mbuf, struct label *mbuflabel, + struct socket *socket, struct label *socketpeerlabel) +{ + +} + +/* + * Labeling event operations: network objects. + */ +static void +mac_test_set_socket_peer_from_socket(struct socket *oldsocket, + struct label *oldsocketlabel, struct socket *newsocket, + struct label *newsocketpeerlabel) +{ + +} + +static void +mac_test_create_bpfdesc(struct ucred *cred, struct bpf_d *bpf_d, + struct label *bpflabel) +{ + +} + +static void +mac_test_create_datagram_from_ipq(struct ipq *ipq, struct label *ipqlabel, + struct mbuf *datagram, struct label *datagramlabel) +{ + +} + +static void +mac_test_create_fragment(struct mbuf *datagram, struct label *datagramlabel, + struct mbuf *fragment, struct label *fragmentlabel) +{ + +} + +static void +mac_test_create_ifnet(struct ifnet *ifnet, struct label *ifnetlabel) +{ + +} + +static void +mac_test_create_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + +} + +static void +mac_test_create_mbuf_from_mbuf(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel) +{ + +} + +static void +mac_test_create_mbuf_linklayer(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + +} + +static void +mac_test_create_mbuf_from_bpfdesc(struct bpf_d *bpf_d, struct label *bpflabel, + struct mbuf *mbuf, struct label *mbuflabel) +{ + +} + +static void +mac_test_create_mbuf_from_ifnet(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + +} + +static void +mac_test_create_mbuf_multicast_encap(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *newmbuf, struct label *newmbuflabel) +{ + +} + +static void +mac_test_create_mbuf_netlayer(struct mbuf *oldmbuf, + struct label *oldmbuflabel, struct mbuf *newmbuf, + struct label *newmbuflabel) +{ + +} + +static int +mac_test_fragment_match(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + + return (1); +} + +static void +mac_test_relabel_ifnet(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + +} + +static void +mac_test_update_ipq(struct mbuf *fragment, struct label *fragmentlabel, + struct ipq *ipq, struct label *ipqlabel) +{ + +} + +/* + * Labeling event operations: processes. + */ +static void +mac_test_create_cred(struct ucred *cred_parent, struct ucred *cred_child) +{ + +} + +static void +mac_test_execve_transition(struct ucred *old, struct ucred *new, + struct vnode *vp, struct label *filelabel) +{ + +} + +static int +mac_test_execve_will_transition(struct ucred *old, struct vnode *vp, + struct label *filelabel) +{ + + return (0); +} + +static void +mac_test_create_proc0(struct ucred *cred) +{ + +} + +static void +mac_test_create_proc1(struct ucred *cred) +{ + +} + +static void +mac_test_relabel_cred(struct ucred *cred, struct label *newlabel) +{ + +} + +/* + * Access control checks. + */ +static int +mac_test_check_bpfdesc_receive(struct bpf_d *bpf_d, struct label *bpflabel, + struct ifnet *ifnet, struct label *ifnetlabel) +{ + + return (0); +} + +static int +mac_test_check_cred_relabel(struct ucred *cred, struct label *newlabel) +{ + + return (0); +} + +static int +mac_test_check_cred_visible(struct ucred *u1, struct ucred *u2) +{ + + return (0); +} + +static int +mac_test_check_ifnet_relabel(struct ucred *cred, struct ifnet *ifnet, + struct label *ifnetlabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_test_check_ifnet_transmit(struct ifnet *ifnet, struct label *ifnetlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (0); +} + +static int +mac_test_check_mount_stat(struct ucred *cred, struct mount *mp, + struct label *mntlabel) +{ + + return (0); +} + +static int +mac_test_check_pipe_ioctl(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, unsigned long cmd, void /* caddr_t */ *data) +{ + + return (0); +} + +static int +mac_test_check_pipe_op(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, int op) +{ + + return (0); +} + +static int +mac_test_check_pipe_relabel(struct ucred *cred, struct pipe *pipe, + struct label *pipelabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_test_check_proc_debug(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_test_check_proc_sched(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_test_check_proc_signal(struct ucred *cred, struct proc *proc) +{ + + return (0); +} + +static int +mac_test_check_socket_bind(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_test_check_socket_connect(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_test_check_socket_listen(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct sockaddr *sockaddr) +{ + + return (0); +} + +static int +mac_test_check_socket_receive(struct socket *socket, struct label *socketlabel, + struct mbuf *m, struct label *mbuflabel) +{ + + return (0); +} + +static int +mac_test_check_socket_visible(struct ucred *cred, struct socket *socket, + struct label *socketlabel) +{ + + return (0); +} + +static int +mac_test_check_socket_relabel(struct ucred *cred, struct socket *socket, + struct label *socketlabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_test_check_vnode_access(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t flags) +{ + + return (0); +} + +static int +mac_test_check_vnode_chdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_test_check_vnode_chroot(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_test_check_vnode_create(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp, struct vattr *vap) +{ + + return (0); +} + +static int +mac_test_check_vnode_delete(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_test_check_vnode_deleteacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + + return (0); +} + +static int +mac_test_check_vnode_exec(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static int +mac_test_check_vnode_getacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type) +{ + + return (0); +} + +static int +mac_test_check_vnode_getextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + + return (0); +} + +static int +mac_test_check_vnode_lookup(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct componentname *cnp) +{ + + return (0); +} + +static int +mac_test_check_vnode_open(struct ucred *cred, struct vnode *vp, + struct label *filelabel, mode_t acc_mode) +{ + + return (0); +} + +static int +mac_test_check_vnode_readdir(struct ucred *cred, struct vnode *dvp, + struct label *dlabel) +{ + + return (0); +} + +static int +mac_test_check_vnode_readlink(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel) +{ + + return (0); +} + +static int +mac_test_check_vnode_relabel(struct ucred *cred, struct vnode *vp, + struct label *vnodelabel, struct label *newlabel) +{ + + return (0); +} + +static int +mac_test_check_vnode_rename_from(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_test_check_vnode_rename_to(struct ucred *cred, struct vnode *dvp, + struct label *dlabel, struct vnode *vp, struct label *label, int samedir, + struct componentname *cnp) +{ + + return (0); +} + +static int +mac_test_check_vnode_revoke(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static int +mac_test_check_vnode_setacl(struct ucred *cred, struct vnode *vp, + struct label *label, acl_type_t type, struct acl *acl) +{ + + return (0); +} + +static int +mac_test_check_vnode_setextattr(struct ucred *cred, struct vnode *vp, + struct label *label, int attrnamespace, const char *name, struct uio *uio) +{ + + return (0); +} + +static int +mac_test_check_vnode_setflags(struct ucred *cred, struct vnode *vp, + struct label *label, u_long flags) +{ + + return (0); +} + +static int +mac_test_check_vnode_setmode(struct ucred *cred, struct vnode *vp, + struct label *label, mode_t mode) +{ + + return (0); +} + +static int +mac_test_check_vnode_setowner(struct ucred *cred, struct vnode *vp, + struct label *label, uid_t uid, gid_t gid) +{ + + return (0); +} + +static int +mac_test_check_vnode_setutimes(struct ucred *cred, struct vnode *vp, + struct label *label, struct timespec atime, struct timespec mtime) +{ + + return (0); +} + +static int +mac_test_check_vnode_stat(struct ucred *cred, struct vnode *vp, + struct label *label) +{ + + return (0); +} + +static struct mac_policy_op_entry mac_test_ops[] = +{ + { MAC_DESTROY, + (macop_t)mac_test_destroy }, + { MAC_INIT, + (macop_t)mac_test_init }, + { MAC_INIT_BPFDESC, + (macop_t)mac_test_init_bpfdesc }, + { MAC_INIT_CRED, + (macop_t)mac_test_init_cred }, + { MAC_INIT_DEVFSDIRENT, + (macop_t)mac_test_init_devfsdirent }, + { MAC_INIT_IFNET, + (macop_t)mac_test_init_ifnet }, + { MAC_INIT_IPQ, + (macop_t)mac_test_init_ipq }, + { MAC_INIT_MBUF, + (macop_t)mac_test_init_mbuf }, + { MAC_INIT_MOUNT, + (macop_t)mac_test_init_mount }, + { MAC_INIT_PIPE, + (macop_t)mac_test_init_pipe }, + { MAC_INIT_SOCKET, + (macop_t)mac_test_init_socket }, + { MAC_INIT_TEMP, + (macop_t)mac_test_init_temp }, + { MAC_INIT_VNODE, + (macop_t)mac_test_init_vnode }, + { MAC_DESTROY_BPFDESC, + (macop_t)mac_test_destroy_bpfdesc }, + { MAC_DESTROY_CRED, + (macop_t)mac_test_destroy_cred }, + { MAC_DESTROY_DEVFSDIRENT, + (macop_t)mac_test_destroy_devfsdirent }, + { MAC_DESTROY_IFNET, + (macop_t)mac_test_destroy_ifnet }, + { MAC_DESTROY_IPQ, + (macop_t)mac_test_destroy_ipq }, + { MAC_DESTROY_MBUF, + (macop_t)mac_test_destroy_mbuf }, + { MAC_DESTROY_MOUNT, + (macop_t)mac_test_destroy_mount }, + { MAC_DESTROY_PIPE, + (macop_t)mac_test_destroy_pipe }, + { MAC_DESTROY_SOCKET, + (macop_t)mac_test_destroy_socket }, + { MAC_DESTROY_TEMP, + (macop_t)mac_test_destroy_temp }, + { MAC_DESTROY_VNODE, + (macop_t)mac_test_destroy_vnode }, + { MAC_EXTERNALIZE, + (macop_t)mac_test_externalize }, + { MAC_INTERNALIZE, + (macop_t)mac_test_internalize }, + { MAC_CREATE_DEVFS_DEVICE, + (macop_t)mac_test_create_devfs_device }, + { MAC_CREATE_DEVFS_DIRECTORY, + (macop_t)mac_test_create_devfs_directory }, + { MAC_CREATE_DEVFS_VNODE, + (macop_t)mac_test_create_devfs_vnode }, + { MAC_CREATE_VNODE, + (macop_t)mac_test_create_vnode }, + { MAC_CREATE_MOUNT, + (macop_t)mac_test_create_mount }, + { MAC_CREATE_ROOT_MOUNT, + (macop_t)mac_test_create_root_mount }, + { MAC_RELABEL_VNODE, + (macop_t)mac_test_relabel_vnode }, + { MAC_UPDATE_DEVFSDIRENT, + (macop_t)mac_test_update_devfsdirent }, + { MAC_UPDATE_PROCFSVNODE, + (macop_t)mac_test_update_procfsvnode }, + { MAC_UPDATE_VNODE_FROM_EXTERNALIZED, + (macop_t)mac_test_update_vnode_from_externalized }, + { MAC_UPDATE_VNODE_FROM_MOUNT, + (macop_t)mac_test_update_vnode_from_mount }, + { MAC_CREATE_MBUF_FROM_SOCKET, + (macop_t)mac_test_create_mbuf_from_socket }, + { MAC_CREATE_PIPE, + (macop_t)mac_test_create_pipe }, + { MAC_CREATE_SOCKET, + (macop_t)mac_test_create_socket }, + { MAC_CREATE_SOCKET_FROM_SOCKET, + (macop_t)mac_test_create_socket_from_socket }, + { MAC_RELABEL_PIPE, + (macop_t)mac_test_relabel_pipe }, + { MAC_RELABEL_SOCKET, + (macop_t)mac_test_relabel_socket }, + { MAC_SET_SOCKET_PEER_FROM_MBUF, + (macop_t)mac_test_set_socket_peer_from_mbuf }, + { MAC_SET_SOCKET_PEER_FROM_SOCKET, + (macop_t)mac_test_set_socket_peer_from_socket }, + { MAC_CREATE_BPFDESC, + (macop_t)mac_test_create_bpfdesc }, + { MAC_CREATE_IFNET, + (macop_t)mac_test_create_ifnet }, + { MAC_CREATE_DATAGRAM_FROM_IPQ, + (macop_t)mac_test_create_datagram_from_ipq }, + { MAC_CREATE_FRAGMENT, + (macop_t)mac_test_create_fragment }, + { MAC_CREATE_IPQ, + (macop_t)mac_test_create_ipq }, + { MAC_CREATE_MBUF_FROM_MBUF, + (macop_t)mac_test_create_mbuf_from_mbuf }, + { MAC_CREATE_MBUF_LINKLAYER, + (macop_t)mac_test_create_mbuf_linklayer }, + { MAC_CREATE_MBUF_FROM_BPFDESC, + (macop_t)mac_test_create_mbuf_from_bpfdesc }, + { MAC_CREATE_MBUF_FROM_IFNET, + (macop_t)mac_test_create_mbuf_from_ifnet }, + { MAC_CREATE_MBUF_MULTICAST_ENCAP, + (macop_t)mac_test_create_mbuf_multicast_encap }, + { MAC_CREATE_MBUF_NETLAYER, + (macop_t)mac_test_create_mbuf_netlayer }, + { MAC_FRAGMENT_MATCH, + (macop_t)mac_test_fragment_match }, + { MAC_RELABEL_IFNET, + (macop_t)mac_test_relabel_ifnet }, + { MAC_UPDATE_IPQ, + (macop_t)mac_test_update_ipq }, + { MAC_CREATE_CRED, + (macop_t)mac_test_create_cred }, + { MAC_EXECVE_TRANSITION, + (macop_t)mac_test_execve_transition }, + { MAC_EXECVE_WILL_TRANSITION, + (macop_t)mac_test_execve_will_transition }, + { MAC_CREATE_PROC0, + (macop_t)mac_test_create_proc0 }, + { MAC_CREATE_PROC1, + (macop_t)mac_test_create_proc1 }, + { MAC_RELABEL_CRED, + (macop_t)mac_test_relabel_cred }, + { MAC_CHECK_BPFDESC_RECEIVE, + (macop_t)mac_test_check_bpfdesc_receive }, + { MAC_CHECK_CRED_RELABEL, + (macop_t)mac_test_check_cred_relabel }, + { MAC_CHECK_CRED_VISIBLE, + (macop_t)mac_test_check_cred_visible }, + { MAC_CHECK_IFNET_RELABEL, + (macop_t)mac_test_check_ifnet_relabel }, + { MAC_CHECK_IFNET_TRANSMIT, + (macop_t)mac_test_check_ifnet_transmit }, + { MAC_CHECK_MOUNT_STAT, + (macop_t)mac_test_check_mount_stat }, + { MAC_CHECK_PIPE_IOCTL, + (macop_t)mac_test_check_pipe_ioctl }, + { MAC_CHECK_PIPE_OP, + (macop_t)mac_test_check_pipe_op }, + { MAC_CHECK_PIPE_RELABEL, + (macop_t)mac_test_check_pipe_relabel }, + { MAC_CHECK_PROC_DEBUG, + (macop_t)mac_test_check_proc_debug }, + { MAC_CHECK_PROC_SCHED, + (macop_t)mac_test_check_proc_sched }, + { MAC_CHECK_PROC_SIGNAL, + (macop_t)mac_test_check_proc_signal }, + { MAC_CHECK_SOCKET_BIND, + (macop_t)mac_test_check_socket_bind }, + { MAC_CHECK_SOCKET_CONNECT, + (macop_t)mac_test_check_socket_connect }, + { MAC_CHECK_SOCKET_LISTEN, + (macop_t)mac_test_check_socket_listen }, + { MAC_CHECK_SOCKET_RECEIVE, + (macop_t)mac_test_check_socket_receive }, + { MAC_CHECK_SOCKET_RELABEL, + (macop_t)mac_test_check_socket_relabel }, + { MAC_CHECK_SOCKET_VISIBLE, + (macop_t)mac_test_check_socket_visible }, + { MAC_CHECK_VNODE_ACCESS, + (macop_t)mac_test_check_vnode_access }, + { MAC_CHECK_VNODE_CHDIR, + (macop_t)mac_test_check_vnode_chdir }, + { MAC_CHECK_VNODE_CHROOT, + (macop_t)mac_test_check_vnode_chroot }, + { MAC_CHECK_VNODE_CREATE, + (macop_t)mac_test_check_vnode_create }, + { MAC_CHECK_VNODE_DELETE, + (macop_t)mac_test_check_vnode_delete }, + { MAC_CHECK_VNODE_DELETEACL, + (macop_t)mac_test_check_vnode_deleteacl }, + { MAC_CHECK_VNODE_EXEC, + (macop_t)mac_test_check_vnode_exec }, + { MAC_CHECK_VNODE_GETACL, + (macop_t)mac_test_check_vnode_getacl }, + { MAC_CHECK_VNODE_GETEXTATTR, + (macop_t)mac_test_check_vnode_getextattr }, + { MAC_CHECK_VNODE_LOOKUP, + (macop_t)mac_test_check_vnode_lookup }, + { MAC_CHECK_VNODE_OPEN, + (macop_t)mac_test_check_vnode_open }, + { MAC_CHECK_VNODE_READDIR, + (macop_t)mac_test_check_vnode_readdir }, + { MAC_CHECK_VNODE_READLINK, + (macop_t)mac_test_check_vnode_readlink }, + { MAC_CHECK_VNODE_RELABEL, + (macop_t)mac_test_check_vnode_relabel }, + { MAC_CHECK_VNODE_RENAME_FROM, + (macop_t)mac_test_check_vnode_rename_from }, + { MAC_CHECK_VNODE_RENAME_TO, + (macop_t)mac_test_check_vnode_rename_to }, + { MAC_CHECK_VNODE_REVOKE, + (macop_t)mac_test_check_vnode_revoke }, + { MAC_CHECK_VNODE_SETACL, + (macop_t)mac_test_check_vnode_setacl }, + { MAC_CHECK_VNODE_SETEXTATTR, + (macop_t)mac_test_check_vnode_setextattr }, + { MAC_CHECK_VNODE_SETFLAGS, + (macop_t)mac_test_check_vnode_setflags }, + { MAC_CHECK_VNODE_SETMODE, + (macop_t)mac_test_check_vnode_setmode }, + { MAC_CHECK_VNODE_SETOWNER, + (macop_t)mac_test_check_vnode_setowner }, + { MAC_CHECK_VNODE_SETUTIMES, + (macop_t)mac_test_check_vnode_setutimes }, + { MAC_CHECK_VNODE_STAT, + (macop_t)mac_test_check_vnode_stat }, + { MAC_OP_LAST, NULL } +}; + +MAC_POLICY_SET(mac_test_ops, trustedbsd_mac_test, "TrustedBSD MAC/Test", + MPC_LOADTIME_FLAG_UNLOADOK, &test_slot); |