<p>Neels Hofmeyr has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/13152">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">use only accepted ran_conns for new transactions<br><br>In connection_for_subscriber(), do not return a ran_conn that is not yet<br>authenticated nor one that is already in release.<br><br>Using a ran_conn that is not yet authenticated may cause an auth/ciph<br>violation.<br><br>Using a ran_conn that is already in release may cause a use-after-free, see<br>OS#3842 for a description.<br><br>To be paranoid, upon releasing a conn, go through the transaction freeing<br>motions again by calling trans_conn_closed(), just in case some odd code path<br>added another transaction while the conn was already in release.<br><br>Related: OS#3842<br>Change-Id: Id957032e0ae1ff8ba055a75c3523447d3d06cbc3<br>---<br>M src/libmsc/gsm_subscriber.c<br>M src/libmsc/ran_conn.c<br>2 files changed, 11 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/52/13152/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/libmsc/gsm_subscriber.c b/src/libmsc/gsm_subscriber.c</span><br><span>index e60344f..c4faa94 100644</span><br><span>--- a/src/libmsc/gsm_subscriber.c</span><br><span>+++ b/src/libmsc/gsm_subscriber.c</span><br><span>@@ -200,8 +200,14 @@</span><br><span>  struct ran_conn *conn;</span><br><span> </span><br><span>   llist_for_each_entry(conn, &net->ran_conns, entry) {</span><br><span style="color: hsl(0, 100%, 40%);">-             if (conn->vsub == vsub)</span><br><span style="color: hsl(0, 100%, 40%);">-                      return conn;</span><br><span style="color: hsl(120, 100%, 40%);">+          if (conn->vsub != vsub)</span><br><span style="color: hsl(120, 100%, 40%);">+                    continue;</span><br><span style="color: hsl(120, 100%, 40%);">+             /* Found a conn, but is it in a usable state? Must not add transactions to a conn that is in release,</span><br><span style="color: hsl(120, 100%, 40%);">+          * and must not start transactions for an unauthenticated subscriber. There will obviously be only one</span><br><span style="color: hsl(120, 100%, 40%);">+                 * conn for this vsub, so return NULL right away. */</span><br><span style="color: hsl(120, 100%, 40%);">+          if (!ran_conn_is_accepted(conn))</span><br><span style="color: hsl(120, 100%, 40%);">+                      return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+          return conn;</span><br><span>         }</span><br><span> </span><br><span>        return NULL;</span><br><span>diff --git a/src/libmsc/ran_conn.c b/src/libmsc/ran_conn.c</span><br><span>index 79709c6..e54e542 100644</span><br><span>--- a/src/libmsc/ran_conn.c</span><br><span>+++ b/src/libmsc/ran_conn.c</span><br><span>@@ -538,8 +538,10 @@</span><br><span> {</span><br><span>    struct ran_conn *conn = fi->priv;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-        if (ran_conn_fsm_has_active_transactions(fi))</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ran_conn_fsm_has_active_transactions(fi)) {</span><br><span>              LOGPFSML(fi, LOGL_ERROR, "Deallocating despite active transactions\n");</span><br><span style="color: hsl(120, 100%, 40%);">+             trans_conn_closed(conn);</span><br><span style="color: hsl(120, 100%, 40%);">+      }</span><br><span> </span><br><span>        if (!conn) {</span><br><span>                 LOGP(DRLL, LOGL_ERROR, "Freeing NULL RAN connection\n");</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/13152">change 13152</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.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.osmocom.org/13152"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-msc </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Id957032e0ae1ff8ba055a75c3523447d3d06cbc3 </div>
<div style="display:none"> Gerrit-Change-Number: 13152 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Neels Hofmeyr <nhofmeyr@sysmocom.de> </div>