Summary
Kamailio's ims_qos_npn module has a stack-based buffer overflow when it copies an attacker-controlled host value from a SIP Via header into a fixed-size buffer without checking its length. An unauthenticated remote attacker may trigger the flaw with a crafted SIP REGISTER request, corrupting stack memory and causing the affected instance to terminate.
Affected context
The issue is reported in Kamailio v6.1.3 and v6.1.4, in the ims_qos_npn module's w_rx_aar_register() function. It becomes a risk when a deployment processes SIP REGISTER requests through this function and the host value from the Via header is copied into the fixed-size stack buffer without length validation.
Exploit preconditions
- Attack surface: SIP request handling by the affected Kamailio module
- Required access: No authentication is required; the attacker needs network reachability to the SIP service
- Trigger point: Processing a crafted
REGISTERrequest containing aViaheader - Why exploitation is possible: The attacker-controlled host value is copied into a 46-byte stack buffer without validating its length
Why this happens
The function copies input from a SIP header into a fixed-size stack buffer without first ensuring the value fits. This is an input-validation weakness (CWE-20) that leads to an out-of-bounds write (CWE-120), specifically a stack-based buffer overflow (CWE-121). The resulting stack corruption can terminate the process; the supplied description identifies denial of service as the impact.
Potential impact
- The affected Kamailio process may terminate, disrupting SIP service
- SIP registration handling may become unavailable until service is restored
- Repeated triggering could cause continued service disruption
General mitigation guidance
Defensive patterns include validating the length and format of header-derived values before copying them, and using bounded operations or dynamically sized storage rather than fixed-size buffers for variable-length input. Treat SIP headers as untrusted, reject values that exceed defined limits, and ensure error handling does not leave the service in an unstable state. Run the service with only the privileges it needs and limit network exposure to trusted SIP peers where feasible.
How teams detect issues like this
- Use static analysis to identify copies into fixed-size buffers where source lengths are not checked or destination bounds are not enforced.
- Review SIP header parsing and handling paths for attacker-controlled values passed to stack buffers.
- Monitor for crashes or restarts in Kamailio associated with malformed or unusually long SIP headers.
- Apply input-size limits and protocol validation at relevant network boundaries, with logging for rejected requests.

