Commit graph

4657 commits

Author SHA1 Message Date
Pallavi Das
cd80aa432e Typos Fix 2025-04-19 20:45:25 +09:00
shellwayxw
90cb00ced3 Always make fqdn a NULL terminated string 2025-04-17 17:14:15 +09:00
shellwayxw
31d3f575d2 Fix stack overflow in ogs_pfcp_extract_node_id() 2025-04-17 17:14:15 +09:00
shellwayxw
726b588d76 Fix integer overflow in PFCP ogs_pfcp_parse_sdf_filter() 2025-04-17 17:14:15 +09:00
Sukchan Lee
1182a99d04 [AMF/MME] Fix potential buffer overflow in ASCII-to-USC2 conversion
In amf_context_parse_config(), update the loop condition to ensure that
((i * 2) + 1) remains below
(OGS_NAS_MAX_NETWORK_NAME_LEN - 1) before performing any writes.
This change prevents potential out-of-bounds memory writes during
the conversion of an ASCII string to USC-2, thereby fixing a buffer
overflow issue.

This issue was observed on Ubuntu 25.04 and reported in the osmocom
nightly package.
2025-04-13 06:55:22 +00:00
Sukchan Lee
9217889f8a [HSS,S6A] Add two Supported-Features AVPs to ULA for 5G-NSA roaming (#3832)
This commit adds support for two Supported-Features AVPs in the
UpdateLocationAnswer (ULA) to enable 5G-NSA roaming. The first AVP
includes subscriber restrictions, while the second AVP signals that NR
as Secondary RAT is supported. Updates include modifications to
lib/diameter/s6a/message.c, lib/diameter/s6a/message.h, and
src/hss/hss-s6a-path.c.
2025-04-06 17:01:54 +09:00
Sukchan Lee
6af18a15c3 [SMF] Add userLocationInfo and timeZone to PCF SM Policy request (#3755)
This commit enhances the SM Policy request sent to the PCF
by incorporating user location information and time zone data.

The SMF now builds a userLocationInfo structure using the session's NR TAI
and NR CGI details, along with a timestamp generated from the current GMT time.

Additionally, the UE's time zone is included in the request context,
and the ratType is explicitly set to NR.
2025-04-06 11:18:49 +09:00
Sukchan Lee
bf1cb6a024 [HSS/DBI] Follow-up on #3829 2025-04-05 18:26:32 +09:00
Farzaneh_sz
51acc388a6 get ifc data from db and insert in cx user data 2025-04-05 18:24:32 +09:00
Sukchan Lee
7dfd9a3964 Release v2.7.5 2025-03-30 22:05:34 +09:00
Sukchan Lee
b326b99f28 [CORE] Fix busy loop and blocking in curl with EPOLLERR handling in Open5GS 2.7.x (#3807, #2411, #2312)
In Open5GS 2.7.x, when using curl 8.x with external epoll, an issue occurred
where the peer connection was closed, triggering EPOLLERR. At this point,
POLL_OUT should have been set to trigger the write event handler, invoking
`event_cb()` and calling `curl_multi_socket_action`. This would allow
`curl_multi_info_read` to execute without blocking.

However, when `event_cb()` wasn't invoked, `curl_multi_socket_action` was
not called, causing `curl_multi_info_read` to block. This resulted in a busy
loop in epoll, continuously checking for the closed peer connection.

This issue specifically affects Open5GS 2.7.x with curl 8.x, and is observed
on Ubuntu versions starting from **noble** and later. It does not occur on
Ubuntu Jammy.

The solution involves globally ignoring SIGPIPE and fixing the epoll logic
to ensure POLL_OUT is triggered when EPOLLERR occurs, allowing `curl_multi_socket_action`
to be invoked and `curl_multi_info_read` to run non-blocking. This resolves
the busy loop and connection issues caused by peer disconnects when using
curl 8.x and external epoll.

This fix improves the stability and performance of Open5GS when used with
curl 8.x and Ubuntu versions **noble** and above.
2025-03-30 21:46:31 +09:00
Sukchan Lee
33fb33be45 Update document for v2.7.4 2025-03-26 20:08:31 +09:00
Sukchan Lee
555395a8e8 Release v2.7.4 2025-03-27 04:46:16 +09:00
Sukchan Lee
ae6cedf8e8 Revert "[SBI] replace calls to free_<nf>_info() with OpenAPI_<nf>_info_free()"
This reverts commit 7ad40395a0.
2025-03-26 10:04:06 +09:00
Sukchan Lee
704083db3b [SBI] Fix improper inclusion of callback headers in non-callback requests (#3798)
This commit fixes an issue where the callback header (3gpp-Sbi-Callback)
was incorrectly added in non-callback requests. Specifically, for registration
(PUT) and subscription requests in the AMF and SMF modules, the callback
header was included even though these are not asynchronous notifications.

Changes include:
- Removing the callback header assignment in src/amf/nudm-build.c and
  src/smf/nudm-build.c for registration and subscription requests.
- Removing the callback header in NRF subscription-related builds in
  lib/sbi/nnrf-build.c where it was not required.
- Adding the callback header only for actual notification or callback
  operations (e.g. in src/amf/nsmf-build.c for N1/N2 transfer failure and
  in src/nrf/nnrf-build.c for NF status notifications).
- Introducing a new callback macro in lib/sbi/message.h for
  Namf_Communication_onN1N2TransferFailure.

This aligns the implementation with the standard, ensuring that callback
headers are only included in genuine callback/notification messages.
2025-03-25 14:50:20 +09:00
Sukchan Lee
1d46a0e475 Update document for v2.7.3 2025-03-23 12:55:19 +09:00
Sukchan Lee
e16a8fc42e Release v2.7.3 2025-03-23 11:56:01 +09:00
Sukchan Lee
708f789792 [UPF/SGWU] fix: validate f_teid_len to avoid TEID swap bug on restart (#3747, #3574)
When UPF/SGW-U is restarted, missing f_teid_len validation causes an error.
This patch adds checks for f_teid_len > 0 in ogs_pfcp_pdr_swap_teid and
in the SGW-U and N4 handler functions.
2025-03-23 11:21:03 +09:00
Sukchan Lee
a5510f1870 [AMF/MME] Fix segfault on NG/S1 handover cancel by checking for NULL target UE (#3789)
When a UE handover occurs, the target UE may already be removed. This
patch adds a NULL pointer check and logs an error instead of causing a
segmentation fault in both enb and sgw deassociation functions.
2025-03-21 20:30:08 +09:00
Bostjan Meglic
fa3edde329 [NAS] add support for 30-seconds unit for GPRS3 timer 2025-03-21 17:52:12 +09:00
Sukchan Lee
63d26667bc [AMF/MME] Fix UE context deletion vulnerability using memento restoration (#3754)
Renamed backup/restore security context functions to save/restore
memento and updated flag to "can_restore_context". Updated AMF and MME
state machines to restore context on failure, preventing malicious
deletion triggered by spoofed NAS messages.
2025-03-21 17:28:47 +09:00
Sukchan Lee
10b161fbb9 [AMF] Refactor AMF Region ID Handling (#3778)
- Changed amf_region_id type from uint16_t to uint8_t in context.h.
- Updated context.c to use ogs_amf_region_id() for extracting and comparing
  the region ID.
2025-03-16 12:22:39 +09:00
Bostjan Meglic
9e6b86b84e [AMF] fix AmfInfo when AMF Set Id was configured beyond 4
AMF Set Id is 10 bits long. Previously only the 2 bits from field "set2"
were used.
2025-03-16 12:12:18 +09:00
Bostjan Meglic
49c5a280da [AMF,SBI] add support for TAI ranges in AmfInfo
- fix an out-of-array-bounds-write to nf_info->amf.nr_tai during list1
TAI parsing, in case that sum of ranges of TAC's was bigger than 16
(OGS_MAX_NUM_OF_TAI).
- add checks for out-of-array-bounds
- fix indents
- fix error check
- subjectively prettify the code

[sbi] DEBUG: ogs_sbi_nf_state_will_register(): ENTRY (../lib/sbi/nf-sm.c:208)
[sbi] ERROR: CHECK CONFIGURATION: No Start/End in TacRange (../lib/sbi/nnrf-build.c:1094)
[sbi] FATAL: ogs_nnrf_nfm_build_nf_profile: Assertion `AmfInfo' failed. (../lib/sbi/nnrf-build.c:342)
[core] FATAL: backtrace() returned 13 addresses (../lib/core/ogs-abort.c:37)

Example configuration with which to trigger AMF crash before the fix:

guami:
  - plmn_id:
      mcc: "001"
      mnc: "01"
    amf_id:
      pointer: 31
      region: 2
      set: 1
  - plmn_id:
      mcc: "999"
      mnc: "93"
    amf_id:
      pointer: 31
      region: 2
      set: 1
  - plmn_id:
      mcc: "010"
      mnc: "310"
    amf_id:
      pointer: 32
      region: 2
      set: 1
tai:
  - plmn_id:
      mcc: "001"
      mnc: "01"
    tac:
      - 1
      - 5-6
  - plmn_id:
      mcc: "999"
      mnc: "93"
    tac:
      - 1
      - 11
  - plmn_id:
      mcc: "010"
      mnc: "310"
    tac:
      - 1011
      - 1020-1030
2025-03-16 12:12:18 +09:00
Bostjan Meglic
8f008c8440 [SBI] replace manual free's with calls to OpenAPI_<struct>_free() 2025-03-16 12:12:18 +09:00
Bostjan Meglic
7ad40395a0 [SBI] replace calls to free_<nf>_info() with OpenAPI_<nf>_info_free() 2025-03-16 12:12:18 +09:00
Sukchan Lee
106a9accd4 [AMF/MME] Fix security context restoration and state transition cleanup (#3756)
- Backup sensitive security context fields (e.g. xres, kasme, rand, autn,
  keys, counters) when transitioning from REGISTERED state.
- Set the can_restore_security_context flag in common_register_state()
  based on whether the transition originates from a REGISTERED or
  de-registered state.
- In emm_state_authentication(), restore the security context and revert
  to the REGISTERED state on authentication failure only if restoration
  is allowed; otherwise, transition to an exception state.
- Remove the redundant unconditional state transition in the cleanup block
  to prevent overriding a valid restoration.
2025-03-16 11:57:14 +09:00
Sukchan Lee
e3dd98cd29 [PFCP] Prevent buffer overflow in PFCP context by using safe string copy (#3775)
Replace unsafe strcpy calls with ogs_cpystrn in both ogs_pfcp_dev_add()
and ogs_pfcp_subnet_add() to ensure proper length checking.

This change prevents potential buffer overflows when handling ifname
and dnn fields, which could otherwise lead to unintended overwrites
(e.g., fd and num_of_range).
2025-03-12 17:50:17 +09:00
Sukchan Lee
70310979c5 [KSI] Update EPC KSI issuance to match 5G Core behavior
Previously, the EPC used the UE-provided KSI directly in the Authentication
Request (except for the special case where the UE sent
OGS_NAS_KSI_NO_KEY_IS_AVAILABLE, which was reset to 0).

This commit changes the EPC to follow the 5G Core approach
for issuing KSI in Attach-Request.

Now, when a Attach Request is received and a new Authentication Vector is
generated, the EPC performs the following steps:

- Extract the KSI value from the UE's request.
- Increment the extracted KSI by 1.
- Use the incremented KSI in the Authentication Request sent to the UE.

This detailed process ensures that the EPC issues the KSI consistently
with 5G Core standards, improving key management and interoperability.
2025-03-10 15:15:47 +09:00
Sukchan Lee
1abc3b6d5f [SMF] Separate EPC-only attach config to avoid NRF register timeout
Previously, sample.yaml was used for both 5GC and EPC attach tests.
Because SMF had SBI configured, it sent a register PUT to NRF even in
EPC-only tests (where nrf/scp was not run), leading to a missing HTTP
response and connection timer expiry.

Now, attach.yaml is used for EPC, preventing the unwanted NRF registration.
2025-03-10 09:53:00 +09:00
jmasterfunk84
ec7c9a80c1 Ignore MIP-H-A-H 2025-03-07 10:23:01 +09:00
Sukchan Lee
cb2359dca0 [PFCP] Validate F-TEID parameters to prevent UPF/SGWU crash (#3747)
This commit introduces robust validation for the F-TEID information element
in the PFCP message handling. Previously, malformed F-TEID values (such as
a zero length, zero TEID, or a TEID exceeding the pool size) could lead
to an assertion failure and crash the UPF.

The changes ensure that:
- The F-TEID length is greater than zero, confirming the IE is present.
- The TEID is a non-zero value, as a valid TEID must be positive.
- The TEID does not exceed the allowed pool size (max_ue * 4 * 16).

If any of these conditions are not met, an error is logged with the F-TEID
length and TEID value, and the function returns an error code
(OGS_PFCP_CAUSE_MANDATORY_IE_INCORRECT), preventing further processing
of the malformed message.
2025-03-07 10:14:57 +09:00
Sukchan Lee
4012f572ed [SBI] Send GOAWAY on shutdown for all sessions to prevent RST (#3470)
When another NF restarts, curl reuses the existing connection, which in
curl 8.9.1 causes the nghttp2 server to send an RST. This commit sends a
GOAWAY frame to every active session on shutdown, ensuring a graceful
termination and avoiding RST errors.

Previous versions such as curl 7.81.0 did not exhibit this behavior.
2025-03-04 14:32:57 +09:00
Sukchan Lee
d187ce245b [SBI] Fix NF recovery failure on NF restart (#3740)
Previously, nf_instance pointers were stored in nf_type_array and
service_type_array. This led to dangling pointers when an NF instance
was removed via ogs_sbi_nf_instance_remove(), causing incomplete cleanup
and improper recovery on UDR or other NF restarts. The issue resulted in
the system falling back to nf_instance->client with the default port 80,
leading to connection failures.

To resolve the problem, nf_instance_id is now stored instead of the
pointer. The validity of an NF instance is verified using
ogs_sbi_nf_instance_find(nf_instance_id), which ensures proper cleanup
and correct recovery.
2025-03-04 14:32:57 +09:00
Sukchan Lee
6c67863971 [SEC] Fix crash when max_num_of_ostreams < 2 2025-02-28 16:44:17 +09:00
Bostjan Meglic
6fe6b88d9b [all] fix possible null dereference when using ProblemDetails
In case that NF do not send ProblemDetails in the response.
Do not assume that ProblemDetails is always present, to prevent null
pointer dereferencing.
2025-02-28 16:15:16 +09:00
Sukchan Lee
8cae6112cc [SEC] Fix crash in eNBDirectInformationTransfer due to missing Inter_SystemInformationTransferType
This commit resolves an issue where the system would crash
when Inter_SystemInformationTransferType was not present.
2025-02-28 14:27:10 +09:00
jmasterfunk84
8bdfdcf5df
[AUSF] Cleanup ausf_ue when it is not found in UDM (#3743)
* Remove ausf_ue when unknown in UDM

* cover both error cases
2025-02-28 07:08:03 +09:00
jmasterfunk84
f98d0a780d
[AUSF] Check length of SUCI_or_SUPI before trying to process (#3742)
* Check length of supi/suci

* check all the things
2025-02-28 07:07:24 +09:00
Sukchan Lee
1b21eba81e [UPF] Fixes: Crash in upf_sess_set_ue_ip when PDN type is invalid (#3727)
When receiving a PFCP Session Establishment Request with an invalid PDN type(0),
the UPF would crash due to a failed assertion.

This commit improves error handling by:

- Removing the session_type assertion check that caused the crash
- Changing warning log to error log for better visibility
- Returning CAUSE_SERVICE_NOT_SUPPORTED instead of proceeding
  with invalid type

This prevents potential DoS attacks through malformed PFCP messages.
2025-02-24 20:54:35 +09:00
Bostjan Meglic
6a2225bb68 [SBI] retrieve all currently registered NF's on app startup
Before this, there were 2 different ways to search for neighbouring
NF's:

a) in the case AMF was started _before_ UDM, AMF would create
subscription to NRF to notify it when a UDM would (un)register. In this
case, NF instance would remain in AMF's context indefinitely.

b) in the case AMF was started _after_ UDM, AMF would have to use NF
discovery mechanism to search for NF's. In this case, NF instance would
remain in AMF's context for the duration of Search's validity (defaults
to 30 seconds). After validity expires, NF would expire. This means that
for heavy traffic situations, AMF would constantly issue discovery
requests.

[SBI] save only wanted NF instances on NF List Retrieval

When retrieving a list of NF Instances from NRF, save only the NF's that
we want. Check the NF instance against our subscription list for either
the NF type or NF Service.
This can still cause a DoS on NRF when NF starts in case there are 100's
of NF's in the network, but prevents using too much memory on NF.
2025-02-20 20:13:18 +09:00
Spencer Sevilla
ba05380f5b also adding a default config option for newly generated sbi connections 2025-02-14 20:03:09 +09:00
Spencer Sevilla
68c6310717 add option to support curl binding local interface/ip for sbi calls 2025-02-14 20:03:09 +09:00
Bostjan Meglic
b32b1e981b [PFCP] fix crash for when PFCP NodeId is FQDN
Test scenario:
- start 5G core
- wait for 5 minutes after SMF establishes PFCP association to UPF (DNS
query refresh interval)
- register UE and establish PDU session
- crash

[upf] DEBUG: upf_state_operational(): UPF_EVT_N4_MESSAGE (../src/upf/upf-sm.c:51)
[upf] DEBUG: upf_pfcp_state_associated(): UPF_EVT_N4_MESSAGE (../src/upf/pfcp-sm.c:185)
[upf] INFO: [Added] Number of UPF-Sessions is now 1 (../src/upf/context.c:217)
[upf] DEBUG: Session Establishment Request (../src/upf/n4-handler.c:66)
[gtp] INFO: gtp_connect() [127.0.0.8]:2152 (../lib/gtp/path.c:60)
[upf] INFO: UE F-SEID[UP:0x1230 CP:0x5817] APN[local] PDN-Type[1] IPv4[10.46.0.2] IPv6[] (../src/upf/context.c:532)
[upf] INFO: UE F-SEID[UP:0x1230 CP:0x5817] APN[local] PDN-Type[1] IPv4[10.46.0.2] IPv6[] (../src/upf/context.c:532)
[upf] DEBUG: Session Establishment Response (../src/upf/n4-build.c:36)
[pfcp] FATAL: ogs_pfcp_sendto: should not be reached. (../lib/pfcp/path.c:158)
[core] FATAL: backtrace() returned 12 addresses (../lib/core/ogs-abort.c:37)
/open5gs/build/src/upf/../../lib/pfcp/libogspfcp.so.2(ogs_pfcp_sendto+0x1c8) [0x7f73c5ac0888]
/open5gs/build/src/upf/../../lib/pfcp/libogspfcp.so.2(ogs_pfcp_xact_commit+0x170) [0x7f73c5ac3510]
/open5gs/./build/src/upf/open5gs-upfd(+0x109eb) [0x55d7f20f99eb]
/open5gs/./build/src/upf/open5gs-upfd(+0x12351) [0x55d7f20fb351]
/open5gs/build/src/upf/../../lib/core/libogscore.so.2(ogs_fsm_dispatch+0x24) [0x7f73c5b57574]
/open5gs/./build/src/upf/open5gs-upfd(+0xc445) [0x55d7f20f5445]
/open5gs/build/src/upf/../../lib/core/libogscore.so.2(ogs_fsm_dispatch+0x24) [0x7f73c5b57574]
/open5gs/./build/src/upf/open5gs-upfd(+0x77fb) [0x55d7f20f07fb]
/open5gs/build/src/upf/../../lib/core/libogscore.so.2(+0xfb05) [0x7f73c5b4cb05]
/lib/x86_64-linux-gnu/libc.so.6(+0x9ca94) [0x7f73c551ea94]
/lib/x86_64-linux-gnu/libc.so.6(__clone+0x44) [0x7f73c55aba34]
2025-02-13 22:44:43 +09:00
Juan Pontón Rodríguez
f1e1f4a2a9 Update context.c 2025-02-13 20:20:34 +09:00
Sukchan Lee
8715915469 [UDM/UDR] Follow up on #3690 2025-02-11 07:04:42 +09:00
jmasterfunk84
600a7629ad
[UDM][UDR] Add support for nssai resource in nudm-sdm (#3690)
* [UDM][UDR] Add support for nssai resource in nudm-sdm

* Resolve Memory Issue

* Protect from multiple field entries, remove macros

* remove request_from_server, make use of xact state

* typo....

* definition cleanup
2025-02-11 07:03:06 +09:00
Sukchan Lee
056b50c9c8 [AMF] Fix crash on duplicate PDU session requests due to NULL SUPI (#3710)
When a duplicate PDU session establishment is received, the AMF logs a
warning and proceeds to update the SM context via the SBI interface. This
process eventually calls amf_nsmf_pdusession_build_create_sm_context(), which
uses the SUPI to build the SBI URI header. If the SUPI is NULL, then the header's
resource component becomes NULL. This leads to a call to ogs_uridup() that
asserts on the NULL value, causing a crash.

This commit adds a check before invoking the SBI update. If the SUPI is NULL,
the update is skipped and a warning is logged. This prevents the invalid URI
build process and avoids the subsequent crash in ogs_uridup().
2025-02-06 21:26:06 +09:00
Sukchan Lee
e31e9965f0 [AMF] Fix AMF crash during UE handover by handling unexpected SBI responses (#3707)
During handover between two gNBs, the AMF enters an invalid state when it
receives an unexpected SBI response from the UDM in the process of sending
a smf-select-data request. This bug could lead to an AMF crash as the state
machine in gmm_state_registration encountered an unknown state.

The fix adds explicit handling for SBI messages with resource names such as
AM_DATA, SMF_SELECT_DATA, UE_CONTEXT_IN_SMF_DATA, and SDM_SUBSCRIPTIONS.
If the HTTP response status is not OK, CREATED, or NO_CONTENT, a warning
is logged and the message is ignored. This prevents the AMF from transitioning
into an abnormal state and improves overall stability during frequent handovers.
2025-02-06 20:56:04 +09:00
Sukchan Lee
07cb42110e [DBI] Improve YAML policy config by adding SUPI range filtering
Previously, policies were configured via YAML files without MongoDB.
This update enhances the YAML approach by adding the 'supi_range' key to
filter policies based on UE SUPI ranges. When both 'supi_range' and
'plmn_id' are provided, both conditions must be met.

Note that PLMN-ID filtering will be deprecated in a future release.
2025-02-05 21:56:15 +09:00