libsepol/cil: do not allow \0 in quoted strings
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.cilsecilc 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
@@ -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
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.cilsecilc 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.
Signed-off-by Nicolas Iooss <[email protected]>
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@@ -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
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.cilsecilc 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.
Signed-off-by Nicolas Iooss <[email protected]>Acked-by James Carter <[email protected]>
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@@ -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