Skip to content

fix: pair curl_global_init with curl_global_cleanup on reload - #3682

Open
fzipi wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
fzipi:v2/issue-3590-curl-global-cleanup
Open

fzipi wants to merge 1 commit into
owasp-modsecurity:v2/masterfrom
fzipi:v2/issue-3590-curl-global-cleanup

Conversation

@fzipi

@fzipi fzipi commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

What

modsecurity_init() (apache2/modsecurity.c) still calls curl_global_init(CURL_GLOBAL_ALL) on every (re)start, but now registers curl_global_cleanup() as a cleanup of the configuration pool it was given, so every init is released when that configuration generation goes away. The old comment explaining why there was no cleanup is replaced by one explaining the pairing.

Why

Nothing in the module ever called curl_global_cleanup(), so each graceful restart initialised libcurl's TLS backend once more on top of the previous state. With a GnuTLS-backed libcurl (the reporter's build) the resources set up per init are never released, and #3590 reports the process failing with GnuTLS errors after a few thousand reloads until a full restart.

The early implementation that cleaned up per utilisation broke mod_ssl with OpenSSL before 1.1.0, which is why the cleanup was removed. Tying it to the configuration pool instead keeps exactly one init/cleanup pair per configuration generation, the same lifetime mod_ssl's own state has, and modern OpenSSL/GnuTLS no longer tear down global state on the last curl_global_cleanup().

Tests

No regression test: the harness cannot drive restarts. Verified in Debian bookworm containers (apache2 2.4.62, prefork, mod_ssl loaded on a TLS vhost, one @contains deny rule) with a graceful-restart loop that checks HTTP, HTTPS and a blocked request afterwards and greps error.log for segfault|gnutls|exit signal|curl:

build branch restarts result
libcurl4-openssl this branch 300 all requests fine, log clean
libcurl4-gnutls (GnuTLS 3.7.9) untouched v2/master 3000 all requests fine, log clean
libcurl4-gnutls (GnuTLS 3.7.9) this branch 1000 all requests fine, log clean

So the reported failure does not reproduce with Debian's GnuTLS 3.7.9 within 3000 reloads; the reporter's environment (older GnuTLS, thousands of reloads over weeks) could not be matched here. What the runs establish is that the pairing is safe with mod_ssl loaded under both curl backends. The change itself follows from the missing cleanup in the code, not from a local reproduction, and the issue stays marked as pending confirmation from a build with this change in the reporter's setup.

References

Fixes #3590

🤖 Generated with Claude Code

modsecurity_init() calls curl_global_init(CURL_GLOBAL_ALL) on every
(re)start and nothing ever called curl_global_cleanup(). Each graceful
restart therefore initialised libcurl's TLS backend once more on top of
the previous state. With a GnuTLS backed libcurl that leaks the random
source set up per init, and after a few thousand reloads the process
fails with GnuTLS errors until a full restart.

curl_global_cleanup() is now registered as a cleanup of the
configuration pool that was passed to modsecurity_init(), so each init
is released when that configuration goes away. The early version that
cleaned up per utilisation broke mod_ssl with OpenSSL before 1.1.0;
tying it to the configuration pool keeps one init/cleanup pair per
configuration generation, the same lifetime mod_ssl's own state has.

Fixes owasp-modsecurity#3590

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0181jBv5JdNQviwDzfnkf1Gy
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9fb57ab-bdc9-44c6-9dc9-9905567e66df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant