Repository navigation
Fix a segfault of showCertificate when TLS certificates are provisioned by ACME - #115976
Conversation
…oned by ACME `showCertificate` took the certificate from the default server `SSL_CTX`. When certificates are provisioned dynamically with the `<acme>` configuration, that context never receives a certificate: `SSL_CTX_get0_certificate` returns a null pointer, `X509_dup` of it returns a null pointer as well, and the result was wrapped into an `X509Certificate` whose every accessor dereferences it. As a result, any user - including a read-only one - could crash the server with `SELECT showCertificate()`. The null check existed in the original implementation and was lost when `Poco::Crypto` was replaced with our own `X509Certificate` wrapper; it became reachable when ACME support was added. Take the certificate from `CertificateReloader` instead - it is the component that owns the certificate actually served to clients. Besides ACME, this also makes the function report the certificate in use after a reload instead of the one loaded into the context at startup. When there is no certificate at all, an empty map is returned, as before. Additionally, `X509Certificate` no longer accepts a null pointer silently: constructing it from `nullptr` now throws instead of producing an object that segfaults on the first use.
|
Workflow [PR], commit [cb0db7b] Summary: ✅
AI ReviewSummaryThis PR fixes the null-dereference in Findings
Final VerdictChanges requested. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 27/36 (75.00%) · Uncovered code |
| /// `CertificateReloader` knows the certificate in use. | ||
| std::optional<X509Certificate> getServerCertificate() | ||
| { | ||
| auto served_certificate = CertificateReloader::instance().getCertificate(Poco::Net::SSLManager::CFG_SERVER_PREFIX); |
There was a problem hiding this comment.
showCertificate() still does not follow the new "certificate actually served" contract on the PostgreSQL wire path. This helper always reads openSSL.server via CFG_SERVER_PREFIX, but PostgreSQLHandler::makeSecureConnectionSSL() can serve a different per-protocol context from prefix, and PostgreSQLHandler::run() never threads that certificate path/prefix into Session the way TCPHandler does. In a deployment with a dedicated PostgreSQL TLS certificate, SELECT showCertificate() over PostgreSQL will still report the native TCP certificate or {}.
Please propagate the PostgreSQL TLS certificate (or at least its config prefix) into ClientInfo and select it here, otherwise the new comment/docs/PR description should be scoped to the native TCP interface only.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units16 translation units recompiled, 68 s compile time in total, 16 of them have a recent master baseline. |
Merge `backport/26.6/115976` into the cherry-pick branch of #115976. The only conflict is in the documentation string of `showCertificate` in `src/Functions/FunctionShowCertificate.cpp`: 26.6 links the TLS guide as `/guides/sre/tls/configuring-tls` while master uses `/concepts/features/security/tls/configuring-tls`. Kept the branch's link and added the new sentence about an empty map being returned. The rest applies as-is: 26.6 already has `registerAdditionalContext`, `data_index`, `data_mutex` and the `<acme>` support that `CertificateReloader::getCertificate` relies on.
Cherry pick #115976 to 26.3: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
…certificates are provisioned by ACME
Cherry pick #115976 to 26.6: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
…certificates are provisioned by ACME
Cherry pick #115976 to 26.5: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
…certificates are provisioned by ACME
Cherry pick #115976 to 26.7: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
…certificates are provisioned by ACME
Backport #115976 to 26.5: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
Backport #115976 to 26.3: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
Backport #115976 to 26.6: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
Backport #115976 to 26.7: Fix a segfault of showCertificate when TLS certificates are provisioned by ACME
showCertificatetook the server certificate from the defaultSSL_CTX. When certificates are provisioned dynamically with the<acme>configuration, that context never receives a certificate:SSL_CTX_get0_certificatereturns a null pointer,X509_dupof it returns a null pointer as well, and the result was wrapped into anX509Certificatewhose every accessor dereferences it. Any user - including a read-only one - could crash the server withSELECT showCertificate():It is reproducible without an ACME server, because it is enough that the certificate is not there:
The null check existed in the original implementation and was lost when
Poco::Cryptowas replaced with our ownX509Certificatewrapper; it became reachable when ACME support was added.The certificate is now taken from
CertificateReloader- the component that owns the certificate actually served to clients. Besides ACME, this also makes the function report the certificate in use after a reload, instead of the one loaded into the SSL context at startup. When there is no certificate at all, an empty map is returned, as it was before ACME.Additionally,
X509Certificateno longer accepts a null pointer silently: constructing it fromnullptrthrows instead of producing an object that segfaults on the first use.Related: #78591
Related: #66315
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a crash of the
showCertificatefunction on a server that obtains its TLS certificate with ACME (Let's Encrypt). The function now reports the certificate that is actually served, also after a certificate reload.Documentation entry for user-facing changes
Workflow [PR]
Sync PR [sync-upstream/pr/115976]
Version info
26.8.1.1943(included in26.8and later)26.7.6.45,26.6.4.33,26.3.24.3