[WIP] Fix crash during TLS handshake in http_pool_post#286
Draft
[WIP] Fix crash during TLS handshake in http_pool_post#286
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_ca_bundle_path()helper function tosource/protocol/http/multicurlinterface.cCURLOPT_SSL_VERIFYHOSTto2Lininit_connection_pool()loopCURLOPT_CAINFOto validated CA bundle path ininit_connection_pool()loopsource/test/protocol/MultiCurlInterfaceTest.cpp: fix pool size env var, remove incorrect pthread_mutex_init/cond_init expectations, add access() mock expectationssource/test/protocol/ProtocolTest.cpp: add defaultaccess()mock expectation to prevent crash in existing protocol testsOriginal prompt
Problem
A crash occurs during the TLS handshake in
http_pool_post()(and potentiallyhttp_pool_get()) whencurl_easy_perform()triggers OpenSSL's CA certificate loading. The crash stack trace shows:Root Cause Analysis
No explicit
CURLOPT_CAINFOorCURLOPT_CAPATHis set ininit_connection_pool()or any request function, so curl uses the system default CA bundle. If the system CA bundle is missing, corrupted, or has malformed entries, OpenSSL crashes during ASN1 parsing in the provider enumeration path (sa_doall).OpenSSL 3.0.15 thread-safety issues: The system uses
lib32-openssl 3.0.15. OpenSSL 3.0.x has known thread-safety issues inossl_method_store_do_all/sa_doallwhen multiple threads concurrently enumerate providers during certificate loading. Since the pool supports multiple concurrent handles (up to 5 viaT2_CONNECTION_POOL_SIZE), eachcurl_easy_perform()may triggerX509_STORE_load_file_exindependently.No CA bundle validation: There is no check to verify the CA certificate file exists and is readable before attempting TLS connections.
Required Changes
In
source/protocol/http/multicurlinterface.c:Add a
CURLOPT_CAINFOconfiguration to explicitly set the CA bundle path during pool initialization (init_connection_pool()), with validation that the file exists and is readable. This avoids relying on the system default which may be in a bad state. Use common RDK CA bundle paths with fallback logic:/etc/ssl/certs/ca-certificates.crt/etc/pki/tls/certs/ca-bundle.crtAdd a helper function
get_ca_bundle_path()that:Set
CURLOPT_CAINFOon each pool entry's easy handle during initialization (in the loop at lines 242-324), right after the existing SSL settings at line 280.Add a
CURLOPT_SSL_VERIFYHOSTsetting set to2Lduring pool initialization for proper hostname verification (currently missing - onlyCURLOPT_SSL_VERIFYPEERis set).Add detailed error logging when the CA bundle file is not found, to aid debugging on devices where certificate issues cause connection failures.
The changes should be minimal and focused - only adding the CA bundle configuration and validation. Do not change any other behavior of the existing mTLS, cert selector, or connection pool logic.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: sa_doall
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/sparse_array.c:86
ossl_method_store_do_all
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/property/property.c:96
evp_generic_do_all
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/evp/evp_fetch.c:676
EVP_KEYMGMT_do_all_provided
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/evp/keymgmt_meth.c:290
ossl_decoder_ctx_setup_for_pkey
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/encode_decode/decoder_pkey.c:350
OSSL_DECODER_CTX_new_for_pkey
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/encode_decode/decoder_pkey.c:454
x509_pubkey_ex_d2i_ex
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/x509/x_pubkey.c:208
asn1_item_embed_d2i
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/asn1/tasn_dec.c:262
asn1_template_noexp_d2i
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/asn1/tasn_dec.c:682
asn1_item_embed_d2i
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/asn1/tasn_dec.c:422
asn1_template_noexp_d2i
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/asn1/tasn_dec.c:682
asn1_item_embed_d2i
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/asn1/tasn_dec.c:422
asn1_item_ex_d2i_intern
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl-3.0.15/crypto/asn1/tasn_dec.c:118
ASN1_item_d2i_ex
/usr/src/debug/lib32-openssl/3.0.15-r1/build/../openssl...
This pull request was created from Copilot chat.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.