[Home]

Summary:ASTERISK-29227: res_pjsip_diversion: sending multiple 181 responses causes memory corruption and crash
Reporter:Ivan Poddubny (ipoddubny)Labels:patch security
Date Opened:2020-12-28 07:03:32.000-0600Date Closed:2021-02-18 10:37:02.000-0600
Priority:BlockerRegression?No
Status:Closed/CompleteComponents:pjproject/pjsip
Versions:13.38.0 13.38.1 16.15.0 16.15.1 17.9.0 17.9.1 18.1.0 18.1.1 Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) 0001-res_pjsip_diversion-Fix-adding-more-than-one-histinf.patch
Description:Every time Asterisk/chan_pjsip transmits a "181 Call is being forwarded" packet, res_pjsip_diversion adds a "histinfo" element to Supported header. It doesn't check if "histinfo" has already been added, nor it performs a bounds check, thus making it possible to overwrite/corrupt memory past the PJSIP_GENERIC_ARRAY_MAX_COUNT elements that pjsip_supported_hdr can contain.

h4. How to reproduce

Make a call from a pjsip endpoint to this diaplan:
{quote}
exten => 181,1,NoOp
same => n,Set(i=9000)
same => n,While($[ $\{DEC\(i)} != 0])
same => n,Set(REDIRECTING(from-num)=$\{i})
same => n,EndWhile
{quote}


h4. How to crash Asterisk remotely

Use Dial application on an unanswered incoming PJSIP channel to connect to a channel indicating AST_CONTROL_REDIRECTING more than PJSIP_GENERIC_ARRAY_MAX_COUNT times (32 by default).
Example:
*  2 PJSIP endpoints \[alice] and \[bob]
*   PJSIP/alice-00000001 executes Dial(PJSIP/bob)
*   PJSIP/bob-00000002 sends an INVITE to bob
*   bob sends 100 Trying, followed by repeating "181 Call Is Being Forwarded"
*   Asterisk transmits 181 Call Is Being Forwarded to alice, adding one more "histinfo" element to Supported, eventually overwriting memory past array boundary until Asterisk crashes.
Comments:By: Asterisk Team (asteriskteam) 2020-12-28 07:03:34.641-0600

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. Please note that log messages and other files should not be sent to the Sangoma Asterisk Team unless explicitly asked for. All files should be placed on this issue in a sanitized fashion as needed.

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.

Please note that by submitting data, code, or documentation to Sangoma through JIRA, you accept the Terms of Use present at [https://www.asterisk.org/terms-of-use/|https://www.asterisk.org/terms-of-use/].

By: Asterisk Team (asteriskteam) 2020-12-28 07:03:38.547-0600

This issue has been automatically restricted and set to a blocker due to being a security type issue. If this is not a security vulnerability issue it will be moved to the appropriate issue type when triaged.

Please DO NOT put a code review up for this change at this time. Attach any applicable patches to this issue.

By: Ivan Poddubny (ipoddubny) 2020-12-28 07:09:01.417-0600

I'm sorry for opening duplicates ASTERISK-29225 and ASTERISK-29226. Please, close them.
JIRA displayed an error message about formatting but nevertheless it created the issues.

By: George Joseph (gjoseph) 2020-12-29 09:51:28.167-0600

We took care of the dups and I've created private gerrit reviews for your patch (which you probably can't see).  I also applied your fix to res_pjsip_path and res_pjsip_outbound_registration since they also add values to the Supported header.  We're still discussing a security release schedule so please don't discuss the issue publically for now.

Thanks for finding this!




By: Friendly Automation (friendly-automation) 2021-02-18 10:37:03.178-0600

Change 15452 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:05.423-0600

Change 15464 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:07.872-0600

Change 15465 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:10.812-0600

Change 15450 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:13.020-0600

Change 15466 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:15.803-0600

Change 15463 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:19.882-0600

Change 15454 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:22.290-0600

Change 15453 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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

By: Friendly Automation (friendly-automation) 2021-02-18 10:37:24.827-0600

Change 15451 merged by George Joseph:
res_pjsip_diversion: Fix adding more than one histinfo to Supported

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