Skip to contentSkip to conversation

sepolgen-ifgen: allow M4 escaped filenames

PATCH Superseded Petr Lautrbach 2 participants 5 messages Aug 19, 2024 – Dec 17, 2024 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sepolgen-ifgen: allow M4 escaped filenames

When a file name in type transition rule used in an interface is same as a keyword, it needs to be M4 escaped so that the keyword is not expanded by M4, e.g.

- filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, "interface")
+ filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, "``interface''")

But sepolgen-ifgen could not parse such string:

    # sepolgen-ifgen
    Illegal character '`'

This change allows M4 escaping inside quoted strings and fixed described problem.

https://bugzilla.redhat.com/show_bug.cgi?id=2254206

---
 python/sepolgen/src/sepolgen/refparser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
python/sepolgen/src/sepolgen/refparser.py +1 -1
index e261d3f78f87..9622ee9a29ce 100644
@@ -261,7 +261,7 @@ def t_IDENTIFIER(t):
     return t
 
 def t_FILENAME(t):
-    r'\"[a-zA-Z0-9_\-\+\.\$\*~ :\[\]]+\"'
+    r'\"`*[a-zA-Z0-9_\-\+\.\$\*~ :\[\]]+\'*\"'
     # Handle any keywords
     t.type = reserved.get(t.value,'FILENAME')
     return t
Signature · 1 line
2.46.0
#1 lore raw

PATCH v2 1/1 sepolgen-ifgen: allow M4 escaped filenames

When a file name in type transition rule used in an interface is same as a keyword, it needs to be M4 escaped so that the keyword is not expanded by M4, e.g.

- filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, "interface")
+ filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, ``"interface"'')

But sepolgen-ifgen could not parse such string:

    # sepolgen-ifgen
    Illegal character '`'

This change allows M4 escaping inside quoted strings and fixed described problem.

https://bugzilla.redhat.com/show_bug.cgi?id=2254206

---

change to v1:

- use ``"..."'' instead of "``..''" - sugested in https://github.com/SELinuxProject/selint/pull/291 by @cgzones

- controls right number of openning and closing quotes

 python/sepolgen/src/sepolgen/refparser.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
python/sepolgen/src/sepolgen/refparser.py +6 -1
index e261d3f78f87..c8a3eb54d679 100644
@@ -486,7 +486,7 @@ def p_interface_call_param(p):
                             | nested_id_set
                             | TRUE
                             | FALSE
-                            | FILENAME
+                            | quoted_filename
     '''
     # Intentionally let single identifiers pass through
     # List means set, non-list identifier
@@ -1027,6 +1027,11 @@ def p_optional_semi(p):
                    | empty'''
     pass
 
+def p_quoted_filename(p):
+    '''quoted_filename : TICK quoted_filename SQUOTE
+                       | FILENAME
+    '''
+    p[0] = p[1]
 
 #
 # Interface to the parser
Signature · 1 line
2.46.0
#2 lore raw
Quoted 12 lines · Petr Lautrbach

When a file name in type transition rule used in an interface is same as a keyword, it needs to be M4 escaped so that the keyword is not expanded by M4, e.g.

(quoted diff) +1 -1
-	filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, "interface")
+	filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, ``"interface"'')

But sepolgen-ifgen could not parse such string:

    # sepolgen-ifgen
    Illegal character '`'
Quoted 6 lines

This change allows M4 escaping inside quoted strings and fixed described problem.

https://bugzilla.redhat.com/show_bug.cgi?id=2254206

If there's no objection I would like to merge before tomorrows rc3.

Petr

Quoted 39 lines

---

change to v1:

- use ``"..."'' instead of "``..''" - sugested in https://github.com/SELinuxProject/selint/pull/291 by @cgzones

- controls right number of openning and closing quotes

 python/sepolgen/src/sepolgen/refparser.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
python/sepolgen/src/sepolgen/refparser.py +6 -1
index e261d3f78f87..c8a3eb54d679 100644
@@ -486,7 +486,7 @@ def p_interface_call_param(p):
                             | nested_id_set
                             | TRUE
                             | FALSE
-                            | FILENAME
+                            | quoted_filename
     '''
     # Intentionally let single identifiers pass through
     # List means set, non-list identifier
@@ -1027,6 +1027,11 @@ def p_optional_semi(p):
                    | empty'''
     pass
 
+def p_quoted_filename(p):
+    '''quoted_filename : TICK quoted_filename SQUOTE
+                       | FILENAME
+    '''
+    p[0] = p[1]
 
 #
 # Interface to the parser
Signature · 1 line
2.46.0
Acked-by on v2 1/1
#3 lore raw
In reply to Petr Lautrbach
Quoted 13 lines · Petr Lautrbach

When a file name in type transition rule used in an interface is same as a keyword, it needs to be M4 escaped so that the keyword is not expanded by M4, e.g.

(quoted diff) +1 -1
-       filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, "interface")
+       filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, ``"interface"'')

But sepolgen-ifgen could not parse such string:

    # sepolgen-ifgen
    Illegal character '`'
Quoted 6 lines

This change allows M4 escaping inside quoted strings and fixed described problem.

https://bugzilla.redhat.com/show_bug.cgi?id=2254206

Sorry, I don't know how I missed this patch earlier.

Quoted 41 lines

---

change to v1:

- use ``"..."'' instead of "``..''" - sugested in https://github.com/SELinuxProject/selint/pull/291 by @cgzones

- controls right number of openning and closing quotes

 python/sepolgen/src/sepolgen/refparser.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
python/sepolgen/src/sepolgen/refparser.py +6 -2
index e261d3f78f87..c8a3eb54d679 100644
@@ -486,7 +486,7 @@ def p_interface_call_param(p):
                             | nested_id_set
                             | TRUE
                             | FALSE
-                            | FILENAME
+                            | quoted_filename
     '''
     # Intentionally let single identifiers pass through
     # List means set, non-list identifier
@@ -1027,6 +1027,11 @@ def p_optional_semi(p):
                    | empty'''
     pass
 
+def p_quoted_filename(p):
+    '''quoted_filename : TICK quoted_filename SQUOTE
+                       | FILENAME
+    '''
+    p[0] = p[1]
 
 #
 # Interface to the parser
--

2.46.0

#4 lore raw
Quoted 18 lines · James Carter
Quoted 16 lines · Petr Lautrbach

When a file name in type transition rule used in an interface is same as a keyword, it needs to be M4 escaped so that the keyword is not expanded by M4, e.g.

(quoted diff) +1 -1
-       filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, "interface")
+       filetrans_pattern($1, virt_var_run_t, virtinterfaced_var_run_t, dir, ``"interface"'')

But sepolgen-ifgen could not parse such string:

    # sepolgen-ifgen
    Illegal character '`'

This change allows M4 escaping inside quoted strings and fixed described problem.

Quoted 8 lines
Quoted 3 lines

https://bugzilla.redhat.com/show_bug.cgi?id=2254206

Sorry, I don't know how I missed this patch earlier.

Merged.
Thanks,
Jim

Quoted 41 lines
Quoted 41 lines

---

change to v1:

- use ``"..."'' instead of "``..''" - sugested in https://github.com/SELinuxProject/selint/pull/291 by @cgzones

- controls right number of openning and closing quotes

 python/sepolgen/src/sepolgen/refparser.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
python/sepolgen/src/sepolgen/refparser.py +6 -2
index e261d3f78f87..c8a3eb54d679 100644
@@ -486,7 +486,7 @@ def p_interface_call_param(p):
                             | nested_id_set
                             | TRUE
                             | FALSE
-                            | FILENAME
+                            | quoted_filename
     '''
     # Intentionally let single identifiers pass through
     # List means set, non-list identifier
@@ -1027,6 +1027,11 @@ def p_optional_semi(p):
                    | empty'''
     pass
 
+def p_quoted_filename(p):
+    '''quoted_filename : TICK quoted_filename SQUOTE
+                       | FILENAME
+    '''
+    p[0] = p[1]
 
 #
 # Interface to the parser
--

2.46.0