Skip to contentSkip to conversation

Allowing MLS->non-MLS and vice versa upon policy reload

PATCH In review Guido Trentalancia 2 participants 9 messages Feb 2, 2010 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allowing MLS->non-MLS and vice versa upon policy reload

Author: Guido Trentalancia <[email protected]>
Date:   Mon Feb 02 14:23:05 2010 +0100

Allow runtime switching between different policy types (e.g. from a MLS/MCS policy to a non-MLS/non-MCS policy or viceversa).

 security/selinux/include/security.h |    3 -
 security/selinux/selinuxfs.c        |    3 -
 security/selinux/ss/context.h       |    9 +--
 security/selinux/ss/mls.c           |   26 ++++-----
 security/selinux/ss/mls.h           |    2 
 security/selinux/ss/mls_types.h     |    5 +
 security/selinux/ss/policydb.c      |   24 +-------
 security/selinux/ss/policydb.h      |    4 +
 security/selinux/ss/services.c      |   73 +++++++++++++++++++++++---
 9 files changed, 100 insertions(+), 49 deletions(-)
security/selinux/include/security.h +2 -1
diff -pruN security-testing-2.6/security/selinux/include/security.h security-testing-2.6-new/security/selinux/include/security.h
@@ -57,7 +57,6 @@
 struct netlbl_lsm_secattr;
 
 extern int selinux_enabled;
-extern int selinux_mls_enabled;
 
 /* Policy capabilities */
 enum {
@@ -80,6 +79,8 @@ extern int selinux_policycap_openperm;
 /* limitation of boundary depth  */
 #define POLICYDB_BOUNDS_MAXDEPTH	4
 
+int security_mls_enabled(void);
+
 int security_load_policy(void *data, size_t len);
 
 int security_policycap_supported(unsigned int req_cap);
security/selinux/selinuxfs.c +2 -1
diff -pruN security-testing-2.6/security/selinux/selinuxfs.c security-testing-2.6-new/security/selinux/selinuxfs.c
@@ -282,7 +282,8 @@ static ssize_t sel_read_mls(struct file 
 	char tmpbuf[TMPBUFLEN];
 	ssize_t length;
 
-	length = scnprintf(tmpbuf, TMPBUFLEN, "%d", selinux_mls_enabled);
+	length = scnprintf(tmpbuf, TMPBUFLEN, "%d",
+			   security_mls_enabled());
 	return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
 }
 
security/selinux/ss/context.h +3 -6
diff -pruN security-testing-2.6/security/selinux/ss/context.h security-testing-2.6-new/security/selinux/ss/context.h
@@ -41,7 +41,7 @@ static inline int mls_context_cpy(struct
 {
 	int rc;
 
-	if (!selinux_mls_enabled)
+	if (!security_mls_enabled())
 		return 0;
 
 	dst->range.level[0].sens = src->range.level[0].sens;
@@ -64,7 +64,7 @@ static inline int mls_context_cpy_low(st
 {
 	int rc;
 
-	if (!selinux_mls_enabled)
+	if (!security_mls_enabled())
 		return 0;
 
 	dst->range.level[0].sens = src->range.level[0].sens;
@@ -82,7 +82,7 @@ out:
 
 static inline int mls_context_cmp(struct context *c1, struct context *c2)
 {
-	if (!selinux_mls_enabled)
+	if (!security_mls_enabled())
 		return 1;
 
 	return ((c1->range.level[0].sens == c2->range.level[0].sens) &&
@@ -93,9 +93,6 @@ static inline int mls_context_cmp(struct
 
 static inline void mls_context_destroy(struct context *c)
 {
-	if (!selinux_mls_enabled)
-		return;
-
 	ebitmap_destroy(&c->range.level[0].cat);
 	ebitmap_destroy(&c->range.level[1].cat);
 	mls_context_init(c);
security/selinux/ss/mls.c +13 -13
diff -pruN security-testing-2.6/security/selinux/ss/mls.c security-testing-2.6-new/security/selinux/ss/mls.c
@@ -39,7 +39,7 @@ int mls_compute_context_len(struct conte
 	struct ebitmap *e;
 	struct ebitmap_node *node;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return 0;
 
 	len = 1; /* for the beginning ":" */
@@ -93,7 +93,7 @@ void mls_sid_to_context(struct context *
 	struct ebitmap *e;
 	struct ebitmap_node *node;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return;
 
 	scontextp = *scontext;
@@ -200,7 +200,7 @@ int mls_context_isvalid(struct policydb 
 {
 	struct user_datum *usrdatum;
 
-	if (!selinux_mls_enabled)
+	if (!p->mls_enabled)
 		return 1;
 
 	if (!mls_range_isvalid(p, &c->range))
@@ -253,7 +253,7 @@ int mls_context_to_sid(struct policydb *
 	struct cat_datum *catdatum, *rngdatum;
 	int l, rc = -EINVAL;
 
-	if (!selinux_mls_enabled) {
+	if (!pol->mls_enabled) {
 		if (def_sid != SECSID_NULL && oldc)
 			*scontext += strlen(*scontext)+1;
 		return 0;
@@ -387,7 +387,7 @@ int mls_from_string(char *str, struct co
 	char *tmpstr, *freestr;
 	int rc;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return -EINVAL;
 
 	/* we need freestr because mls_context_to_sid will change
@@ -407,7 +407,7 @@ int mls_from_string(char *str, struct co
 /*
  * Copies the MLS range `range' into `context'.
  */
-static inline int mls_range_set(struct context *context,
+int mls_range_set(struct context *context,
 				struct mls_range *range)
 {
 	int l, rc = 0;
@@ -427,7 +427,7 @@ static inline int mls_range_set(struct c
 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
 			 struct context *usercon)
 {
-	if (selinux_mls_enabled) {
+	if (policydb.mls_enabled) {
 		struct mls_level *fromcon_sen = &(fromcon->range.level[0]);
 		struct mls_level *fromcon_clr = &(fromcon->range.level[1]);
 		struct mls_level *user_low = &(user->range.level[0]);
@@ -477,7 +477,7 @@ int mls_convert_context(struct policydb 
 	struct ebitmap_node *node;
 	int l, i;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return 0;
 
 	for (l = 0; l < 2; l++) {
@@ -516,7 +516,7 @@ int mls_compute_sid(struct context *scon
 	struct range_trans rtr;
 	struct mls_range *r;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return 0;
 
 	switch (specified) {
@@ -559,7 +559,7 @@ int mls_compute_sid(struct context *scon
 void mls_export_netlbl_lvl(struct context *context,
 			   struct netlbl_lsm_secattr *secattr)
 {
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return;
 
 	secattr->attr.mls.lvl = context->range.level[0].sens - 1;
@@ -579,7 +579,7 @@ void mls_export_netlbl_lvl(struct contex
 void mls_import_netlbl_lvl(struct context *context,
 			   struct netlbl_lsm_secattr *secattr)
 {
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return;
 
 	context->range.level[0].sens = secattr->attr.mls.lvl + 1;
@@ -601,7 +601,7 @@ int mls_export_netlbl_cat(struct context
 {
 	int rc;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return 0;
 
 	rc = ebitmap_netlbl_export(&context->range.level[0].cat,
@@ -629,7 +629,7 @@ int mls_import_netlbl_cat(struct context
 {
 	int rc;
 
-	if (!selinux_mls_enabled)
+	if (!policydb.mls_enabled)
 		return 0;
 
 	rc = ebitmap_netlbl_import(&context->range.level[0].cat,
security/selinux/ss/mls.h +2 -0
diff -pruN security-testing-2.6/security/selinux/ss/mls.h security-testing-2.6-new/security/selinux/ss/mls.h
@@ -39,6 +39,8 @@ int mls_context_to_sid(struct policydb *
 
 int mls_from_string(char *str, struct context *context, gfp_t gfp_mask);
 
+int mls_range_set(struct context *context, struct mls_range *range);
+
 int mls_convert_context(struct policydb *oldp,
 			struct policydb *newp,
 			struct context *context);
security/selinux/ss/mls_types.h +3 -2
diff -pruN security-testing-2.6/security/selinux/ss/mls_types.h security-testing-2.6-new/security/selinux/ss/mls_types.h
@@ -15,6 +15,7 @@
 #define _SS_MLS_TYPES_H_
 
 #include "security.h"
+#include "ebitmap.h"
 
 struct mls_level {
 	u32 sens;		/* sensitivity */
@@ -27,7 +28,7 @@ struct mls_range {
 
 static inline int mls_level_eq(struct mls_level *l1, struct mls_level *l2)
 {
-	if (!selinux_mls_enabled)
+	if (!security_mls_enabled())
 		return 1;
 
 	return ((l1->sens == l2->sens) &&
@@ -36,7 +37,7 @@ static inline int mls_level_eq(struct ml
 
 static inline int mls_level_dom(struct mls_level *l1, struct mls_level *l2)
 {
-	if (!selinux_mls_enabled)
+	if (!security_mls_enabled())
 		return 1;
 
 	return ((l1->sens >= l2->sens) &&
security/selinux/ss/policydb.c +4 -20
diff -pruN security-testing-2.6/security/selinux/ss/policydb.c security-testing-2.6-new/security/selinux/ss/policydb.c
@@ -52,8 +52,6 @@ static char *symtab_name[SYM_NUM] = {
 };
 #endif
 
-int selinux_mls_enabled;
-
 static unsigned int symtab_sizes[SYM_NUM] = {
 	2,
 	32,
@@ -455,7 +453,7 @@ static int policydb_index_others(struct 
 
 	printk(KERN_DEBUG "SELinux:  %d users, %d roles, %d types, %d bools",
 	       p->p_users.nprim, p->p_roles.nprim, p->p_types.nprim, p->p_bools.nprim);
-	if (selinux_mls_enabled)
+	if (p->mls_enabled)
 		printk(", %d sens, %d cats", p->p_levels.nprim,
 		       p->p_cats.nprim);
 	printk("\n");
@@ -1717,14 +1715,12 @@ int policydb_read(struct policydb *p, vo
 	int i, j, rc;
 	__le32 buf[4];
 	u32 nodebuf[8];
-	u32 len, len2, config, nprim, nel, nel2;
+	u32 len, len2, nprim, nel, nel2;
 	char *policydb_str;
 	struct policydb_compat_info *info;
 	struct range_trans *rt;
 	struct mls_range *r;
 
-	config = 0;
-
 	rc = policydb_init(p);
 	if (rc)
 		goto out;
@@ -1772,7 +1768,7 @@ int policydb_read(struct policydb *p, vo
 	kfree(policydb_str);
 	policydb_str = NULL;
 
-	/* Read the version, config, and table sizes. */
+	/* Read the version and table sizes. */
 	rc = next_entry(buf, fp, sizeof(u32)*4);
 	if (rc < 0)
 		goto bad;
@@ -1787,13 +1783,7 @@ int policydb_read(struct policydb *p, vo
 	}
 
 	if ((le32_to_cpu(buf[1]) & POLICYDB_CONFIG_MLS)) {
-		if (ss_initialized && !selinux_mls_enabled) {
-			printk(KERN_ERR "SELinux: Cannot switch between non-MLS"
-				" and MLS policies\n");
-			goto bad;
-		}
-		selinux_mls_enabled = 1;
-		config |= POLICYDB_CONFIG_MLS;
+		p->mls_enabled = 1;
 
 		if (p->policyvers < POLICYDB_VERSION_MLS) {
 			printk(KERN_ERR "SELinux: security policydb version %d "
@@ -1801,12 +1791,6 @@ int policydb_read(struct policydb *p, vo
 				p->policyvers);
 			goto bad;
 		}
-	} else {
-		if (ss_initialized && selinux_mls_enabled) {
-			printk(KERN_ERR "SELinux: Cannot switch between MLS and"
-				" non-MLS policies\n");
-			goto bad;
-		}
 	}
 	p->reject_unknown = !!(le32_to_cpu(buf[1]) & REJECT_UNKNOWN);
 	p->allow_unknown = !!(le32_to_cpu(buf[1]) & ALLOW_UNKNOWN);
security/selinux/ss/policydb.h +4 -0
diff -pruN security-testing-2.6/security/selinux/ss/policydb.h security-testing-2.6-new/security/selinux/ss/policydb.h
@@ -27,6 +27,8 @@
 #include "symtab.h"
 #include "avtab.h"
 #include "sidtab.h"
+#include "ebitmap.h"
+#include "mls_types.h"
 #include "context.h"
 #include "constraint.h"
 
@@ -185,6 +187,8 @@ struct genfs {
 
 /* The policy database */
 struct policydb {
+	int mls_enabled;
+
 	/* symbol tables */
 	struct symtab symtab[SYM_NUM];
 #define p_commons symtab[SYM_COMMONS]
security/selinux/ss/services.c +67 -6

122 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Guido Trentalancia
Author: Guido Trentalancia <[email protected]>
Date:   Mon Feb 02 14:23:05 2010 +0100

Allow runtime switching between different policy types (e.g. from a MLS/MCS policy to a non-MLS/non-MCS policy or viceversa).

Patch mangled by your mail client, probably because you signed it. Read and follow the instructions in Documentation/email-clients.txt, or switch to another client. In the case of Evolution, for example, you set the paragraph style to Preformat and then use Insert->Text File to insert the patch into the message. To test, email it to yourself, save the email message and try applying it.

You want a "---" line before the diffstat output so that it doesn't get included in the git log.

Did you give up on addressing the initial SID issue or are you saving that for a later, separate patch?

Technically, security_mls_enabled() does not return True or False; it returns 1 or 0.

Your if (args->oldp->mls_enabled...)else if...else block is hard to read with the comment placement. I'd move them within the conditional block and use { } for all three clauses for ease of reading.

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

Hello again !

Quoted 7 lines · Stephen Smalley

On Tue, 2010-02-02 at 15:22 +0100, Guido Trentalancia wrote:
Patch mangled by your mail client, probably because you signed it. Read and follow the instructions in Documentation/email-clients.txt, or switch to another client. In the case of Evolution, for example, you set the paragraph style to Preformat and then use Insert->Text File to insert the patch into the message. To test, email it to yourself, save the email message and try applying it.

That's really odd. I have followed the advice in Documentation/email-clients.txt which you quoted... I don't know what else to do. Perhaps, I can send the final version as an attachment to the list and then you can forward that to the kernel mailing list ?

Quoted 2 lines

You want a "---" line before the diffstat output so that it doesn't get included in the git log.

That's fine. I'll add such a line between the description and the diffstat output.

Quoted 5 lines

Did you give up on addressing the initial SID issue or are you saving that for a later, separate patch?

Technically, security_mls_enabled() does not return True or False; it returns 1 or 0.

Yes, of course, I was just following your style since the next function comments "boolean" (read "integer to be interpreted as a boolean"). However I have now changed the comment.

Quoted 3 lines

Your if (args->oldp->mls_enabled...)else if...else block is hard to read with the comment placement. I'd move them within the conditional block and use { } for all three clauses for ease of reading.

That's what I did, but then checkpatch.pl was complaining about the {} block with a single statement (in disagreement with CodingStyle, so it's an inconsistency in the script with respect to the guidelines). I can do that easily, but then we'll get a warning !

Please let me know about the oops for ebitmap_destroy(). Do you think it is due to the initial SID issue rather than to calling mls_destroy() for a standard policy ? I wasn't saving that for a separate patch, it's just that we did not discuss that further...

Regards,

Guido

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

#3 lore raw
Quoted 11 lines · Guido Trentalancia

Hello again !

Quoted 7 lines · Stephen Smalley

On Tue, 2010-02-02 at 15:22 +0100, Guido Trentalancia wrote:
Patch mangled by your mail client, probably because you signed it. Read and follow the instructions in Documentation/email-clients.txt, or switch to another client. In the case of Evolution, for example, you set the paragraph style to Preformat and then use Insert->Text File to insert the patch into the message. To test, email it to yourself, save the email message and try applying it.

Quoted 4 lines

That's really odd. I have followed the advice in Documentation/email-clients.txt which you quoted... I don't know what else to do. Perhaps, I can send the final version as an attachment to the list and then you can forward that to the kernel mailing list ?

You can't digitally sign the message w/o causing the inlined patch to be encoded. So don't digitally sign patch postings.

Quoted 4 lines

That's what I did, but then checkpatch.pl was complaining about the {} block with a single statement (in disagreement with CodingStyle, so it's an inconsistency in the script with respect to the guidelines). I can do that easily, but then we'll get a warning !

That's ok. checkpatch is just advisory; it still falls to a person to make the final judgment.

Quoted 4 lines

Please let me know about the oops for ebitmap_destroy(). Do you think it is due to the initial SID issue rather than to calling mls_destroy() for a standard policy ? I wasn't saving that for a separate patch, it's just that we did not discuss that further...

I'd rather track down the cause and see if we can allow mls_context_destroy() to be unconditionally safe. In fact, I'm tempted to drop the mls_enabled tests from all of those inline functions and just ensure that the fields are always properly initialized and thus the functions will just evaluate properly even in the non-MLS case.

Chris is correct btw - the kernel has no notions of "standard", or "MCS". It only knows about MLS-enabled vs MLS-disabled.

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

Hello again !

Quoted 6 lines · Stephen Smalley
Quoted 3 lines · Guido Trentalancia

Hello again !

On Tue, 2010-02-02 at 11:44 -0500, Stephen Smalley wrote:

You can't digitally sign the message w/o causing the inlined patch to be encoded. So don't digitally sign patch postings.

That's fine. I won't sign patch postings anymore.

Quoted 2 lines

That's ok. checkpatch is just advisory; it still falls to a person to make the final judgment.

Ok.

Quoted 10 lines
Quoted 4 lines

Please let me know about the oops for ebitmap_destroy(). Do you think it is due to the initial SID issue rather than to calling mls_destroy() for a standard policy ? I wasn't saving that for a separate patch, it's just that we did not discuss that further...

I'd rather track down the cause and see if we can allow mls_context_destroy() to be unconditionally safe. In fact, I'm tempted to drop the mls_enabled tests from all of those inline functions and just ensure that the fields are always properly initialized and thus the functions will just evaluate properly even in the non-MLS case.

Well, after you told me to do that, we have context_destroy() calling mls_context_destroy(), which in turn calls:

ebitmap_destroy(&c->range.level[i].cat); for i={0,1}
memset(&c->range, 0, sizeof(c->range));

But in the case of a standard policy, there is no range field I suppose.

Quoted 2 lines

Chris is correct btw - the kernel has no notions of "standard", or "MCS". It only knows about MLS-enabled vs MLS-disabled.

Ok. So, I have now changed the message accordingly. Thanks again Chris for pointing that out !

By the way, I think I have now got confused about the initial SID issue that you mentioned earlier on... Could you please be more specific ? You should know what the code looks like at the moment in ss/services.c.

Regards,

Guido

--
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
Quoted 7 lines · Guido Trentalancia

Well, after you told me to do that, we have context_destroy() calling mls_context_destroy(), which in turn calls:

ebitmap_destroy(&c->range.level[i].cat); for i={0,1}
memset(&c->range, 0, sizeof(c->range));

But in the case of a standard policy, there is no range field I suppose.

struct context is defined in context.h and always has a struct mls_range range field (that was made unconditional when MLS support was turned into a runtime option rather than a compile-time option). context_init() always clears the entire structure, so all fields should be initialized to zero.

A struct mls_range is an array of mls_level structures with two elements (for the low and high). A struct mls_level is an unsigned integer sensitivity value and a struct ebitmap category set. A struct ebitmap is a node pointer and an unsigned integer highbit.

So if the structure was properly initialized, we should have an ebitmap with a NULL node pointer and a 0 highbit value. In that situation, ebitmap_destroy() should merely re-clear the two fields and return without any difficulty.

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.
#6 lore raw
In reply to Stephen Smalley

Stephen,

did you mean something like the code below when mentioning about the initial SID issue ? I remember you mentioned about matching oc->sid[0] with the argument key of convert_context, so we can first scan for the "unlabeled" SID and copy the MLS range only (as done in the previous patch) and then afterwards if we find a match with the key argument, we can copy the whole context over.

Quoted 3 lines · Stephen Smalley

On Tue, 2010-02-02 at 15:22 +0100, Guido Trentalancia wrote:
Did you give up on addressing the initial SID issue or are you saving that for a later, separate patch?

	/*
	 * Switching between non-MLS and MLS policy:
	 * ensure that the MLS fields of the context for all
	 * existing entries in the sidtab are filled in with a
	 * suitable default value, likely taken from one of the
	 * initial SIDs.
	 */
	else if (!args->oldp->mls_enabled && args->newp->mls_enabled) {
		int number_of_isids = 0;
		int matching_key = 0;
		oc = args->newp->ocontexts[OCON_ISID];
		while (oc) {
			if (oc->sid[0] == key)
				matching_key = 1;
			oc = oc->next;
			number_of_isids = number_of_isids + 1;
		}
		oc = args->newp->ocontexts[OCON_ISID];
		if (!matching_key) {
			while (oc && oc->sid[0] != SECINITSID_UNLABELED)
				oc = oc->next;
			if (!oc) {
				printk(KERN_ERR "SELinux:  unable to look up"
					" the initial SIDs list\n");
				goto bad;
			}
			range = &oc->context[0].range;
			/* set only the MLS range from "unlabeled" */
			rc = mls_range_set(c, range);
			if (rc)
				goto bad;
		} else {
			while (oc && oc->sid[0] != key)
				oc = oc->next;
			/* copy the whole context */
			rc = context_cpy(c, oc->context[0]);
			if (rc)
				goto bad;
		}
	}

I look forward to hearing from you about the above issue.

Regards,

Guido

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

#7 lore raw
Quoted 55 lines · Guido Trentalancia

Stephen,

did you mean something like the code below when mentioning about the initial SID issue ? I remember you mentioned about matching oc->sid[0] with the argument key of convert_context, so we can first scan for the "unlabeled" SID and copy the MLS range only (as done in the previous patch) and then afterwards if we find a match with the key argument, we can copy the whole context over.

Quoted 3 lines · Stephen Smalley

On Tue, 2010-02-02 at 15:22 +0100, Guido Trentalancia wrote:
Did you give up on addressing the initial SID issue or are you saving that for a later, separate patch?

	/*
	 * Switching between non-MLS and MLS policy:
	 * ensure that the MLS fields of the context for all
	 * existing entries in the sidtab are filled in with a
	 * suitable default value, likely taken from one of the
	 * initial SIDs.
	 */
	else if (!args->oldp->mls_enabled && args->newp->mls_enabled) {
		int number_of_isids = 0;
		int matching_key = 0;
		oc = args->newp->ocontexts[OCON_ISID];
		while (oc) {
			if (oc->sid[0] == key)
				matching_key = 1;
			oc = oc->next;
			number_of_isids = number_of_isids + 1;
		}
		oc = args->newp->ocontexts[OCON_ISID];
		if (!matching_key) {
			while (oc && oc->sid[0] != SECINITSID_UNLABELED)
				oc = oc->next;
			if (!oc) {
				printk(KERN_ERR "SELinux:  unable to look up"
					" the initial SIDs list\n");
				goto bad;
			}
			range = &oc->context[0].range;
			/* set only the MLS range from "unlabeled" */
			rc = mls_range_set(c, range);
			if (rc)
				goto bad;
		} else {
			while (oc && oc->sid[0] != key)
				oc = oc->next;
			/* copy the whole context */
			rc = context_cpy(c, oc->context[0]);
			if (rc)
				goto bad;
		}
	}
Quoted 1 line

I look forward to hearing from you about the above issue.

We later talked about using policydb_load_isids(). See:
http://marc.info/?l=selinux&m=126505150603677&w=2

This would be more general and would address reloading of initial SIDs even when staying within the same kind of policy.

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.
#8 lore raw
Quoted 56 lines · Stephen Smalley
Quoted 55 lines · Guido Trentalancia

Stephen,

did you mean something like the code below when mentioning about the initial SID issue ? I remember you mentioned about matching oc->sid[0] with the argument key of convert_context, so we can first scan for the "unlabeled" SID and copy the MLS range only (as done in the previous patch) and then afterwards if we find a match with the key argument, we can copy the whole context over.

Quoted 3 lines · Stephen Smalley

On Tue, 2010-02-02 at 15:22 +0100, Guido Trentalancia wrote:
Did you give up on addressing the initial SID issue or are you saving that for a later, separate patch?

	/*
	 * Switching between non-MLS and MLS policy:
	 * ensure that the MLS fields of the context for all
	 * existing entries in the sidtab are filled in with a
	 * suitable default value, likely taken from one of the
	 * initial SIDs.
	 */
	else if (!args->oldp->mls_enabled && args->newp->mls_enabled) {
		int number_of_isids = 0;
		int matching_key = 0;
		oc = args->newp->ocontexts[OCON_ISID];
		while (oc) {
			if (oc->sid[0] == key)
				matching_key = 1;
			oc = oc->next;
			number_of_isids = number_of_isids + 1;
		}
		oc = args->newp->ocontexts[OCON_ISID];
		if (!matching_key) {
			while (oc && oc->sid[0] != SECINITSID_UNLABELED)
				oc = oc->next;
			if (!oc) {
				printk(KERN_ERR "SELinux:  unable to look up"
					" the initial SIDs list\n");
				goto bad;
			}
			range = &oc->context[0].range;
			/* set only the MLS range from "unlabeled" */
			rc = mls_range_set(c, range);
			if (rc)
				goto bad;
		} else {
			while (oc && oc->sid[0] != key)
				oc = oc->next;
			/* copy the whole context */
			rc = context_cpy(c, oc->context[0]);
			if (rc)
				goto bad;
		}
	}
Quoted 7 lines
Quoted 1 line

I look forward to hearing from you about the above issue.

We later talked about using policydb_load_isids(). See:
http://marc.info/?l=selinux&m=126505150603677&w=2

This would be more general and would address reloading of initial SIDs even when staying within the same kind of policy.

Let's leave that for a separate, later patch though.

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.