Skip to content

mod_ssl: Free parsed ASN1_OBJECT in ssl_ext_list when cert is absent - #1117

Open
professor-moody wants to merge 1 commit into
apache:trunkfrom
professor-moody:fix-mod-ssl-ext-list-oid-leak-trunk
Open

professor-moody wants to merge 1 commit into
apache:trunkfrom
professor-moody:fix-mod-ssl-ext-list-oid-leak-trunk

Conversation

@professor-moody

Copy link
Copy Markdown

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 -x onto 2.4.x.

In modules/ssl/ssl_engine_vars.c, ssl_ext_list calls OBJ_txt2obj(extension, 0) on line 1286 and then fetches the certificate on line 1294 via SSL_get_peer_certificate or SSL_get_certificate. When if (xs == NULL) holds on line 1295, ssl_ext_list returned NULL without calling ASN1_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 for PeerExtList in docs/manual/mod/mod_ssl.xml), OBJ_txt2obj dynamically allocates an ASN1_OBJECT and its DER-encoded data buffer on the OpenSSL/C heap rather than from an APR request pool. Evaluating PeerExtList through SSLRequire or Require expr on 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): call ASN1_OBJECT_free(oid) before returning NULL when xs == NULL, matching the cleanup on the non-NULL return path and covering both peer and server certificate lookups while preserving APLOGNO(01970) logging for unparseable OIDs.
  • test/modules/ssl/test_008_peer_ext_list_leak.py (TestPeerExtListOidLeak):
    • Added test_ssl_ext_list_valid_client_cert_control verifying that a valid client certificate carrying custom OID "1.3.6.1.4.1.18060.12.0" succeeds under both SSLRequire and Require 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 logging AH01970.
    • Added test_ssl_ext_list_missing_peer_cert_reject_no_leak exercising both SSLRequire and Require expr with PeerExtList for 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

  • Verified git apply --check cleanly against trunk (52a80d65774306a562cad1174bbbfd3e03fe9099) and strict C89 compilation (-std=c89 -Wall -Werror) of modules/ssl/ssl_engine_vars.c.
  • Compiled modules/ssl/ssl_engine_vars.c from 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 from OBJ_txt2obj (modules/ssl/ssl_engine_vars.c:1286) in ssl_ext_list; patched passes all positive controls and missing-certificate checks with 0 leaks.
  • Verified Python syntax (python3 -m py_compile) and pytest collection (2 tests collected) for test/modules/ssl/test_008_peer_ext_list_leak.py against the trunk test tree, complementing the end-to-end pyhttpd ASan+LSan, ASan+UBSan+LSan, Clang Release, and GCC Release full test/modules/ssl verification previously run for mod_ssl: Free parsed ASN1_OBJECT in ssl_ext_list when cert is absent #1113.

  • This PR does not report or address a security vulnerability (see SECURITY.md and https://www.apache.org/security/#reporting-a-vulnerability). (Confirmed by the Apache Httpd Security Team on 2026-11-27 that this is not a vulnerability in Apache Httpd and a public PR is fine.)
  • Code follows the httpd style guide (strict C89 verified with -std=c89 -Wall -Werror and matching surrounding indentation).
  • New log messages (level debug or higher) use an empty APLOGNO() tag; numbers are assigned by a committer at merge time (see docs/log-message-tags/README). (No new log messages added; existing APLOGNO(01970) is preserved.)
  • If the change is user-visible, a changes-entries/*.txt file 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 cases based on pyhttpd are included where appropriate, in the test/modules/xxx directory matching the modules/xxx module source, or test/modules/core for core server changes. On Unix, verify these pass locally with e.g. make check-pytest PYTEST_DIRS=test/modules/xxx (added test/modules/ssl/test_008_peer_ext_list_leak.py; syntax and pytest collection verified on trunk alongside full test/modules/ssl execution 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant