Skip to content
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

Bug 5390: Non-POD SquidConfig::ssl_client::sslContext exit crash #273

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eduard-bagdasaryan
Copy link

@eduard-bagdasaryan eduard-bagdasaryan commented Nov 17, 2024

Squid may crash when the SquidConfig global is auto-destructed after
main() ends. Since SquidConfig global is used by cleanup code, we should
keep its fields alive, essentially emulating "No New Globals" policy
effects. This surgical fix will be followed up with more changes to
address general OpenSSL cleanup problems exposed by this bug.

This bug fix facilitates backporting by using FuturePeerContext shim.

Squid may crash when SquidConfig global destruction is initiated by
exit() handlers. The problem is that when its non-POD
ssl_client::sslContext field is destructed and and SSL_CTX_free()
cleanup starts, some of the required SSL environment may be already
unavailable. Now we avoid these problems by allocating
ssl_client::sslContext dynamically and ensuring that its destructor
never starts.
src/cache_cf.cc Outdated Show resolved Hide resolved
src/cache_cf.cc Outdated Show resolved Hide resolved
src/cache_cf.cc Outdated Show resolved Hide resolved
Copy link

@rousskov rousskov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one minor adjustment, thank you!

@@ -505,7 +505,7 @@ class SquidConfig
struct {
Security::FuturePeerContext *defaultPeerContext;
// TODO: Remove when FuturePeerContext above becomes PeerContext
Security::ContextPointer sslContext;
Security::ContextPointer *sslContext;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this field only shows up in construction/destruction code diff. Let's confirm and ban its use elsewhere:

Suggested change
Security::ContextPointer *sslContext;
/// \deprecated Legacy storage. Use defaultPeerContext instead.
Security::ContextPointer *sslContext_;

... and then adjust the rest of PR code to compile, of course.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (dc66a68).

src/cache_cf.cc Outdated
@@ -968,9 +970,9 @@ configDoConfigure(void)
#endif
}
#if USE_OPENSSL
Ssl::useSquidUntrusted(Config.ssl_client.sslContext.get());
Ssl::useSquidUntrusted(Config.ssl_client.sslContext->get());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this code should be using defaultPeerContext.raw instead, but defaultPeerContext is initialized later. I suggest using the deprecated field here unless others insist on reordering a few lines of code to use defaultPeerContext for this useSquidUntrusted() call:

Suggested change
Ssl::useSquidUntrusted(Config.ssl_client.sslContext->get());
Ssl::useSquidUntrusted(Config.ssl_client.sslContext_->get());

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (dc66a68).

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.

2 participants