Skip to content

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

Closed
professor-moody wants to merge 1 commit into
apache:2.4.xfrom
professor-moody:2.4.x
Closed

professor-moody wants to merge 1 commit into
apache:2.4.xfrom
professor-moody:2.4.x

Conversation

@professor-moody

Copy link
Copy Markdown

Summary

In modules/ssl/ssl_engine_vars.c, ssl_ext_list calls OBJ_txt2obj(extension, 0) on line 1078 and then fetches the certificate on line 1086 via SSL_get_peer_certificate or SSL_get_certificate. When if (xs == NULL) holds on line 1087, 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 1088): 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 both 2.4.x (3e9acba50c01ddc9668c8402b12e11fdd97d2020) and trunk (477078fb3b3bd3794c710db29d08eba32cf2ed00, re-verified at c94c5c074096cbbec5b68922e1bc1a132904d814), plus strict C89 compilation (-std=c89 -Wall -Werror) of modules/ssl/ssl_engine_vars.c.
  • Clang 21.1.8 AddressSanitizer + LeakSanitizer (-O2 -g -DNDEBUG): unpatched fails test_ssl_ext_list_missing_peer_cert_reject_no_leak with 100,000 bytes leaked in 4,000 allocations from OBJ_txt2obj via ssl_ext_list (exit 1); patched passes both tests in test/modules/ssl/test_008_peer_ext_list_leak.py with 0 leaks (exit 0).
  • Clang 21.1.8 AddressSanitizer + UndefinedBehaviorSanitizer + LeakSanitizer (-O1, -fno-sanitize=function): unpatched fails with the same 100,000-byte leak (exit 1); patched passes cleanly (exit 0).
  • Pure Release builds (Clang 21.1.8 -O2 -g -DNDEBUG and GCC 15.3.1 -O2 -g -DNDEBUG -fstack-protector-strong, zero sanitizers): unpatched fails test_ssl_ext_list_missing_peer_cert_reject_no_leak with > 9 MB worker VmRSS growth across 100,000 requests (exit 1); patched passes both tests in test/modules/ssl/test_008_peer_ext_list_leak.py (exit 0) and the full test/modules/ssl suite with 0 failures (exit 0).

  • 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 yet included; can be added following README.CHANGES once disclosure and branch handling are confirmed.)
  • 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 and verified test/modules/ssl locally with 0 failures).

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.
@covener

covener commented Nov 28, 2026

Copy link
Copy Markdown
Member

Thanks for followup up on this, can you start on trunk and cherry-pick -x onto 2.4 after it's merged?

@professor-moody

Copy link
Copy Markdown
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.

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.

2 participants