[Home]

Summary:ASTERISK-17761: [patch] [regression] segfault in _sip_tcp_helper_thread() caused by bad merge in r314628
Reporter:Stefan Knoblich (stknob)Labels:
Date Opened:2011-04-27 11:43:55Date Closed:2011-05-20 13:19:52
Priority:BlockerRegression?Yes
Status:Closed/CompleteComponents:Channels/chan_sip/General
Versions:Frequency of
Occurrence
Related
Issues:
causesASTERISK-17846 [crash] SegFault / TCP enabled in _sip_tcp_helper_thread
Environment:Attachments:( 0) 10-tcptls-unreachable-peer-segfault.patch
( 1) 10-tcptls-unreachable-peer-segfault-1.8.4.patch
( 2) backtrace-threads.txt
( 3) core-show-locks.txt
Description:This happens if ast_tcptls_session_start() in _sip_tcp_helper_thread() on line 2506 in chan_sip.c fails (returns NULL).

To reproduce,
 - create a tcp sip peer that can not be reached (e.g. blocked by firewall)
 - use sip qualify peer X  (or set qualify=yes in sip.conf)

chan_sip will try to create the connection by calling ast_tcptls_session_start().
the connection fails and ast_tcptls_session_start() returns NULL:

  if ((!(ca = tcptls_session->parent)) ||
       (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"))) ||
        (!(tcptls_session = ast_tcptls_client_start(tcptls_session)))) {
              goto cleanup;
  }

setting tcptls_session to NULL and jumping to cleanup:

  cleanup:
       if (!tcptls_session->client && !authenticated) {
               ast_atomic_fetchadd_int(&unauth_sessions, -1);
       }

*boom*
asterisk[8204]: segfault at 18 ip 00007f497d4499f0 sp 00007f4966ef5450 error 4 in chan_sip.so[7f497d3c7000+a6000]
Comments:By: Stefan Knoblich (stknob) 2011-05-13 08:06:16

Jep, Chainsaw's patch fixed it:

*CLI> sip qualify peer sip_proxy-out
*CLI>
[May 13 14:51:03] ERROR[31979]: tcptls.c:379 ast_tcptls_client_start: Unable to connect SIP socket to 10.10.10.10:5060: Connection timed out
*CLI>

By: Harpreet (vois) 2011-05-13 10:02:38

Cannot apply the patch, see below:

wget 'https://issues.asterisk.org/file_download.php?file_id=29408&type=bug' [^] -O - | patch -p0
--2011-05-13 08:50:10-- https://issues.asterisk.org/file_download.php?file_id=29408&type=bug [^]
Resolving issues.asterisk.org... 76.164.171.231, 2001:470:e0d4::e7
Connecting to issues.asterisk.org|76.164.171.231|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 543 [text/plain]
Saving to: `STDOUT'

100%[==============================================================================================================================>] 543 --.-K/s in 0s

2011-05-13 08:50:13 (19.7 MB/s) - written to stdout [543/543]

patching file asterisk-1.8.4/channels/chan_sip.c
Hunk #1 FAILED at 2728.
1 out of 1 hunk FAILED -- saving rejects to file asterisk-1.8.4/channels/chan_sip.c.rej

By: Freddi Hansen (freddi_fonet) 2011-05-13 10:38:55

Looks like we have the exact same issue with latest 1.6.2 eventhough this is listed under 1.8.3.3

By: Sean Bright (seanbright) 2011-05-13 11:07:05

vois: try the new patch (10-tcptls-unreachable-peer-segfault-1.8.4.patch) that I attached.  It's the same except for it should apply cleanly.

Whoever ends up committing this, make sure Chainsaw is credited for the patch and not me.

By: Harpreet (vois) 2011-05-13 11:13:55

i am able to apply the new patch. Will provide feed back after testing it.



By: Harpreet (vois) 2011-05-16 06:36:24

Asterisk hanged after applying the patch, i was unable to stop the asterisk from CLI, i had to kill the pid of asterisk. I have attached core show locks and backtrace-thread. I saw following messages continuously running while this:

[May 16 05:28:02] ERROR[7447]: tcptls.c:378 ast_tcptls_client_start: Unable to connect SIP socket to ip:port: Connection refused
[May 16 05:28:02] ERROR[6979]: chan_sip.c:2723 _sip_tcp_helper_thread: Unknown tcptls thread alert '1579792892'
[May 16 05:28:02] WARNING[20856]: chan_sip.c:3256 __sip_xmit: sip_xmit of 0x7fa1005c1de0 (len 616) to ip:port returned -2: Success
[May 16 05:28:02] ERROR[7451]: tcptls.c:378 ast_tcptls_client_start: Unable to connect SIP socket to ip:port: Connection refused
[May 16 05:28:02] ERROR[7452]: tcptls.c:378 ast_tcptls_client_start: Unable to connect SIP socket to ip:port:9403: Connection refused
[May 16 05:28:02] ERROR[7462]: tcptls.c:378 ast_tcptls_client_start: Unable to connect SIP socket to ip:port: Connection refused
[May 16 05:28:02] ERROR[7463]: tcptls.c:378 ast_tcptls_client_start: Unable to connect SIP socket to ip:port: Connection refused
[May 16 05:28:02] WARNING[6468]: chan_sip.c:2714 _sip_tcp_helper_thread: Failure to write to tcp/tls socket
[May 16 05:28:02] WARNING[20856]: chan_sip.c:3256 __sip_xmit: sip_xmit of 0x7fa1006e63f0 (len 616) to ip:port: returned -2: Success
[May 16 05:28:02] WARNING[20856]: chan_sip.c:3256 __sip_xmit: sip_xmit of 0x7fa1006e63f0 (len 618) to ip:port: returned -2: Success
[May 16 05:28:02] ERROR[7470]: tcptls.c:378 ast_tcptls_client_start: Unable to connect SIP socket to ip:port: Connection refused



By: Tony Vroon (chainsaw) 2011-05-16 07:21:23

vois, please test 1.8.5-rc1 later today; this patch is getting merged (as per leifmadsen). I believe you are hitting a different bug now that TCP/TLS no longer explodes instantly.

By: Digium Subversion (svnbot) 2011-05-16 10:51:55

Repository: asterisk
Revision: 319141

U   branches/1.6.2/channels/chan_sip.c

------------------------------------------------------------------------
r319141 | mnicholson | 2011-05-16 10:51:54 -0500 (Mon, 16 May 2011) | 9 lines

Make sure tcptls_session exists before dereferencing it.

(closes issue ASTERISK-17761)
Reported by: stknob
Patches:
     10-tcptls-unreachable-peer-segfault.patch uploaded by Chainsaw (license 723)
Tested by: vois, Chainsaw


------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=319141

By: Digium Subversion (svnbot) 2011-05-16 10:53:28

Repository: asterisk
Revision: 319142

U   branches/1.8/channels/chan_sip.c

------------------------------------------------------------------------
r319142 | mnicholson | 2011-05-16 10:53:27 -0500 (Mon, 16 May 2011) | 8 lines

Make sure tcptls_session exists before dereferencing it.

(closes issue ASTERISK-17761)
Reported by: stknob
Patches:
     10-tcptls-unreachable-peer-segfault.patch uploaded by Chainsaw (license 723)
Tested by: vois, Chainsaw

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=319142

By: Digium Subversion (svnbot) 2011-05-16 10:54:54

Repository: asterisk
Revision: 319143

_U  trunk/
U   trunk/channels/chan_sip.c

------------------------------------------------------------------------
r319143 | mnicholson | 2011-05-16 10:54:54 -0500 (Mon, 16 May 2011) | 15 lines

Merged revisions 319142 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8

........
 r319142 | mnicholson | 2011-05-16 10:53:26 -0500 (Mon, 16 May 2011) | 8 lines
 
 Make sure tcptls_session exists before dereferencing it.
 
 (closes issue ASTERISK-17761)
 Reported by: stknob
 Patches:
       10-tcptls-unreachable-peer-segfault.patch uploaded by Chainsaw (license 723)
 Tested by: vois, Chainsaw
........

------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=319143

By: Digium Subversion (svnbot) 2011-05-20 13:19:52

Repository: asterisk
Revision: 320171

U   tags/1.8.4.1/channels/chan_sip.c

------------------------------------------------------------------------
r320171 | lmadsen | 2011-05-20 13:19:52 -0500 (Fri, 20 May 2011) | 1 line

Merge changes per issue ASTERISK-17761.
------------------------------------------------------------------------

http://svn.digium.com/view/asterisk?view=rev&revision=320171