[Home]

Summary:ASTERISK-28463: res_pjsip_path: Crash when invalid contact is configured
Reporter:Juan Martin (jmartin)Labels:pjsip
Date Opened:2019-06-27 06:12:24Date Closed:2019-09-26 04:48:20
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Resources/res_pjsip_path
Versions:13.27.0 16.4.0 Frequency of
Occurrence
Constant
Related
Issues:
is duplicated byASTERISK-28547 PJSIP AOR configuration "contact=sip:" crash
Environment:Debian Stretch 9.9 (Intel x86_64)Attachments:( 0) backtrace_16.2.1.7z
( 1) backtrace_16.4.0.7z
( 2) bt.txt
( 3) core-brief.txt
( 4) core-full.txt
( 5) core-locks.txt
( 6) core-thread1.txt
( 7) pjsip_endpoints.conf
Description:Hi,

I discovered that if you put a bad contact in the aor configuration, it crashes asterisk when the phone is registered, concretelly with  segmentation fault (SIGSEGV).

I tested it with 16.2.1 and it's also reproducible with 16.4.0.

h5. Example:

\[200]
type=aor
max_contacts=1
{{contact=sip:200@*:5060}}
qualify_frequency=60

h6. If the phone is not connected it causes some errors but asterisk continue working:

{{\[2019-06-27 12:08:48.462] ERROR\[20447]: res_pjsip.c:3859 create_out_of_dialog_request: Unable to create outbound OPTIONS request to endpoint 200 as URI 'sip:200@*:5060' is not valid}}
{{\[2019-06-27 12:08:48.462] ERROR\[20447]: res_pjsip/pjsip_options.c:877 sip_options_qualify_contact: Unable to create request to qualify contact sip:200@*:5060 on AOR 200}}

h6. Then, as soon as the phone registers in asterisk it crashes the main process:

{{CLI>     -- Added contact 'sip:200@192.168.75.102:5060' to AOR '200' with expiration of 3600 seconds}}
{{Segmentation fault (`core' generated)}}

h6. In syslog:

{{Jun 26 13:48:43 desarrolloV3 kernel: asterisk\[2285]: segfault at 0 ip 00007fa597ec11f8 sp 00007fa592c1eb30 error 4 in res_pjsip_path.so\[7fa597ec0000+3000]}}
{{Jun 26 13:48:43 desarrolloV3 kernel: Code: 8d 64 24 c8 48 8b 07 48 c7 45 c8 00 00 00 00 48 85 c0 74 05 80 38 00 75 11 48 8d 65 d8 31 c0 5b 41 5c 41 5d 41 5e 41 5f 5d c3 <48> 8b 06 48 89 fb 48 89 f7 ff 50 08 48 89 45 a8 49 89 c6 48 8b 40}}
{{Jun 26 13:48:43 desarrolloV3 systemd\[1]: asterisk.service: Main process exited, code=killed, status=11/SEGV}}
{{Jun 26 13:48:43 desarrolloV3 systemd\[1]: asterisk.service: Control process exited, code=exited status=1}}

h5. Conclusion

Avoiding the part of why there is a wildcard in the contact instead an IP address (contact=sip:200@*:5060), it's bad, I know. But I think that it should
not crash the entire system a bad line in configuration.

Write access to config files is required to exploit this problem. Severity: low.
Perhaps you could include a filter when parsing the pjsip config files.

If you remove the malformed contact line in the sample config, asterisk works fine.

I'll upload the backtraces to provide more info about the crash.
Comments:By: Asterisk Team (asteriskteam) 2019-06-27 06:12:25.709-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

Please note that once your issue enters an open state it has been accepted. As Asterisk is an open source project there is no guarantee or timeframe on when your issue will be looked into. If you need expedient resolution you will need to find and pay a suitable developer. Asking for an update on your issue will not yield any progress on it and will not result in a response. All updates are posted to the issue when they occur.

By: Juan Martin (jmartin) 2019-06-27 06:16:42.015-0500

Backtraces of the crash and complete endpoint configuration.

By: Joshua C. Colp (jcolp) 2019-06-27 06:32:05.588-0500

In the future please ensure your Asterisk is built[1] such that backtraces are useful in case the provided instructions aren't enough to reproduce the problem. If you take a look at the bt.txt file from mine and your own backtrace, you can see the difference it makes.

[1] https://wiki.asterisk.org/wiki/display/AST/Getting+a+Backtrace#GettingaBacktrace-PreparingAsteriskToProduceCoreFilesOnCrash

By: Juan Martin (jmartin) 2019-06-27 07:13:56.988-0500

Hi Joshua, ok I'll take note about your suggestions for future backtraces I read the page before but due the starting of better backtraces paragraph I thought that it was relative to versions 1.4, 1.6 and 1.8. (I saw a lot of 'No symbol table info available' that took my attention... noted)

Very interesting how you reach the exact line with gdb, after seeing it I was able to reach it.
It could be interesting for developers to put in the getting backtrace help a section showing how to do it because prior to this I only know that the problem was related with res_pjsip_path but no idea where to start looking.

Thanks for your help.

By: Joshua C. Colp (jcolp) 2019-06-27 07:22:20.181-0500

In order to actually analyze a backtrace you have to have knowledge of the code in question and how things work which is why there aren't instructions for going any deeper. Providing a backtrace with symbols is usually enough for a developer to see what is going on, I just went deeper because I had the backtrace at hand.

By: Friendly Automation (friendly-automation) 2019-09-26 04:48:23.966-0500

Change 12954 merged by Friendly Automation:
res_pjsip_registrar: Validate Contact URI before adding to responses

[https://gerrit.asterisk.org/c/asterisk/+/12954|https://gerrit.asterisk.org/c/asterisk/+/12954]

By: Friendly Automation (friendly-automation) 2019-09-26 04:52:27.591-0500

Change 12955 merged by Joshua Colp:
res_pjsip_registrar: Validate Contact URI before adding to responses

[https://gerrit.asterisk.org/c/asterisk/+/12955|https://gerrit.asterisk.org/c/asterisk/+/12955]

By: Friendly Automation (friendly-automation) 2019-09-26 04:53:15.736-0500

Change 12957 merged by Friendly Automation:
res_pjsip_registrar: Validate Contact URI before adding to responses

[https://gerrit.asterisk.org/c/asterisk/+/12957|https://gerrit.asterisk.org/c/asterisk/+/12957]

By: Friendly Automation (friendly-automation) 2019-09-26 07:11:01.286-0500

Change 12956 merged by George Joseph:
res_pjsip_registrar: Validate Contact URI before adding to responses

[https://gerrit.asterisk.org/c/asterisk/+/12956|https://gerrit.asterisk.org/c/asterisk/+/12956]