Repository navigation
mod_ssl: Free parsed ASN1_OBJECT in ssl_ext_list when cert is absent - #1113
Closed
professor-moody wants to merge 1 commit into
Closed
professor-moody wants to merge 1 commit into
professor-moody wants to merge 1 commit into
Conversation
In modules/ssl/ssl_engine_vars.c, ssl_ext_list() parses the extension argument with OBJ_txt2obj(extension, 0) before retrieving the X.509 certificate via SSL_get_peer_certificate() or SSL_get_certificate(). When no certificate is present (xs == NULL), the function returned NULL without calling ASN1_OBJECT_free(oid). For built-in OIDs in OpenSSL's static NID table, ASN1_OBJECT_free() is a no-op. For numeric OIDs not registered in the static table (such as private enterprise OIDs documented for PeerExtList()), OBJ_txt2obj() dynamically allocates an ASN1_OBJECT and its DER buffer on the OpenSSL heap rather than from the APR request pool. Each evaluation of PeerExtList() via SSLRequire or Require expr on a TLS connection without a client certificate therefore leaked that ASN1_OBJECT for the lifetime of the worker process. Free oid with ASN1_OBJECT_free(oid) before returning NULL when xs == NULL, matching the normal return path at the end of ssl_ext_list() and preserving APLOGNO(01970) debug logging for unparseable OIDs. Add test/modules/ssl/test_008_peer_ext_list_leak.py with positive controls (valid client certificate carrying custom OID, non-matching client certificate, built-in OID, and invalid OID logging AH01970) and regression checks for SSLRequire and Require expr with PeerExtList() when no client certificate is presented.
Member
|
Thanks for followup up on this, can you start on trunk and cherry-pick -x onto 2.4 after it's merged? |
Author
|
Closing this 2.4.x PR per @covener's request to land on trunk first. Opening the trunk PR next and will cherry-pick -x onto 2.4.x after merge. |
4 of 5 tasks
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.
Summary
In
modules/ssl/ssl_engine_vars.c,ssl_ext_listcallsOBJ_txt2obj(extension, 0)on line 1078 and then fetches the certificate on line 1086 viaSSL_get_peer_certificateorSSL_get_certificate. Whenif (xs == NULL)holds on line 1087,ssl_ext_listreturnedNULLwithout callingASN1_OBJECT_free(oid).When the extension string is a custom numeric OID not in OpenSSL's built-in NID table (for example
"1.3.6.1.4.1.18060.12.0"or"1.2.3.4.5.6"as documented forPeerExtListindocs/manual/mod/mod_ssl.xml),OBJ_txt2objdynamically allocates anASN1_OBJECTand its DER-encoded data buffer on the OpenSSL/C heap rather than from an APR request pool. EvaluatingPeerExtListthroughSSLRequireorRequire expron a TLS connection without a client certificate leaked that allocation on every request for the lifetime of the worker process.Changes
modules/ssl/ssl_engine_vars.c(ssl_ext_list, line 1088): callASN1_OBJECT_free(oid)before returningNULLwhenxs == NULL, matching the cleanup on the non-NULL return path and covering both peer and server certificate lookups while preservingAPLOGNO(01970)logging for unparseable OIDs.test/modules/ssl/test_008_peer_ext_list_leak.py(TestPeerExtListOidLeak):test_ssl_ext_list_valid_client_cert_controlverifying that a valid client certificate carrying custom OID"1.3.6.1.4.1.18060.12.0"succeeds under bothSSLRequireandRequire expr, a client certificate without that extension is rejected with HTTP 403, and missing-certificate requests against a built-in OID ("2.5.29.17") and an invalid OID ("not-a-valid-oid") return HTTP 403 while loggingAH01970.test_ssl_ext_list_missing_peer_cert_reject_no_leakexercising bothSSLRequireandRequire exprwithPeerExtListfor custom OID"1.3.6.1.4.1.18060.12.0"without a client certificate, verifying LeakSanitizer reports zero leaked allocations under AddressSanitizer builds and worker VmRSS stays bounded under Release builds.Verification
git apply --checkcleanly against both2.4.x(3e9acba50c01ddc9668c8402b12e11fdd97d2020) andtrunk(477078fb3b3bd3794c710db29d08eba32cf2ed00, re-verified atc94c5c074096cbbec5b68922e1bc1a132904d814), plus strict C89 compilation (-std=c89 -Wall -Werror) ofmodules/ssl/ssl_engine_vars.c.test_ssl_ext_list_missing_peer_cert_reject_no_leakwith 100,000 bytes leaked in 4,000 allocations fromOBJ_txt2objviassl_ext_list(exit 1); patched passes both tests intest/modules/ssl/test_008_peer_ext_list_leak.pywith 0 leaks (exit 0).test_ssl_ext_list_missing_peer_cert_reject_no_leakwith > 9 MB worker VmRSS growth across 100,000 requests (exit 1); patched passes both tests intest/modules/ssl/test_008_peer_ext_list_leak.py(exit 0) and the fulltest/modules/sslsuite with 0 failures (exit 0).APLOGNO()tag; numbers are assigned by a committer at merge time (seedocs/log-message-tags/README). (No new log messages added; existingAPLOGNO(01970)is preserved.)changes-entries/*.txtfile is included, following the template inREADME.CHANGES(not needed otherwise). (Not yet included; can be added followingREADME.CHANGESonce disclosure and branch handling are confirmed.)test/modules/xxxdirectory matching themodules/xxxmodule source, ortest/modules/corefor core server changes. On Unix, verify these pass locally with e.g.make check-pytest PYTEST_DIRS=test/modules/xxx(addedtest/modules/ssl/test_008_peer_ext_list_leak.pyand verifiedtest/modules/ssllocally with 0 failures).AI assistance was used in drafting and validating this change; the patch and tests were reviewed and verified by the author.