Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/iocore/net/P_SSLCertLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
#include "iocore/eventsystem/ConfigProcessor.h"
#include "iocore/net/SSLTypes.h"
#include "records/RecCore.h"
#include <shared_mutex>

#include <set>
#include <openssl/ssl.h>
#include <mutex>
#include <unordered_map>
#include <utility>
Comment thread
c-taylor marked this conversation as resolved.

Expand Down Expand Up @@ -94,8 +94,8 @@ using shared_ssl_ticket_key_block = std::shared_ptr<ssl_ticket_key_block>;
*/
struct SSLCertContext {
private:
mutable std::mutex ctx_mutex;
shared_SSL_CTX ctx;
mutable std::shared_mutex ctx_mutex;
shared_SSL_CTX ctx;

public:
SSLCertContext() : ctx_mutex(), ctx(nullptr), opt(SSLCertContextOption::OPT_NONE), userconfig(nullptr), keyblock(nullptr) {}
Expand Down
9 changes: 5 additions & 4 deletions src/iocore/net/SSLCertLookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "P_SSLUtils.h"

#include <mutex>
#include <unordered_map>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -237,7 +238,7 @@ SSLCertContext::SSLCertContext(SSLCertContext const &other)
userconfig = other.userconfig;
keyblock = other.keyblock;
ctx_type = other.ctx_type;
std::lock_guard<std::mutex> lock(other.ctx_mutex);
std::shared_lock lock(other.ctx_mutex);
ctx = other.ctx;
}

Expand All @@ -249,7 +250,7 @@ SSLCertContext::operator=(SSLCertContext const &other)
this->userconfig = other.userconfig;
this->keyblock = other.keyblock;
this->ctx_type = other.ctx_type;
std::lock_guard<std::mutex> lock(other.ctx_mutex);
std::shared_lock lock(other.ctx_mutex);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

SSLCertContext::operator= writes this->ctx without taking this->ctx_mutex. Since getCtx()/setCtx() use ctx_mutex to synchronize access to ctx, this assignment can cause a data race if the object is assigned while other threads are calling getCtx()/setCtx() (e.g., during reload). Consider taking an exclusive lock on this->ctx_mutex while updating ctx (and avoid deadlock by locking other.ctx_mutex and this->ctx_mutex with a consistent ordering / std::lock).

Suggested change
std::shared_lock lock(other.ctx_mutex);
std::shared_lock other_lock(other.ctx_mutex, std::defer_lock);
std::unique_lock this_lock(this->ctx_mutex, std::defer_lock);
std::lock(other_lock, this_lock);

Copilot uses AI. Check for mistakes.
this->ctx = other.ctx;
}
return *this;
Expand All @@ -258,14 +259,14 @@ SSLCertContext::operator=(SSLCertContext const &other)
shared_SSL_CTX
SSLCertContext::getCtx()
{
std::lock_guard<std::mutex> lock(ctx_mutex);
std::shared_lock lock(ctx_mutex);
return ctx;
}

void
SSLCertContext::setCtx(shared_SSL_CTX sc)
{
std::lock_guard<std::mutex> lock(ctx_mutex);
std::lock_guard lock(ctx_mutex);
ctx = std::move(sc);
}

Expand Down