sergey-safarov created an issue (kamailio/kamailio#4534)
### Description
On Alpine Linux th `tls` module load is crashing Kamailio with a coredump
```
#0 0x00007fcbdf45f8d2 in __pthread_getspecific (k=0) at
src/thread/pthread_getspecific.c:7
self = 0x7fcbdf4ac588 <builtin_tls+136>
#1 0x00007fcbdeb6201c in mod_init () at tls_mod.c:406
method = <optimized out>
verify_client = <optimized out>
rand_buf =
"\270\f=\337\313\177\000\000\230X\201\203\000\001\000\000\000\001\000\000\0011\0010\00217\003172\a"
k = 0
__func__ = "mod_init"
__llevel = <optimized out>
__kld = <optimized out>
#2 0x00005557fdcdf2a7 in init_mod (m=0x7fcbded4a390) at core/sr_module.c:1037
ret = <optimized out>
__func__ = "init_mod"
#3 0x00005557fdcdf060 in init_mod (m=0x7fcbded4d9d0) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#4 0x00005557fdcdf060 in init_mod (m=0x7fcbded4e380) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#5 0x00005557fdcdf060 in init_mod (m=0x7fcbded4f100) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#6 0x00005557fdcdf060 in init_mod (m=0x7fcbded51380) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#7 0x00005557fdcdf060 in init_mod (m=0x7fcbded51b90) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#8 0x00005557fdcdf060 in init_mod (m=0x7fcbded52af0) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#9 0x00005557fdcdf060 in init_mod (m=0x7fcbded5d010) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#10 0x00005557fdcdf060 in init_mod (m=0x7fcbded5d650) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#11 0x00005557fdcdf060 in init_mod (m=0x7fcbded5ea30) at core/sr_module.c:1032
ret = <optimized out>
__func__ = "init_mod"
#12 0x00005557fdce389b in init_modules () at core/sr_module.c:1068
t = <optimized out>
i = <optimized out>
__func__ = "init_modules"
#13 0x00005557fdab83b2 in main (argc=<optimized out>, argv=<optimized out>) at
main.c:3353
cfg_stream = <optimized out>
c = <optimized out>
r = <optimized out>
tmp = 0x3d3980 <error: Cannot access memory at address 0x3d3980>
tmp_len = 32715
port = 5060
proto = 0
aproto = 0
ahost = 0x0
socket_name = <optimized out>
aport = 0
listen_field_count = <optimized out>
listen_fields = {0x0, 0x0, 0x0}
options = 0x5557fdd8ec35
":f:cm:M:dVIhEeb:B:l:L:n:vKrRDTN:W:w:t:u:g:P:G:SQ:O:a:A:x:X:Y:"
ret = -1
seed = 3379987412
rfd = <optimized out>
debug_save = <optimized out>
debug_flag = <optimized out>
dont_fork_cnt = <optimized out>
n_lst = <optimized out>
p = <optimized out>
tbuf = 0x13190 <error: Cannot access memory at address 0x13190>
tbuf_tmp = <optimized out>
st = {st_dev = 82, st_ino = 15305750, st_nlink = 2, st_mode = 16877,
st_uid = 100, st_gid = 0, __pad0 = 0, st_rdev = 0, st_size = 6, st_blksize =
4096, st_blocks = 0, st_atim = {
tv_sec = 1766246263, tv_nsec = 624197245}, st_mtim = {tv_sec =
1766246163, tv_nsec = 172268511}, st_ctim = {tv_sec = 1766246163, tv_nsec =
172268511}, __unused = {0, 0, 0}}
l1 = <optimized out>
lim = {rlim_cur = 1024, rlim_max = 524288}
option_index = 12
long_options = {{name = 0x5557fdd90051 "help", has_arg = 0, flag = 0x0,
val = 104}, {name = 0x5557fdd9dc1d "version", has_arg = 0, flag = 0x0, val =
118}, {
name = 0x5557fdda8d6e "alias", has_arg = 1, flag = 0x0, val =
1024}, {name = 0x5557fdd90056 "subst", has_arg = 1, flag = 0x0, val = 1025},
{name = 0x5557fdd9005c "substdef",
has_arg = 1, flag = 0x0, val = 1026}, {name = 0x5557fdd90065
"substdefs", has_arg = 1, flag = 0x0, val = 1027}, {name = 0x5557fdd9006f
"server-id", has_arg = 1, flag = 0x0,
val = 1028}, {name = 0x5557fdd90079 "loadmodule", has_arg = 1, flag
= 0x0, val = 1029}, {name = 0x5557fdd90084 "modparam", has_arg = 1, flag = 0x0,
val = 1030}, {
name = 0x5557fdd9008d "log-engine", has_arg = 1, flag = 0x0, val =
1031}, {name = 0x5557fdd9dd3a "debug", has_arg = 1, flag = 0x0, val = 1032},
{name = 0x5557fdd90098 "cfg-print",
has_arg = 0, flag = 0x0, val = 1033}, {name = 0x5557fdd900a2
"atexit", has_arg = 1, flag = 0x0, val = 1034}, {name = 0x5557fdd900a9
"all-errors", has_arg = 0, flag = 0x0,
val = 1035}, {name = 0x0, has_arg = 0, flag = 0x0, val = 0}}
__func__ = "main"
```
Here is called `pthread_getspecific`
https://github.com/kamailio/kamailio/blob/6.0.4/src/modules/tls/tls_mod.c#L406
Source code for this function at
https://github.com/kraj/musl/blob/kraj/master/src/thread/pthread_getspecific.c#L7C15-L7C18
In the standard musl package `self` variable is optimised and not available for
printing.
I have compiled musl with disabled optimization and the `self` variable
available for printing.
```
(gdb) p self
$5 = (struct __pthread *) 0x7fcbdf4ac588 <builtin_tls+136>
(gdb) p *self
$6 = {self = 0x7fcbdf4ac588 <builtin_tls+136>, dtv = 0x7fcbdf4ac500
<builtin_tls>, prev = 0x7fcbdf4ac588 <builtin_tls+136>, next = 0x7fcbdf4ac588
<builtin_tls+136>, sysinfo = 0,
canary = 5087873141211791600, tid = 30511, errno_val = 9, detach_state = 2,
cancel = 0, canceldisable = 0 '\000', cancelasync = 0 '\000', tsd_used = 0
'\000', dlerror_flag = 0 '\000',
map_base = 0x0, map_size = 0, stack = 0x0, stack_size = 0, guard_size = 0,
result = 0x0, cancelbuf = 0x0, tsd = 0x0, robust_list = {head = 0x7fcbdf4ac610
<builtin_tls+272>, off = 0,
pending = 0x0}, h_errno_val = 0, timer_id = 0, locale = 0x7fcbdf4aa8b8
<__libc+56>, killlock = {0}, dlerror_buf = 0x0, stdio_locks = 0x0}
(gdb) p self->tsd
$7 = (void **) 0x0
(gdb) p self->tsd[0]
Cannot access memory at address 0x0
```
Probably need to call `pthread_setspecific` before calling
`pthread_getspecific`.
### Additional Information
* **Kamailio Version** - output of `kamailio -v`
```
~/packages/root/x86_64 # kamailio -v
version: kamailio 6.0.4 (x86_64/Linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE,
USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, MEM_JOIN_FREE, Q_MALLOC,
F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT,
USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES,
TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_SEND_BUFFER_SIZE
262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled on 16:06:16 Dec 16 2025 with gcc 15.2.0
```
* **Operating System**:
```
~/packages/root/x86_64 # cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.23.2
PRETTY_NAME="Alpine Linux v3.23"
HOME_URL="https://alpinelinux.org/"
BUG_REPORT_URL="https://gitlab.alpinelinux.org/alpine/aports/-/issues"
```
--
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/4534
You are receiving this because you are subscribed to this thread.
Message ID: <kamailio/kamailio/issues/[email protected]>_______________________________________________
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!