<p>Friendly Automation <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13505">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Frederic LE FOLL: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">sig_pri:  Fix deadlock caused by sig_pri_queue_hangup<br><br>The change to add setting hangupsource to sig_pri_queue_hangup()<br>made in https://gerrit.asterisk.org/c/asterisk/+/12857 casued<br>deadlocks when a hangup request was received from the core at the<br>same time a hanguprequest was received from the remote end via the<br>D channel.<br><br>Although the PRI's channel private structure was being unlocked<br>before setting the hangupsource, the PRI's own lock was still being<br>held during the process.  If channel actions were also coming from<br>the core, a deadlock on the PRI could result.  This deadlock could<br>then escalate to the entire DAHDI subsystem via DAHDI's global<br>interface list lock, especially if someone used the PRI CLI commands.<br><br>Fix:<br><br>* We now unlock the PRI as well as the PRI's channel private<br>  structure before setting the hangupsource, then relock both<br>  afterwards.<br><br>ASTERISK-28605<br>Reported by: Dirk Wendland<br><br>Change-Id: Id74aaa5d4e3746063dbe9deed188eb65193cb9c9<br>---<br>M channels/sig_pri.c<br>1 file changed, 7 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/sig_pri.c b/channels/sig_pri.c</span><br><span>index 90dc051..3fda34a 100644</span><br><span>--- a/channels/sig_pri.c</span><br><span>+++ b/channels/sig_pri.c</span><br><span>@@ -1387,6 +1387,10 @@</span><br><span>  * \note Assumes the pri->lock is already obtained.</span><br><span>  * \note Assumes the sig_pri_lock_private(pri->pvts[chanpos]) is already obtained.</span><br><span>  *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note The unlocking/locking sequence now present has been stress tested</span><br><span style="color: hsl(120, 100%, 40%);">+ *       without deadlocks.  Please don't change it without consulting</span><br><span style="color: hsl(120, 100%, 40%);">+ *       core development team members.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span>  * \return Nothing</span><br><span>  */</span><br><span> static void sig_pri_queue_hangup(struct sig_pri_span *pri, int chanpos)</span><br><span>@@ -1404,9 +1408,11 @@</span><br><span>              ast_queue_hangup(owner);</span><br><span>             ast_channel_unlock(owner);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-          /* Tell the CDR this DAHDI channel hung up */</span><br><span>                sig_pri_unlock_private(pri->pvts[chanpos]);</span><br><span style="color: hsl(120, 100%, 40%);">+                ast_mutex_unlock(&pri->lock);</span><br><span style="color: hsl(120, 100%, 40%);">+          /* Tell the CDR this DAHDI channel hung up */</span><br><span>                ast_set_hangupsource(owner, ast_channel_name(owner), 0);</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_mutex_lock(&pri->lock);</span><br><span>           sig_pri_lock_private(pri->pvts[chanpos]);</span><br><span> </span><br><span>             ao2_ref(owner, -1);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13505">change 13505</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/13505"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Id74aaa5d4e3746063dbe9deed188eb65193cb9c9 </div>
<div style="display:none"> Gerrit-Change-Number: 13505 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Frederic LE FOLL <frederic.lefoll@c-s.fr> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>