python/sepolgen: allow any policy statement in ifndef
PATCH 1/1 python/sepolgen: allow any policy statement in ifndef
"ifndef" statements can be used to conditionally define an interface, but this syntax is not recognised by sepolgen-ifgen.
Fix sepolgen-ifgen to allow any policy statement inside an "ifndef" statement.
Fixes:
$ cat <<EOF > i.if
ifndef(`apache_manage_pid_files',`
interface(`apache_manage_pid_files',`
manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t)
')
') #sepolgen-ifgen --interface=i.if
i.if: Syntax error on line 2 interface [type=INTERFACE] i.if: Syntax error on line 4 ' [type=SQUOTE]
--- python/sepolgen/src/sepolgen/refparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
python/sepolgen/src/sepolgen/refparser.py +1 -1
@@ -434,7 +434,7 @@ def p_ifelse(p): def p_ifdef(p): '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statement SQUOTE CPAREN optional_semi | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi ''' x = refpolicy.IfDef(p[4])
Signature · 1 line
2.29.2
Quoted 27 lines · Vit Mojzis
"ifndef" statements can be used to conditionally define an interface, but this syntax is not recognised by sepolgen-ifgen.
Fix sepolgen-ifgen to allow any policy statement inside an "ifndef" statement.Fixes:
$ cat <<EOF > i.if ifndef(`apache_manage_pid_files',` interface(`apache_manage_pid_files',` manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t) ') ')#sepolgen-ifgen --interface=i.if
i.if: Syntax error on line 2 interface [type=INTERFACE] i.if: Syntax error on line 4 ' [type=SQUOTE]Signed-off-by Vit Mojzis <[email protected]>--- python/sepolgen/src/sepolgen/refparser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)python/sepolgen/src/sepolgen/refparser.py +0
-0
python/sepolgen/src/sepolgen/refparser.py def p_ifelse(p): · line 438
Quoted 6 lines
python/sepolgen/src/sepolgen/refparser.py +1
-1@@ -434,7 +434,7 @@ def p_ifelse(p): def p_ifdef(p): '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statement SQUOTE CPAREN optional_semi | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi
IMHO we should be consistent and allow any statements also in ifdefs (i.e. make an equivalent change in the line before and after).
Quoted 5 lines
python/sepolgen/src/sepolgen/refparser.py +0
-1''' x = refpolicy.IfDef(p[4]) --2.29.2
Signature · 3 lines
Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.
PATCH v2 1/1 python/sepolgen: allow any policy statement in if(n)def
"ifdef/ifndef" statements can be used to conditionally define an interface, but this syntax is not recognised by sepolgen-ifgen. Fix sepolgen-ifgen to allow any policy statement inside an "fidef/ifndef" statement.
Fixes:
$ cat <<EOF > i.if
ifndef(`apache_manage_pid_files',`
interface(`apache_manage_pid_files',`
manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t)
')
') #sepolgen-ifgen --interface=i.if
i.if: Syntax error on line 2 interface [type=INTERFACE] i.if: Syntax error on line 4 ' [type=SQUOTE]
---
Thanks. Fixed. And I replaced "statement" with "statements" to allow multiple statements (as was possible with interface_stmts). I'm not all that sure about the last line since I didn't manage to find it's meaning (but I assume IF-THEN-ELSE).
python/sepolgen/src/sepolgen/refparser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
python/sepolgen/src/sepolgen/refparser.py +3 -3
@@ -433,9 +433,9 @@ def p_ifelse(p): def p_ifdef(p): - '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi + '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi ''' x = refpolicy.IfDef(p[4]) if p[1] == 'ifdef':
Signature · 1 line
2.29.2
Re: [PATCH v2] python/sepolgen: allow any policy statement in if(n)def
Quoted 17 lines · Vit Mojzis
"ifdef/ifndef" statements can be used to conditionally define an interface, but this syntax is not recognised by sepolgen-ifgen. Fix sepolgen-ifgen to allow any policy statement inside an "fidef/ifndef" statement.
Fixes:
$ cat <<EOF > i.if ifndef(`apache_manage_pid_files',` interface(`apache_manage_pid_files',` manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t) ') ')#sepolgen-ifgen --interface=i.if
i.if: Syntax error on line 2 interface [type=INTERFACE] i.if: Syntax error on line 4 ' [type=SQUOTE]
Quoted 6 lines
Signed-off-by Vit Mojzis <[email protected]>---
Thanks. Fixed. And I replaced "statement" with "statements" to allow multiple statements (as was possible withinterface_stmts). I'm not all that sure about the last line since I didn't manage to find it's meaning (but I assume IF-THEN-ELSE).
Yes, the third argument is basically an optional 'else' branch:
https://www.gnu.org/software/m4/manual/m4-1.4.15/html_node/Ifdef.html
Quoted 22 lines
python/sepolgen/src/sepolgen/refparser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)python/sepolgen/src/sepolgen/refparser.py +3
-4@@ -433,9 +433,9 @@ def p_ifelse(p): def p_ifdef(p): - '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi + '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi ''' x = refpolicy.IfDef(p[4]) if p[1] == 'ifdef': --
Quoted 2 lines
2.29.2
--
Ondrej Mosnacek
Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.
Re: [PATCH v2] python/sepolgen: allow any policy statement in if(n)def
Quoted 39 lines · Ondrej Mosnacek
Quoted 17 lines · Vit Mojzis
"ifdef/ifndef" statements can be used to conditionally define an interface, but this syntax is not recognised by sepolgen-ifgen. Fix sepolgen-ifgen to allow any policy statement inside an "fidef/ifndef" statement.
Fixes:
$ cat <<EOF > i.if ifndef(`apache_manage_pid_files',` interface(`apache_manage_pid_files',` manage_files_pattern($1, httpd_var_run_t, httpd_var_run_t) ') ')#sepolgen-ifgen --interface=i.if
i.if: Syntax error on line 2 interface [type=INTERFACE] i.if: Syntax error on line 4 ' [type=SQUOTE]Quoted 6 lines
Signed-off-by Vit Mojzis <[email protected]>---
Thanks. Fixed. And I replaced "statement" with "statements" to allow multiple statements (as was possible withinterface_stmts). I'm not all that sure about the last line since I didn't manage to find it's meaning (but I assume IF-THEN-ELSE).Yes, the third argument is basically an optional 'else' branch:
https://www.gnu.org/software/m4/manual/m4-1.4.15/html_node/Ifdef.htmlQuoted 11 lines
python/sepolgen/src/sepolgen/refparser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)python/sepolgen/src/sepolgen/refparser.py +0
-0@@ -433,9 +433,9 @@ def p_ifelse(p):
Quoted 15 lines
Quoted 11 lines
python/sepolgen/src/sepolgen/refparser.py +3
-4def p_ifdef(p): - '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi - | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK interface_stmts SQUOTE COMMA TICK interface_stmts SQUOTE CPAREN optional_semi + '''ifdef : IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFNDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi + | IFDEF OPAREN TICK IDENTIFIER SQUOTE COMMA TICK statements SQUOTE COMMA TICK statements SQUOTE CPAREN optional_semi ''' x = refpolicy.IfDef(p[4]) if p[1] == 'ifdef': --Quoted 2 lines
2.29.2
Acked-by Ondrej Mosnacek <[email protected]>
Merged:
https://github.com/SELinuxProject/selinux/commit/e12f71e82f523513c249dbe5a2e35c1916370992
Signature · 3 lines
Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.