<p>Harald Welte <strong>merged</strong> this change.</p><p><a href="https://gerrit.osmocom.org/9935">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Disarm T3395 when dettaching mmctx from pdpctx<br><br>In sgsn_pdp_ctx_terminate, a pdp ctx is terminated and the mm ctx is<br>detached. However, T3395 may still be armed and then pdpctx_timer_cb<br>will trigger, and attempt to use the pdp->mm ctx which was already<br>detached (set to NULL) when calling<br>gsm48_tx_gsm_deact_pdp_req()->mmctx2msgid().<br><br>Following list of log lines shows the scenario+crash, in which osmo-sgsn<br>is trying to deactivate the ctx all the time but the PCU doesn't ACK it,<br>and then at some point the PDP context is forced released.<br><br>osmo-sgsn/src/gprs/gprs_gmm.c:2294 MM(901700000015254/d7e9ab95) <- DEACTIVATE PDP CONTEXT REQ<br>osmo-sgsn/src/gprs/gprs_gmm.c:1464 MM(901700000015254/d7e9ab95) -> GMM DETACH REQUEST TLLI=0xd7e9ab95 type=GPRS detach Power-off<br>osmo-sgsn/src/gprs/gprs_gmm.c:313 MM(901700000015254/d7e9ab95) Cleaning MM context due to GPRS DETACH REQUEST<br>osmo-sgsn/src/gprs/gprs_sgsn.c:332 MM(901700000015254/d7e9ab95) Dropping PDP context for NSAPI=5<br>osmo-sgsn/src/gprs/gprs_sgsn.c:434 PDP(901700000015254/0) Forcing release of PDP context<br>osmo-sgsn/src/gprs/gprs_sndcp.c:508 SNSM-DEACTIVATE.ind (lle=0x62100001bca0, TLLI=d7e9ab95, SAPI=3, NSAPI=5)<br>osmo-sgsn/src/gprs/sgsn_libgtp.c:310 PDP(---/0) Delete PDP Context<br>osmo-sgsn/src/gprs/gprs_gmm.c:2294 MM(---/ffffffff) <- DEACTIVATE PDP CONTEXT REQ<br>osmo-sgsn/src/gprs/gprs_gmm.c:305:25: runtime error: member access within null pointer of type 'const struct sgsn_mm_ctx'<br><br>Program received signal SIGSEGV, Segmentation fault.<br>0x0000555555698c1b in mmctx2msgid (msg=0x61d0000172e0, mm=0x0)<br>    at /home/pespin/dev/sysmocom/git/osmo-sgsn/src/gprs/gprs_gmm.c:305<br>305             msgb_tlli(msg) = mm->gb.tlli;<br>(gdb) bt<br> #0  0x0000555555698c1b in mmctx2msgid (msg=0x61d0000172e0, mm=0x0)<br>    at osmo-sgsn/src/gprs/gprs_gmm.c:305<br> #1  0x00005555556b170a in _gsm48_tx_gsm_deact_pdp_req (mm=0x0, tid=0 '\000',<br>    sm_cause=38 '&')<br>    at osmo-sgsn/src/gprs/gprs_gmm.c:2297<br> #2  0x00005555556b1a2e in gsm48_tx_gsm_deact_pdp_req (pdp=0x6140000008a0,<br>    sm_cause=38 '&')<br>    at osmo-sgsn/src/gprs/gprs_gmm.c:2311<br> #3  0x00005555556b876c in pdpctx_timer_cb (_pdp=0x6140000008a0)<br>    at osmo-sgsn/src/gprs/gprs_gmm.c:2717<br> #4  0x00007ffff355eb3e in osmo_timers_update ()<br>    at libosmocore/src/timer.c:257<br> #5  0x00007ffff356255c in osmo_select_main (polling=0)<br>    at libosmocore/src/select.c:254<br> #6  0x00005555556f17cb in main (argc=3, argv=0x7fffffffe298)<br>    at osmo-sgsn/src/gprs/sgsn_main.c:531<br><br>Change-Id: I2120e53ade6cabad37f9bd99e6680a453411821b<br>---<br>M include/osmocom/sgsn/gprs_gmm.h<br>M src/gprs/gprs_gmm.c<br>M src/gprs/gprs_sgsn.c<br>3 files changed, 13 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/sgsn/gprs_gmm.h b/include/osmocom/sgsn/gprs_gmm.h</span><br><span>index 3c93efc..28c96ce 100644</span><br><span>--- a/include/osmocom/sgsn/gprs_gmm.h</span><br><span>+++ b/include/osmocom/sgsn/gprs_gmm.h</span><br><span>@@ -43,4 +43,6 @@</span><br><span> /* TODO: move extract_subscr_* when gsm48_gmm_authorize() got removed */</span><br><span> void extract_subscr_msisdn(struct sgsn_mm_ctx *ctx);</span><br><span> void extract_subscr_hlr(struct sgsn_mm_ctx *ctx);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+void pdp_ctx_detach_mm_ctx(struct sgsn_pdp_ctx *pdp);</span><br><span> #endif /* _GPRS_GMM_H */</span><br><span>diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c</span><br><span>index 6a5c5d9..9d8a869 100644</span><br><span>--- a/src/gprs/gprs_gmm.c</span><br><span>+++ b/src/gprs/gprs_gmm.c</span><br><span>@@ -2192,6 +2192,16 @@</span><br><span>    osmo_timer_del(&pdp->timer);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+void pdp_ctx_detach_mm_ctx(struct sgsn_pdp_ctx *pdp)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Detach from MM context */</span><br><span style="color: hsl(120, 100%, 40%);">+  llist_del(&pdp->list);</span><br><span style="color: hsl(120, 100%, 40%);">+ pdp->mm = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  /* stop timer 3395 */</span><br><span style="color: hsl(120, 100%, 40%);">+ pdpctx_timer_stop(pdp, 3395);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #if 0</span><br><span> static void msgb_put_pdp_addr_ipv4(struct msgb *msg, uint32_t ipaddr)</span><br><span> {</span><br><span>diff --git a/src/gprs/gprs_sgsn.c b/src/gprs/gprs_sgsn.c</span><br><span>index 55ce096..ab5e79a 100644</span><br><span>--- a/src/gprs/gprs_sgsn.c</span><br><span>+++ b/src/gprs/gprs_sgsn.c</span><br><span>@@ -443,9 +443,7 @@</span><br><span>         osmo_signal_dispatch(SS_SGSN, S_SGSN_PDP_TERMINATE, &sig_data);</span><br><span> </span><br><span>      /* Detach from MM context */</span><br><span style="color: hsl(0, 100%, 40%);">-    llist_del(&pdp->list);</span><br><span style="color: hsl(0, 100%, 40%);">-   pdp->mm = NULL;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+    pdp_ctx_detach_mm_ctx(pdp);</span><br><span>  sgsn_delete_pdp_ctx(pdp);</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/9935">change 9935</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/9935"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-sgsn </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I2120e53ade6cabad37f9bd99e6680a453411821b </div>
<div style="display:none"> Gerrit-Change-Number: 9935 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Pau Espin Pedrol <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Harald Welte <laforge@gnumonks.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>