Skip to contentSkip to conversation

Small changes, now available in git form

RFC PATCH Superseded Paul Moore 2 participants 8 messages Oct 2, 2007 SELinux security module

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Paul Moore

author
#0 lore raw

v3 cover Small changes, now available in git form

Not a whole lot of changes in this revision, mostly just the policy version name change discussed on the list and some small fixes I've noticed while looking at the code. I'm also making these patches available in git form for those of you who want to help out with testing ...

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

You'll note the patches aren't signed off yet, that's because I'm not ready for them to get pulled anywhere important just yet.

Next on my list is the ability to dynamically enable/disable the packet access checks for labeled IPsec and SECMARK based on the presence of any configuration - similar to what we are doing today with NetLabel and the netlbl_enabled() function.

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 v3 1/2 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/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      |   38 +++++++++++++++
 5 files changed, 156 insertions(+), 6 deletions(-)
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..3ed4e4e 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 +37 -1
index 6100fc0..60e07d4 100644
@@ -16,12 +16,13 @@
  * Updated: Hewlett-Packard <[email protected]>
  *
  *      Added support for NetLabel
+ *      Added support for the policy capability bitmap
  *
  * Updated: Chad Sellers <[email protected]>
  *
  *  Added validation of kernel classes and permissions
  *
- * Copyright (C) 2006 Hewlett-Packard Development Company, L.P.
+ * Copyright (C) 2006 - 2007 Hewlett-Packard Development Company, L.P.
  * Copyright (C) 2004-2006 Trusted Computer Solutions, Inc.
  * Copyright (C) 2003 - 2004, 2006 Tresys Technology, LLC
  * Copyright (C) 2003 Red Hat, Inc., James Morris <[email protected]>
@@ -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
  */
@@ -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;
@@ -2102,6 +2108,36 @@ err:
 	return rc;
 }
 
+int security_get_policycaps(int *len, int **values)
+{
+	int rc = -ENOMEM;
+	unsigned int iter;
+
+	POLICY_RDLOCK;
+
+	*values = kcalloc(POLICYDB_CAPABILITY_MAX, sizeof(int), GFP_ATOMIC);
+	if (*values == NULL)
+		goto out;
+	for (iter = 0; iter < POLICYDB_CAPABILITY_MAX; iter++)
+		(*values)[iter] = ebitmap_get_bit(&policydb.policycaps, iter);
+	*len = POLICYDB_CAPABILITY_MAX;
+
+out:
+	POLICY_RDUNLOCK;
+	return rc;
+}
+
+int security_policycap_supported(unsigned int req_cap)
+{
+	int rc;
+
+	POLICY_RDLOCK;
+	rc = ebitmap_get_bit(&policydb.policycaps, req_cap);
+	POLICY_RDUNLOCK;
+
+	return rc;
+}
+
 struct selinux_audit_rule {
 	u32 au_seqno;
 	struct context au_ctxt;

--
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 v3 1/2] [SELINUX] Add a capabilities bitmap to SELinux policy version 22

Quoted 19 lines

diff --git a/security/selinux/include/security.h b/security/selinux/include/security.h index 83bdd4d..cc53ce4 100644
--- a/security/selinux/include/security.h
+++ b/security/selinux/include/security.h
@@ -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

Quoted 1 line

struct netlbl_lsm_secattr;

This needs to be fixed and supported in security/selinux/Kconfig as well.

Quoted 9 lines

-#define SEL_INITCON_INO_OFFSET 0x01000000
-#define SEL_BOOL_INO_OFFSET 0x02000000
-#define SEL_CLASS_INO_OFFSET 0x04000000
-#define SEL_INO_MASK 0x00ffffff
+#define SEL_INITCON_INO_OFFSET 0x01000000
+#define SEL_BOOL_INO_OFFSET 0x02000000
+#define SEL_CLASS_INO_OFFSET 0x04000000
+#define SEL_POLICYCAP_INO_OFFSET 0x08000000
+#define SEL_INO_MASK 0x00ffffff

I like it no matter what they say :)

Quoted 7 lines

+static ssize_t sel_read_policycap(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ int value;
+ char tmpbuf[TMPBUFLEN];
+ ssize_t length;
+ unsigned long inode = file->f_path.dentry->d_inode->i_ino;

can we call this i_ino please? i know its a nit, but i was confused when i read the next line and initialy thought inode was a struct inode * like everywhere else

Quoted 18 lines

+
+ value = security_policycap_supported(inode & SEL_INO_MASK);
+ length = scnprintf(tmpbuf, TMPBUFLEN, "%d", value);
+
+ return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
+}
+
+static const struct file_operations sel_policycap_ops = {
+ .read = sel_read_policycap,
+};
+
static int sel_make_perm_files(char *objclass, int classvalue,
struct dentry *dir)
{
@@ -1530,6 +1569,36 @@ out:
return rc;
}

Quoted 10 lines

+static int sel_make_policycap(void)
+{
+ unsigned int iter;
+ struct dentry *dentry = NULL;
+ struct inode *inode = NULL;
+
+ sel_remove_entries(policycap_dir);
+
+ for (iter = 0; iter <= POLICYDB_CAPABILITY_MAX; iter++) {
+ if (iter <= ARRAY_SIZE(policycap_names))

aren't these going to grow together and always array_size(policycap_names) == POLICYDB_CAP_MAX + 1 ??

assuming they were different, aren't you running one off the end of the policycap_names array? Don't you need to be strictly < ARRAY_SIZE ?

[snip]

Quoted 10 lines

@@ -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,

+ }
};

I don't care if policydb_compat[] does it wrong. Tabs, not spaces.

[snip]

Quoted 1 line

+int security_get_policycaps(int *len, int **values)

Who is using this function? ints just seem huge to hold one bit each :(

Quoted 7 lines

+{
+ int rc = -ENOMEM;
+ unsigned int iter;
+
+ POLICY_RDLOCK;
+
+ *values = kcalloc(POLICYDB_CAPABILITY_MAX, sizeof(int), GFP_ATOMIC);

Depedning on who you think is going to use this, we might not need GFP_ATOMIC...

Quoted 9 lines

+ if (*values == NULL)
+ goto out;
+ for (iter = 0; iter < POLICYDB_CAPABILITY_MAX; iter++)
+ (*values)[iter] = ebitmap_get_bit(&policydb.policycaps, iter);
+ *len = POLICYDB_CAPABILITY_MAX;
+
+out:
+ POLICY_RDUNLOCK;
+ return rc;

--
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 v3 1/2] [SELINUX] Add a capabilities bitmap to SELinux policy version 22

Quoted 10 lines · Eric Paris
Quoted 10 lines

/* 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

Quoted 3 lines
Quoted 1 line

struct netlbl_lsm_secattr;

This needs to be fixed and supported in security/selinux/Kconfig as well.

Didn't know that was there - thank you.

Quoted 11 lines
Quoted 7 lines

+static ssize_t sel_read_policycap(struct file *file, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ int value;
+ char tmpbuf[TMPBUFLEN];
+ ssize_t length;
+ unsigned long inode = file->f_path.dentry->d_inode->i_ino;

can we call this i_ino please? i know its a nit, but i was confused when i read the next line and initialy thought inode was a struct inode * like everywhere else

I'll make the change, but just because it's you :)

Quoted 11 lines
Quoted 10 lines

+static int sel_make_policycap(void)
+{
+ unsigned int iter;
+ struct dentry *dentry = NULL;
+ struct inode *inode = NULL;
+
+ sel_remove_entries(policycap_dir);
+
+ for (iter = 0; iter <= POLICYDB_CAPABILITY_MAX; iter++) {
+ if (iter <= ARRAY_SIZE(policycap_names))

Quoted 2 lines

aren't these going to grow together and always array_size(policycap_names) == POLICYDB_CAP_MAX + 1 ??

Yes, technically this may be unnecessary, but I thought it might be a nice bit of added safety.

Quoted 2 lines

assuming they were different, aren't you running one off the end of the policycap_names array? Don't you need to be strictly < ARRAY_SIZE ?

Sure looks like it doesn't it - fixed.

Quoted 11 lines
Quoted 10 lines

@@ -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,

+ }
};

Quoted 1 line

I don't care if policydb_compat[] does it wrong. Tabs, not spaces.

I place the blame squarely on the "paste" functionality of my editor. Bad editor! ... Bad! ... Bad! ... Bad!

Quoted 3 lines
Quoted 1 line

+int security_get_policycaps(int *len, int **values)

Who is using this function? ints just seem huge to hold one bit each :(

Right now nobody, but I threw it in for future use since it seems reasonable to export a function so that the SELinux portions outside the security server could query the policy capability bitmap. If you feel strongly about it I can rip it out and then we'll just add it back in later ... technically it is dead code I suppose.

Quoted 10 lines
Quoted 7 lines

+{
+ int rc = -ENOMEM;
+ unsigned int iter;
+
+ POLICY_RDLOCK;
+
+ *values = kcalloc(POLICYDB_CAPABILITY_MAX, sizeof(int), GFP_ATOMIC);

Depedning on who you think is going to use this, we might not need GFP_ATOMIC...

It seems safer and in keeping with the other related functions.

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
#4 lore raw

RFC PATCH v3 2/2 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      |   76 +++++++++++++++++++++++++++++++++++
 3 files changed, 101 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 +76 -0

82 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.

#5 lore raw

Re: [RFC PATCH v3 2/2] [SELINUX] Better integration between peer labeling subsystems

security/selinux/ss/services.c out: · line 2056

Quoted 4 lines · Paul Moore
security/selinux/ss/services.c +4 -0
+       if (!ss_initialized || !selinux_mls_enabled) {
+               *peer_sid = SECSID_NULL;
+               return 0;
+       }

Is it possible for both netlbl_sid and xfrm_sid to be != SECSID_NULL if !ss_initialized? What label to packets get while !ss_initialized?

The selinux_mls_enabled check is (i think) also useless at the moment since if MLS is off won't netlbl_sid be null? But I guess it doesn't
hurt to leave it in there. We can't call mls_context_cmp() the way
you are below if !selinux_mls_enabled since apparently no MLS != no MLS (which i wonder if it's right, but i didn't check all the callers of it)

</nit picking>

-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.

#6 lore raw

Re: [RFC PATCH v3 2/2] [SELINUX] Better integration between peer labeling subsystems

In reply to Paul Moore
Quoted 6 lines · Paul Moore
security/selinux/ss/services.c +6 -0
+               goto out_slowpath;
+       }
+       rc = mls_context_cmp(nlbl_ctx, xfrm_ctx);
+
+out_slowpath:
+       POLICY_RDUNLOCK;

security/selinux/ss/services.c out: · line 2089

Quoted 10 lines
security/selinux/ss/services.c +10 -0
+       if (rc == 0)
+               /* at present NetLabel SIDs/labels really only carry MLS
+                * information so if the MLS portion of the NetLabel SID
+                * matches the MLS portion of the labeled XFRM SID/label
+                * then pass along the XFRM SID as it has the most peer label
+                * information */
+               *peer_sid = xfrm_sid;
+       else
+               *peer_sid = SECSID_NULL;
+       return rc;

Actually now that I look at it, doesn't mls_context_cmp return 1 if they are the same and 0 if they are different? So you'd need rc = !mls_context_cmp () and we can then drop both the ss_initialized and the mls_enabled stuff I was talking about before?

Am reading this wrong?

-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
#7 lore raw

Re: [RFC PATCH v3 2/2] [SELINUX] Better integration between peer labeling subsystems

Quoted 8 lines · Eric Paris

security/selinux/ss/services.c out: · line 2056

Quoted 4 lines · Paul Moore
security/selinux/ss/services.c +4 -0
+       if (!ss_initialized || !selinux_mls_enabled) {
+               *peer_sid = SECSID_NULL;
+               return 0;
+       }

Is it possible for both netlbl_sid and xfrm_sid to be != SECSID_NULL if !ss_initialized? What label to packets get while !ss_initialized?

Hmmm ... so you're thinking ss_initialized is redundant here. Good catch. Looking at the NetLabel secattr_to_sid code in ss/services.c you're right - it has it's own ss_initialized check which will always result in netlbl_sid == SECSID_NULL when the security server is not initialized. While I don't quickly see something similar in the labeled XFRM code I suspect it would get tripped up on the context_to_sid and sid_to_context calls. Regardless, we only need one to be SECSID_NULL and netlbl_sid would catch it so you're right - out with the check (and in with a comment so we don't wonder later why it's not there).

Quoted 3 lines

The selinux_mls_enabled check is (i think) also useless at the moment since if MLS is off won't netlbl_sid be null? But I guess it doesn't hurt to leave it in there.

This is rather interesting, if you ignore the selinux_mls_enabled check I believe you would end up a netlbl_sid which is equal to SECINITSID_NETMSG. Look in security_netlbl_secattr_to_sid() in the if block when (secattr->flags & NETLBL_SECATTR_MLS_LVL) and you'll see that the key security server MLS calls are to mls_import_netlbl_lvl() which will be a no-op and to mls_context_isvalid() which will declare the context valid as the default "base sid" which in this case is SECINITSID_NETMSG. Perhaps not the most obvious conclusion at first glance but it does make sense.

Quoted 4 lines

We can't call mls_context_cmp() the way
you are below if !selinux_mls_enabled since apparently no MLS != no MLS (which i wonder if it's right, but i didn't check all the callers of it)

You lost me on the "no MLS != no MLS". Other than the obvious brain-o on the mls_context_cmp() return value I think we'd be okay calling mls_context_cmp() even when selinux_mls_enabled if false as we would end up returning the xfrm_sid which would be the right thing to do in this case.

I'm going to leave the selinux_mls_enabled check in for now as my gut tells me it is "safer", although I believe the function would still operate correctly even if the check were not in place.

Quoted 1 line

</nit picking>

Fine with me, I'm glad it's getting nit picked - that's why I keep posting the patches :) Once development slows a bit I'll start doing more testing which should help sort out some of these problems too, but if anyone wants to get a head start ...

Quoted 13 lines · Eric Paris

security/selinux/ss/services.c out: · line 2089

Quoted 12 lines
security/selinux/ss/services.c +7 -0
+out_slowpath:
+       POLICY_RDUNLOCK;
+       if (rc == 0)
+               /* at present NetLabel SIDs/labels really only carry MLS
+                * information so if the MLS portion of the NetLabel SID
+                * matches the MLS portion of the labeled XFRM SID/label
+                * then pass along the XFRM SID as it has the most peer

label + * information */

security/selinux/ss/services.c +4 -0
+               *peer_sid = xfrm_sid;
+       else
+               *peer_sid = SECSID_NULL;
+       return rc;
Quoted 4 lines

Actually now that I look at it, doesn't mls_context_cmp return 1 if they are the same and 0 if they are different? So you'd need rc = !mls_context_cmp () and we can then drop both the ss_initialized and the mls_enabled stuff I was talking about before?

See my comments above. You are correct that I mixed up the return values. I remember checking that when I was writing the code but I guess I'm too used to memcmp()/strcmp() and friends ...

Thanks for taking the time to look at the code.

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.