From b54cbfc9589518d15abcab6bae63f61afd204fd1 Mon Sep 17 00:00:00 2001 From: Sasank Date: Tue, 2 Jun 2026 23:19:27 +0530 Subject: [PATCH] Fix data race in SSLCertContext copy & assignment Resolve concurrent read/write data races by using std::scoped_lock in operator= and locking other.ctx_mutex at the start of the copy constructor. --- src/iocore/net/SSLCertLookup.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/iocore/net/SSLCertLookup.cc b/src/iocore/net/SSLCertLookup.cc index 4b51a21579e..f7f0699786b 100644 --- a/src/iocore/net/SSLCertLookup.cc +++ b/src/iocore/net/SSLCertLookup.cc @@ -34,6 +34,7 @@ #include "P_SSLUtils.h" #include +#include #include #include #include @@ -234,24 +235,24 @@ ssl_create_ticket_keyblock(const char *ticket_key_path) SSLCertContext::SSLCertContext(SSLCertContext const &other) { + std::shared_lock lock(other.ctx_mutex); opt = other.opt; userconfig = other.userconfig; keyblock = other.keyblock; ctx_type = other.ctx_type; - std::shared_lock lock(other.ctx_mutex); - ctx = other.ctx; + ctx = other.ctx; } SSLCertContext & SSLCertContext::operator=(SSLCertContext const &other) { if (&other != this) { + std::scoped_lock lock(this->ctx_mutex, other.ctx_mutex); this->opt = other.opt; this->userconfig = other.userconfig; this->keyblock = other.keyblock; this->ctx_type = other.ctx_type; - std::shared_lock lock(other.ctx_mutex); - this->ctx = other.ctx; + this->ctx = other.ctx; } return *this; }