Commit Graph

2293 Commits

Author SHA1 Message Date
Sukchan Lee 94bd68aa7b [MME] Follow-up on #2916
When there is no MME-UE Context, going to cleanup without setting
s6a_message could cause a segmentation fault.

We fixed the problem by moving the location of setting s6a_message
to before cleanup.
2024-02-08 18:46:45 +09:00
Sukchan Lee 82398811db [UPF] Report after Session was Deleted (#2936)
The UPF is sending Session Report Request after the Session was Deleted,
when the Gy interface is active.

UPF is sending PFCP session report request after the session has been deleted
when the Gy interface is active. This is because some of the timers related to
the report are not deleted when the session is deleted.

We have fixed it to delete all the timers in the session
when the SESSION is deleted.
2024-02-04 09:32:33 +09:00
Sukchan Lee 8762425fbc [AMF] Fixed sm_context_ref failed (#2603, #2917) 2024-02-03 16:59:47 +09:00
Sukchan Lee 7e8f145973 Rollback Pull Request (#1911)
Problems with Purge-UE-Request/Answer can occur in the following situations

1. Attach Request
2. Authentication request
3. Authentication reject
4. UEContextReleaseCommand
5. UEContextReleaseComplete
6. Purge-UE-Request
7. Attach Request
8. Purge-UE-Answer
9. (UE Context Remove)

To resolve this issue, we have changed to delete the UE-Context
via mme_ue_remove() immediately upon receiving UEContextReleaseComplete()
without calling mme_s6a_send_pur().
2024-02-03 16:18:26 +09:00
Sukchan Lee d1d3ec6fcb [SEC] Several vulnerabilities have been resolved.
1. Reachable assertion in ogs_nas_5gmm_decode

Location: lib/nas/5gs/decoder.c:4445

```c
int ogs_nas_5gmm_decode(ogs_nas_5gs_message_t *message, ogs_pkbuf_t *pkbuf)
{
    int size = 0;
    int decoded = 0;

    ogs_assert(pkbuf);
    ogs_assert(pkbuf->data);
    ogs_assert(pkbuf->len);
```

When a NAS payload is received over `src/amf/context.c:1675`NGAP that has no data, the ogs_assert(pkbuf->len) assertion will be triggered.

2.Reachable assertion in ogs_nas_emm_decode

```
int ogs_nas_emm_decode(ogs_nas_eps_message_t *message, ogs_pkbuf_t *pkbuf)
{
    int size = 0;
    int decoded = 0;

    ogs_assert(pkbuf);
    ogs_assert(pkbuf->data);
    ogs_assert(pkbuf->len);
```

Nearly identical to (1), but for LTE.

3. Reachable assertion in nas_eps_send_emm_to_esm

```
int nas_eps_send_emm_to_esm(mme_ue_t *mme_ue,
        ogs_nas_esm_message_container_t *esm_message_container)
{
    int rv;
    ogs_pkbuf_t *esmbuf = NULL;

    if (!mme_ue_cycle(mme_ue)) {
        ogs_error("UE(mme-ue) context has already been removed");
        return OGS_NOTFOUND;
    }

    ogs_assert(esm_message_container);
    ogs_assert(esm_message_container->length);
```

The ESM message payload may be 0-length, as the length is determined by a field in the NAS payload (which can be chosen arbitrarily by an attacker). This leads to the length assertion above being triggered.

5. Reachable assertion and incorrect hash calculation in ogs_kdf_hash_mme

```
void ogs_kdf_hash_mme(const uint8_t *message, uint8_t message_len, uint8_t *hash_mme)
{
    uint8_t key[32];
    uint8_t output[OGS_SHA256_DIGEST_SIZE];

    ogs_assert(message);
    ogs_assert(message_len);
    ogs_assert(hash_mme);

    memset(key, 0, 32);
    ogs_hmac_sha256(key, 32, message, message_len,
            output, OGS_SHA256_DIGEST_SIZE);

    memcpy(hash_mme, output+24, OGS_HASH_MME_LEN);
}
```

When handling NAS attach requests or TAU requests, the ogs_kdf_hash_mme function is passed the NAS payload. However, the length field is represented as an unsigned 8-bit integer, which the passed length of the packet may overflow. This leads to the passed value being truncated.

When the passed value is a multiple of 256, the above assertion (ogs_assert(message_len)) is triggered. Otherwise, the hash is computed on only the first n bits of the message (where n = actual_message_len % 256).
2024-02-03 10:41:12 +09:00
Sukchan Lee be12610fb6 [AMF/MME] No STATE Change for the EMM/GMM-STATUS 2024-02-03 10:16:16 +09:00
Sukchan Lee 47419be650 [AMF/SMF] Resolved the Issue of Session Release Based on the Order of N1/N2 Messages (#2917)
There is an issue with SESSION RELEASE not working properly
depending on the PDU session release complete order
in the PDUSessionResourceReleaseResponse.

If the AMF receives PDUSessionResourceReleaseResponse
followed by PDU session release complete, it works correctly.

However, if it receives PDU session release complete
followed by PDUSessionResourceReleaseResponse, it does not work correctly
and sends an Error Indication to the UE/gNB.

To fix this issue, we added pdu_session_release_complete_received and
pdu_session_resource_release_response_received to the content
so that CLEAR_SM_CONTEXT_REF() is executed when both are received.
2024-02-03 09:42:09 +09:00
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
Sukchan Lee 93110d011e [GTP-U] Fixed ogs_pfcp_find_gtpu_resource()(#2923)
As mentioned in the sgwu.yaml configuration file, it is possible to configure multiple addresses with different source_interface values for the gtpu interface.

Following the this section, I defined two addresses, one with source_interface set to 0 and another with source_interface set to 1. My expectation was to see different addresses for the two PDRs in the Session Establishment Response message during session establishment. However, both addresses were the same, and it was the address I had set for source_interface = 0.

When I looked into the code, I found the reason for the issue. In the lib/pfcp/context.c file, on line 1185, the function that determines the address is called as follows:

...
        } else {
            ogs_gtpu_resource_t *resource = NULL;
            resource = ogs_pfcp_find_gtpu_resource(
                    &ogs_gtp_self()->gtpu_resource_list,
                    pdr->dnn, OGS_PFCP_INTERFACE_ACCESS);
            if (resource) {
...
In the last parameter of this function, a constant value, OGS_PFCP_INTERFACE_ACCESS, is used. This causes every PDR with any source_interface to be considered as "access," and the value 0 is used for its interface.

I replaced the value with pdr->src_if, and the bug was resolved.
2024-01-30 22:39:34 +09:00
Pau Espin 88a77f7bc5 [SMF,MME] Gn: Set Maximum SDU Size QoS field to 1500
Before this patch, it was set as 0, which is Reserved in Network to MS
direction.
2024-01-27 07:11:44 +09:00
Pau Espin a613be8c4c [SMF,MME] Gn: Set Delivery of erroneous SDUs QoS field to No
Before this patch, it was set as 0, which is Reserved in Network to MS
direction.
2024-01-27 07:11:44 +09:00
Pau Espin d95c82b21c [SMF,MME] Gn: Set Delivery order QoS field to No
Before this patch, it was set as 0, which is Reserved in Network to MS
direction.
2024-01-27 07:11:44 +09:00
Pau Espin a5feccf4c8 [SMF] Fix fixed-0 IPCP identifier in PCO ack 2024-01-27 07:10:55 +09:00
Sukchan Lee 3886891833 [MME] Crash due to a race condition
A race condition can occur in the following situations.
In conclusion, we can use this situation to determine
whether or not the UE Context has been removed and avoiding a crash.

For example, suppose a UE Context is removed in the followings.

1. Attach Request
2. Authentication-Information-Request
3. Authentication-Information-Answer
4. Authentication Request
5. Authentication Response(MAC Failed)
6. Authentication Reject
7. UEContextReleaseCommand
8. UEContextReleaseComplete

The MME then sends a Purge-UE-request to the HSS and deletes
the UE context as soon as it receives a Purge-UE-Answer.

Suppose an Attach Request is received from the same UE
between Purge-UE-Request/Answer, then the MME and HSS start
the Authentication-Information-Request/Answer process.

This can lead to the following situations.

1. Purge-UE-Request
2. Attach Request
3. Authentication-Information-Request
4. Purge-UE-Answer
5. [UE Context Removed]
6. Authentication-Information-Answer

Since the UE Context has already been deleted
when the Authentication-Information-Answer is received,
it cannot be processed properly.

Therefore, mme_ue_cycle() is used to check
whether the UE Context has been deleted and
decide whether to process or
ignore the Authentication-Information-Answer as shown below.
2024-01-25 23:27:34 +09:00
Pau Espin 609c234f0b Document Gy interface spec reference 2024-01-25 07:05:33 +09:00
Pau Espin 64598fab2e Document Gx interface spec references 2024-01-25 07:05:33 +09:00
Pau Espin 29ea85ca4c cosmetic: pcrf/pcrf-gx-path.c: Fix trailing whitespace 2024-01-25 07:05:33 +09:00
Bostjan Meglic a3afc4764c memset input/output structure inside the function
Instead of checking if caller memset'ted the structure to zero, memset
it inside the function regardless.
There is no added benefit of a memset() + memcmp() to check if caller
cleared the structure used for outputing data from the database.
2024-01-22 17:34:59 +09:00
Bostjan Meglic e650b66305 fix mismatch of parameters between prototype and declaration 2024-01-22 17:34:59 +09:00
jmasterfunk84 2583fd3c08 Introduce ability for multiple SDM_Subscriptions 2024-01-21 13:16:21 +09:00
Sukchan Lee b94173ab41 [AMF/MME] Fixed M-TMSI pool release (#2307)
M-TMSI pool release was incorrectly modified and has now been corrected.
2024-01-21 11:58:43 +09:00
Gaber Stare d7b896affb [SMF] Build URR at bearer modification 2024-01-20 08:20:24 +09:00
Pau Espin 60691b02d2 [MME] Gn: Introduce initial support for 2G->4G cell reselection
In an Inter-RAT setup a UE could perform a TAU coming from a 2G/3G network.
In that case the UE/MS is unknown to the MME and it should request the
SGSN context (MM, PDP) from the old SGSN. This is done through the following
GTPv1C message exchange on the Gn interface of SGSN and MME:
SGSN <- MME: SGSN Context Request
SGSN -> MME: SGSN Context Response
SGSN <- MME: SGSN Context Acknowledge

Diagram with full set of steps can be found at 3GPP TS 23.401 D.3.6.

This commit doesn't aim to be a complete implementation of the mentioned
procedure, since it's quite a complex one, with lots of fields and logic
required. This so far only implements in general the minimally
successful case by filling as much as possible the required set of
fields.
This will allow for a base onto which do incremental improvements and
fixes while testing against UEs and SGSNs (such as osmo-sgsn, which
doesn't yet support this procedure but will potentially earn it soon).

The reverse direction, aka UE issuing cell reselection 4G->2G was
already implemented (same as here, initial non-complete implementation)
in open5gs-mmed in commit 3d693da73e.

Related: https://osmocom.org/issues/6294
2024-01-17 23:05:19 +09:00
Sukchan Lee 4088cdf17d [MME] Hangs on an invalid S1AP message
Within the PathSwitchRequest packet,
the E-RABToBeSwitchedDLList has two bearers.

If the E-RAB-ID of both bearers is 5, the MME's list memory is destroyed
and the MME crashes. To fix this issue, we modified the code so that
the MME can work correctly with invalid S1AP messages.
2024-01-17 20:17:55 +09:00
Pau Espin 52be56b839 [MME] Match any SGSN in same RAI if none with specific RAI+CI found
This will be useful for other procedures where only the RAI is known,
but not the specific CI. This is the case of idle mobility from Gb or Iu
to EUTRAN, where MME needs to request contexts based on the RAI mapped
in the GUTI obtained from the UE during TAU.
This also makes the config more resilient in RIM scenario, where an SGSN
can be picked now even if CI doesn't match, instead of failing or faling
back to the default route SGSN.
2024-01-16 06:37:29 +09:00
Sukchan Lee b0cf9fcbe7 [AMF] Issue during Concurrent UE Registration (#2839)
While they were continuing their fuzzy testing and developing PacketRusher, an unusual issue with the AMF was observed. The problem arises when a single Ethernet frame containing three bundled SCTP chunks is sent. This behavior is reproduced with PacketRusher when attempting to concurrently register two UEs with the same MSIN.

The expected behavior is that the PDU Session Establishment Accept is sent inside a DownlinkNASTransport to RAN UE NGAP ID 1. However, it is actually sent inside an InitialContextSetupRequest to RAN UE NGAP ID 2. The MAC of this NAS message is invalid for the Security Context of RAN UE NGAP ID 2 (probably valid for RAN UE NGAP ID 1)
2024-01-13 23:16:50 +09:00
Emanuele Di Pascale 21f99ad08d MME: support for IDR EPS_USER_STATE
keep track of whether we failed to page the UE, as that is
needed to provide the correct user state to the HSS.
2024-01-13 12:00:20 +09:00
Bostjan Meglic a4babef9eb [AMF] Add initialRegistrationInd field in Amf3GppAccessRegistration request to UDM 2024-01-10 22:37:56 +09:00
Pau Espin ba59c8309a cosmetic: mme: Fix trailing whitespace 2024-01-09 21:33:01 +09:00
Bostjan Meglic ad216c0b77 [core] Fix a couple of warnings when using C++ compiler or more strict settings
../lib/core/ogs-list.h:62:24: warning: invalid conversion from 'void*' to 'ogs_list_t*' {aka 'ogs_list_s*'} [-fpermissive]
../lib/core/ogs-rbtree.h:79:32: warning: invalid conversion from 'const void*' to 'const ogs_rbnode_t*' {aka 'const ogs_rbnode_s*'} [-fpermissive]

[SBI] Fix compiler error - possible uninitialized variable

[SCP] Fix compiler error - Error: this condition has identical branches

In case of additional compiler warnings turned on, the compiler warns
about potentially unused variables. Fix those issues.
2024-01-09 17:50:22 +09:00
Pau Espin 4ab275ad70 Rename and move ogs_gtp2_paa_to_ip() to lib/proto/conv
Both types are defined under lib/proto/type.h, and the conversion
function is used in several different protocols, so let's better move it
to generic lib/proto/conv.h and remove the "gtp2" prefix.
2024-01-06 07:44:14 +09:00
Pau Espin b3845d5b0b [MME] Constify params in mme-context and depending APIs 2024-01-06 07:42:32 +09:00
Pau Espin 3457435071 [MME] Fix potential null ptr dereference
The assert is checking for sess->session->name, but afterwards there's a
check to skip ses->session not being null, which means the assert can
crash while dereferencing sess->session.
2024-01-06 07:42:32 +09:00
Sukchan Lee b1515a16ff [SMF] Fixes crash when PDU session release
I've resolved an issue where sending continuous
'PDU Session Release Request' message to the same session,
when more than two sessions were created, was causing an SMF crash.

For your reference, this problem did not occur
when only one session was created.
2024-01-05 21:15:34 +09:00
Pau Espin 8f58b55e14 [MME] Fix incorrect function name printed in error line 2024-01-05 05:52:56 +09:00
jmasterfunk84 ad2154ac2a
[HSS] Add hss_event_init after change to event system (#2838)
* Add hss_event_init after change to event system

* also include hss_event_final
2024-01-03 21:15:16 +09:00
Pau Espin 7d9f6181f3 [MME] cosmetic: Fix typo in comment 2024-01-02 21:25:42 +09:00
jmasterfunk84 f0de33833b Use SUPI not SUCI in error message 2023-12-31 11:30:27 +09:00
Pau Espin 6cb20185fa cosmetic: mme: emm-*.c fix trailing whitespace 2023-12-23 09:57:11 +09:00
Pau Espin 3d693da73e [MME] Gn: Introduce initial support for 4G->2G cell reselection
In an Inter-RAT setup a UE could perform a RAU coming from a 4G network.
In that case the UE/MS is unknown to the SGSN and it should request the
SGSN context (MM, PDP) from the MME. This is done through the following
GTPv1C message exchange on the Gn interface of SGSN and MME:
SGSN -> MME: SGSN Context Request
SGSN <- MME: SGSN Context Response
SGSN -> MME: SGSN Context Acknowledge

This commit doesn't aim to be a complete implementation of the mentioned
procedure, since it's quite a complex one, with lots of fields and logic
required. This so far only implements in general the minimally
successful case by filling as much as possible the required set of
fields.
This will allow for a base onto which do incremental improvements and
fixes while testing against UEs and SGSNs (such as osmo-sgsn, which
doesn't yet support this procedure but will potentially earn it soon).

This commit doesn't implement the reverse direction, aka UE issuing cell
reselection 2G->4G. Initial support for this scenario will hopefully be
added soon as a follow-up patch, similar to this one.

Related: https://osmocom.org/issues/6294
2023-12-23 09:56:55 +09:00
Sukchan Lee 080f5bfd70 [NRF] crash after sending invalid message (#2808)
NRF crash after receiving
curl --http2-prior-knowledge http://127.0.0.10:7777/nnrf-disc/v1/nf-instances?target-nf-type=AUSF&requester-plmn-list=[{"mcc":"999","mnc":"70"}]&requester-nf-type=AMF&service-names=nausf-auth&target-plmn-list=[{"mcc":"999","mnc":"70"}]
curl --http2-prior-knowledge http://127.0.0.10:7777/nnrf-disc/v1/nf-instances\?target-nf-type=AUSF\&requester-plmn-list=%5B%7B%22mcc%22%3A%22999%22%2C%22mnc%22%3A%2270%22%7D%5D\&requester-nf-type\=AMF\&service-names=nausf-auth\&target-plmn-list=%5B%7B%22mcc%22%3A%22999%22%2C%22mnc%22%3A%2210%22%7D%5D
2023-12-23 09:55:19 +09:00
Pau Espin 14932a7254 [MME] Split Gn local TEID generation from S11 TEID generation 2023-12-22 06:04:03 +09:00
Pau Espin 6a9c7f16c1 Revert "[MME] Gn: Introduce initial support for 4G->2G cell reselection"
This reverts commit 5a31af36e0.
2023-12-22 06:02:11 +09:00
Pau Espin ab51ba9dd5 cosmetic: mme: Fix trailing whitespace 2023-12-21 22:12:20 +09:00
Pau Espin 5a31af36e0 [MME] Gn: Introduce initial support for 4G->2G cell reselection
In an Inter-RAT setup a UE could perform a RAU coming from a 4G network.
In that case the UE/MS is unknown to the SGSN and it should request the
SGSN context (MM, PDP) from the MME. This is done through the following
GTPv1C message exchange on the Gn interface of SGSN and MME:
SGSN -> MME: SGSN Context Request
SGSN <- MME: SGSN Context Response
SGSN -> MME: SGSN Context Acknowledge

This commit doesn't aim to be a complete implementation of the mentioned
procedure, since it's quite a complex one, with lots of fields and logic
required. This so far only implements in general the minimally
successful case by filling as much as possible the required set of
fields.
This will allow for a base onto which do incremental improvements and
fixes while testing against UEs and SGSNs (such as osmo-sgsn, which
doesn't yet support this procedure but will potentially earn it soon).

This commit doesn't implement the reverse direction, aka UE issuing cell
reselection 2G->4G. Initial support for this scenario will hopefully be
added soon as a follow-up patch, similar to this one.

Related: https://osmocom.org/issues/6294
2023-12-21 22:11:49 +09:00
Pau Espin 5061a3aec0 [MME] Store decoded PAA into session->ue_ip and session_type
This will be used by the Gn interface to obtain the UE IP and provide
it to new SGSN when transmitting SGSN Context Response.
2023-12-19 06:57:35 +09:00
Pau Espin 414f81fcd5 [MME] Store received PGW S5C IP address in mme_sess_t
This information will be required by the Gn interface in MME when
answering an SGSN with an "SGSN Context Response" message during MS cell
reselection EUTRAN->GERAN.
2023-12-19 06:57:18 +09:00
Stare Gaber 4655507a00 [AMF] Fix deregistration request De-registration type 2023-12-19 06:47:54 +09:00
Sukchan Lee 1ba3fd3cf8
[AMF/MME] UEContextReleaseCommand after Interity Protected (#2786) (#2794)
* [AMF/MME] UEContextReleaseCommand in Integrity (#2786)

Modified not to send UEContextReleaseCommand in Integrity Unprotected
NAS message such like Registration or Service request.

* [AMF/MME] UEContextReleaseCommand after Interity Protected (#2786)

Modified not to send UEContextReleaseCommand in Integrity Unprotected
NAS message such like Registration or Service request.
2023-12-13 17:54:37 +09:00
Oliver Smith 66c39f2085
[MME] [AMF] Set Daylight Saving Time (#2766)
Fix DST always being set to 0 ("No adjustment for Daylight
Saving Time").

Related: 3GPP TS 24.008 § 10.5.3.12
2023-12-06 20:24:33 +09:00
Sukchan Lee e42048e8a5
Reset the number of TA, SLICE, and PLMN supported by AMF/MME(#2761) (#2765)
* update it

* update it

* update it

* update it

* update it

* udpate it

* uupdate it
2023-12-03 23:52:29 +09:00
Sukchan Lee f68a1f3283
[AMF] Modification to context setup (#2729) (#2764)
Send out PduModifySessionRequest while no other PDU-related procedure is
in progress (i.e. InitialContextSetupResponse was alreay received).
2023-12-01 23:20:18 +09:00
Sukchan Lee ab64ff9514
[IPv6] Fixed to include MTU in SLAAC RA (#2754) (#2758) 2023-11-28 17:38:51 +09:00
Oliver Smith 5070ddfa3e
[MME] [AMF] Add no_time_zone_information param (#2745)
Allow network operators to omit the time zone in the 4G EMM Information
and 5G Configuration Update. This is useful for better compatibility
with some UEs.

The parameter is optional according to:
* 4G: 3GPP TS 24.301 Table 8.2.13.1
* 5G: 3GPP TS 24.501 Table 8.2.19.1.1
2023-11-27 22:26:12 +09:00
gstaa 060acee5df
[AMF] Fix Nudm_SDM_Get for re-registration (#2751)
Bug:

In case that AMF does not have subscription data for the UE,
PDU session remains unreleased after implicit de-registeration.

The exact test case:
- UE registered (integrity protection applied)
- UE deregistered (Nudm_SDM_Unsubscribe, Nudm_UECM_Registration (purgeFlag))
- UE registered, PDU session activated

    UE data are still stored in AMF. So if integrity protected applies,
    the steps 4 - 14 [ETSI TS 123 502 V16.7.0](https://www.etsi.org/deliver/etsi_ts/123500_123599/123502/16.07.00_60/ts_123502v160700p.pdf) are skipped.
    Only AM Policy Association Establishment is performed.
- UE is moved out of radio coverage, 2 x (4 min + Timer t3512) expires

Result: UE is implicitly de-registered, PDU session is not released

The steps of implicit de-registeration:
  1. Implicit Timer Expiration
  2. UDM_SDM_Unsubscribe
  3. UDM_UECM_Deregistration
  4. PDU session release request
  5. PDUSessionResourceReleaseCommand + PDU session release command
  6. PDUSessionResourceReleaseResponse
  7. AM_Policy_Association_Termination

So PDU session release is performed after the confirmation of
UDM_UECM_Deregistration.
Since there is no UDM_SDM subscription, the UDM steps are skipped
and PDU session is not released.

Fix:

If the AMF does not have subscription data for the UE which registers,
the AMF registers with the UDM using Nudm_UECM_Registration and
retrieves subscription data with Nudm_SDM_Get.

[ETSI TS 123 502 V16.7.0](https://www.etsi.org/deliver/etsi_ts/123500_123599/123502/16.07.00_60/ts_123502v160700p.pdf), 4.2.2.2.2 General Registration, 14a-c:
> If the AMF does not have subscription data for the UE, the AMF retrieves the Access and Mobility Subscription data, SMF
> Selection Subscription data, UE context in SMF data and LCS mobile origination using Nudm_SDM_Get.
2023-11-27 22:19:29 +09:00
Sukchan Lee ee964f48dd
[AMF/MME] Fixed crash when receiving invalid packet (#2737) (#2755) 2023-11-27 22:16:11 +09:00
Sukchan Lee ab1c3493c6 [NRF] Fixed crash due to invalid PATCH body (#2735) 2023-11-25 22:03:28 +09:00
Sukchan Lee 7278714133 [AMF] Fixed Nudm_UECM_Registration crash (#2733)
1. UE sends RegistrationRequest to AMF.
2. AMF sends Nudm_UECM_Registration to UDM.
3. UE sends RegistrationRequest to AMF.
4. GMM state is gmm_state_authentication
5. UDM sends Nudm_UECM_Registration response to AMF.
6. AMF crashs since no Handler in gmm_state_authentication state
2023-11-25 21:21:23 +09:00
Bostjan Meglic adcdcf6426
[SBI] Change discovery option TAI from array to single item (#2725)
According to 3GPP TS 29.510, the search parameter "tai" should be a
single item, not an array of items.

TS 29.510: Table 6.2.3.2.3.1-1:
URI query parameters supported by the GET method on this resource

Revert "[SBI] Change discovery option TAI from array to single item"

This reverts commit b4beff1ae16c64b3c6d84d8bdb47c36e19b705f2.

wip
2023-11-22 20:37:06 +09:00
Sukchan Lee e92293e0af
[SEPP] Initial Update for 5G Roaming (#2739)
[SEPP] Initial Update for 5G Roaming
2023-11-19 19:34:51 +09:00
Pau Espin 9d7dc91f21
[SMF] Gy: Keep sending extra AVPs in INITIAL_REQUEST (#2721)
This commit splits filling Requested-Service-Unit, Used-Service-Unit and
QoS-Information into their own helper functions for better readibility,
and then partially reverts 125740727e,
where lots of AVPs were left out of INITIAL_REQUEST messagesi during the
changes made.
After looking through 3GPP TS 32.299 and rfc4006, it seems expected to
send Requested-Service-Unit only during INITIAL_REQUEST, and
Used-Service-Unit during UPDATE_REQUEST, so that part is kept.

However, I am not able to find clear indications that AVPs such as QoS
Information and RAT-Type should not be sent during INITIAL_REQUEST.
So, since we have the info, better set it already during
INITIAL_REQUEST, since the OCS may want to grant different resources
based on that information if available too.
2023-11-01 03:19:10 +09:00
Šimon Lukašík 490a3ecb99
A minor typo fix (#2707)
* minor typo fix

* typo fix: faimly -> family
2023-10-28 22:11:58 +09:00
Sukchan Lee e9c15f57e3 Follow-up on #2706 2023-10-28 21:51:08 +09:00
Bostjan Meglic 18fba0d3db
Delete authentication data on UE deregistration (#2706)
* [AUSF] Fix removing UE context on authentication removal request

AUSF crashed when trying to access ausf_ue->sm fields after they were
already deleted.

* [AMF] Delete UE authentication result after UE deregisters from 5G core

Based on TS 29.509 - 5.2.2.2.5 Authentication Result Removal with 5G AKA
method:
In the case that the Purge of subscriber data in AMF after the UE
deregisters from the network or the NAS SMC fails following the
successful authentication in the registration procedure, the NF Service
Consumer (AMF) requests the AUSF to inform the UDM to remove the
authentication result.
2023-10-28 21:48:33 +09:00
Sukchan Lee b2be7393a0
[AMF] Fixed TAC configuration error (#2700) (#2711) 2023-10-28 21:30:32 +09:00
Sukchan Lee e3c2fd00d9 [SBI] Do not raise ASSERT when not enough CLIENT pool (#2701) 2023-10-25 21:40:37 +09:00
Sukchan Lee d406fbeb92 Fixed incorrect SMF selection in Multi-SMF (#2557) 2023-10-23 22:40:35 +09:00
Sukchan Lee 783defc52f [SMF] Remove unused varaible in gy-handler.c 2023-10-18 07:09:54 +09:00
Sukchan Lee de7b094191
Merge branch 'main' into sigscale-ocs 2023-10-18 06:54:29 +09:00
Sukchan Lee 7da45cde66 [AMF] mac_failed should be initialized (#2679)
amf_ue->mac_failed flag to be cleared during security mode procedure but it was not.
At this point, the only way to cleare the amf_ue->mac_failed flag is by UE Context Release.
But I'd like to connect UEs as fast as possible without UE Context Release.
2023-10-17 22:28:23 +09:00
Pau Espin 79d3c7078f hss: Don't send IDR for Operator-Determined-Barring changes if Subscriber-Status=SERVICE_GRANTED 2023-10-14 11:41:43 +09:00
Pau Espin e108d6297c HSS: Add support for Operator-Determined-Barring field
* Add "subscriber_status" cmd to open5gs-dbctl to set values for
  "subscriber_status" and "operator_determined_barring" DB fields.
* Add webui View+Edit for those same fields.
* open5gs-hssd now takes those values into account and submits
  Operator-Determined-Barring AVP with DB-retrieved value if
subscriber_status is set to OPERATOR_DETERMINED_BARRING.

For more information, see TS 29.272 section 5.2.2.1.3  and 7.3.30.
2023-10-12 07:17:54 +09:00
Emanuele Di Pascale 7ea37ef618 smf: don't assert if we run out of IPs
currently if no IP address is available from the configured
subnets in the SMF when attempting to assign an IP to an UE
we assert and the SMF crashes. Handle the error more gracefully
by returning an error cause instead.
2023-10-11 20:42:31 +09:00
Sukchan Lee 53fe8f1e6d [MME] SGaAP-MO-CSFB-INDICATION w/ TAI/ECGI (#2664)
Added TAI/ECGI to the SGaAP-MO-CSFB-INDICATION message.
2023-10-11 20:37:12 +09:00
Pau Espin cb114eca5e cosmetic: HSS: Fix trailing whitespace 2023-10-10 08:04:01 +09:00
Sukchan Lee 3f9ca906da [PCF] Remove SM Policy Association Terminatation (#2650) 2023-10-04 20:27:47 +09:00
Sukchan Lee 445bf26ef2 [AUSF] Fixed crash due to ausf_ue_add (#2637) 2023-09-25 22:33:03 +09:00
Sukchan Lee d4f2b545a3 [SBI] Fixed invalid format of subscrCond (#2630)
The format of subscrCond must be 'oneOf'.
2023-09-24 09:01:59 +09:00
Sukchan Lee 8a3dbd44ae [MME] Protection code for No IMSI (#2613, #2614) 2023-09-16 22:27:21 +09:00
Sukchan Lee a3a683e5a6 [MME] Implement ENBConfigurationUpdate (#2589) 2023-09-16 20:58:58 +09:00
Sukchan Lee 05ed95d623 [GTPU] Fixed PDCP SN handling (#2584, #2477)
Scenario is handover on S1AP, data forwarding is enabled, and
the Source ENB is forwarding DL PDCP packets to EPC(SGWU)
with PDCP SN included. SGWU is also forwarding these packets
to the Target ENB.

However the PDCP SN is not present in the forwarded packets
from SGWU to Target ENB.

I modified this part, and there was the same problem in 5GC, fixed it as well.

A lot of code in GTP-U has been modified,
so if you have any problems, please let us know right away.
2023-09-10 22:37:42 +09:00
Sukchan Lee 260eabb317 [SMF] Invalid Message(SmContextCreateData) (#2590)
curl --noproxy '*' --http2-prior-knowledge -X POST --header "Content-Type: multipart/related" --data-binary @pdu http:/192.168.29.231:7777/nsmf-pdusession/v1/sm-contexts
Attaching file 'pdu'

SMF crashes as not able to decode the message properly. SmContextCreateData is not accessible.
2023-09-07 22:38:45 +09:00
Sukchan Lee 2aa12449aa [NRF] Fixed NRF crash when Custom nfType (#2576)
NF Instance Registration to reproduce crash:

curl -v -X PUT -d '{"nfInstanceId":"0b8a8d59-af80-4fb7-8645-b832fd69d94a","nfType":"CUSTOM_INF","nfStatus":"REGISTERED","ipv4Addresses":["127.0.13.37"]}' --http2-prior-knowledge http://127.0.0.10:7777/nnrf-nfm/v1/nf-instances/0b8a8d59-af80-4fb7-8645-b832fd69d94a
2023-09-05 22:11:19 +09:00
Sukchan Lee 2f8ae91b0b Fixed dynamic-stack-buffer-overflow (#2578, #2577) 2023-09-05 21:58:05 +09:00
Sukchan Lee 298fed260b [UDM] Fixed crash for invalid SUCI (#2571)
Modifications were made to resolve the following assertion..

Invalid HNET PKI Value [0] (../lib/sbi/conv.c:135)
ogs_supi_from_supi_or_suci: Expectation `supi' failed. (../lib/sbi/conv.c:262)
udm_ue_add: Assertion `udm_ue->supi' failed. (../src/udm/context.c:144)
backtrace() returned 8 addresses (../lib/core/ogs-abort.c:37)
2023-09-04 07:03:16 +09:00
Sukchan Lee dcdf821542 [AMF] amf_ue_set_suci: Assertion `suci` (#2567)
Cannot convert SUCI in `Not implemented SUPI format [4]`
2023-09-03 17:59:10 +09:00
theodorsm d5eff9e24a Fix typo and remove trailing whitespaces in nas-security 2023-09-02 08:24:24 +09:00
Sukchan Lee 654fe4010c [GTP] gtp_message_fuzz: Abrt in ogs_abort
See below for details.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=59414
2023-08-24 22:19:42 +09:00
Sukchan Lee 04f7958420 [SMF] Deregister issue during sess release (#2537)
A situation in which you establish two sessions and release both of them.

In the first SESSION, the UE normally sent PDUSessionResourceReleaseResponse
and PDU session release complete. However, these were not sent when releasing
the second SESSION.

At this point, when the UE tried to do a deregistration,
the SMF was not properly handling the exception.

I've just fixed this.
2023-08-24 21:26:23 +09:00
Sukchan Lee 4b0bade80e [TLV] PFCP parser crash from FuzzingLabs (#2523) 2023-08-18 22:19:46 +09:00
Sukchan Lee fc4072590e [SMF] Added SMF registrations (#2514, #2524) 2023-08-18 20:21:08 +09:00
Sukchan Lee e01f46eb6c
Use x1000 multiplier for Kbps, Mbps, ... etc. (#2515)
NAS, GTP, PFCP, SBI, all except S1AP/NGAP use x1000 multiplier for Kbps, Mbps, Gbps ... etc.

From now on in WebUI all units also use a multiplier of x1000.
2023-08-13 18:19:45 +09:00
Sukchan Lee af67b2486b [SBI] UDR stores PEI instead of PCF 2023-08-13 11:49:01 +09:00
Sukchan Lee d33d67b2af [AMF/MME] Defaults 9 minutes for T3412/T3512 2023-08-13 11:16:06 +09:00
Sukchan Lee e625f9222a [AMF/MME] Follow-up on #2491 2023-08-11 09:44:19 +09:00
Sukchan Lee e7f7c4274e [SMF] Fix crash on double policy deletion (#2489) 2023-08-10 22:14:48 +09:00
Sukchan Lee 93e05f481b S1Setup failure with invalid MCC/MNC (#2491) 2023-08-10 15:40:05 +09:00
Sukchan Lee 84ed9a0dd3 UE slice shall be also available in RAN (#2482)
Changed to that registration can be accepted only
when the UE slice is available in the RAN slice.
2023-08-09 16:06:39 +09:00
gstaa f22fbb45da
[UPF] Fix wrong number of QoS flows metric (#2490) 2023-08-08 22:32:06 +09:00
Sukchan Lee 9f19210f22 Add trace log for debugging #2287 2023-08-07 22:13:35 +09:00