open5gs/lib/core
Sukchan Lee 3f0979dab2 [MME] Fixes crash in building s1ap message
Because a race condition can occur between S6A Diameter and S1AP message,
the following error handling code has been added.

1. InitialUEMessage + Attach Request + PDN Connectivity request
2. Authentication-Information-Request/Authentication-Information-Answer
3. Authentication Request/Response
4. Security-mode command/complete
5. Update-Location-Request/Update-Location-Answer
6. Detach request/accept

In the ULR/ULA process in step 6, the PDN Connectivity request is
pushed to the queue as an ESM_MESSAGE because the NAS-Type is still
an Attach Request.

See the code below in 'mme-s6a-handler.c' for where the queue is pushed.

  if (mme_ue->nas_eps.type == MME_EPS_TYPE_ATTACH_REQUEST) {
      rv = nas_eps_send_emm_to_esm(mme_ue,
              &mme_ue->pdn_connectivity_request);
      if (rv != OGS_OK) {
          ogs_error("nas_eps_send_emm_to_esm() failed");
          return OGS_NAS_EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED;
      }
  } else if (mme_ue->nas_eps.type == MME_EPS_TYPE_TAU_REQUEST) {
      r = nas_eps_send_tau_accept(mme_ue,
              S1AP_ProcedureCode_id_InitialContextSetup);
      ogs_expect(r == OGS_OK);
      ogs_assert(r != OGS_ERROR);
  } else {
      ogs_error("Invalid Type[%d]", mme_ue->nas_eps.type);
      return OGS_NAS_EMM_CAUSE_PROTOCOL_ERROR_UNSPECIFIED;
  }

If you perform step 7 Detach request/accept here,
the NAS-Type becomes Detach Request and the EMM state changes
to emm_state_de_registered().

Since the PDN, which is an ESM message that was previously queued,
should not be processed in de_registered, the message is ignored
through error handling below.

Otherwise, MME will crash because there is no active bearer
in the initial_context_setup_request build process.

See the code below in 's1ap-build.c' for where the crash occurs.
  ogs_list_for_each(&mme_ue->sess_list, sess) {
      ogs_list_for_each(&sess->bearer_list, bearer) {
          ...
          if (mme_ue->nas_eps.type == MME_EPS_TYPE_ATTACH_REQUEST) {
          } else if (OGS_FSM_CHECK(&bearer->sm, esm_state_inactive)) {
              ogs_warn("No active EPS bearer [%d]", bearer->ebi);
              ogs_warn("    IMSI[%s] NAS-EPS Type[%d] "
                      "ENB_UE_S1AP_ID[%d] MME_UE_S1AP_ID[%d]",
                      mme_ue->imsi_bcd, mme_ue->nas_eps.type,
                      enb_ue->enb_ue_s1ap_id, enb_ue->mme_ue_s1ap_id);
              continue;
          }
          ...
      }
  }
2024-02-02 21:17:41 +09:00
..
abts.c Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
abts.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
arc4random.c Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
meson.build Introduced Subscription identifier de-concealing 2022-12-24 20:22:45 +09:00
ogs-abort.c Add exception handling for #568 2020-09-18 19:39:02 -04:00
ogs-abort.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-compat.h test: Porting FreeBSD 2021-02-08 14:25:40 -05:00
ogs-conv.c ogs-conv.{c,h}: Constify several parameters 2024-01-03 07:10:09 +09:00
ogs-conv.h ogs-conv.{c,h}: Constify several parameters 2024-01-03 07:10:09 +09:00
ogs-core.c [PFCP/GTP] SEID/TEID Randomness (#1303) 2023-04-16 12:30:36 +09:00
ogs-core.h Introduced Subscription identifier de-concealing 2022-12-24 20:22:45 +09:00
ogs-env.c Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-env.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-epoll.c [MME] Fixes crash in building s1ap message 2024-02-02 21:17:41 +09:00
ogs-errno.c [ALL] Removing trailing whitespace and tab 2022-09-02 23:38:39 +09:00
ogs-errno.h [AMF/MME] Fixed crash when no NG/S1 context(#2012) 2023-01-23 10:37:22 +09:00
ogs-file.c Introduced Subscription identifier de-concealing 2022-12-24 20:22:45 +09:00
ogs-file.h Introduced Subscription identifier de-concealing 2022-12-24 20:22:45 +09:00
ogs-fsm.c Move src/../nf-sm.[ch] to lib/sbi/nf-sm.[ch] 2022-08-12 14:03:53 +09:00
ogs-fsm.h Move src/../nf-sm.[ch] to lib/sbi/nf-sm.[ch] 2022-08-12 14:03:53 +09:00
ogs-getopt.c License update 2020-11-12 20:58:08 -05:00
ogs-getopt.h License update 2020-11-12 20:58:08 -05:00
ogs-hash.c Fixed MacOSX compile error 2023-04-04 21:53:39 +09:00
ogs-hash.h [5GC/EPC] tested with concurrent 500 UEs (#949) 2021-04-29 22:01:34 +09:00
ogs-kqueue.c [ALL] Removing trailing whitespace and tab 2022-09-02 23:38:39 +09:00
ogs-list.h [MME] Hangs on an invalid S1AP message 2024-01-17 20:17:55 +09:00
ogs-log.c Release v2.0.0 2020-08-21 23:33:45 -04:00
ogs-log.h [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-macros.h [CORE] Increase SDU buffer to 32k (#2008) 2023-01-24 21:43:20 +09:00
ogs-memory.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-memory.h [PFCP/GTP] SEID/TEID Randomness (#1303) 2023-04-16 12:30:36 +09:00
ogs-misc.c License update 2020-11-12 20:58:08 -05:00
ogs-misc.h License update 2020-11-12 20:58:08 -05:00
ogs-notify.c Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-notify.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-pkbuf.c [PFCP/GTP] SEID/TEID Randomness (#1303) 2023-04-16 12:30:36 +09:00
ogs-pkbuf.h [core] Fix a couple of warnings when using C++ compiler or more strict settings 2024-01-09 17:50:22 +09:00
ogs-poll-private.h Change Number of UEs usage [#533] 2020-08-25 23:05:01 -04:00
ogs-poll.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-poll.h [5GC/EPC] tested with concurrent 500 UEs (#949) 2021-04-29 22:01:34 +09:00
ogs-pool.h [AMF/MME] Fixed M-TMSI pool release (#2307) 2024-01-21 11:58:43 +09:00
ogs-process.c License update 2020-11-12 20:58:08 -05:00
ogs-process.h [ALL] Fix differences in function parameter names between definition and declaration 2022-07-01 21:38:47 +09:00
ogs-queue.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-queue.h License update 2020-11-12 20:58:08 -05:00
ogs-rand.c [ALL] Removing trailing whitespace and tab 2022-09-02 23:38:39 +09:00
ogs-rand.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-rbtree.c Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-rbtree.h [core] Fix a couple of warnings when using C++ compiler or more strict settings 2024-01-09 17:50:22 +09:00
ogs-select.c Update ogs_pollset library 2020-11-09 22:57:14 -05:00
ogs-signal.c [ALL] Removing trailing whitespace and tab 2022-09-02 23:38:39 +09:00
ogs-signal.h License update 2020-11-12 20:58:08 -05:00
ogs-sockaddr.c [MME] Constify params in mme-context and depending APIs 2024-01-06 07:42:32 +09:00
ogs-sockaddr.h [MME] Constify params in mme-context and depending APIs 2024-01-06 07:42:32 +09:00
ogs-socket.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-socket.h Improve the socket option configuration (#1404) 2022-03-15 22:03:50 +09:00
ogs-socknode.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-socknode.h Improve the socket option configuration (#1404) 2022-03-15 22:03:50 +09:00
ogs-sockopt.c Change EPERM to OGS_EPERM (#1436,#1404) 2022-03-16 20:32:19 +09:00
ogs-sockopt.h Move src/../nf-sm.[ch] to lib/sbi/nf-sm.[ch] 2022-08-12 14:03:53 +09:00
ogs-sockpair.c Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-sockpair.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-strings.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-strings.h [PFCP/GTP] SEID/TEID Randomness (#1303) 2023-04-16 12:30:36 +09:00
ogs-tcp.c Improve the socket option configuration (#1404) 2022-03-15 22:03:50 +09:00
ogs-tcp.h Improve the socket option configuration (#1404) 2022-03-15 22:03:50 +09:00
ogs-thread.c [LOG] remove ogs_expect_or_return()/return_val() 2023-01-24 00:01:36 +09:00
ogs-thread.h Rename Project to Open5GS 2019-10-27 17:41:14 +09:00
ogs-time.c Follow-up on #1770 2022-09-25 16:42:46 +09:00
ogs-time.h [CORE] time: Add APIs to manage NTP 32-bit timestamps (#1439) 2022-03-16 11:25:30 +09:00
ogs-timer.c [MME] Crash due to a race condition 2024-01-25 23:27:34 +09:00
ogs-timer.h [AMF/MME] Remove code that doesn't work (#2013) 2023-07-23 14:54:06 +09:00
ogs-tlv-msg.c [GTP] gtp_message_fuzz: Abrt in ogs_abort 2023-08-24 22:19:42 +09:00
ogs-tlv-msg.h Changes MAX TLV MORE to 16 2022-06-29 14:35:01 +09:00
ogs-tlv.c A minor typo fix (#2707) 2023-10-28 22:11:58 +09:00
ogs-tlv.h Introduce Gn interface (GTPv1C) Support to PGW (#1351) 2022-02-18 22:23:45 +09:00
ogs-udp.c Improve the socket option configuration (#1404) 2022-03-15 22:03:50 +09:00
ogs-udp.h Improve the socket option configuration (#1404) 2022-03-15 22:03:50 +09:00
ogs-uuid.c Follow-up on #1770 2022-09-25 16:42:46 +09:00
ogs-uuid.h License update 2020-11-12 20:58:08 -05:00