The vulnerability lies in the Free5GC Access and Mobility Management Function (AMF) and its failure to comply with 3GPP standards for concurrent security procedures. Specifically, the AMF does not correctly handle the interplay between N2 handover procedures and NAS Security Mode Command (SMC) procedures, as required by 3GPP TS 33.501 §6.9.5.1.
The root cause is a lack of cross-procedural checks in two key functions:
-
handleHandoverRequiredMain in internal/ngap/handler.go: This function is responsible for initiating the N2 handover procedure. The vulnerability occurs because the function sets the OnGoingProcedureN2Handover state without first checking if a NAS SMC procedure is already in progress. This violates the 3GPP rule that prohibits starting a new N2 procedure while an SMC is ongoing.
-
SecurityMode in internal/gmm/sm.go: This function handles the NAS security mode procedure. It is vulnerable because it initiates the SMC procedure on EntryEvent without checking if an N2 handover is already in progress. This violates the 3GPP rule that prohibits initiating an SMC procedure while an N2 procedure is ongoing.
The concurrent execution of these two procedures can lead to a race condition, resulting in a mismatch of security keys (KAMF and KgNB) between the User Equipment (UE), the source gNB, and the target gNB. This mismatch can compromise the integrity of the communication channel and may lead to handover failures or other service disruptions. The vulnerability is a classic example of CWE-358: Improperly Implemented Security Check for Standard.