Skip to contentSkip to conversation

Added new checks for labeled IPsec & SECMARK [en|dis]able

RFC PATCH In review Paul Moore 4 participants 11 messages Oct 5, 2007 – Oct 10, 2007

Subsystems (4)
lore
Share & tools
lore

Paul Moore

author
#0 lore raw

v4 cover Added new checks for labeled IPsec & SECMARK [en|dis]able

I've updated the first two patches in this series based on Eric's comments (thanks again Eric) and added a new patch which provides a way to determine if labeled IPsec and SECMARK have been configured. If they have been actively configured we assume that they are enabled. This is similar to the existing netlbl_enabled() function and should allow us to dynamically enable/disable the network access controls when using the new flow control checks as well the local packet receive check when the new controls are active (i.e. new policy).

The SECMARK changes here are a bit on the ugly side, but due to it's ability to be compiled as a module are options are somewhat limited. If anyone has some great ideas on the topic I'd love to hear them.

I've also updated the git tree for those of you who prefer to look at things that way:

* git://git.infradead.org/users/pcmoore/lblnet-2.6_testing

Signature · 8 lines
paul moore
linux security @ hp


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#1 lore raw

RFC PATCH v4 1/3 Add a capabilities bitmap to SELinux policy version 22

Add a new policy capabilities bitmap to SELinux policy version 22. This bitmap will enable the security server to query the policy to determine which features it supports.
---

 security/selinux/Kconfig            |    2 -
 security/selinux/include/security.h |   15 ++++++
 security/selinux/selinuxfs.c        |   89 +++++++++++++++++++++++++++++++++--
 security/selinux/ss/policydb.c      |   18 +++++++
 security/selinux/ss/policydb.h      |    2 +
 security/selinux/ss/services.c      |   62 ++++++++++++++++++++++++
 6 files changed, 181 insertions(+), 7 deletions(-)
security/selinux/Kconfig +1 -1
index b32a459..2b517d6 100644
@@ -145,7 +145,7 @@ config SECURITY_SELINUX_POLICYDB_VERSION_MAX
 config SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 	int "NSA SELinux maximum supported policy format version value"
 	depends on SECURITY_SELINUX_POLICYDB_VERSION_MAX
-	range 15 21
+	range 15 22
 	default 19
 	help
 	  This option sets the value for the maximum policy format version
security/selinux/include/security.h +14 -1
index 83bdd4d..cc53ce4 100644
@@ -25,13 +25,14 @@
 #define POLICYDB_VERSION_MLS		19
 #define POLICYDB_VERSION_AVTAB		20
 #define POLICYDB_VERSION_RANGETRANS	21
+#define POLICYDB_VERSION_POLCAP		22
 
 /* Range of policy versions we understand*/
 #define POLICYDB_VERSION_MIN   POLICYDB_VERSION_BASE
 #ifdef CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX
 #define POLICYDB_VERSION_MAX	CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX_VALUE
 #else
-#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_RANGETRANS
+#define POLICYDB_VERSION_MAX	POLICYDB_VERSION_POLCAP
 #endif
 
 struct netlbl_lsm_secattr;
@@ -39,8 +40,19 @@ struct netlbl_lsm_secattr;
 extern int selinux_enabled;
 extern int selinux_mls_enabled;
 
+/* Policy capabilities */
+enum {
+	POLICYDB_CAPABILITY_NETPEER,
+	__POLICYDB_CAPABILITY_MAX
+};
+#define POLICYDB_CAPABILITY_MAX (__POLICYDB_CAPABILITY_MAX - 1)
+
+extern int selinux_policycap_netpeer;
+
 int security_load_policy(void * data, size_t len);
 
+int security_policycap_supported(unsigned int req_cap);
+
 #define SEL_VEC_MAX 32
 struct av_decision {
 	u32 allowed;
@@ -90,6 +102,7 @@ int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid);
 
 int security_get_classes(char ***classes, int *nclasses);
 int security_get_permissions(char *class, char ***perms, int *nperms);
+int security_get_policycaps(int *len, int **values);
 
 #define SECURITY_FS_USE_XATTR		1 /* use xattr */
 #define SECURITY_FS_USE_TRANS		2 /* use transition SIDs, e.g. devpts/tmpfs */
security/selinux/selinuxfs.c +85 -4

143 lines not on this page · raw message

security/selinux/ss/policydb.c +18 -0
index f05f97a..4c82a83 100644
@@ -13,6 +13,11 @@
  *
  * 	Added conditional policy language extensions
  *
+ * Updated: Hewlett-Packard <[email protected]>
+ *
+ *      Added support for the policy capability bitmap
+ *
+ * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
  * Copyright (C) 2004-2005 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2004 Tresys Technology, LLC
  *	This program is free software; you can redistribute it and/or modify
@@ -102,6 +107,11 @@ static struct policydb_compat_info policydb_compat[] = {
 		.sym_num        = SYM_NUM,
 		.ocon_num       = OCON_NUM,
 	},
+	{
+		.version	= POLICYDB_VERSION_POLCAP,
+		.sym_num	= SYM_NUM,
+		.ocon_num	= OCON_NUM,
+	}
 };
 
 static struct policydb_compat_info *policydb_lookup_compat(int version)
@@ -183,6 +193,8 @@ static int policydb_init(struct policydb *p)
 	if (rc)
 		goto out_free_avtab;
 
+	ebitmap_init(&p->policycaps);
+
 out:
 	return rc;
 
@@ -677,6 +689,8 @@ void policydb_destroy(struct policydb *p)
 	}
 	kfree(p->type_attr_map);
 
+	ebitmap_destroy(&p->policycaps);
+
 	return;
 }
 
@@ -1531,6 +1545,10 @@ int policydb_read(struct policydb *p, void *fp)
 		}
 	}
 
+	if (p->policyvers >= POLICYDB_VERSION_POLCAP &&
+	    ebitmap_read(&p->policycaps, fp) != 0)
+		goto bad;
+
 	info = policydb_lookup_compat(p->policyvers);
 	if (!info) {
 		printk(KERN_ERR "security:  unable to find policy compat info "
security/selinux/ss/policydb.h +2 -0
index 8319d5f..e621048 100644
@@ -241,6 +241,8 @@ struct policydb {
 	/* type -> attribute reverse mapping */
 	struct ebitmap *type_attr_map;
 
+	struct ebitmap policycaps;
+
 	unsigned int policyvers;
 };
 
security/selinux/ss/services.c +61 -1

91 lines not on this page · raw message

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#2 lore raw

Re: [RFC PATCH v4 1/3] [SELinux] Add a capabilities bitmap to SELinux policy version 22

Quoted 28 lines · Paul Moore

Add a new policy capabilities bitmap to SELinux policy version 22. This bitmap will enable the security server to query the policy to determine which features it supports.
---

 security/selinux/Kconfig            |    2 -
 security/selinux/include/security.h |   15 ++++++
 security/selinux/selinuxfs.c        |   89 +++++++++++++++++++++++++++++++++--
 security/selinux/ss/policydb.c      |   18 +++++++
 security/selinux/ss/policydb.h      |    2 +
 security/selinux/ss/services.c      |   62 ++++++++++++++++++++++++
 6 files changed, 181 insertions(+), 7 deletions(-)
security/selinux/ss/services.c +2 -0
index 6100fc0..7059400 100644
@@ -59,6 +60,8 @@
 extern void selnl_notify_policyload(u32 seqno);
 unsigned int policydb_loaded_version;
 
+int selinux_policycap_netpeer;
+
 /*
  * This is declared in avc.c
  */

security/selinux/ss/services.c int security_load_policy(void *data, size_t len) · line 1315

Quoted 9 lines
security/selinux/ss/services.c +3 -0
@@ -1304,6 +1307,9 @@ int security_load_policy(void *data, size_t len)
 			return -EINVAL;
 		}
 		policydb_loaded_version = policydb.policyvers;
+		selinux_policycap_netpeer =
+		  ebitmap_get_bit(&policydb.policycaps,
+				  POLICYDB_CAPABILITY_NETPEER);
 		ss_initialized = 1;
 		seqno = ++latest_granting;
 		LOAD_UNLOCK;

Only handles the initial policy load case, not reloads.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#3 lore raw

Re: [RFC PATCH v4 1/3] [SELinux] Add a capabilities bitmap to SELinux policy version 22

Quoted 13 lines · Stephen Smalley

security/selinux/ss/services.c int security_load_policy(void *data, size_t len) · line 1315

Quoted 10 lines · Paul Moore
security/selinux/ss/services.c +3 -0
@@ -1304,6 +1307,9 @@ int security_load_policy(void *data, size_t len)
 			return -EINVAL;
 		}
 		policydb_loaded_version = policydb.policyvers;
+		selinux_policycap_netpeer =
+		  ebitmap_get_bit(&policydb.policycaps,
+				  POLICYDB_CAPABILITY_NETPEER);
 		ss_initialized = 1;
 		seqno = ++latest_granting;
 		LOAD_UNLOCK;

Only handles the initial policy load case, not reloads.

So it does, thanks. I just added the same assignment further down in the security_load_policy() function to handle the reload case.

Signature · 7 lines
paul moore
linux security @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw

Re: [RFC PATCH v4 1/3] [SELinux] Add a capabilities bitmap to SELinux policy version 22

Quoted 15 lines · Paul Moore
Quoted 13 lines · Stephen Smalley

security/selinux/ss/services.c int security_load_policy(void *data, size_t len) · line 1315

Quoted 10 lines · Paul Moore
security/selinux/ss/services.c +3 -0
@@ -1304,6 +1307,9 @@ int security_load_policy(void *data, size_t len)
                    return -EINVAL;
            }
            policydb_loaded_version = policydb.policyvers;
+           selinux_policycap_netpeer =
+             ebitmap_get_bit(&policydb.policycaps,
+                             POLICYDB_CAPABILITY_NETPEER);
            ss_initialized = 1;
            seqno = ++latest_granting;
            LOAD_UNLOCK;

Only handles the initial policy load case, not reloads.

Quoted 2 lines

So it does, thanks. I just added the same assignment further down in the security_load_policy() function to handle the reload case.

Do we expect to have more of these? are we going to keep making load_policy larger and larger or should this type of assignment just be made in its own function to start with?

-Eric

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

author
#5 lore raw

Re: [RFC PATCH v4 1/3] [SELinux] Add a capabilities bitmap to SELinux policy version 22

Quoted 16 lines · Eric Paris
Quoted 15 lines · Paul Moore
Quoted 13 lines · Stephen Smalley

security/selinux/ss/services.c int security_load_policy(void *data, size_t · line 1315

Quoted 10 lines · Paul Moore
security/selinux/ss/services.c +3 -0
@@ -1304,6 +1307,9 @@ int security_load_policy(void *data, size_t
 len) return -EINVAL;
            }
            policydb_loaded_version = policydb.policyvers;
+           selinux_policycap_netpeer =
+             ebitmap_get_bit(&policydb.policycaps,
+                             POLICYDB_CAPABILITY_NETPEER);
            ss_initialized = 1;
            seqno = ++latest_granting;
            LOAD_UNLOCK;

Only handles the initial policy load case, not reloads.

Quoted 6 lines
Quoted 2 lines

So it does, thanks. I just added the same assignment further down in the security_load_policy() function to handle the reload case.

Do we expect to have more of these? are we going to keep making load_policy larger and larger or should this type of assignment just be made in its own function to start with?

My crystal ball is a bit hazy, but I think it's reasonable to expect that we will get more of these variables in the future. I'll move it out to a separate function unless I hear any strong objections.

Signature · 7 lines
paul moore
linux security @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#6 lore raw

RFC PATCH v4 2/3 Better integration between peer labeling subsystems

In reply to Paul Moore

Rename the existing selinux_skb_extlbl_sid() function to selinux_skb_peerlbl_sid() and modify it's behavior such that it now reconciles multiple peer/external labels and if reconciliation is not possible it returns an error to the caller.
---

 security/selinux/hooks.c            |   42 ++++++++++---------
 security/selinux/include/security.h |    2 +
 security/selinux/ss/services.c      |   79 +++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 19 deletions(-)
security/selinux/hooks.c +23 -19
index 0753b20..9923c01 100644
@@ -3132,32 +3132,31 @@ static int selinux_parse_skb(struct sk_buff *skb, struct avc_audit_data *ad,
 }
 
 /**
- * selinux_skb_extlbl_sid - Determine the external label of a packet
+ * selinux_skb_peerlbl_sid - Determine the peer label of a packet
  * @skb: the packet
- * @sid: the packet's SID
+ * @sid: the packet's peer label SID
  *
  * Description:
- * Check the various different forms of external packet labeling and determine
- * the external SID for the packet.  If only one form of external labeling is
- * present then it is used, if both labeled IPsec and NetLabel labels are
- * present then the SELinux type information is taken from the labeled IPsec
- * SA and the MLS sensitivity label information is taken from the NetLabel
- * security attributes.  This bit of "magic" is done in the call to
- * selinux_netlbl_skbuff_getsid().
+ * Check the various different forms of network peer labeling and determine
+ * the peer label/SID for the packet; most of the magic actually occurs in
+ * the security server function security_net_peersid_cmp().  The function
+ * returns zero if the value in @sid is valid (although it may be SECSID_NULL)
+ * or -EACCES if @sid is invalid due to inconsistencies with the different
+ * peer labels.
  *
  */
-static void selinux_skb_extlbl_sid(struct sk_buff *skb, u32 *sid)
+static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u32 *sid)
 {
 	u32 xfrm_sid;
 	u32 nlbl_sid;
 
 	selinux_skb_xfrm_sid(skb, &xfrm_sid);
-	if (selinux_netlbl_skbuff_getsid(skb,
-					 (xfrm_sid == SECSID_NULL ?
-					  SECINITSID_NETMSG : xfrm_sid),
-					 &nlbl_sid) != 0)
-		nlbl_sid = SECSID_NULL;
-	*sid = (nlbl_sid == SECSID_NULL ? xfrm_sid : nlbl_sid);
+	selinux_netlbl_skbuff_getsid(skb, SECINITSID_NETMSG, &nlbl_sid);
+
+	if (security_net_peersid_resolve(nlbl_sid, xfrm_sid, sid) != 0)
+		return -EACCES;
+
+	return 0;
 }
 
 /* socket security operations */
@@ -3640,6 +3639,9 @@ static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
 	if (err)
 		goto out;
 
+	/* XXX - make use of selinux_skb_peerlbl_sid() here but only once we
+	 *       have the new peer object class in place */
+
 	err = selinux_netlbl_sock_rcv_skb(sksec, skb, &ad);
 	if (err)
 		goto out;
@@ -3701,7 +3703,7 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *
 	if (sock && sock->sk->sk_family == PF_UNIX)
 		selinux_get_inode_sid(SOCK_INODE(sock), &peer_secid);
 	else if (skb)
-		selinux_skb_extlbl_sid(skb, &peer_secid);
+		selinux_skb_peerlbl_sid(skb, &peer_secid);
 
 	if (peer_secid == SECSID_NULL)
 		err = -EINVAL;
@@ -3762,7 +3764,9 @@ static int selinux_inet_conn_request(struct sock *sk, struct sk_buff *skb,
 	u32 newsid;
 	u32 peersid;
 
-	selinux_skb_extlbl_sid(skb, &peersid);
+	err = selinux_skb_peerlbl_sid(skb, &peersid);
+	if (err)
+		return err;
 	if (peersid == SECSID_NULL) {
 		req->secid = sksec->sid;
 		req->peer_secid = SECSID_NULL;
@@ -3800,7 +3804,7 @@ static void selinux_inet_conn_established(struct sock *sk,
 {
 	struct sk_security_struct *sksec = sk->sk_security;
 
-	selinux_skb_extlbl_sid(skb, &sksec->peer_sid);
+	selinux_skb_peerlbl_sid(skb, &sksec->peer_sid);
 }
 
 static void selinux_req_classify_flow(const struct request_sock *req,
security/selinux/include/security.h +2 -0
index cc53ce4..f193693 100644
@@ -100,6 +100,8 @@ int security_validate_transition(u32 oldsid, u32 newsid, u32 tasksid,
 
 int security_sid_mls_copy(u32 sid, u32 mls_sid, u32 *new_sid);
 
+int security_net_peersid_resolve(u32 nlbl_sid, u32 xfrm_sid, u32 *peer_sid);
+
 int security_get_classes(char ***classes, int *nclasses);
 int security_get_permissions(char *class, char ***perms, int *nperms);
 int security_get_policycaps(int *len, int **values);
security/selinux/ss/services.c +79 -0

85 lines not on this page · raw message

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

author
#7 lore raw

RFC PATCH v4 3/3 Enable dynamic enable/disable of the network access checks

In reply to Paul Moore

This patch introduces a mechanism for checking when labeled IPsec or SECMARK are in use by keeping introducing a configuration reference counter for each subsystem. In the case of labeled IPsec, whenever a labeled SA or SPD entry is created the labeled IPsec/XFRM reference count is increased and when the entry is removed it is decreased. In the case of SECMARK, when a SECMARK target is created the reference count is increased and later decreased when the target is removed. These reference counters allow SELinux to quickly determine if either of these subsystems are enabled.

NetLabel already has a similar mechanism which provides the netlbl_enabled() function.

This patch also renames the selinux_relabel_packet_permission() function to selinux_secmark_relabel_packet_permission() as the original name and description were misleading in that they referenced a single packet label which is not the case.
---

 include/linux/selinux.h         |   45 +++++++++++++++++++++++++-----
 net/netfilter/xt_SECMARK.c      |   13 ++++++++-
 security/selinux/exports.c      |   25 +++++++++++++++--
 security/selinux/hooks.c        |   27 ++++++++++++++++++
 security/selinux/include/xfrm.h |    2 +
 security/selinux/xfrm.c         |   58 ++++++++++++++++++++++++++++++++++++++-
 6 files changed, 157 insertions(+), 13 deletions(-)
include/linux/selinux.h +37 -8
index d1b7ca6..691170b 100644
@@ -120,16 +120,35 @@ void selinux_get_task_sid(struct task_struct *tsk, u32 *sid);
 int selinux_string_to_sid(char *str, u32 *sid);
 
 /**
- *     selinux_relabel_packet_permission - check permission to relabel a packet
- *     @sid: ID value to be applied to network packet (via SECMARK, most likely)
+ *     selinux_secmark_relabel_packet_permission - secmark permission check
+ *     @sid: SECMARK ID value to be applied to network packet
  *
- *     Returns 0 if the current task is allowed to label packets with the
- *     supplied security ID.  Note that it is implicit that the packet is always
- *     being relabeled from the default unlabled value, and that the access
- *     control decision is made in the AVC.
+ *     Returns 0 if the current task is allowed to set the SECMARK label of
+ *     packets with the supplied security ID.  Note that it is implicit that
+ *     the packet is always being relabeled from the default unlabeled value,
+ *     and that the access control decision is made in the AVC.
  */
-int selinux_relabel_packet_permission(u32 sid);
+int selinux_secmark_relabel_packet_permission(u32 sid);
 
+/**
+ *     selinux_secmark_refcount_inc - increments the secmark use counter
+ *
+ *     SELinux keeps track of the current SECMARK targets in use so it knows
+ *     when to apply SECMARK label access checks to network packets.  This
+ *     function incements this reference count to indicate that a new SECMARK
+ *     target has been configured.
+ */
+void selinux_secmark_refcount_inc(void);
+
+/**
+ *     selinux_secmark_refcount_dec - decrements the secmark use counter
+ *
+ *     SELinux keeps track of the current SECMARK targets in use so it knows
+ *     when to apply SECMARK label access checks to network packets.  This
+ *     function decements this reference count to indicate that one of the
+ *     existing SECMARK targets has been removed/flushed.
+ */
+void selinux_secmark_refcount_dec(void);
 #else
 
 static inline int selinux_audit_rule_init(u32 field, u32 op,
@@ -184,11 +203,21 @@ static inline int selinux_string_to_sid(const char *str, u32 *sid)
        return 0;
 }
 
-static inline int selinux_relabel_packet_permission(u32 sid)
+static inline int selinux_secmark_relabel_packet_permission(u32 sid)
 {
 	return 0;
 }
 
+static inline void selinux_secmark_refcount_inc(void)
+{
+	return;
+}
+
+static inline void selinux_secmark_refcount_dec(void)
+{
+	return;
+}
+
 #endif	/* CONFIG_SECURITY_SELINUX */
 
 #endif /* _LINUX_SELINUX_H */
net/netfilter/xt_SECMARK.c +12 -1
index c83779a..18cd936 100644
@@ -72,12 +72,13 @@ static bool checkentry_selinux(struct xt_secmark_target_info *info)
 		return false;
 	}
 
-	err = selinux_relabel_packet_permission(sel->selsid);
+	err = selinux_secmark_relabel_packet_permission(sel->selsid);
 	if (err) {
 		printk(KERN_INFO PFX "unable to obtain relabeling permission\n");
 		return false;
 	}
 
+	selinux_secmark_refcount_inc();
 	return true;
 }
 
@@ -109,11 +110,20 @@ static bool checkentry(const char *tablename, const void *entry,
 	return true;
 }
 
+void destroy(const struct xt_target *target, void *targinfo)
+{
+	switch (mode) {
+	case SECMARK_MODE_SEL:
+		selinux_secmark_refcount_dec();
+	}
+}
+
 static struct xt_target xt_secmark_target[] __read_mostly = {
 	{
 		.name		= "SECMARK",
 		.family		= AF_INET,
 		.checkentry	= checkentry,
+		.destroy	= destroy,
 		.target		= target,
 		.targetsize	= sizeof(struct xt_secmark_target_info),
 		.table		= "mangle",
@@ -123,6 +133,7 @@ static struct xt_target xt_secmark_target[] __read_mostly = {
 		.name		= "SECMARK",
 		.family		= AF_INET6,
 		.checkentry	= checkentry,
+		.destroy	= destroy,
 		.target		= target,
 		.targetsize	= sizeof(struct xt_secmark_target_info),
 		.table		= "mangle",
security/selinux/exports.c +23 -2
index b6f9694..eec5dd5 100644
@@ -17,10 +17,15 @@
 #include <linux/selinux.h>
 #include <linux/fs.h>
 #include <linux/ipc.h>
+#include <linux/spinlock.h>
 
 #include "security.h"
 #include "objsec.h"
 
+/* SECMARK reference count */
+static DEFINE_SPINLOCK(selinux_secmark_refcount_lock);
+extern u32 selinux_secmark_refcount;
+
 int selinux_sid_to_string(u32 sid, char **ctx, u32 *ctxlen)
 {
 	if (selinux_enabled)
@@ -74,7 +79,7 @@ int selinux_string_to_sid(char *str, u32 *sid)
 }
 EXPORT_SYMBOL_GPL(selinux_string_to_sid);
 
-int selinux_relabel_packet_permission(u32 sid)
+int selinux_secmark_relabel_packet_permission(u32 sid)
 {
 	if (selinux_enabled) {
 		struct task_security_struct *tsec = current->security;
@@ -84,4 +89,20 @@ int selinux_relabel_packet_permission(u32 sid)
 	}
 	return 0;
 }
-EXPORT_SYMBOL_GPL(selinux_relabel_packet_permission);
+EXPORT_SYMBOL_GPL(selinux_secmark_relabel_packet_permission);
+
+void selinux_secmark_refcount_inc(void)
+{
+	spin_lock(&selinux_secmark_refcount_lock);
+	selinux_secmark_refcount++;
+	spin_unlock(&selinux_secmark_refcount_lock);
+}
+EXPORT_SYMBOL_GPL(selinux_secmark_refcount_inc);
+
+void selinux_secmark_refcount_dec(void)
+{
+	spin_lock(&selinux_secmark_refcount_lock);
+	selinux_secmark_refcount--;
+	spin_unlock(&selinux_secmark_refcount_lock);
+}
+EXPORT_SYMBOL_GPL(selinux_secmark_refcount_dec);
security/selinux/hooks.c +27 -0
index 9923c01..857c05d 100644
@@ -85,6 +85,12 @@ extern unsigned int policydb_loaded_version;
 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
 extern int selinux_compat_net;
 
+/* SECMARK reference count
+ * This reference counter is read-only via RCU (see selinux_secmark_enabled())
+ * in this file, it is updated by the selinux_secmark_refcount_[inc|dec]()
+ * functions with spinlocks providing write protection. */
+u32 selinux_secmark_refcount = 0;
+
 #ifdef CONFIG_SECURITY_SELINUX_DEVELOP
 int selinux_enforcing = 0;
 
@@ -151,6 +157,27 @@ getsecurity_exit:
 	return len;
 }
 
+/**
+ * selinux_secmark_enabled - Check to see if SECMARK is currently enabled
+ *
+ * Description:
+ * This function checks the SECMARK reference counter to see if any SECMARK
+ * targets are currently configured, if the reference counter is greater than
+ * zero SECMARK is considered to be enabled.  Returns true (1) if SECMARK is
+ * enabled, false (0) if SECMARK is disabled.
+ *
+ */
+static int selinux_secmark_enabled(void)
+{
+	int rc;
+
+	rcu_read_lock();
+	rc = (selinux_secmark_refcount > 0 ? 1 : 0);
+	rcu_read_unlock();
+
+	return rc;
+}
+
 /* Allocate and free functions for each kind of security blob. */
 
 static int task_alloc_security(struct task_struct *task)
security/selinux/include/xfrm.h +2 -0
index 31929e3..729d86e 100644
@@ -7,6 +7,8 @@
 #ifndef _SELINUX_XFRM_H_
 #define _SELINUX_XFRM_H_
 
+int selinux_xfrm_enabled(void);
+
 int selinux_xfrm_policy_alloc(struct xfrm_policy *xp,
 		struct xfrm_user_sec_ctx *sec_ctx);
 int selinux_xfrm_policy_clone(struct xfrm_policy *old, struct xfrm_policy *new);
security/selinux/xfrm.c +56 -2

106 lines not on this page · raw message

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#8 lore raw
In reply to Paul Moore

I think it'd be good to get these into 2.6.24. Any acks/nacks ?

Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#9 lore raw
Quoted 1 line · James Morris

I think it'd be good to get these into 2.6.24. Any acks/nacks ?

Technically the ability to dynamically enable/disable the network access controls alters user visible behavior and could cause complaints from users. Granted, the chance of someone complaining about a missing unlabeled_t access check when they haven't explicitly configured labeled networking is pretty slim, but it still is possible and I don't want to knowingly cause things to break.

It's tempting from a performance point of view to run with this now, but I personally tend to think it's best to wait and implement it in policy rev 22 when we can hide it behind the new capability bitmap field (my thinking is that it goes in with the new peer permission class and flow controls).

Signature · 7 lines
paul moore
linux security @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
author
#10 lore raw
Quoted 2 lines · Paul Moore
Quoted 1 line · James Morris

I think it'd be good to get these into 2.6.24. Any acks/nacks ?

Sorry, I thought you were asking just about the last patch (dynamic enable/disable) and not the whole patchset.

I don't think we're going to be ready for 2.6.24 with these patches. My goal at this point is to get these three patches, the new unified peer label access controls and the work Venkat has been doing on flow control into 2.6.25. This should give us plenty of time to get the userspace pieces into place and perform a decent amount of testing on the whole combination.

Signature · 7 lines
paul moore
linux security @ hp

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.