-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Out-Of-Memory when matching exec
-like functions
#390
Comments
I add your testcase in ad623f1 but it doesn't reproduce in the CI. Can you confirm that it should be a faithful reproducer of your problem? |
I'm investigating for other things which may be involved in this issue. Note however that I do not think that this issue is linked to PCRE, as it happens no matters if the parameter name actually exists or not (using |
I got the "why", but don't ask me about the "how" ;) . Seemingly Snuffleupagus doesn't like when its configuration file is set from the Apache configuration file using the
Knowing this, I have remade the layout of my php.ini files to avoid the issue and will add a drop rule preventing runtime overwrite of the Nevertheless, I don't know whether there is any plan to support the
For me the first choice seem both the easiest and the safest, as it should also prevent an attacker from potentially disabling Snuffleupagus through .htaccess or .user.ini files. |
I didn't went deep in Snuffleupagus source code, but as per my understanding snuffleupagus.c defines a callback function If the BTW, the way It is also worth noting that this situation where Snuffleupagus has to handle different local and master values will also be present in #260. |
I removed |
8353de0 might™ prevent the issue, can you test @WhiteWinterWolf ? |
Sadly 8353de0 doesn't seem to have any effect on the issue :( Reproduced on another environment, I can confirm it happens when I use the The only consequences I can see for now for Snuffleupagus in the presence of this settings:
What I've seen is that the issue doesn't come directly from the fact that the "master" and "local" value are different: as long as the globing results in the very same files to be loaded, there is no issue. The issue happens when the |
In case it might be useful, I've added log messages when entering and quittting
The normal behavior, when there is no issue, produces the following logs:
=> A single entry immediately followed by a single exit. The erroneous behavior produces the following logs:
=> Infinite entry until memory exhaustion, no exit. This gives the impression that the recursion happens here. |
The last line being executed from this function being |
I also took a look on the name and address of the function being hooked in this function:
We can see that while in both cases the name of the targeted function remains correct, With a bit of further reverse engineering, my understanding is that this pointer value is defined in
It shows that there is no issue during the initialization phase, as both the sane and bogus Apache settings produce the exact same output, showing two call to this function (I would expect a single call, I don't know if this is normal, but the same behavior can also be seen for all other hooked functions):
However, as soon as PHP handles an incoming request invoking the hooked
Once all functions have been re-hooked comes the loop:
Sadly, Next step: why does Snuffleupagus attempt to reload its configuration / re-hook its functions? I don't know yet, but as a reminder this issue occurs only when hooking |
Hi, I'll look into it sometime next week o/ |
Any updates regarding this or any help needed? |
Can you try with the current |
Thanks @jvoisin, I will check this as soon as I can and keep you informed. |
The default rules matching the
exec
-like functions (tested withexec()
andsystem()
) crashes PHP with an Out-Of-Memory error.Using the following minimal test file directly invoked from the web root:
The default rule:
Generates the following error:
This issue is not linked to the regex or even anything actually related to the parameter, as replacing this rule by:
or even:
Generates even worse Out-Of-Memory errors, this time uncontrolled by PHP: the HTTP process goes from around 100 MB to over 1 GB, depending what limit is imposed by the OS, and finally gets killed by the OS, producing either:
or more often:
error messages.
Commenting-out these rules in Snuffleupagus configuration removes the issues.
Other rules seem to work OK, including regex rules matching on SQL requests for instance which use the same syntax. I have therefore the impression that this issue is linked to some specific behavior or implementation of these
exec
-like functions.I'm using FreeBSD with PHP as an Apache module, latest packages version: php80-8.0.6, php80-snuffleupagus-0.7.0.
The text was updated successfully, but these errors were encountered: