Repository navigation
mod_ssl: Free parsed ASN1_OBJECT in ssl_ext_list when cert is absent - #1117
Open
professor-moody wants to merge 1 commit into
Open
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.
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
This PR targets trunk as a follow-up to #1113 per maintainer feedback so the fix can land on trunk first and then be cherry-picked with
git cherry-pick -xonto 2.4.x.In
modules/ssl/ssl_engine_vars.c,ssl_ext_listcallsOBJ_txt2obj(extension, 0)on line 1286 and then fetches the certificate on line 1294 viaSSL_get_peer_certificateorSSL_get_certificate. Whenif (xs == NULL)holds on line 1295,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 1296): 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 trunk (52a80d65774306a562cad1174bbbfd3e03fe9099) and strict C89 compilation (-std=c89 -Wall -Werror) ofmodules/ssl/ssl_engine_vars.c.modules/ssl/ssl_engine_vars.cfrom trunk linked with APR and OpenSSL 3.6.4 under Clang 23.1.1 AddressSanitizer + LeakSanitizer (-O2 -g -DNDEBUG), Clang 23.1.1 ASan + UBSan + LSan (-O1 -g), and Release (-O2 -g -DNDEBUG with OpenSSL allocation accounting): unpatched leaks 100,000 bytes in 4,000 allocations fromOBJ_txt2obj(modules/ssl/ssl_engine_vars.c:1286) inssl_ext_list; patched passes all positive controls and missing-certificate checks with 0 leaks.python3 -m py_compile) and pytest collection (2 tests collected) fortest/modules/ssl/test_008_peer_ext_list_leak.pyagainst the trunk test tree, complementing the end-to-end pyhttpd ASan+LSan, ASan+UBSan+LSan, Clang Release, and GCC Release fulltest/modules/sslverification previously run for mod_ssl: Free parsed ASN1_OBJECT in ssl_ext_list when cert is absent #1113.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 in README.CHANGES (not needed otherwise). (Not included; can be added following README.CHANGES if requested at review time.)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.py; syntax and pytest collection verified on trunk alongside fulltest/modules/sslexecution from mod_ssl: Free parsed ASN1_OBJECT in ssl_ext_list when cert is absent #1113).AI assistance was used in drafting and validating this change; the patch and tests were reviewed and verified by the author.