4783 Commits

Author SHA1 Message Date
Sukchan Lee
33960bbb66 [NRF] Implemented PLMN list update handling in nrf_nnrf_handle_nf_update (#3566)
- Added functionality to parse and validate the plmnList JSON array
  during a PATCH request.
- Updated the nf_instance structure with new PLMN data from the request.
- Ensured robust error handling for invalid PLMN entries
  and excessive PLMN counts.
- Responded with appropriate HTTP status codes for success and error scenarios.
2024-12-26 14:38:00 +09:00
Sukchan Lee
2ce9f2b27e [SEC] Fix overflow issue of adjusting the URR access (#3642)
Adjusted the URR access logic to prevent out-of-bounds access
by ensuring the URR ID is within the valid range.
2024-12-25 18:04:42 +09:00
Sukchan Lee
badbefe7b3 [SGsAP] Refactor SCTP socket creation (#3344)
- Removed `create_sctp_socket_from_addr_list` function.
- Introduced direct use of `sctp_socket_family_from_addr_list` in
  `ogs_sctp_server` and `ogs_sctp_client`.
- Ensured proper handling of address family selection for SCTP sockets,
  defaulting to `AF_INET` or `AF_INET6` based on the address list.
- Added error handling for cases where no suitable address family is found.
2024-12-25 12:21:35 +09:00
Sukchan Lee
68375f6c35 [SGsAP] Change SCTP socket to SOCK_STREAM and remove 'addr' field (#3344)
Addressed feedback on commit 33532a5 by switching SGsAP's SCTP socket
from SOCK_SEQPACKET to SOCK_STREAM. This change eliminates the need
for the 'addr' field, as SOCK_STREAM does not require specifying the address
in sctp_sendmsg.

All references to the 'addr' field have been removed from the VLR structure
and related functions, simplifying SCTP message handling and ensuring better
compatibility with multiple addresses.

Updated `sgsap-sctp.c` accordingly to reflect these changes
and improve the reliability of SCTP connections.
2024-12-25 11:09:07 +09:00
Sukchan Lee
08b9e7c55f [DBI] Fix crash in ogs_dbi_auth_info due to invalid SUPI (#3635)
Added checks to validate the SUPI ID in the ogs_dbi_auth_info function
before calling ogs_assert. This prevents a crash when the SUPI ID is malformed,
such as when it does not contain a hyphen.

The fix ensures that invalid SUPI values are logged and handled gracefully,
avoiding assertion failures and crashes in the UDR.
2024-12-24 17:14:50 +09:00
Sukchan Lee
4016293214 [SEC] Fix overflow issue with QFI in QoS flow and adjust URR access (#3642)
- Modified the `ogs_nas_qos_rule_s` structure to increase the size
  of the `identifier` field from 4 bits to 6 bits in order to allow
  for larger QoS Flow Identifiers (QFI).
- Adjusted the URR access logic in `upf_sess_urr_acc_add` to prevent
  out-of-bounds access by ensuring the URR ID is within the valid range.
2024-12-24 16:42:23 +09:00
Sukchan Lee
3b7654061f [SCTP] Refactor SCTP socket creation to use address family from sa_list (#3344)
Refactored the SCTP socket creation logic to dynamically select
the address family based on the provided address list.

A new function, `create_sctp_socket_from_addr_list`, was introduced
to check for the presence of an IPv6 address in the address list and
create an SCTP socket accordingly.

If an IPv6 address is found, it uses AF_INET6; otherwise, it defaults
to AF_INET. This change was applied to both the `ogs_sctp_server` and
`ogs_sctp_client` functions.
2024-12-24 15:30:46 +09:00
Sukchan Lee
33532a5858 [SGsAP] Refactor VLR Lookup to Use Socket Pointers Instead of Addresses (#3344)
Updated the VLR (mme_vlr_t) lookup mechanism to identify VLR instances
using socket pointers rather than IP addresses.

Replaced the `mme_vlr_find_by_addr` function with `mme_vlr_find_by_sock` across
relevant modules, including `mme-context.c`, `mme-context.h`, and `mme-sm.c`.

Adjusted memory management for the `addr` field within the VLR structure
to ensure proper allocation and deallocation. Removed address assignments
in `sgsap-sctp.c` for usrsctp and updated logging to reflect the new socket-based
identification.
2024-12-24 15:22:00 +09:00
Sukchan Lee
b0bfd35c63 [SCTP] Support setting local address (#3344)
Added support for binding to local IP addresses in ogs_sctp_client and
ogs_sctp_server, and correct SGsAP configuration

Implemented the ability to bind to one or multiple local IP addresses using
`sctp_bindx()` in both the `ogs_sctp_client()` and `ogs_sctp_server()` APIs.

Users can now specify local addresses in the configuration files under the new
`local_addresses` field, reducing unnecessary complexity and signaling caused
by binding to `ANY_ADDR`.

This update addresses issue https://osmocom.org/issues/6509 by ensuring
correct operation in multi-interface and complex networking setups.

Additionally, corrected the `sgsap` configuration by changing it
from `server` to `client`, and added support for specifying `local_addresses`
for local binding as follows:

```
sgsap:
  client:
    - address: msc.open5gs.org # SCTP server address configured on the MSC/VL
      local_address: 127.0.0.2 # SCTP local IP addresses to be bound in the M
```
2024-12-23 21:16:15 +09:00
Sukchan Lee
b44d159c7b [SMF] Add check for relay peer in ogs_diam_is_relay_or_app_advertised function (#3589)
Modify the function to return true if the peer is a relay,
otherwise check for advertised application.
2024-12-13 14:56:44 +09:00
Sukchan Lee
6ffd7c978f [BSF] Remove mandatory BSF dependency for PDU session establishment (#3626)
Modified the PCF logic to bypass the BSF dependency when it is not available.
This change ensures that the 5G Core can operate without requiring a BSF,
allowing PDU sessions to be established successfully in setups
where only a single PCF is used.
2024-12-12 17:00:17 +09:00
Sukchan Lee
92515a9721 [NAS] Fix heap-buffer-overflow vulnerability in NAS message decoding (#3622)
Resolved a heap-buffer-overflow issue
in the ogs_nas_5gs_decode_registration_request function caused
by improper handling of empty pkbuf.

Added validation checks to ensure pkbuf size is non-zero
before accessing its data.

Reviewed similar patterns in other decoding functions
to prevent similar vulnerabilities.
2024-12-11 21:21:09 +09:00
AlbertoBerlin
531e301f4d When building a PCO response, if the incoming PCO has MS_SUPPORT_LOCAL_ADDR_TFT_INDICATOR, the SMF will also reply with the indication. Otherwise newer phones will reject the type of TFT that SMF sends for dedicated bearers (e.g. VoNR or VoLTE) because they do include the local address without having advertised support for it. 2024-12-11 20:43:02 +09:00
Bostjan Meglic
7e00910bfc [AMF] save mapped HPLMN from Session Est Req
In case that UE sends "mapped HPLMN" in the Session Establishment
Request, AMF did not save it and forward it in the request to SMF.
2024-12-05 18:34:30 +09:00
Sukchan Lee
1b167ef44d [AMF] Fix state machine crash during UE context transfer in REGISTERED state (#3613)
Added a handler in gmm_state_registered() to process SBI client events
for UE context transfer, preventing fatal errors and AMF crashes during
Initial Registration.
2024-12-05 10:19:03 +09:00
Sukchan Lee
43bcf08d51 [AMF] Resolve crash caused by incorrect handling of UE registration in multiple states (#3608, #3612)
This commit resolves additional crashes in the AMF caused by improper handling
of UE registration requests in various states of the GMM state machine.

The issue occurs when the AMF receives multiple registration requests
from the same UE while the previous UE context is being released,
leading to outdated or invalid authentication vectors being processed.

Although a previous fix addressed this problem in the gmm_state_exception
function, similar crashes were identified in other states within gmm-sm.c.

To address this, the handling of multiple registration requests
from the same UE has been refined across all relevant states.

The fix ensures proper synchronization and validation of UE contexts,
preventing the AMF from processing outdated authentication data and
maintaining stability during such edge cases.
2024-12-04 14:24:01 +09:00
Sukchan Lee
525695501e [PFCP] Add assertion to ensure F-TEID.ch is false before TEID swap (#3036, #3574, #3610)
This prevents incorrect restoration behavior by ensuring the TEID is only
swapped when F-TEID.ch is false, indicating the TEID has already been assigned.
2024-12-03 08:59:34 +09:00
Sukchan Lee
e5f50f53f6 [PFCP] Ensure correct TEID restoration behavior by checking F-TEID.ch value (#3574)
Added a check to ensure that TEID restoration via swap occurs only
when F-TEID.ch is false. In the restoration process, when F-TEID.ch is false,
it indicates that the TEID has already been assigned, and the swap operation is
necessary to restore the TEID. However, if F-TEID.ch is true, it means that
the UPF needs to assign a new TEID for the first time, and performing a swap
in this case would be incorrect.

This check ensures that the swap operation is only triggered
when the TEID is already assigned and prevents potential issues
during the TEID assignment process.
2024-12-02 16:53:38 +09:00
Sukchan Lee
f780f9af45 [AMF] Fix crash due to incorrect handling of UE registration requests (#3608)
This commit addresses an issue in the AMF where it crashes
upon receiving the Nausf_UEAuthentication_Authenticate response
in the gmm_state_exception function.

The crash occurs when the same UE continuously sends registration requests
while the previous UE context is released before the AUSF response is received,
leading to incorrect states in the gmm state machine.

The root cause was a lack of proper handling in the gmm_state_exception function
for the scenario where multiple registration requests from the same UE cause
the AMF to process outdated authentication vectors.

This update introduces a fix to handle this edge case
and prevent the AMF from crashing.
2024-12-02 11:24:20 +09:00
Sukchan Lee
76060ff22b [AMF/MME] Add validation for NAS PDU and mitigate DoS attacks (#3607, #3606, #3131)
- Added handling for empty NAS PDUs to prevent potential heap-buffer-overflow.

- Implemented safeguards to reject invalid NAS messages and mitigate DoS attacks
  by removing S1/NG Context for affected UEs.
2024-12-02 10:07:16 +09:00
liuxiaoxinxinxin
e690005a24 Update ngap-path.c 2024-12-02 10:04:15 +09:00
dchard
c67bddd2b4 [MME] Add fake combined attach
In case an external HSS is used, and the NAM field is set to 0 (PACKET_ONLY),
Open5GS MME will only respond with an "EPS_ONLY" attach accept. This behavior
causes a lot of UEs (mainly phones) to disconnect after 1-2 seconds without
further signalling.

To resolve this, a new flag is introduced:

```
global:
  parameter:
    fake_csfb: true
```

If this flag is set to 'ture', the MME will respond with a combined EPS/IMSI
attach accept even if the HSS NAM field is set to "PACKET_ONLY", or if the
MME has no SGs connection towards a CS core.

By default this flag is false, thus not modifying the original behavior.

Note: some commercial core network vendors do include the LAI part in a
"fake" combined EPS/IMSI attach accept message. As that field is optional, and
testing also indicates that it is not needed, this patch does not implement it.
2024-11-28 22:32:58 +09:00
Sukchan Lee
b8208464a2 [NRF] Remove nfProfileChangesSupportInd from responses (#3585)
According to TS 29.510, the NFProfile structure in the NFDiscovery API does not
include the nfProfileChangesSupportInd attribute. However, Open5GS NRF currently
includes this attribute in NFDiscovery API responses, which has led to
complaints from certain NF vendors.

This commit modifies the nrf_nnrf_handle_nf_discover function
in src/nrf/nnrf-handler.c to ensure that the nfProfileChangesSupportInd
attribute is excluded when constructing NFProfile for NFDiscovery responses.
2024-11-28 20:47:16 +09:00
Sukchan Lee
c3dccf13fc Revert "Removing from discovery responses an invalid nfProfileChangesSupportInd which should not be there"
This reverts commit 02e1729ca6.
2024-11-28 20:46:45 +09:00
AlbertoBerlin
02e1729ca6 Removing from discovery responses an invalid nfProfileChangesSupportInd which should not be there 2024-11-28 20:46:05 +09:00
AlbertoBerlin
df83767653 Support for nf-instance-id as Subscription Condition in subscriptions to notifications from NRF 2024-11-28 20:46:05 +09:00
Pau Espin Pedrol
3358e5128f [MME] Fix typo in log line 2024-11-26 06:44:48 +09:00
Sukchan Lee
0bbbd0166e Added use_upg_vpp parameter for UPG-VPP configuration (#3591)
This commit introduces a new parameter in the global configuration
to support UPG-VPP UPF. When the following setting is added:

```
global:
  parameter:
    use_upg_vpp: true
```

The SMF generates PFCP messages specifically tailored for UPG-VPP UPF.
This allows seamless integration and operation with UPG-VPP
by automatically adapting the message structure to its requirements.
2024-11-25 16:47:03 +09:00
Sukchan Lee
b47bad8b84 [HR] Implement GTP-U processing for HR Roaming in User Plane (#2194)
- Added support for the N9 For Roaming interface type:
  - Core interface act as V-UPF.
  - Access interface act as H-UPF.

- Modified V-UPF behavior:
  - V-UPF updates only the TEID and IP Address in the GTP-U header.
  - The content following the Extension Header is passed through directly
    between the UE and H-UPF.

This implementation ensures seamless data flow between the UE, V-UPF, and H-UPF
while maintaining integrity for Home Routed Roaming scenarios.
2024-11-23 17:51:42 +09:00
mitmitmitm
f5de72b996 Support non-integer bitrate strings more accurately
TS 29.571 - 5.5.2 Simple Data Types defines BitRate type as

	String representing a bit rate that shall be formatted as follows:

	Pattern: '^\d+(\.\d+)? (bps|Kbps|Mbps|Gbps|Tbps)$'

	Examples: "125 Mbps", "0.125 Gbps", "125000 Kbps"

Taking the "0.125 Gbps" example, rather than round 0.125 down to 0, parse it as
a double-float first before multiplying by 10^9, resulting in 1.25e8 (bps).
2024-11-21 16:39:36 +09:00
Sukchan Lee
f03e220761 [DOCS] Update link of Mesaurement of UPF Performance (#3553) 2024-11-20 10:52:28 +09:00
Bostjan Meglic
5ebb2eb76e [SMF] fix wrong return value (int -> bool) 2024-11-19 17:17:31 +09:00
Bostjan Meglic
cfff6d28aa [AMF] prevent null-dereferencing
Break early in case resouce allocation fails.
2024-11-19 17:17:31 +09:00
nick
1c2098bf71 fix indentation issue in srsenb.yaml and rename srslte.yaml to srsenb.yaml in guide02 docs 2024-11-19 08:43:16 +09:00
Sukchan Lee
1fa8e5468e [AMF/MME] Fix handover failing due to GNB/eNBID hash table handling (#3569)
Resolved an issue where Handover was failing when attempting to handover
from GNB-ID/eNB-ID 1 to GNB-ID/eNB-ID 0.

The problem occurred because the hash table managing GNB_ID values would
remove any entry with the default GNB-ID/eNB-ID of 0 before re-adding entries.

Consequently, any GNB/eNB configured with a GNB-ID/eNB-ID of 0
would be inadvertently deleted whenever another GNB was added.

This fix modifies the handling of the hash table to prevent the default
GNB-ID/eNB-ID (0) from being removed unintentionally, allowing handovers
between GNB-ID/eNB-ID 0 and other GNBs/eNBs to proceed without error.
2024-11-14 16:26:49 +09:00
Sukchan Lee
dd7217acde [MME] Fix handling of unknown PLMN in S1 Setup Request (#3544, #3570)
```
TS36.413

8.7.3 S1 Setup
8.7.3.4 Abnormal Conditions
If the eNB initiates the procedure by sending a S1 SETUP REQUEST message
including the PLMN Identity IEs and none of the PLMNs provided by the eNB
is identified by the MME, then the MME shall reject the eNB S1 Setup Request
procedure with the appropriate cause value, e.g., “Unknown PLMN”
```

Modified code to address abnormal conditions where the eNB initiates
the S1 Setup Request with a PLMN Identity IE that is unrecognized by the MME.

In this case, the MME now properly rejects the S1 Setup Request
with the cause value "Unknown PLMN" in compliance with the 3GPP specification
(8.7.3.4).
2024-11-13 11:17:06 +09:00
Sukchan Lee
1519f73f0f [AMF] for (k, i, j) -> for(i, j, k) (#3544, #3570) 2024-11-13 11:08:50 +09:00
draga
85bb717bf6 fixed function to compare with amf supported plmns 2024-11-13 10:55:36 +09:00
Sukchan Lee
51fd59e7cf [UDM] Prevent crash by limiting the number of TOKENs (#3564)
we modified the ogs_supi_from_suci function to prevent the crash
by limiting the number of tokens parsed
2024-11-11 16:09:45 +09:00
Sukchan Lee
70c888f4c9 Merge branch 'main' into home-routed 2024-11-07 17:52:48 +09:00
Sukchan Lee
e227d57972 [SBI] Enable Custom Info in User-Agent Header for HTTP/2 Requests (#3555)
In accordance with TS29.500 Section 5.2.2.2 on mandatory HTTP standard headers,
the User-Agent header in HTTP/2 requests is required to include the NF type
of the HTTP/2 client. Additionally, it is specified that the content
of the User-Agent header may be followed by a hyphen and custom information
when needed, providing greater flexibility for identifying the originating
NF type or adding other specific details.

To accommodate this requirement, I modified the code to allow for additional
information to be appended after the NF type in the User-Agent header,
separated by a hyphen.

This change ensures that the User-Agent header format can be customized
as needed for indirect communication scenarios and requests originating
from the SCP, improving compliance with the specification and enhancing
the adaptability of the header format for HTTP/2 communications.
2024-11-07 11:20:40 +09:00
Sukchan Lee
421126682e [SMF] Change the Max Number of PCO from 16 to 32 2024-11-05 16:49:04 +09:00
Sukchan Lee
ae2a3255a5 [CSFB] Fix Location Update for non-EPS (#3381)
While experimenting with CSFB, it was observed that when the UE returns
to E-UTRAN after a CS call, the UE performs a Tracking Area Update
with a combined Tracking Area/Location Area update and IMSI attach.
Currently, Open5GS's MME simply responds with a TAU Accept message
but does not inform the MSC/VLR.

As a result, no further MT (Mobile Terminated) CS/SMS services are possible
in cases where the MSC/VLR only attempts paging on GERAN.
However, some MSC/VLR implementations with fast fallback may still attempt
paging on E-UTRAN, allowing MT CS/SMS services to function intermittently.

According to 3GPP TS 29.118 Section 5.2.2 Procedures in the MME,
specifically Section 5.2.2.2.1, if the timer Ts6-1 is not running,
the MME shall start the location update for non-EPS services procedure
upon receiving a combined Tracking Area Update Request indicating
combined TA/LA updating with IMSI attach. However, SGs timers are not
implemented in Open5GS, which is a separate issue.

To comply with the specification and ensure that the MSC/VLR is informed
when the UE becomes reachable via SGs, the following changes have been
implemented:

1. Delay UEContextReleaseCommand:

When the active_flag is set to 0, the UEContextReleaseCommand is now delayed
until the MME receives the TAU Complete message from the UE. This ensures
that the UE has acknowledged the new P-TMSI before the network releases
the context, maintaining proper synchronization between the UE and the network.

2. Include Mobile Identity Only When P-TMSI Changes:

The Mobile Identity is now included in the Attach/TAU Accept messages
only when the MSC/VLR updates the P-TMSI. This ensures that the UE receives
the Mobile Identity information solely when there is an actual change
in the P-TMSI, preventing unnecessary or incorrect handling
of TAU Complete messages.

3. Send SGsAP-REALLOCATION-COMPLETE Conditionally:

The SGsAP-REALLOCATION-COMPLETE message is now sent to the MSC/VLR
only upon receiving a Attach/TAU Complete message from the UE.
This confirmation indicates that the UE has successfully updated its P-TMSI,
ensuring that the MSC/VLR is accurately informed of the change.

4. Handle P-TMSI Confirmation:

When the MSC/VLR updates the P-TMSI, Open5GS stores the new P-TMSI
in the next field of the mme_ue structure. Upon receiving the TAU Complete
message from the UE, indicating acknowledgment of the new P-TMSI,
Open5GS confirms the update by transferring the P-TMSI from the next field
to the current field. This ensures that the MME maintains an accurate and
up-to-date record of the P-TMSI as confirmed by the UE.
2024-11-05 16:37:45 +09:00
Sukchan Lee
c888e2d62a [SBI] Fixed an issue in SCP TLS communication for Open5GS (#3541)
Fixed an issue in SCP TLS communication for Open5GS where omitted port numbers
in HTTP/HTTPS URIs (e.g., "https://scp.localdomain" implying port 443) were not
handled correctly.

Updated the code to ensure that during FQDN and port comparisons,
cases where the port number is set to 0 are accounted for.

This fix resolves the problem with indirect SBI communication over SCP using TLS
allowing proper connectivity between network functions like BSF and NRF.
2024-11-03 21:47:29 +09:00
Sukchan Lee
2031f7d8a1 [SBI] Make 'global' configuration optional instead of mandatory (#3466)
Previously, the global configuration section was required for NF to start,
which differed from earlier versions where it was optional. This commit modifies
the implementation to make the global section optional again,
allowing NF to start without explicitly defining global settings.

This change restores the previous behavior and improves usability for users
who do not need to customize global settings.
2024-11-01 15:32:46 +09:00
Sukchan Lee
1f42ddace1 [SCP/SEPP] Fixed memory leak in specific exception handling scenarios
The memory leaks occurring in specific exception handling scenarios have been
resolved. For instance, when an HTTP2 connection closes, memory associated
with objects like response messages was not being freed properly.

This update addresses and fixes these issues.
2024-11-01 14:31:11 +09:00
Sukchan Lee
bc02e48d1a [ePDG] Add Node-Identifier IE support in GTPv2 S2b Create-Session-Request for SMF Diameter S6b Routing (#3507)
Implement support for Node-Identifier IE in GTPv2 S2b Create-Session-Request
to SMF for Diameter S6b integration

This patch adds support for processing the Node-Identifier IE within GTPv2
Create-Session-Request messages sent via the S2b interface to the SMF.
When the ePDG includes the Node-Identifier IE containing both host and realm
of the AAA-Server, the SMF now uses this information to populate
the Destination-Realm and Destination-Host AVPs in the Diameter S6b AAR message.

This enables seamless integration and allows the SMF to route requests directly
to the appropriate AAA-Server, enhancing interoperability in setups
where the host and realm data are required by the Diameter network.
2024-10-31 22:22:25 +09:00
Sukchan Lee
ce36143f5c [PFCP] Add Missing 3GPP Interface Type in PFCP Messages
This field was previously omitted, which could lead to
improper handling of interface-specific logic in certain scenarios.

The addition of the 3GPP Interface Type ensures correct behavior
in compliance with the 3GPP standards for PFCP message handling.
2024-10-20 22:54:08 +09:00
Sukchan Lee
151275d708 [PFCP] Fix SGW-U/UPF Bugs and Improve Header Handling
1. Fix SGW-U/UPF bug by comparing QFI only when PDI's QFI is present
Resolved an issue where the QoS Flow Identifier in the GTP-U Extension Header
was incorrectly compared regardless of the presence of PDI's QFI.
Updated the implementation to perform the comparison
only when PDI's QFI is present.

2. Add Outer Header Removal settings to SGW's PDR where necessary
Addressed the absence of Outer Header Removal in the SGW's PDR
by adding it to all required locations, ensuring proper header handling.

3. Remove unnecessary GTP-U Extension Header Removals
Eliminated all instances of GTP-U Extension Header Removal
since they should only be used during handover from 5GS to EPS.
This cleanup prevents improper header removals in other scenarios.

4. Delete unnecessary usage of Network Interface and UE IP Address
Removed all redundant references to Network Interface and UE IP Address,
streamlining the codebase and reducing potential confusion.

5. Change precedence so that Control has higher priority than Data
Adjusted the precedence settings to ensure that Control messages
are given higher priority over Data, enhancing the system's efficiency
and responsiveness.
2024-10-20 18:52:21 +09:00
Sukchan Lee
0e441cf710 [MME] TAI and E_CGI IEs in SGs (#3518)
Added UE's current TAI and E-CGI to SGsAP-LOCATION-UPDATE-REQUEST message
as per TS 29.118 5.2.2.2.1
2024-10-20 16:40:49 +09:00