fix: add msc_fullinfo() to check JIT compilation #3375
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
what
I usually use mod_security2 Apache module with these build options:
During an issue investigation I ran into an interesting message. Consider this rule:
and this payload:
When I send this request:
I see these messages in debug.log:
Which is not true.
why
The problem is that the regex engine (in case of using PCRE2) does not handle the
jit
variable correctly (in case ofverifyCC
operator this variable is here, as you can see it's initialized with0
).Let's see what happens when the engine runs any of the relevant codes (and user used the same build options).
The engine has its own
regex
structure which has a member with namejit_compile_rc
. This stores the information about the engine is able to use JIT or not.When a rule use the PCRE engine, it fills the
regex
object and setjit_compile_rc
member here.As I wrote above, at the operator the
jit
variable is initialized with0
, and in case of PCRE2 it does not change during the execution.The condition is here:
The variable
rc
is set here:so the
rc
will hold the value ofpcre2_jit_compile()
's return value. Let's see what is the return value of this function:So the variable
rc
will be0
(if JIT is available). But what about the variablejit
? It's still0
. As you can see in case of old PCRE code, it callsmsc_fullinfo()
, which in case of PCRE2 decides JIT is usable or not with calling the functionpcre2_pattern_info()
. See how does it work:This is necessary to get a full description of JIT status in current call, and sets the correct value of
jit
.