<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13505">View Change</a></p><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.  This was caused by using the incorrect locking model of<br>which there are 2.  One for core-initiated requests and one for D<br>channel initiated requests.  sig_pri_queue_hangup() is only ever<br>called by the d-channel thread but the core model was being used.<br><br>ast_set_hangupsource() was being called after the channel was being<br>unlocked and even though it does relock the channel itself (twice),<br>the gaps in the locks allowed the core-initiated hangup to get in.<br>However, the locking model for core-initiated and<br>dchannel-initiated requests is inverted with respect to channels<br>(core gets channel first, dchannel gets channel last).  Combined<br>with the fact that both request types also try to get the pri's<br>lock and the pri's private channel structure lock and the fact<br>that sig_pri_queue_hangup() was actually unlocking the pri's private<br>channel structure lock, then relocking it again after calling<br>ast_set_hangupsource(), this results in massive deadlocks that can<br>escalate to the entire DAHDI subsystem via the global DAHDI<br>interface lock.<br><br>The fix is actually easy.  We no longer unlock the pri's private<br>channel structure before calling ast_set_hangupsource() and relock<br>it afterwards, and we also now hold the channel lock until after<br>ast_set_hangupsource() has finished.<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, 1 insertion(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/05/13505/1</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..52fef84 100644</span><br><span>--- a/channels/sig_pri.c</span><br><span>+++ b/channels/sig_pri.c</span><br><span>@@ -1402,13 +1402,11 @@</span><br><span>       if (owner) {</span><br><span>                 ao2_ref(owner, +1);</span><br><span>          ast_queue_hangup(owner);</span><br><span style="color: hsl(0, 100%, 40%);">-                ast_channel_unlock(owner);</span><br><span> </span><br><span>               /* Tell the CDR this DAHDI channel hung up */</span><br><span style="color: hsl(0, 100%, 40%);">-           sig_pri_unlock_private(pri->pvts[chanpos]);</span><br><span>               ast_set_hangupsource(owner, ast_channel_name(owner), 0);</span><br><span style="color: hsl(0, 100%, 40%);">-                sig_pri_lock_private(pri->pvts[chanpos]);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+              ast_channel_unlock(owner);</span><br><span>           ao2_ref(owner, -1);</span><br><span>  }</span><br><span> }</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: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>