Skip to contentSkip to conversation

selinux: fix non-MLS handling in mls_context_to_sid()

PATCH In review Paul Moore 1 participant 2 messages Nov 14, 2018 SELinux security module

lore
Share & tools
lore

Paul Moore

author maintainer
#0 lore raw

PATCH 1/1 selinux: fix non-MLS handling in mls_context_to_sid()

Commit 95ffe194204a ("selinux: refactor mls_context_to_sid() and make it stricter") inadvertently changed how we handle labels that did not contain MLS information. This patch restores the proper behavior in mls_context_to_sid() and adds a comment explaining the proper behavior to help ensure this doesn't happen again.

Fixes 95ffe194204a ("selinux: refactor mls_context_to_sid() and make it stricter")
---
 security/selinux/ss/mls.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
security/selinux/ss/mls.c +7 -3
index 2fe459df3c85..b7efa2296969 100644
@@ -245,9 +245,13 @@ int mls_context_to_sid(struct policydb *pol,
 	char *rangep[2];
 
 	if (!pol->mls_enabled) {
-		if ((def_sid != SECSID_NULL && oldc) || (*scontext) == '\0')
-			return 0;
-		return -EINVAL;
+		/*
+		 * With no MLS, only return -EINVAL if there is a MLS field
+		 * and it did not come from an xattr.
+		 */
+		if (oldc && def_sid == SECSID_NULL)
+			return -EINVAL;
+		return 0;
 	}
 
 	/*
author maintainer
#1 lore raw
Quoted 6 lines · Paul Moore

Commit 95ffe194204a ("selinux: refactor mls_context_to_sid() and make it stricter") inadvertently changed how we handle labels that did not contain MLS information. This patch restores the proper behavior in mls_context_to_sid() and adds a comment explaining the proper behavior to help ensure this doesn't happen again.

Quoted 6 lines
Fixes 95ffe194204a ("selinux: refactor mls_context_to_sid() and make it stricter")
---
 security/selinux/ss/mls.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Building a test kernel now, assuming all goes well I'll merge this into selinux/stable-4.20 and send it to Linus this week.

Quoted 22 lines
security/selinux/ss/mls.c +7 -3
index 2fe459df3c85..b7efa2296969 100644
@@ -245,9 +245,13 @@ int mls_context_to_sid(struct policydb *pol,
        char *rangep[2];
 
        if (!pol->mls_enabled) {
-               if ((def_sid != SECSID_NULL && oldc) || (*scontext) == '\0')
-                       return 0;
-               return -EINVAL;
+               /*
+                * With no MLS, only return -EINVAL if there is a MLS field
+                * and it did not come from an xattr.
+                */
+               if (oldc && def_sid == SECSID_NULL)
+                       return -EINVAL;
+               return 0;
        }
 
        /*
Signature · 2 lines
paul moore
www.paul-moore.com