4783 Commits

Author SHA1 Message Date
herlesupreeth
8e286b67f1 [PCF] Add AF in list of allowed NF types for PCF 2025-05-08 11:20:25 +09:00
Spencer Sevilla
a82a63bb1f need to NULL out poll/sock pointers to prevent mme crash on vlr detach 2025-05-07 21:29:57 +09:00
Sukchan Lee
cfa4457502 [AMF/MME] Remove fatal assertions on oversized SCTP messages in NGAP and S1AP handlers (#3878)
Previously, any SCTP recv would trigger ogs_fatal and an assert_if_reached
when MSG_EOR wasn’t set, causing the AMF or MME to crash on oversized
or fragmented packets. Since we rely on a 32 KB receive buffer and
do not support SCTP reassembly, this change replaces the conditional
fatal/assert logic with a single ogs_error call in both ngap_recv_handler
and s1ap_recv_handler.

Oversized or partial SCTP messages are now logged and dropped instead of
crashing the process.
2025-05-06 17:52:51 +09:00
Sukchan Lee
62cb997552 [AMF/MME] Modify common_register_state to handle missing UE contexts gracefully (#3874)
Previously, both AMF and MME assumed that RAN UE contexts would always
be present, triggering fatal assertions when a context lookup failed.

This change introduces explicit checks in the common_register_state handlers
to detect missing NG and S1 contexts without crashing:
2025-05-06 16:28:48 +09:00
Sukchan Lee
9a524df8c0 Merge branch 'main' of https://github.com/open5gs/open5gs 2025-05-06 15:49:33 +09:00
Sukchan Lee
aab6940cd5 [AMF] improve HTTP/2 timeout handling and error logging (#3862, #3863)
- Check ran_ue existence and abort if NG context has already been removed
- Detect deassociated RAN-UE (invalid amf_ue_id) and
  break to avoid further processing
- Validate AMF-UE ID matches ran_ue->amf_ue_id and skip on mismatch
2025-05-06 15:47:17 +09:00
Sukchan Lee
3b53144ca5 [AMF/MME] default to Non-GBR flow when MBR/GBR parameters are missing (#3858)
- Replace hard assertions on MBR/GBR presence in S1AP e‐RAB setup
  with a runtime check: if any of the four parameters (MBR DL/UL, GBR DL/UL)
  is missing, log an error and treat the bearer as Non-GBR
- Mirror the same logic in SMF’s NGAP build routines for PDU Session Resource
  Setup and Modify transfers: drop the assertions, emit detailed error messages
  with the missing MBR/GBR values, and omit GBR IEs
- Ensures graceful handling of incomplete QoS configurations by defaulting
  to best‐effort (Non-GBR) rather than crashing
2025-05-05 22:06:44 +09:00
Sukchan Lee
2231e48870 [AMF] guard ran_ue to avoid assertion crash [#3851]
If `ran_ue` has already been removed, log a warning using the UE’s SUPI
instead of triggering an assertion failure.
2025-05-05 10:14:48 +09:00
Sukchan Lee
c145fc88aa [NRF] prevent invalid NF type registration DoS (#3846)
Ensure that NFs with invalid types are rejected and never added,
preventing the denial-of-service crash.
2025-05-05 09:54:29 +09:00
Sukchan Lee
e0dc936016 [NRF] reject SELF nf instance in SBI operations (#3845)
Prevent the NRF from processing requests that target its own
instance ID. This prevents a denial of service vulnerability.
If an SBI request attempts to delete or modify the local NRF
instance, respond with 404 Not Found and log an error, avoiding
a crash due to the state machine assertion.
2025-05-05 09:32:25 +09:00
Sukchan Lee
3706479582 [ipfw] guard token parsing loop against buffer overflow
The token parsing loop in ogs_ipfw_compile_rule() lacked a bound on the
number of tokens stored in the 'av' array. This could overflow the stack
buffer when parsing overly long flow descriptions. Add a check to ensure
'i' remains below MAX_NUM_OF_TOKEN-2 before assigning to 'av[i]'.
2025-05-05 07:55:45 +09:00
Sukchan Lee
ca61a901d5 Implement PDU Session Release for Home-Routed Roaming and fix N4 step ordering in 4.3.4.2
- Add support for PDU Session Release in 3GPP TS 23.502 section 4.3.4.3
  Note: PCF-initiated release flow for Home-Routed Roaming is not implemented;
- Fix N4 release step ordering in 3GPP TS 23.502 section 4.3.4.2 UE or network requested PDU Session Release for Non-Roaming and Roaming with Local Breakout
2025-05-02 21:28:25 +09:00
ethonshield
7b40d5a3f1 Add tutorial doc on how to configure Open5GS with 5G-Sharp-Orchestrator 2025-04-29 22:46:14 +09:00
Spencer Sevilla
4c2f40d2c2 more verbose DNN reject message 2025-04-27 08:15:51 +09:00
Pallavi Das
fba00abd75 Typos Fix 2025-04-27 08:14:54 +09:00
Sukchan Lee
d3edce9e91 [UDM] Update UE state machine to handle authentication retrieval errors (#3864)
- In `udm_ue_state_operational()`:
  - Wrap the call to `udm_nudr_dr_handle_subscription_authentication()`
    in an `if` check.
  - On failure (`false`), log an error via
    `ogs_error("udm_nudr_dr_handle_subscription_authentication() failed")`.
  - Transition the FSM to `udm_ue_state_exception` using `OGS_FSM_TRAN()`.

This change ensures that failures during subscription authentication
REST calls are not silently ignored, and that the UE state machine moves into
an exception state for proper error handling and recovery.
2025-04-19 20:57:39 +09:00
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
d66d6f868a Merge branch 'main' into home-routed 2025-04-06 18:37:36 +09:00
Sukchan Lee
46f74c8019 Merge branch 'main' into home-routed 2025-04-06 18:36:57 +09: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 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