Skip to contentSkip to conversation

libsepol/cil: do not allow \0 in quoted strings

PATCH In review Nicolas Iooss 2 participants 3 messages Jul 12, 2021 – Jul 13, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: do not allow \0 in quoted strings

Using the '\0' character in strings in a CIL policy is not expected to happen, and makes the flex tokenizer very slow. For example when generating a file with:

    python -c 'print("\"" + "\0"*100000 + "\"")' > policy.cil

secilc fails after 26 seconds, on my desktop computer. Increasing the numbers of \0 makes this time increase significantly. But replacing \0 with another character makes secilc fail in only few milliseconds.

Fix this "possible denial of service" issue by forbidding \0 in strings in CIL policies.

---
 libsepol/cil/src/cil_lexer.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_lexer.l +1 -1
index e28c33ecb9f1..8bf2b6e7765a 100644
@@ -49,7 +49,7 @@ spec_char	[\[\]\.\@\=\/\*\-\_\$\%\+\-\!\|\&\^\:\~\`\#\{\}\'\<\>\?\,]
 symbol		({digit}|{alpha}|{spec_char})+
 white		[ \t]
 newline		[\n\r]
-qstring		\"[^"\n]*\"
+qstring		\"[^"\n\0]*\"
 hll_lm          ^;;\*
 comment		;
 
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Nicolas Iooss

Using the '\0' character in strings in a CIL policy is not expected to happen, and makes the flex tokenizer very slow. For example when generating a file with:

    python -c 'print("\"" + "\0"*100000 + "\"")' > policy.cil

secilc fails after 26 seconds, on my desktop computer. Increasing the numbers of \0 makes this time increase significantly. But replacing \0 with another character makes secilc fail in only few milliseconds.

Quoted 6 lines

Fix this "possible denial of service" issue by forbidding \0 in strings in CIL policies.

Quoted 20 lines
---
 libsepol/cil/src/cil_lexer.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_lexer.l +1 -2
index e28c33ecb9f1..8bf2b6e7765a 100644
@@ -49,7 +49,7 @@ spec_char     [\[\]\.\@\=\/\*\-\_\$\%\+\-\!\|\&\^\:\~\`\#\{\}\'\<\>\?\,]
 symbol         ({digit}|{alpha}|{spec_char})+
 white          [ \t]
 newline                [\n\r]
-qstring                \"[^"\n]*\"
+qstring                \"[^"\n\0]*\"
 hll_lm          ^;;\*
 comment                ;
 
--

2.32.0

#2 lore raw
Quoted 13 lines · James Carter
Quoted 11 lines · Nicolas Iooss

Using the '\0' character in strings in a CIL policy is not expected to happen, and makes the flex tokenizer very slow. For example when generating a file with:

    python -c 'print("\"" + "\0"*100000 + "\"")' > policy.cil

secilc fails after 26 seconds, on my desktop computer. Increasing the numbers of \0 makes this time increase significantly. But replacing \0 with another character makes secilc fail in only few milliseconds.

Quoted 8 lines
Quoted 6 lines

Fix this "possible denial of service" issue by forbidding \0 in strings in CIL policies.

Merged.
Thanks!
Nicolas

Quoted 20 lines
Quoted 20 lines
---
 libsepol/cil/src/cil_lexer.l | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_lexer.l +1 -2
index e28c33ecb9f1..8bf2b6e7765a 100644
@@ -49,7 +49,7 @@ spec_char     [\[\]\.\@\=\/\*\-\_\$\%\+\-\!\|\&\^\:\~\`\#\{\}\'\<\>\?\,]
 symbol         ({digit}|{alpha}|{spec_char})+
 white          [ \t]
 newline                [\n\r]
-qstring                \"[^"\n]*\"
+qstring                \"[^"\n\0]*\"
 hll_lm          ^;;\*
 comment                ;
 
--

2.32.0