Skip to content

Fix dangling secure_renegotiation pointer after TLSX_FreeAll#10210

Open
ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
ColtonWilley:fix-scr-dangling-ptr-after-tlsx-freeall
Open

Fix dangling secure_renegotiation pointer after TLSX_FreeAll#10210
ColtonWilley wants to merge 3 commits intowolfSSL:masterfrom
ColtonWilley:fix-scr-dangling-ptr-after-tlsx-freeall

Conversation

@ColtonWilley
Copy link
Copy Markdown
Contributor

Summary

  • ssl->secure_renegotiation caches a pointer into extension data owned by the ssl->extensions list. Three call sites free that list via TLSX_FreeAll without NULLing the cached pointer, leaving it dangling: wolfSSL_clear(), FreeHandshakeResources(), and wolfSSL_ResourceFree().
  • After wolfSSL_clear(), calling wolfSSL_SSL_get_secure_renegotiation_support() reads the freed SecureRenegotiation struct. Confirmed heap-use-after-free under ASan with nginx, haproxy, and openssl-compat build profiles.
  • NULL the pointer at all three sites. Add regression test covering the wolfSSL_clear path.

Test plan

  • Existing CI passes
  • New test_wolfSSL_clear_secure_renegotiation passes
  • ASan build does not report heap-use-after-free on the wolfSSL_clear → wolfSSL_SSL_get_secure_renegotiation_support sequence

ssl->secure_renegotiation caches a pointer into extension data owned by
the ssl->extensions list. Three call sites free that list via TLSX_FreeAll
without NULLing the cached pointer, leaving it dangling:

- wolfSSL_clear()
- FreeHandshakeResources() (TLSX_FreeAll branch)
- wolfSSL_ResourceFree()

After wolfSSL_clear(), calling wolfSSL_SSL_get_secure_renegotiation_support()
reads the freed SecureRenegotiation struct. Confirmed heap-use-after-free
under ASan with nginx, haproxy, and openssl-compat build profiles.

NULL the pointer at all three sites. Add regression test covering the
wolfSSL_clear path.
@ColtonWilley ColtonWilley marked this pull request as draft April 13, 2026 21:57
@mattia-moffa mattia-moffa self-assigned this Apr 15, 2026
@mattia-moffa
Copy link
Copy Markdown
Contributor

Jenkins retest this please

@mattia-moffa mattia-moffa marked this pull request as ready for review April 20, 2026 20:46
Copilot AI review requested due to automatic review settings April 20, 2026 20:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a use-after-free where ssl->secure_renegotiation could dangle after TLSX_FreeAll() frees the extensions list that owns the underlying SecureRenegotiation struct.

Changes:

  • Clear ssl->secure_renegotiation when wolfSSL_clear() frees ssl->extensions via TLSX_FreeAll().
  • Clear ssl->secure_renegotiation (and also NULL ssl->extensions) when wolfSSL_ResourceFree() and FreeHandshakeResources() free the extensions list.
  • Add a regression test covering the wolfSSL_clear() -> wolfSSL_SSL_get_secure_renegotiation_support() sequence.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
tests/api.c Adds regression test to ensure secure_renegotiation is cleared by wolfSSL_clear() and the query API behaves safely afterward.
src/ssl.c Clears ssl->secure_renegotiation when wolfSSL_clear() frees the extensions list.
src/internal.c Clears ssl->secure_renegotiation (and NULLs ssl->extensions) in additional cleanup paths that free the extensions list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/internal.c Outdated
Comment thread src/internal.c Outdated
Comment thread tests/api.c
Comment thread src/ssl.c
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 21, 2026

MemBrowse Memory Report

No memory changes detected for:

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.

3 participants