-
Notifications
You must be signed in to change notification settings - Fork 1.7k
modsecurity high memory usage 60-70% #785
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
Comments
Hi @ton31337, Are you running custom rules? OWASP CRS? or others? Just to confirm, your ModSecurity is using low amount of memory when you start it, but slow increase the usage amount until reach (after 2 ~ 3 days) a high amount of memory used, is that correct? |
Hi @zimmerle, we are using OWASP CRS together with Commercial rules. Yes, after few days it consumes almost the whole memory. Need to restart nginx to free the memory. Maybe it would be possible to tell mmap() / malloc() to do not cache it or just to call madvise() with MADV_DONTNEED flag? Donatas. |
@zimmerle Can you explain this snippet?
Why modsec_pcre_free() does nothing? Maybe here is a leak? I can try to trace of course to check, but just saw this interesting part :) |
Hi @ton31337, It seems to be a memory leak in fact, but not sure if it is attached to this exactly part of the code. The apr works with memory pools which should be destroy after used (e.g. connection end, or so..), thus, this piece of memory should be free by apr, while the pool is destroyed. Can you tell me if your SecResponseBodyAccess (https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#SecResponseBodyAccess) is enabled? If so, can you disable it to test? |
@zimmerle SecResponseBodyAccess is disabled in my case. That's really odd. O tried with / without this option, result is the same in both cases.. |
What about SecRequestBodyAccess ? is it enabled or disabled? |
This is disabled as well. |
This ModSecurity was a custom build or it is an distro package? Do you know if --enable-pcre-study was used during the compilation? (Ref: #610). Btw, what version are you using (nginx and modsec) ? |
No, we don't compile ModSecurity with this option (--enable-pcre-study). Nginx's version is 1.7.2 and ModSecurity is downloaded from trunk. (2.8.0) |
Can you try this branch: https://github.com/SpiderLabs/ModSecurity/tree/nginx_refactoring ? Not sure if it will fix this specific problem but worth a try. It is currently under developer, it is a refactoring of our nginx version. |
@zimmerle I tried this as well :) Actually this branch is I'm testing on :) |
cool! :) Please let me know if it is working or not. |
@zimmerle result is the same:
This output is after nginx restart. It eats 15% of memory in advance. In this case it's about 700MB. |
strace looks good, no memory leak looking into mmap()/unmap() syscalls. |
Allocated/Freed memory is the same..
|
Hi @zimmerle, problem is that we are using ModSecurity with different waf rules for different website. For example:
Inside website*_waf are lot of flles. Adding additional such one eats additional ~12% of memory. Why it maps everything into the memory? Maybe it's possible to read these rules from the disk instead of memory? By the way, it doesn't matter if ModSecurityEnabled off or on. It keeps everything mapped into the memory.. If commenting ModSecurityEnabled and ModSecurityConfig directives, usage drops.
From this output it seems memory isn't mapped from a file.. So, why it allocates so much memory when ModSecurity is enabled, depending on how much rules are added. Donatas. |
Hi @ton31337, This problem of ModSecurity using resources even if it is disabled is being discussed at #644. Currently there is no such option to load the rules on demand. Once you start the web server all the rules are loaded. In particular @pmFromFile uses a lot of memory. Not sure if it is the case, as the memory used while loading the rules are allocated on the startup. It won't increase after the service is running. One test that you can do is to complete disable all the rules, and check if after a while it still increasing the memory usage, even without rules. This may help to identify if the problem is associate with a particular rule or with the nginx-module. |
Hi @zimmerle , seems that no memory is increasing after disabling Request/ResponseBody filtering. But it's crazy still why ModSecurity loads all the rules into the memory.. It will be good to have an option to load all rules in advance or just on demand, or even do not load into the memory at all. Maybe you can give me an advice, what the function is responsible for loading into the memory the rules? I will take a look myself on this. D. |
Hello, Somebody know, what's the method for find precisely what ModSecurity is consuming in memory with Nginx ? Thanks |
Hi @MEN18, I recommend you to switch to libModSecurity and nginx connector: |
Hello @zimmerle Thanks for your answer ! It's precisely what i use (with CRS rule in v3.0), but my problem is about increasing memory in Nginx. My conf : Usage of Memory |
Do you mind to open another issue to keep track of this memory problem? Initially #785 refers to ModSecurity version 2.x |
Ok, Done #1318 |
Hello,
is it possible to avoid caching all the rules including body content in memory? Because after 2-3 days we have 60-70% memory usage.. Extracting memory dumps there are as expected, rules and body cached inside the memory.
Any idea how to bypass this caching? Or maybe is any way to reduce to minimal this behavior?
Donatas.
The text was updated successfully, but these errors were encountered: