Skip to contentSkip to conversation

Load the initial SIDs upon every policy load

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Load the initial SIDs upon every policy load

Stephen,

attached please find the tiny patch for always loading the initial SIDs. Should I say "for review" ? It relies on SECINITSID_NUM which at the moment is statically defined in flask.h (and represents the maximum initial SID).

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

Always load the initial SIDs, even in the case of a policy reload and not just at the initial policy load. This comes particularly handy after the introduction of a recent patch for enabling runtime switching between different policy types, although this patch is in theory independent from that feature.

---

 security/selinux/ss/services.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
security/selinux/ss/services.c +10 -4
@@ -1506,7 +1506,10 @@ static int clone_sid(u32 sid,
 {
 	struct sidtab *s = arg;
 
-	return sidtab_insert(s, sid, context);
+	if (sid > SECINITSID_NUM)
+		return sidtab_insert(s, sid, context);
+	else
+		return 0;
 }
 
 static inline int convert_context_handle_invalid_context(struct context *context)
@@ -1552,7 +1555,10 @@ static int convert_context(u32 key,
 	struct user_datum *usrdatum;
 	char *s;
 	u32 len;
-	int rc;
+	int rc = 0;
+
+	if (key <= SECINITSID_NUM)
+		goto out;
 
 	args = p;
 
@@ -1712,9 +1718,9 @@ int security_load_policy(void *data, siz
 	if (policydb_read(&newpolicydb, fp))
 		return -EINVAL;
 
-	if (sidtab_init(&newsidtab)) {
+	if (policydb_load_isids(&newpolicydb, &newsidtab)) {
 		policydb_destroy(&newpolicydb);
-		return -ENOMEM;
+		return -EINVAL;
 	}
 
 	if (selinux_set_mapping(&newpolicydb, secclass_map,
Author: Guido Trentalancia <[email protected]>
Date:   Mon Feb 02 22:11:05 2010 +0100

Always load the initial SIDs, even in the case of a policy reload and not just at the initial policy load. This comes particularly handy after the introduction of a recent patch for enabling runtime switching between different policy types, although this patch is in theory independent from that feature.

---

 security/selinux/ss/services.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
security/selinux/ss/services.c +10 -4
@@ -1506,7 +1506,10 @@ static int clone_sid(u32 sid,
 {
 	struct sidtab *s = arg;
 
-	return sidtab_insert(s, sid, context);
+	if (sid > SECINITSID_NUM)
+		return sidtab_insert(s, sid, context);
+	else
+		return 0;
 }
 
 static inline int convert_context_handle_invalid_context(struct context *context)
@@ -1552,7 +1555,10 @@ static int convert_context(u32 key,
 	struct user_datum *usrdatum;
 	char *s;
 	u32 len;
-	int rc;
+	int rc = 0;
+
+	if (key <= SECINITSID_NUM)
+		goto out;
 
 	args = p;
 
@@ -1712,9 +1718,9 @@ int security_load_policy(void *data, siz
 	if (policydb_read(&newpolicydb, fp))
 		return -EINVAL;
 
-	if (sidtab_init(&newsidtab)) {
+	if (policydb_load_isids(&newpolicydb, &newsidtab)) {
 		policydb_destroy(&newpolicydb);
-		return -ENOMEM;
+		return -EINVAL;
 	}
 
 	if (selinux_set_mapping(&newpolicydb, secclass_map,
#1 lore raw
Quoted 6 lines · Guido Trentalancia

Stephen,

attached please find the tiny patch for always loading the initial SIDs. Should I say "for review" ? It relies on SECINITSID_NUM which at the moment is statically defined in flask.h (and represents the maximum initial SID).

Normally you'd put [RFC] in the Subject line to indicate for review only, not for committing yet. No big deal though.

Quoted 22 lines
Author: Guido Trentalancia <[email protected]>
Date:   Mon Feb 02 22:11:05 2010 +0100

Always load the initial SIDs, even in the case of a policy reload and not just at the initial policy load. This comes particularly handy after the introduction of a recent patch for enabling runtime switching between different policy types, although this patch is in theory independent from that feature.

---

 security/selinux/ss/services.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
security/selinux/ss/services.c +0 -0
@@ -1712,9 +1718,9 @@ int security_load_policy(void *data, siz
 	if (policydb_read(&newpolicydb, fp))

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

Quoted 10 lines
security/selinux/ss/services.c +2 -2
 		return -EINVAL;
 
-	if (sidtab_init(&newsidtab)) {
+	if (policydb_load_isids(&newpolicydb, &newsidtab)) {
 		policydb_destroy(&newpolicydb);
-		return -ENOMEM;
+		return -EINVAL;
 	}
 
 	if (selinux_set_mapping(&newpolicydb, secclass_map,

One minor nit: Given that policydb_load_isids() may fail with either ENOMEM (sidtab_init failure) or EINVAL, you need to save the return code from it and return that instead of always returning EINVAL.

Otherwise, looks good - have you tested it?

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.