Module: kamailio
Branch: master
Commit: d53dc5ab9b95b82a2e8769351d77e33ce8d43bb7
URL: 
https://github.com/kamailio/kamailio/commit/d53dc5ab9b95b82a2e8769351d77e33ce8d43bb7

Author: Joey Golan <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2026-03-08T21:29:05+01:00

tls: fix segfault on musl libc due to uninitialized pthread TSD

On musl libc (Alpine Linux), pthread thread-specific data (TSD) for
the main thread is not initialized until pthread_key_create() is
called at least once. The diagnostic loop in mod_init() calls
pthread_getspecific() with raw integer keys 0-31 before any key has
been created, causing a NULL pointer dereference on musl.

Force TSD initialization by creating and immediately deleting a
pthread key before the diagnostic loop.

Fixes: kamailio/kamailio-ci#20
Related: #4534
Made-with: Cursor

---

Modified: src/modules/tls/tls_mod.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/d53dc5ab9b95b82a2e8769351d77e33ce8d43bb7.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d53dc5ab9b95b82a2e8769351d77e33ce8d43bb7.patch

---

diff --git a/src/modules/tls/tls_mod.c b/src/modules/tls/tls_mod.c
index 5ce10e5d227..a21299a327a 100644
--- a/src/modules/tls/tls_mod.c
+++ b/src/modules/tls/tls_mod.c
@@ -410,6 +410,11 @@ static int mod_init(void)
        }
 #endif
 #if OPENSSL_VERSION_NUMBER >= 0x10101000L
+       {
+               pthread_key_t _ksr_tsd_init;
+               pthread_key_create(&_ksr_tsd_init, NULL);
+               pthread_key_delete(_ksr_tsd_init);
+       }
        for(k = 0; k < 32; k++) {
                if(pthread_getspecific(k) != 0) {
                        LM_WARN("detected initialized thread-locals created 
before tls.so; "

_______________________________________________
Kamailio - Development Mailing List -- [email protected]
To unsubscribe send an email to [email protected]
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to