Skip to contentSkip to conversation

libselinux: do not log on unexpected escaped character

PATCH In review Thiébaud Weksteen 3 participants 3 messages Mar 11 – Apr 14 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: do not log on unexpected escaped character

For file_contexts entries relying on PCRE2, there are multiple escaped characters that are valid (e.g., \d). If such a character is identified, a log message is emitted. While this may have been useful for debugging, there is nothing actionable from that info message. Remove it.

Fixes 92306daf521 ("libselinux: rework selabel_file(5) database")
---
 libselinux/src/label_file.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
libselinux/src/label_file.h +3 -5
index 8fcf74e3..13451680 100644
@@ -231,7 +231,7 @@ static inline const char* file_kind_to_string(uint8_t file_kind)
  * Determine whether the regular expression specification has any meta characters
  * or any unsupported escape sequence.
  */
-static bool regex_has_meta_chars(const char *regex, size_t *prefix_len, const char *path, unsigned int lineno)
+static bool regex_has_meta_chars(const char *regex, size_t *prefix_len)
 {
 	const char *p = regex;
 	size_t plen = 0;
@@ -275,8 +275,7 @@ static bool regex_has_meta_chars(const char *regex, size_t *prefix_len, const ch
 			case ',':
 				continue;
 			default:
-				COMPAT_LOG(SELINUX_INFO, "%s:  line %u has unsupported escaped character %c (%#x) for literal matching, continuing using regex\n",
-					   path, lineno, isprint((unsigned char)*p) ? *p : '?', *p);
+				/* Unsupported escaped character, continuing using regex */
 				*prefix_len = plen;
 				return true;
 			}
@@ -343,7 +342,6 @@ static int regex_simplify(const char *regex, size_t len, char **out, const char
 				*p++ = regex[i++];
 				break;
 			default:
-				/* regex_has_meta_chars() reported already the notable occurrences */
 				free(result);
 				return 0;
 			}
@@ -523,7 +521,7 @@ static int insert_spec(const struct selabel_handle *rec, struct saved_data *data
 		return -1;
 	}
 
-	has_meta = regex_has_meta_chars(regex, &prefix_len, path, lineno);
+	has_meta = regex_has_meta_chars(regex, &prefix_len);
 
 	/* Ensured by read_spec_entry() */
 	assert(prefix_len < UINT16_MAX);
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Thiébaud Weksteen

For file_contexts entries relying on PCRE2, there are multiple escaped characters that are valid (e.g., \d). If such a character is identified, a log message is emitted. While this may have been useful for debugging, there is nothing actionable from that info message. Remove it.

Fixes 92306daf521 ("libselinux: rework selabel_file(5) database")
Quoted 47 lines
---
 libselinux/src/label_file.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
libselinux/src/label_file.h +3 -6
index 8fcf74e3..13451680 100644
@@ -231,7 +231,7 @@ static inline const char* file_kind_to_string(uint8_t file_kind)
  * Determine whether the regular expression specification has any meta characters
  * or any unsupported escape sequence.
  */
-static bool regex_has_meta_chars(const char *regex, size_t *prefix_len, const char *path, unsigned int lineno)
+static bool regex_has_meta_chars(const char *regex, size_t *prefix_len)
 {
        const char *p = regex;
        size_t plen = 0;
@@ -275,8 +275,7 @@ static bool regex_has_meta_chars(const char *regex, size_t *prefix_len, const ch
                        case ',':
                                continue;
                        default:
-                               COMPAT_LOG(SELINUX_INFO, "%s:  line %u has unsupported escaped character %c (%#x) for literal matching, continuing using regex\n",
-                                          path, lineno, isprint((unsigned char)*p) ? *p : '?', *p);
+                               /* Unsupported escaped character, continuing using regex */
                                *prefix_len = plen;
                                return true;
                        }
@@ -343,7 +342,6 @@ static int regex_simplify(const char *regex, size_t len, char **out, const char
                                *p++ = regex[i++];
                                break;
                        default:
-                               /* regex_has_meta_chars() reported already the notable occurrences */
                                free(result);
                                return 0;
                        }
@@ -523,7 +521,7 @@ static int insert_spec(const struct selabel_handle *rec, struct saved_data *data
                return -1;
        }
 
-       has_meta = regex_has_meta_chars(regex, &prefix_len, path, lineno);
+       has_meta = regex_has_meta_chars(regex, &prefix_len);
 
        /* Ensured by read_spec_entry() */
        assert(prefix_len < UINT16_MAX);
--

2.53.0.473.g4a7958ca14-goog

#2 lore raw
Quoted 8 lines · Christian Göttsche
Quoted 6 lines · Thiébaud Weksteen

For file_contexts entries relying on PCRE2, there are multiple escaped characters that are valid (e.g., \d). If such a character is identified, a log message is emitted. While this may have been useful for debugging, there is nothing actionable from that info message. Remove it.

Quoted 5 lines
Quoted 2 lines
Fixes 92306daf521 ("libselinux: rework selabel_file(5) database")

This patch has been merged.
Thanks,
Jim

Quoted 48 lines
Quoted 47 lines
---
 libselinux/src/label_file.h | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
libselinux/src/label_file.h +3 -6
index 8fcf74e3..13451680 100644
@@ -231,7 +231,7 @@ static inline const char* file_kind_to_string(uint8_t file_kind)
  * Determine whether the regular expression specification has any meta characters
  * or any unsupported escape sequence.
  */
-static bool regex_has_meta_chars(const char *regex, size_t *prefix_len, const char *path, unsigned int lineno)
+static bool regex_has_meta_chars(const char *regex, size_t *prefix_len)
 {
        const char *p = regex;
        size_t plen = 0;
@@ -275,8 +275,7 @@ static bool regex_has_meta_chars(const char *regex, size_t *prefix_len, const ch
                        case ',':
                                continue;
                        default:
-                               COMPAT_LOG(SELINUX_INFO, "%s:  line %u has unsupported escaped character %c (%#x) for literal matching, continuing using regex\n",
-                                          path, lineno, isprint((unsigned char)*p) ? *p : '?', *p);
+                               /* Unsupported escaped character, continuing using regex */
                                *prefix_len = plen;
                                return true;
                        }
@@ -343,7 +342,6 @@ static int regex_simplify(const char *regex, size_t len, char **out, const char
                                *p++ = regex[i++];
                                break;
                        default:
-                               /* regex_has_meta_chars() reported already the notable occurrences */
                                free(result);
                                return 0;
                        }
@@ -523,7 +521,7 @@ static int insert_spec(const struct selabel_handle *rec, struct saved_data *data
                return -1;
        }
 
-       has_meta = regex_has_meta_chars(regex, &prefix_len, path, lineno);
+       has_meta = regex_has_meta_chars(regex, &prefix_len);
 
        /* Ensured by read_spec_entry() */
        assert(prefix_len < UINT16_MAX);
--

2.53.0.473.g4a7958ca14-goog