Skip to contentSkip to conversation

libselinux: Fix file labels for regexes with metachars

PATCH Applied Jeff Vander Stoep 3 participants 3 messages Jul 1, 2015 – Jul 6, 2015 SELinux security module

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: Fix file labels for regexes with metachars

File labels assigned using the lookup_best_match() function do not assign the best match if its regex contains metacharacters.

For non-exact regex matches, lookup_best_match() finds the closest match by tracking the length of the matching prefix. Prefix match is tracked via the prefix_len variable. This was previously calculated and set in the spec_hasMetaChars() function. Commit 3cb6078 removed the prefix_len calculation, this commit restores it.

---
 libselinux/src/label_file.h | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.h +2 -0
index 73bcbba..30bc911 100644
@@ -148,6 +148,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
 	end = c + len;
 
 	spec->hasMetaChars = 0;
+	spec->prefix_len = len;
 
 	/* Look at each character in the RE specification string for a
 	 * meta character. Return when any meta character reached. */
@@ -164,6 +165,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
 		case '(':
 		case '{':
 			spec->hasMetaChars = 1;
+			spec->prefix_len = c - spec->regex_str;
 			return;
 		case '\\':	/* skip the next character */
 			c++;
Signature · 1 line
2.4.3.573.g4eafbef
#1 lore raw
Quoted 13 lines · Jeff Vander Stoep
Quoted 1 line

File labels assigned using the lookup_best_match() function do not

assign the best match if its regex contains metacharacters.

For non-exact regex matches, lookup_best_match() finds the closest match by tracking the length of the matching prefix. Prefix match is tracked via the prefix_len variable. This was previously calculated and set in the spec_hasMetaChars() function. Commit 3cb6078 removed the prefix_len calculation, this commit restores it.

Ack - Thanks fixes the problem

Quoted 34 lines

---
libselinux/src/label_file.h | 2 ++

1 file changed, 2 insertions(+)
libselinux/src/label_file.h +2 -0
index 73bcbba..30bc911 100644
@@ -148,6 +148,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
    end = c + len;
 
    spec->hasMetaChars = 0;
+    spec->prefix_len = len;
 
    /* Look at each character in the RE specification string for a
     * meta character. Return when any meta character reached. */
@@ -164,6 +165,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
        case '(':
        case '{':
            spec->hasMetaChars = 1;
+            spec->prefix_len = c - spec->regex_str;
            return;
        case '\\':    /* skip the next character */
            c++;
Signature · 8 lines
2.4.3.573.g4eafbef

_______________________________________________
Selinux mailing list
[email protected]
To unsubscribe, send email to [email protected].
To get help, send an email containing "help" to 
[email protected].
#2 lore raw
In reply to Jeff Vander Stoep
Quoted 10 lines · Jeff Vander Stoep

File labels assigned using the lookup_best_match() function do not assign the best match if its regex contains metacharacters.

For non-exact regex matches, lookup_best_match() finds the closest match by tracking the length of the matching prefix. Prefix match is tracked via the prefix_len variable. This was previously calculated and set in the spec_hasMetaChars() function. Commit 3cb6078 removed the prefix_len calculation, this commit restores it.

Thanks, applied.

Quoted 25 lines
---
 libselinux/src/label_file.h | 2 ++
 1 file changed, 2 insertions(+)
libselinux/src/label_file.h +2 -0
index 73bcbba..30bc911 100644
@@ -148,6 +148,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
 	end = c + len;
 
 	spec->hasMetaChars = 0;
+	spec->prefix_len = len;
 
 	/* Look at each character in the RE specification string for a
 	 * meta character. Return when any meta character reached. */
@@ -164,6 +165,7 @@ static inline void spec_hasMetaChars(struct spec *spec)
 		case '(':
 		case '{':
 			spec->hasMetaChars = 1;
+			spec->prefix_len = c - spec->regex_str;
 			return;
 		case '\\':	/* skip the next character */
 			c++;