Skip to contentSkip to conversation

policy defined range transitions

PATCH In review Darrel Goeddel 3 participants 3 messages Feb 16, 2005 – Feb 17, 2005 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 policy defined range transitions

Attached are patches that implement range_transition statements for the policy.
The range_transitions will be used for admin users invoking certain programs.
Examples include starting/stopping daemons, working with log files, etc. This
allows the admin to perform tasks that need to be done at a certain MLS level without the need to manually switch level before doing so. It is the MLS counterpart to type_transition and role_transition (more akin to role_transition because it only deals with process transitions). The syntax is:

range_transition "process domain" "executable type" "new range";

The mlsconstraints (for process transition) requires either that the current domain has the privilege to change its level (mlsprocsetsl), or that the current domain has the privilege to "use" a range_transition (privrangetrans) AND that the new domain has the mlsrangetrans attribute. The patch does not currently add the privrangetrans to any domains (a likely candidate is sysadm_t). The MLS range that is transitioned to is also subject to the usual restriction of falling within the user's allowed MLS range.

PLEASE NOTE: This patch changes the binary policy format. However, it does not change the binary policy version. The binary policy version was bumped to 19 for the previous mls changes and has not yet been included in an official release - these changes would become a part of the version 18 to 19 update. People keeping up with the latest CVS snapshot will need to recompile the kernel, libsepol, checkpolicy, and the policy.

Questions/comments?

Thanks,

Signature · 1 line
Darrel
security/selinux/ss/mls.c +27 -22
diff -ruNp linux-2.6-nsa-20050215/security/selinux/ss/mls.c linux-2.6-20050216/security/selinux/ss/mls.c
@@ -374,32 +374,23 @@ static inline int mls_scopy_context(stru
 }
 
 /*
- * Copy the MLS level into the context.
+ * Copies the MLS range `range' into `context'.
  */
-int mls_level_cpy_and_set(struct context *scontext, struct mls_level *nlevel,
-                          struct context *ncontext)
+static inline int mls_range_set(struct context *context,
+                                struct mls_range *range)
 {
-	int rc;
+	int l, rc = 0;
 
-	/* copy in the current clearance */
-	ncontext->range.level[1].sens = scontext->range.level[1].sens;
-	rc = ebitmap_cpy(&ncontext->range.level[1].cat,
-	                 &scontext->range.level[1].cat);
-	if (rc)
-		return rc;
-
-	/* copy in the new level */
-	ncontext->range.level[0].sens = nlevel->sens;
-	rc = ebitmap_cpy(&ncontext->range.level[0].cat, &nlevel->cat);
-	if (rc)
-		return rc;
-
-	/* check validity of new context */
-	rc = mls_context_isvalid(&policydb, ncontext);
-	if (!rc)
-		return -EINVAL;
+	/* Copy the MLS range into the  context */
+	for (l = 0; l < 2; l++) {
+		context->range.level[l].sens = range->level[l].sens;
+		rc = ebitmap_cpy(&context->range.level[l].cat,
+				 &range->level[l].cat);
+		if (rc)
+			break;
+	}
 
-	return 0;
+	return rc;
 }
 
 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
@@ -497,6 +488,20 @@ int mls_compute_sid(struct context *scon
 
 	switch (specified) {
 	case AVTAB_TRANSITION:
+		if (tclass == SECCLASS_PROCESS) {
+			struct range_trans *rangetr;
+			/* Look for a range transition rule. */
+			for (rangetr = policydb.range_tr; rangetr;
+			     rangetr = rangetr->next) {
+				if (rangetr->dom == scontext->type &&
+				    rangetr->type == tcontext->type) {
+					/* Set the range from the rule */
+					return mls_range_set(newcontext,
+					                     &rangetr->range);
+				}
+			}
+		}
+		/* Fallthrough */
 	case AVTAB_CHANGE:
 		if (tclass == SECCLASS_PROCESS)
 			/* Use the process MLS attributes. */
security/selinux/ss/mls.h +0 -3
diff -ruNp linux-2.6-nsa-20050215/security/selinux/ss/mls.h linux-2.6-20050216/security/selinux/ss/mls.h
@@ -38,8 +38,5 @@ int mls_compute_sid(struct context *scon
 int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
                          struct context *usercon);
 
-int mls_level_cpy_and_set(struct context *scontext, struct mls_level *nlevel,
-                          struct context *ncontext);
-
 #endif	/* _SS_MLS_H */
 
security/selinux/ss/policydb.c +30 -0
diff -ruNp linux-2.6-nsa-20050215/security/selinux/ss/policydb.c linux-2.6-20050216/security/selinux/ss/policydb.c
@@ -1395,6 +1395,7 @@ int policydb_read(struct policydb *p, vo
 	u32 buf[8], len, len2, config, nprim, nel, nel2;
 	char *policydb_str;
 	struct policydb_compat_info *info;
+	struct range_trans *rt, *lrt;
 
 	config = 0;
 
@@ -1800,6 +1801,35 @@ int policydb_read(struct policydb *p, vo
 		}
 	}
 
+	if (p->policyvers >= POLICYDB_VERSION_MLS) {
+		rc = next_entry(buf, fp, sizeof(u32));
+		if (rc < 0)
+			goto bad;
+		nel = le32_to_cpu(buf[0]);
+		lrt = NULL;
+		for (i = 0; i < nel; i++) {
+			rt = kmalloc(sizeof(*rt), GFP_KERNEL);
+			if (!rt) {
+				rc = -ENOMEM;
+				goto bad;
+			}
+			memset(rt, 0, sizeof(*rt));
+			if (lrt)
+				lrt->next = rt;
+			else
+				p->range_tr = rt;
+			rc = next_entry(buf, fp, (sizeof(u32) * 2));
+			if (rc < 0)
+				goto bad;
+			rt->dom = le32_to_cpu(buf[0]);
+			rt->type = le32_to_cpu(buf[1]);
+			rc = mls_read_range_helper(&rt->range, fp);
+			if (rc)
+				goto bad;
+			lrt = rt;
+		}
+	}
+
 	rc = 0;
 out:
 	return rc;
security/selinux/ss/policydb.h +10 -0
diff -ruNp linux-2.6-nsa-20050215/security/selinux/ss/policydb.h linux-2.6-20050216/security/selinux/ss/policydb.h
@@ -105,6 +105,13 @@ struct cat_datum {
 	unsigned char isalias;  /* is this category an alias for another? */
 };
 
+struct range_trans {
+	u32 dom;			/* current process domain */
+	u32 type;			/* program executable type */
+	struct mls_range range;		/* new range */
+	struct range_trans *next;
+};
+
 /* Boolean data type */
 struct cond_bool_datum {
 	__u32 value;		/* internal type value */
@@ -227,6 +234,9 @@ struct policydb {
 	   fixed labeling behavior. */
   	struct genfs *genfs;
 
+	/* range transitions */
+	struct range_trans *range_tr;
+
 	unsigned int policyvers;
 };
 
security/selinux/ss/services.c +0 -7
diff -ruNp linux-2.6-nsa-20050215/security/selinux/ss/services.c linux-2.6-20050216/security/selinux/ss/services.c
@@ -844,13 +888,6 @@ static int security_compute_sid(u32 ssid
 				}
 			}
 		}
-
-		if (!type_change && !roletr) {
-			/* No change in process role or type. */
-			*out_sid = ssid;
-			goto out_unlock;
-
-		}
 		break;
 	default:
 		break;
checkpolicy/policy_parse.y +188 -0

218 lines not on this page · raw message

checkpolicy/policy_scan.l +2 -0
diff -ruNp selinux-usr-nsa-20050215/checkpolicy/policy_scan.l selinux-usr-20050216/checkpolicy/policy_scan.l
@@ -88,6 +88,8 @@ TYPE_CHANGE |
 type_change			{ return(TYPE_CHANGE); }
 ROLE_TRANSITION |
 role_transition			{ return(ROLE_TRANSITION); }
+RANGE_TRANSITION |
+range_transition		{ return(RANGE_TRANSITION); }
 SENSITIVITY |
 sensitivity			{ return(SENSITIVITY); }
 DOMINANCE |
libsepol/include/sepol/mls.h +0 -3
diff -ruNp selinux-usr-nsa-20050215/libsepol/include/sepol/mls.h selinux-usr-20050216/libsepol/include/sepol/mls.h
@@ -48,8 +48,5 @@ int mls_compute_sid(policydb_t *policydb
 int mls_setup_user_range(context_struct_t *fromcon, user_datum_t *user,
                          context_struct_t *usercon);
 
-int mls_level_cpy_and_set(policydb_t *policydb, context_struct_t *scontext,
-                          mls_level_t *nlevel, context_struct_t *ncontext);
-
 #endif	/* _MLS_H_ */
 
libsepol/include/sepol/policydb.h +10 -0
diff -ruNp selinux-usr-nsa-20050215/libsepol/include/sepol/policydb.h selinux-usr-20050216/libsepol/include/sepol/policydb.h
@@ -116,6 +116,13 @@ typedef struct cat_datum {
 	unsigned char isalias;  /* is this category an alias for another? */
 } cat_datum_t;
 
+typedef struct range_trans {
+	uint32_t dom;			/* current process domain */
+	uint32_t type;			/* program executable type */
+	mls_range_t range;		/* new range */
+	struct range_trans *next;
+} range_trans_t;
+
 /* Boolean data type */
 typedef struct cond_bool_datum {
 	uint32_t value;		/* internal type value */
@@ -240,6 +247,9 @@ typedef struct policydb {
 	   fixed labeling behavior. */
   	genfs_t *genfs;
 
+	/* range transitions */
+	range_trans_t *range_tr;
+
 	unsigned policyvers;
 } policydb_t;
 
libsepol/src/mls.c +27 -23

68 lines not on this page · raw message

libsepol/src/policydb.c +27 -0
diff -ruNp selinux-usr-nsa-20050215/libsepol/src/policydb.c selinux-usr-20050216/libsepol/src/policydb.c
@@ -1355,6 +1355,7 @@ int policydb_read(policydb_t * p, struct
 {
 	role_allow_t *ra, *lra;
 	role_trans_t *tr, *ltr;
+	range_trans_t *rt, *lrt;
 
 	ocontext_t *l, *c, *newc;
 	genfs_t *genfs_p, *genfs, *newgenfs;
@@ -1700,6 +1701,32 @@ int policydb_read(policydb_t * p, struct
 		}
 	}
 
+	if (r_policyvers >= POLICYDB_VERSION_MLS) {
+		buf = next_entry(fp, sizeof(uint32_t));
+		if (!buf)
+			goto bad;
+		nel = le32_to_cpu(buf[0]);
+		lrt = NULL;
+		for (i = 0; i < nel; i++) {
+			rt = malloc(sizeof(range_trans_t));
+			if (!rt)
+				goto bad;
+			memset(rt, 0, sizeof(range_trans_t));
+			if (lrt)
+				lrt->next = rt;
+			else
+				p->range_tr = rt;
+			buf = next_entry(fp, (sizeof(uint32_t) * 2));
+			if (!buf)
+				goto bad;
+			rt->dom = le32_to_cpu(buf[0]);
+			rt->type = le32_to_cpu(buf[1]);
+			if (mls_read_range_helper(&rt->range, fp))
+				goto bad;
+			lrt = rt;
+		}
+	}
+
 	return 0;
 bad:
 	policydb_destroy(p);
libsepol/src/services.c +0 -7
diff -ruNp selinux-usr-nsa-20050215/libsepol/src/services.c selinux-usr-20050216/libsepol/src/services.c
@@ -752,13 +752,6 @@ static int sepol_compute_sid(security_id
 				}
 			}
 		}
-
-		if (!type_change && !roletr) {
-			/* No change in process role or type. */
-			*out_sid = ssid;
-			goto out;
-
-		}
 		break;
 	default:
 		break;
libsepol/src/write.c +20 -0
diff -ruNp selinux-usr-nsa-20050215/libsepol/src/write.c selinux-usr-20050216/libsepol/src/write.c
@@ -695,6 +695,7 @@ int policydb_write(policydb_t * p, struc
 {
 	struct role_allow *ra;
 	struct role_trans *tr;
+	struct range_trans *rt;
 	ocontext_t *c;
 	genfs_t *genfs;
 	int i, j, num_syms;
@@ -914,6 +915,25 @@ int policydb_write(policydb_t * p, struc
 		}
 	}
 
+	if (policyvers >= POLICYDB_VERSION_MLS) {
+		nel = 0;
+		for (rt = p->range_tr; rt; rt = rt->next)
+			nel++;
+		buf[0] = cpu_to_le32(nel);
+		items = put_entry(buf, sizeof(uint32_t), 1, fp);
+		if (items != 1)
+			return -1;
+		for (rt = p->range_tr; rt; rt = rt->next) {
+			buf[0] = cpu_to_le32(rt->dom);
+			buf[1] = cpu_to_le32(rt->type);
+			items = put_entry(buf, sizeof(uint32_t), 2, fp);
+			if (items != 2)
+				return -1;
+			if (mls_write_range_helper(&rt->range, fp))
+				return -1;
+		}
+	}
+
 	return 0;
 }
 
policy/attrib.te +2 -0
diff -ruNp selinux-usr-nsa-20050215/policy/attrib.te selinux-usr-20050216/policy/attrib.te
@@ -52,6 +52,8 @@ attribute mlsxwindowngrade;
 
 attribute mlstrustedobject;
 
+attribute privrangetrans;
+attribute mlsrangetrans;
 
 #########################
 # Attributes for domains:
policy/mls +7 -3
diff -ruNp selinux-usr-nsa-20050215/policy/mls selinux-usr-20050216/policy/mls
@@ -434,9 +434,13 @@ mlsconstrain msg send
 # MLS policy for the process class
 #
 
-# new process labels must be dominated by the relabling subject's clearance and
-# sensitivity level changes require privilege
-mlsconstrain process { transition dyntransition }
+# new process labels must be dominated by the relabeling subject's clearance
+# and sensitivity level changes require privilege
+mlsconstrain process transition
+	(( h1 dom h2 ) and
+	 (( l1 eq l2 ) or ( t1 == mlsprocsetsl ) or
+	  (( t1 == privrangetrans ) and ( t2 == mlsrangetrans ))));
+mlsconstrain process dyntransition
 	(( h1 dom h2 ) and
 	 (( l1 eq l2 ) or ( t1 == mlsprocsetsl )));
 
#1 lore raw
Quoted 1 line · Darrel Goeddel

Questions/comments?

Looks ok to me.

- James

Signature · 9 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.
#2 lore raw
In reply to Darrel Goeddel
Quoted 18 lines · Darrel Goeddel

Attached are patches that implement range_transition statements for the policy.
The range_transitions will be used for admin users invoking certain programs. Examples include starting/stopping daemons, working with log files, etc. This
allows the admin to perform tasks that need to be done at a certain MLS level without the need to manually switch level before doing so. It is the MLS counterpart to type_transition and role_transition (more akin to role_transition because it only deals with process transitions). The syntax is:

range_transition "process domain" "executable type" "new range";

The mlsconstraints (for process transition) requires either that the current domain has the privilege to change its level (mlsprocsetsl), or that the current domain has the privilege to "use" a range_transition (privrangetrans) AND that the new domain has the mlsrangetrans attribute. The patch does not currently add the privrangetrans to any domains (a likely candidate is sysadm_t). The MLS range that is transitioned to is also subject to the usual restriction of falling within the user's allowed MLS range.

Quoted 6 lines

PLEASE NOTE: This patch changes the binary policy format. However, it does not change the binary policy version. The binary policy version was bumped to 19 for the previous mls changes and has not yet been included in an official release - these changes would become a part of the version 18 to 19 update. People keeping up with the latest CVS snapshot will need to recompile the kernel, libsepol, checkpolicy, and the policy.

Thanks, merged into sourceforge CVS (kernel >= 2.6.10-selinux6, libsepol

Quoted 1 line

= 1.3.5, checkpolicy >= 1.21.4).

Signature · 8 lines
Stephen Smalley <[email protected]>
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.