RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1388656 - ModSecurity: collections_remove_stale: Failed deleting collection
Summary: ModSecurity: collections_remove_stale: Failed deleting collection
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: mod_security
Version: 7.4
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: ---
Assignee: Daniel Kopeček
QA Contact: Jakub Heger
URL:
Whiteboard:
: 1400625 (view as bug list)
Depends On:
Blocks: 1420851
TreeView+ depends on / blocked
 
Reported: 2016-10-25 20:59 UTC by Robert Bost
Modified: 2021-07-13 01:36 UTC (History)
13 users (show)

Fixed In Version: mod_security-2.9.2-1.el7
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1650268 (view as bug list)
Environment:
Last Closed: 2018-04-10 16:34:21 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
upstream patch (960 bytes, patch)
2016-12-06 09:06 UTC, Daniel Kopeček
no flags Details | Diff
proposed patch (549 bytes, patch)
2016-12-06 09:13 UTC, Daniel Kopeček
no flags Details | Diff
proposed patch (9.16 KB, patch)
2017-02-16 13:40 UTC, Daniel Kopeček
no flags Details | Diff
SRPM for testing purposes (977.59 KB, application/x-rpm)
2017-02-16 13:46 UTC, Daniel Kopeček
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 2789821 0 None None None 2016-12-01 15:56:17 UTC
Red Hat Product Errata RHBA-2018:0908 0 None None None 2018-04-10 16:34:43 UTC

Description Robert Bost 2016-10-25 20:59:45 UTC
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.

Comment 3 Robert Bost 2016-11-19 21:57:46 UTC
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.

Comment 4 Robert Bost 2016-12-01 15:59:26 UTC
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?

Comment 5 Daniel Kopeček 2016-12-06 09:06:14 UTC
Created attachment 1228341 [details]
upstream patch

Comment 6 Daniel Kopeček 2016-12-06 09:13:59 UTC
Created attachment 1228355 [details]
proposed patch

Comment 7 Daniel Kopeček 2016-12-06 09:18:06 UTC
(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.

Comment 13 Daniel Kopeček 2017-02-16 13:40:41 UTC
Created attachment 1250867 [details]
proposed patch

based on https://github.com/SpiderLabs/ModSecurity/pull/1224

Comment 14 Daniel Kopeček 2017-02-16 13:46:10 UTC
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?

Comment 21 Daniel Kopeček 2017-03-10 13:27:23 UTC
*** Bug 1400625 has been marked as a duplicate of this bug. ***

Comment 34 Daniel Kopeček 2017-05-22 12:00:19 UTC
The upstream PR was merged as a compile-time option:

https://github.com/SpiderLabs/ModSecurity/pull/1224#issuecomment-302938891

Comment 45 errata-xmlrpc 2018-04-10 16:34:21 UTC
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


Note You need to log in before you can comment on or make changes to this bug.