Hide Forgot
Description of problem: Repeating error message about failure to delete from collection: [Fri Sep 23 10:52:17.022473 2016] [:error] [pid 14825] [client ::1] ModSecurity: collections_remove_stale: Failed deleting collection (name "ip", key "44.33.55.777_17c09ec5cebff2507db855e6cac332d395dd43c7"): Internal error [hostname "192.168.1.2"] [uri "*"] [unique_id "V@TtQHqZvlSpAUCIOTgi@gAAACc"] Files in SecTmpDir and SecDataDir become very large and may be related to the error above. -rw-r-----. 1 apache apache 0 Sep 19 16:03 global.dir -rw-r-----. 1 apache apache 0 Sep 19 16:03 global.pag -rw-r-----. 1 apache apache 36K Sep 23 11:11 ip.dir -rw-r-----. 1 apache apache 287M Sep 23 11:11 ip.pag -rw-r-----. 1 apache apache 96K Sep 23 11:10 resource.dir -rw-r-----. 1 apache apache 932M Sep 23 11:11 resource.pag Version-Release number of selected component (if applicable): mod_security-2.7.3-5.el7 How reproducible: Seems to be reproduced over a period of time or after many requests. Actual results: .pag files become very large and require manual cleanup. Expected results: .pag files would be cleaned up automatically and not see "collections_remove_stale: Failed". Additional info: Customer seeing this issue has only added this single directive: SecRule REMOTE_ADDR "@ipMatch 44.33.0.0/16,192.168.1.0/24,10.0.0.0/8" "phase:1,id:'981033',nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off They also have the stock configuration shipped with mod_security.
I think this issue is related to https://issues.jboss.org/browse/JWS-489. Basically, looks like two threads are trying to delete a stale entry from database but one is winning and the other one throws the "Failed deleting collection" error.
This issue has changed slightly since initially reported. The reason for noticing the issue was that the database was growing very very large. The customer had to stop httpd, remove the mod_security collection files in SecDataDir, and then start httpd back up. There is already a solution for this in mod_security 2.9.1: https://github.com/SpiderLabs/ModSecurity/pull/836 The root cause was a bad call to srand before calling rand to determine if garbage collection should run (i.e. the logic that removes expired elements from collection). Can RHEL 7 mod_security be rebased to 2.9.1 or can that one line change in the pull request above be backported?
Created attachment 1228341 [details] upstream patch
Created attachment 1228355 [details] proposed patch
(In reply to Robert Bost from comment #4) > This issue has changed slightly since initially reported. The reason for > noticing the issue was that the database was growing very very large. The > customer had to stop httpd, remove the mod_security collection files in > SecDataDir, and then start httpd back up. > > There is already a solution for this in mod_security 2.9.1: > > https://github.com/SpiderLabs/ModSecurity/pull/836 > > The root cause was a bad call to srand before calling rand to determine if > garbage collection should run (i.e. the logic that removes expired elements > from collection). > > Can RHEL 7 mod_security be rebased to 2.9.1 or can that one line change in > the pull request above be backported? Looks like an easy fix since we already have a patch for this. Getting the acks for 7.4 might be harder.
Created attachment 1250867 [details] proposed patch based on https://github.com/SpiderLabs/ModSecurity/pull/1224
Created attachment 1250868 [details] SRPM for testing purposes Upstream did not accept the solution in PR#1224 yet. That is because of fears of a performance hit that a solution based on a global mutex locking might cause. Would it be possible to test the provided SRPM w.r.t. to performance in a real world environment?
*** Bug 1400625 has been marked as a duplicate of this bug. ***
The upstream PR was merged as a compile-time option: https://github.com/SpiderLabs/ModSecurity/pull/1224#issuecomment-302938891
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2018:0908