diff options
author | rwatson <rwatson@FreeBSD.org> | 2009-06-03 18:46:28 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2009-06-03 18:46:28 +0000 |
commit | 849a8ce20b26266bfcee925d683db20bee2a0ccd (patch) | |
tree | c959f41a3828e52e4d9970ee9fff5c64a88ca36e /sys/security/mac/mac_net.c | |
parent | 673e1d1fc9eb778be5e4ca28de814387aca23ab8 (diff) | |
download | FreeBSD-src-849a8ce20b26266bfcee925d683db20bee2a0ccd.zip FreeBSD-src-849a8ce20b26266bfcee925d683db20bee2a0ccd.tar.gz |
Continue work to optimize performance of "options MAC" when no MAC policy
modules are loaded by avoiding mbuf label lookups when policies aren't
loaded, pushing further socket locking into MAC policy modules, and
avoiding locking MAC ifnet locks when no policies are loaded:
- Check mac_policies_count before looking for mbuf MAC label m_tags in MAC
Framework entry points. We will still pay label lookup costs if MAC
policies are present but don't require labels (typically a single mbuf
header field read, but perhaps further indirection if IPSEC or other
m_tag consumers are in use).
- Further push socket locking for socket-related access control checks and
events into MAC policies from the MAC Framework, so that sockets are
only locked if a policy specifically requires a lock to protect a label.
This resolves lock order issues during sonewconn() and also in local
domain socket cross-connect where multiple socket locks could not be
held at once for the purposes of propagatig MAC labels across multiple
sockets. Eliminate mac_policy_count check in some entry points where it
no longer avoids locking.
- Add mac_policy_count checking in some entry points relating to network
interfaces that otherwise lock a global MAC ifnet lock used to protect
ifnet labels.
Obtained from: TrustedBSD Project
Diffstat (limited to 'sys/security/mac/mac_net.c')
-rw-r--r-- | sys/security/mac/mac_net.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/security/mac/mac_net.c b/sys/security/mac/mac_net.c index ecd4195..73154148 100644 --- a/sys/security/mac/mac_net.c +++ b/sys/security/mac/mac_net.c @@ -296,6 +296,9 @@ void mac_ifnet_create(struct ifnet *ifp) { + if (mac_policy_count == 0) + return; + MAC_IFNET_LOCK(ifp); MAC_POLICY_PERFORM_NOSLEEP(ifnet_create, ifp, ifp->if_label); MAC_IFNET_UNLOCK(ifp); @@ -315,6 +318,9 @@ mac_bpfdesc_create_mbuf(struct bpf_d *d, struct mbuf *m) BPFD_LOCK_ASSERT(d); + if (mac_policy_count == 0) + return; + label = mac_mbuf_to_label(m); MAC_POLICY_PERFORM_NOSLEEP(bpfdesc_create_mbuf, d, d->bd_label, m, @@ -326,6 +332,9 @@ mac_ifnet_create_mbuf(struct ifnet *ifp, struct mbuf *m) { struct label *label; + if (mac_policy_count == 0) + return; + label = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); @@ -344,6 +353,9 @@ mac_bpfdesc_check_receive(struct bpf_d *d, struct ifnet *ifp) BPFD_LOCK_ASSERT(d); + if (mac_policy_count == 0) + return (0); + MAC_IFNET_LOCK(ifp); MAC_POLICY_CHECK_NOSLEEP(bpfdesc_check_receive, d, d->bd_label, ifp, ifp->if_label); @@ -364,6 +376,9 @@ mac_ifnet_check_transmit(struct ifnet *ifp, struct mbuf *m) M_ASSERTPKTHDR(m); + if (mac_policy_count == 0) + return (0); + label = mac_mbuf_to_label(m); MAC_IFNET_LOCK(ifp); |