Fix N2 handover integrity failures by enabling ciphering during handover setup
Problem: During N2 handover with integrity protection (NIA1/NIA2), the target gNB was disabling ciphering when configuring SRB1 security, while the UE continued using the old security context from the source gNB until it received and processed the RRC Reconfiguration with masterKeyUpdate. The first PDUs sent after CFRA were still ciphered with the old keys, but the target gNB had ciphering disabled, causing it to skip deciphering and attempt integrity verification on ciphered data, leading to MAC-I mismatches and integrity failures. Specification Reference: According to TS 33.501 section 6.11, "the UE shall keep the K gNB used in the source cell until the handover or a connection re-establishment has been completed successfully". This means the UE continues using the old security context (old KRRCint, KRRCenc) until it receives and processes the RRC Reconfiguration with masterKeyUpdate. The target gNB must therefore enable ciphering during handover setup to correctly decipher and verify integrity of PDUs sent with the old security context before the UE switches to the new keys. Root Cause: The code was calling nr_rrc_pdcp_config_security(UE, false) during handover setup, which disabled ciphering. This was incorrect because: 1. The UE already has security active from the source gNB 2. The UE continues using old ciphered keys until masterKeyUpdate 3. The UE sends ciphered PDUs immediately after CFRA succeeds 4. The target gNB must be able to decipher these PDUs to verify integrity Why it only manifested when drb_integrity = "yes": The bug was always present, but only caused visible failures when integrity verification was enabled. When drb_integrity = "no", the config typically also sets integrity_algorithms to only NIA0, resulting in UE->integrity_algorithm = 0, which causes has_integrity = 0 for SRB1, skipping integrity verification and hiding the underlying ciphering bug. When drb_integrity = "yes", integrity_algorithms typically includes NIA1/NIA2, resulting in has_integrity = 1 for SRB1, causing integrity checks to run on ciphered data and fail. Fix: Change nr_rrc_pdcp_config_security(UE, false) to nr_rrc_pdcp_config_security(UE, true) during handover setup to enable ciphering immediately, allowing the target gNB to correctly decipher and verify integrity of PDUs sent with the old security context. Note: This fix is specific to handover. During initial context setup, ciphering should remain disabled until SecurityModeComplete is received, as the UE hasn't activated ciphering yet at that point.
Showing
Please register or sign in to comment