The vulnerability, described as 'Improper Restriction of Operations within the Bounds of a Memory Buffer' in the 'NGReset Message Handler', is caused by insufficient validation of input from NGAP and NAS messages. The provided patch addresses multiple instances of this issue across the codebase.
The analysis of the patch 34bc6724acc97dba1f8691e586da95b042cb612d reveals several key vulnerable functions:
-
ngap.HandleNGReset: The vulnerability description explicitly mentions the 'NGReset Message Handler'. The patch confirms a flaw where the code could attempt to dereference a nil pointer if a UE context was not found, leading to a crash. This is a classic denial-of-service vulnerability triggerable by a malformed NGReset message.
-
util.PlmnIdStringToModels: This function had a critical flaw where it did not validate the length of its input string before slicing it. An input string shorter than 3 characters would cause an out-of-bounds read and a panic. This is a direct example of the 'Improper Restriction of Operations within the Bounds of a Memory Buffer' (CWE-119) mentioned.
-
gmm.HandleRegistrationRequest and gmm.HandleIdentityResponse: These functions were vulnerable because they used the flawed util.PlmnIdStringToModels function to parse data from incoming messages. A malformed SUCI in either a registration request or an identity response could trigger the panic in the utility function, crashing the service.
-
nas_security.FetchUeContextWithMobileIdentity: This function was vulnerable to an out-of-bounds read when processing a deregistration request. It accessed the first element of a slice without checking if the slice was empty, which could be caused by a malformed message.
In all these cases, a remote attacker could craft a malicious NGAP or NAS message to trigger a panic, resulting in a denial of service of the AMF component. The patch mitigates these issues by adding the necessary nil checks and input validation to prevent crashes.