ssl_api_ext: lock ticket key context in the public key APIs - #11403
ssl_api_ext: lock ticket key context in the public key APIs#11403yosuke-wolfssl wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The locking and NO_TLS gating are consistent with the context initialization guard and are backed by a targeted threaded regression test.
Pull request overview
This PR hardens the session ticket key public APIs against concurrent access by taking the existing ticketKeyCtx.mutex across the full key blob copy, and aligns API availability with the actual initialization conditions (notably !NO_TLS). It also adds a threaded regression test to catch mixed/teared reads during key rotation.
Changes:
- Add mutex locking to
wolfSSL_CTX_get_tlsext_ticket_keys()/wolfSSL_CTX_set_tlsext_ticket_keys()to serialize full-blob reads/writes of the ticket key context. - Add
!defined(NO_TLS)to the compile guards for the public prototypes and the implementation so the APIs are absent when TLS is disabled. - Add and register a threaded API test that validates reads always return an intact, whole key blob under concurrent writes.
File summaries
| File | Description |
|---|---|
src/ssl_api_ext.c |
Locks ctx->ticketKeyCtx.mutex around the full key copy for get/set, and updates doc comments to include mutex-lock failure as a return case. |
wolfssl/ssl.h |
Adds !defined(NO_TLS) to the prototype guard to match the implementation/initializer availability. |
tests/api/test_session.c |
Adds test_wolfSSL_ticket_keys_threaded() to exercise concurrent setter/getter behavior and detect mixed key blobs. |
tests/api/test_session.h |
Registers the new threaded session ticket keys test in the session test group. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11403
Scan targets checked: wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
7666ccc to
a0b8844
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11403
Scan targets checked: wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src
Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
- wolfSSL_CTX_get_tlsext_ticket_keys() and wolfSSL_CTX_set_tlsext_ticket_keys() hold ticketKeyCtx.mutex across the name, key and expirary copy and return WOLFSSL_FAILURE when the lock fails, under !SINGLE_THREADED. The @return line of each names that failure. - The #if around both functions in src/ssl_api_ext.c and around their prototypes in wolfssl/ssl.h adds !defined(NO_TLS). - tests/api/test_session.c gains test_wolfSSL_ticket_keys_threaded(), a writer thread rotating two key blobs against a reader asserting each get returns one blob whole and that both blobs were seen. Declared and registered in tests/api/test_session.h. Issue: F-13440
a0b8844 to
0458577
Compare
Problem
wolfSSL_CTX_get_tlsext_ticket_keys()andwolfSSL_CTX_set_tlsext_ticket_keys()read and overwritectx->ticketKeyCtx.name,key[0],key[1]andexpirary[0..1]field by field with no lock, whileDefTicketEncCb()guards those same fields withticketKeyCtx.mutex. A management thread rotating session ticket keys on a liveWOLFSSL_CTXraces a handshake: the setter can leave a name from one key set beside a key from another, producing tickets that cannot be resumed, and the getter can return a key set that never existed. Closes f-13440.A second, latent issue in the same code:
TicketEncCbCtx_Init()is only called whenNO_TLSis undefined, but both APIs compiled regardless, so a--disable-tls --enable-session-ticketbuild reached a mutex that was never initialized.Fix (
src/ssl_api_ext.c)Both functions take
ticketKeyCtx.mutexacross the entire copy, via a lockingelse ifthat extends the existing argument-validation chain — no new scope block and nogoto:wc_LockMutex()failure returnsWOLFSSL_FAILURE; the doc comment of each function now names that as a failure case.wc_UnLockMutex()runs at the end of the copy branch.#ifndef SINGLE_THREADED— themutexfield only exists there.The guard now matches the one on the context's initializer:
TicketEncCbCtx_Init()call,src/internal.cHAVE_SESSION_TICKET,!NO_WOLFSSL_SERVER,!WOLFSSL_NO_DEF_TICKET_ENC_CB,!NO_TLSsrc/ssl_api_ext.c!NO_TLSadded)wolfssl/ssl.h!NO_TLSadded)Test harness (
tests/api/test_session.c)test_wolfSSL_ticket_keys_threaded()seeds the context with one key blob, then runs a writer thread alternating two blobs through the setter while the main thread calls the getter and asserts every read returns one blob whole. Guarded on the file's existing condition plus!SINGLE_THREADED; registered intests/api/test_session.h.Verification
data raceonticketKeyCtx.expirary[0]between the setter and getter before the fix, zero reports after.make check5 passed / 5 skipped / 0 failed; session group 3 passed / 0 failed.--enable-singlethreaded(test reportsskipped) and under--disable-tls --enable-session-ticket, where both symbols are correctly absent from the library.Not in this PR
The encrypt path in
DefTicketEncCb()still readskeyCtx->nameandkey[keyIdx]without the lock — a deliberate lock-light design documented in that function. A setter racing an in-flight encrypt can therefore still tear.