Commit c783f1ce authored by Paul Moore's avatar Paul Moore Committed by James Morris

NetLabel: Remove unneeded RCU read locks

This patch removes some unneeded RCU read locks as we can treat the reads as
"safe" even without RCU.  It also converts the NetLabel configuration refcount
from a spinlock protected u32 into atomic_t to be more consistent with the rest
of the kernel.
Signed-off-by: default avatarPaul Moore <paul.moore@hp.com>
Signed-off-by: default avatarJames Morris <jmorris@namei.org>
parent 0ba6c33b
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <net/genetlink.h> #include <net/genetlink.h>
#include <net/netlabel.h> #include <net/netlabel.h>
#include <net/cipso_ipv4.h> #include <net/cipso_ipv4.h>
#include <asm/atomic.h>
#include "netlabel_user.h" #include "netlabel_user.h"
#include "netlabel_cipso_v4.h" #include "netlabel_cipso_v4.h"
...@@ -421,7 +422,7 @@ static int netlbl_cipsov4_add(struct sk_buff *skb, struct genl_info *info) ...@@ -421,7 +422,7 @@ static int netlbl_cipsov4_add(struct sk_buff *skb, struct genl_info *info)
break; break;
} }
if (ret_val == 0) if (ret_val == 0)
netlbl_mgmt_protocount_inc(); atomic_inc(&netlabel_mgmt_protocount);
audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_ADD, audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_ADD,
&audit_info); &audit_info);
...@@ -698,7 +699,7 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info) ...@@ -698,7 +699,7 @@ static int netlbl_cipsov4_remove(struct sk_buff *skb, struct genl_info *info)
&audit_info, &audit_info,
netlbl_cipsov4_doi_free); netlbl_cipsov4_doi_free);
if (ret_val == 0) if (ret_val == 0)
netlbl_mgmt_protocount_dec(); atomic_dec(&netlabel_mgmt_protocount);
audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_DEL, audit_buf = netlbl_audit_start_common(AUDIT_MAC_CIPSOV4_DEL,
&audit_info); &audit_info);
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <net/netlabel.h> #include <net/netlabel.h>
#include <net/cipso_ipv4.h> #include <net/cipso_ipv4.h>
#include <asm/bug.h> #include <asm/bug.h>
#include <asm/atomic.h>
#include "netlabel_domainhash.h" #include "netlabel_domainhash.h"
#include "netlabel_unlabeled.h" #include "netlabel_unlabeled.h"
...@@ -262,7 +263,7 @@ int netlbl_enabled(void) ...@@ -262,7 +263,7 @@ int netlbl_enabled(void)
/* At some point we probably want to expose this mechanism to the user /* At some point we probably want to expose this mechanism to the user
* as well so that admins can toggle NetLabel regardless of the * as well so that admins can toggle NetLabel regardless of the
* configuration */ * configuration */
return (netlbl_mgmt_protocount_value() > 0 ? 1 : 0); return (atomic_read(&netlabel_mgmt_protocount) > 0);
} }
/** /**
......
...@@ -37,14 +37,14 @@ ...@@ -37,14 +37,14 @@
#include <net/genetlink.h> #include <net/genetlink.h>
#include <net/netlabel.h> #include <net/netlabel.h>
#include <net/cipso_ipv4.h> #include <net/cipso_ipv4.h>
#include <asm/atomic.h>
#include "netlabel_domainhash.h" #include "netlabel_domainhash.h"
#include "netlabel_user.h" #include "netlabel_user.h"
#include "netlabel_mgmt.h" #include "netlabel_mgmt.h"
/* NetLabel configured protocol count */ /* NetLabel configured protocol counter */
static DEFINE_SPINLOCK(netlabel_mgmt_protocount_lock); atomic_t netlabel_mgmt_protocount = ATOMIC_INIT(0);
static u32 netlabel_mgmt_protocount = 0;
/* Argument struct for netlbl_domhsh_walk() */ /* Argument struct for netlbl_domhsh_walk() */
struct netlbl_domhsh_walk_arg { struct netlbl_domhsh_walk_arg {
...@@ -70,63 +70,6 @@ static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = { ...@@ -70,63 +70,6 @@ static const struct nla_policy netlbl_mgmt_genl_policy[NLBL_MGMT_A_MAX + 1] = {
[NLBL_MGMT_A_CV4DOI] = { .type = NLA_U32 }, [NLBL_MGMT_A_CV4DOI] = { .type = NLA_U32 },
}; };
/*
* NetLabel Misc Management Functions
*/
/**
* netlbl_mgmt_protocount_inc - Increment the configured labeled protocol count
*
* Description:
* Increment the number of labeled protocol configurations in the current
* NetLabel configuration. Keep track of this for use in determining if
* NetLabel label enforcement should be active/enabled or not in the LSM.
*
*/
void netlbl_mgmt_protocount_inc(void)
{
spin_lock(&netlabel_mgmt_protocount_lock);
netlabel_mgmt_protocount++;
spin_unlock(&netlabel_mgmt_protocount_lock);
}
/**
* netlbl_mgmt_protocount_dec - Decrement the configured labeled protocol count
*
* Description:
* Decrement the number of labeled protocol configurations in the current
* NetLabel configuration. Keep track of this for use in determining if
* NetLabel label enforcement should be active/enabled or not in the LSM.
*
*/
void netlbl_mgmt_protocount_dec(void)
{
spin_lock(&netlabel_mgmt_protocount_lock);
if (netlabel_mgmt_protocount > 0)
netlabel_mgmt_protocount--;
spin_unlock(&netlabel_mgmt_protocount_lock);
}
/**
* netlbl_mgmt_protocount_value - Return the number of configured protocols
*
* Description:
* Return the number of labeled protocols in the current NetLabel
* configuration. This value is useful in determining if NetLabel label
* enforcement should be active/enabled or not in the LSM.
*
*/
u32 netlbl_mgmt_protocount_value(void)
{
u32 val;
rcu_read_lock();
val = netlabel_mgmt_protocount;
rcu_read_unlock();
return val;
}
/* /*
* NetLabel Command Handlers * NetLabel Command Handlers
*/ */
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#define _NETLABEL_MGMT_H #define _NETLABEL_MGMT_H
#include <net/netlabel.h> #include <net/netlabel.h>
#include <asm/atomic.h>
/* /*
* The following NetLabel payloads are supported by the management interface. * The following NetLabel payloads are supported by the management interface.
...@@ -168,9 +169,7 @@ enum { ...@@ -168,9 +169,7 @@ enum {
/* NetLabel protocol functions */ /* NetLabel protocol functions */
int netlbl_mgmt_genl_init(void); int netlbl_mgmt_genl_init(void);
/* NetLabel misc management functions */ /* NetLabel configured protocol reference counter */
void netlbl_mgmt_protocount_inc(void); extern atomic_t netlabel_mgmt_protocount;
void netlbl_mgmt_protocount_dec(void);
u32 netlbl_mgmt_protocount_value(void);
#endif #endif
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/rcupdate.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/socket.h> #include <linux/socket.h>
...@@ -48,7 +47,6 @@ ...@@ -48,7 +47,6 @@
#include "netlabel_unlabeled.h" #include "netlabel_unlabeled.h"
/* Accept unlabeled packets flag */ /* Accept unlabeled packets flag */
static DEFINE_SPINLOCK(netlabel_unlabel_acceptflg_lock);
static u8 netlabel_unlabel_acceptflg = 0; static u8 netlabel_unlabel_acceptflg = 0;
/* NetLabel Generic NETLINK CIPSOv4 family */ /* NetLabel Generic NETLINK CIPSOv4 family */
...@@ -84,11 +82,8 @@ static void netlbl_unlabel_acceptflg_set(u8 value, ...@@ -84,11 +82,8 @@ static void netlbl_unlabel_acceptflg_set(u8 value,
struct audit_buffer *audit_buf; struct audit_buffer *audit_buf;
u8 old_val; u8 old_val;
spin_lock(&netlabel_unlabel_acceptflg_lock);
old_val = netlabel_unlabel_acceptflg; old_val = netlabel_unlabel_acceptflg;
netlabel_unlabel_acceptflg = value; netlabel_unlabel_acceptflg = value;
spin_unlock(&netlabel_unlabel_acceptflg_lock);
audit_buf = netlbl_audit_start_common(AUDIT_MAC_UNLBL_ALLOW, audit_buf = netlbl_audit_start_common(AUDIT_MAC_UNLBL_ALLOW,
audit_info); audit_info);
if (audit_buf != NULL) { if (audit_buf != NULL) {
...@@ -155,11 +150,9 @@ static int netlbl_unlabel_list(struct sk_buff *skb, struct genl_info *info) ...@@ -155,11 +150,9 @@ static int netlbl_unlabel_list(struct sk_buff *skb, struct genl_info *info)
goto list_failure; goto list_failure;
} }
rcu_read_lock();
ret_val = nla_put_u8(ans_skb, ret_val = nla_put_u8(ans_skb,
NLBL_UNLABEL_A_ACPTFLG, NLBL_UNLABEL_A_ACPTFLG,
netlabel_unlabel_acceptflg); netlabel_unlabel_acceptflg);
rcu_read_unlock();
if (ret_val != 0) if (ret_val != 0)
goto list_failure; goto list_failure;
...@@ -245,17 +238,10 @@ int netlbl_unlabel_genl_init(void) ...@@ -245,17 +238,10 @@ int netlbl_unlabel_genl_init(void)
*/ */
int netlbl_unlabel_getattr(struct netlbl_lsm_secattr *secattr) int netlbl_unlabel_getattr(struct netlbl_lsm_secattr *secattr)
{ {
int ret_val; if (netlabel_unlabel_acceptflg == 0)
return -ENOMSG;
rcu_read_lock();
if (netlabel_unlabel_acceptflg == 1) {
netlbl_secattr_init(secattr); netlbl_secattr_init(secattr);
ret_val = 0; return 0;
} else
ret_val = -ENOMSG;
rcu_read_unlock();
return ret_val;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment