Skip to content

Issue 890 - ModSecurity corrupts the global pool's cleanups linked list with threaded MPMs. #2049

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

Closed
wants to merge 2 commits into from

Conversation

lightsey
Copy link

I tested the first commit fixing the re_precomp rules ( msre_op_validateHash_execute and msre_op_rx_execute ) using the example configuration I provided in issue #890.

The second commit fixing the other usage of rule->ruleset->mp in functions that are run during HTTP requests hasn't gone through any real testing. Nothing stands out to me in the code as suggesting that these should be using storage pools that are shared between all the threads in the process, but I'm not that very familiar with ModSecurity's codebase and could be mistaken.

The code for testing regexes with embedded Apache variables
(rule->re_precomp == 1) during request processing was utilizing the global
engine pool for the storage of temporary values. This approach is not
threadsafe, retains the temporary variables longer than they are usable,
and causes corruption of the global pool's "cleanups" linked-lists when
Apache is configured with a threaded MPM.
@victorhora victorhora self-assigned this Mar 21, 2019
@victorhora victorhora added this to the v2.9.4 milestone Mar 21, 2019
@victorhora victorhora added Platform - Apache 2.x Related to ModSecurity version 2.x pr available labels Mar 21, 2019
@markblackman
Copy link

This is a perfect fit for CGI problem we are seeing in #2101 and we will test your PR

@lightsey
Copy link
Author

cPanel has shipped this patch to customers for several months now without any apparent problems.

https://github.com/CpanelInc/mod_security2

@marcstern
Copy link

cPanel has shipped this patch to customers for several months now without any apparent problems.

https://github.com/CpanelInc/mod_security2

Apparently not. The file in the source doesn't have that patch (https://github.com/CpanelInc/mod_security2/blob/master/SOURCES/modsecurity-2.9.3.tar.gz)

@markblackman
Copy link

Although I updated #2101 at the time, last year, I will also point out here that this patch fixed our thread problem. Mod_security 2.x was not written with thread safety in mind and there was at least too much unsafe sharing of global pools between threads in an apache 2.4 event MPM.

@lightsey
Copy link
Author

cPanel has shipped this patch to customers for several months now without any apparent problems.
https://github.com/CpanelInc/mod_security2

Apparently not. The file in the source doesn't have that patch (https://github.com/CpanelInc/mod_security2/blob/master/SOURCES/modsecurity-2.9.3.tar.gz)

The patch is applied while building the RPM. The tar.gz file in this repo should be a pristine copy of the original modsecurity tarball.

https://github.com/CpanelInc/mod_security2/blob/master/SOURCES/0003-Store-temporaries-in-the-request-pool-for-regexes-co.patch

https://github.com/CpanelInc/mod_security2/blob/ecbb7b9802f628a89610b2dcce23961161c2fc31/SPECS/ea-apache24-mod_security2.spec#L56

@marcstern
Copy link

Indeed.
So, running for 11 months in prod on CPanel should be considered as robust, no?

@marcstern
Copy link

Any chance to have this merged? Thanks

zimmerle pushed a commit that referenced this pull request Jan 14, 2021
@zimmerle
Copy link
Contributor

Merged! Thanks @lightsey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to ModSecurity version 2.x Platform - Apache pr available
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants