open5gs/lib
Sukchan Lee dd7c518a56 amf: snapshot RAN-UE ID in SBI transaction to avoid race during SM Context Update
Several users reported intermittent AMF crashes when SM Context Update
procedures overlap with NG context release or a new Registration
procedure. In these situations the RAN-UE associated with a session may
change before the asynchronous SBI response arrives.

Typical trigger scenarios include:

  * UEContextReleaseRequest followed by a new Registration Request
  * PDU Session Update overlapping with UE deactivation or handover
  * Registration Request arriving while a previous Service Request is
    still being processed

In these cases the AMF may send an Update SM Context request to the SMF
while the NG context is being released or replaced. When the asynchronous
SBI response arrives later, the AMF uses the session's current ran_ue
pointer. However, that pointer may already have been switched to a new
RAN-UE or cleared due to the release procedure.

As a result, the AMF may reference the wrong RAN-UE context or an
inconsistent state, eventually triggering an assertion such as:

  amf_nsmf_pdusession_handle_update_sm_context:
      Assertion `ran_ue->deactivation.group' failed

The root cause is that SBI client transactions do not preserve the
RAN-UE association at the time the request was sent. Because SBI
operations are asynchronous, the session context may change before the
response is processed.

This patch introduces a generic mechanism to attach user-defined context
to an SBI transaction:

  - Add `user_data` and `user_data_free` to `ogs_sbi_xact_t`
  - Allow NF-specific code to store per-transaction context
  - Ensure the memory is released automatically when the transaction
    is removed

The AMF now stores a snapshot of the RAN-UE ID in the SBI transaction
when sending an Update SM Context request. When the SBI response is
processed, the AMF retrieves the RAN-UE using this snapshot instead of
the session's current ran_ue pointer. This guarantees that the response
is associated with the correct RAN context even if the session state has
changed in the meantime.

This approach avoids race conditions between asynchronous SBI responses
and NG context lifecycle events, preventing the AMF from accessing an
incorrect or partially released RAN-UE context.

Reported-by:
  multiple users on v2.7.6 environments

Issues: #4174, #4274
2026-03-05 22:30:31 +09:00
..
app [MME] Add Emergency Number List to "Attach Accept" NAS message 2025-10-27 21:28:53 +09:00
asn1c [MME] unify TAU procedure handling and BCS check across all S1AP cases(#4112, #4113, #4117) 2025-10-25 21:31:45 +09:00
core core/sbi: Prevent DoS in requester-features parsing (uint64 overflow) 2026-02-28 09:48:23 +09:00
crypt clang scan-build static analysis findings/resolutions (#3387) 2024-08-16 16:42:12 +09:00
dbi Merge branch 'main' into home-routed 2025-04-06 18:37:36 +09:00
diameter [MME] S6a ULR: Add SMS-Register-Request AVP with SMS in MME Not Preferred 2026-02-25 22:34:31 +09:00
gtp gtp2: Add runtime boundary validation in ogs_gtp2_parse_tft() 2026-02-28 22:17:00 +09:00
ipfw pfcp/ipfw: Improve error handling in PDR creation/update and ipfw rule parsing 2025-11-20 16:39:17 +09:00
metrics [metrics] fix memory leak 2025-11-13 20:02:25 +09:00
nas Follow up on #4102 2025-10-27 21:31:21 +09:00
ngap [MME/AMF] Fixed crash following Handover Request (#3014) 2024-02-29 23:02:38 +09:00
pfcp core,gtp,pfcp,sgwc: avoid fatal asserts on pool and timer exhaustion 2025-12-30 11:49:40 +09:00
proto Fix DNN Operator-Identifier format and refactor OI parsing for HR roaming interop 2025-12-06 22:23:34 +09:00
s1ap [Release-17] Upgrade S1AP/NGAP to v17.3.9 2023-02-21 21:48:06 +09:00
sbi amf: snapshot RAN-UE ID in SBI transaction to avoid race during SM Context Update 2026-03-05 22:30:31 +09:00
sctp [PFCP] Refactor PFCP address handling (#3431) 2025-01-11 20:33:02 +09:00
tun [AMF] Follow-up on #3880 2025-06-17 17:34:18 +09:00
meson.build [SEPP] Initial Update for 5G Roaming (#2739) 2023-11-19 19:34:51 +09:00