The vulnerability lies in the SPDY/3 frame parser of the moby/spdystream library, where it fails to validate attacker-controlled counts and lengths before allocating memory. This can be exploited by a remote attacker sending a small number of malformed SPDY control frames, causing the server to allocate gigabytes of memory, leading to an out-of-memory crash and a denial of service.
The analysis of the patches between the vulnerable version v0.5.0 and the fixed version v0.5.1 reveals three primary vulnerable functions:
-
(*spdy.SettingsFrame).read: This function handled SPDY SETTINGS frames. The vulnerability was in its failure to check the numSettings field against the actual frame payload length. The patch adds a bounds check (numSettings <= (length-4)/8) to ensure the number of settings is consistent with the frame size before allocating memory.
-
spdy.parseHeaderValueBlock: This function was responsible for parsing header blocks in SYN_STREAM, SYN_REPLY, and HEADERS frames. It was vulnerable to two distinct allocation attacks: one based on an excessive number of headers (numHeaders) and another on an excessive size for individual header names or values. The patch introduces configurable limits for both the header count and the individual field sizes and refactors the function to be a method of the Framer struct to access these limits.
-
(*spdy.Framer).parseControlFrame: This is a general-purpose function for parsing control frames. It was vulnerable because it didn't limit the length field of the control frame header. The patch adds a check to ensure the frame's length does not exceed a configured maximum payload size, preventing large allocation attempts.
An attacker would trigger these vulnerabilities by sending a specially crafted SPDY frame (e.g., SETTINGS, SYN_STREAM) that contains inflated length or count values. The vulnerable functions, upon parsing these frames, would then attempt to allocate an unreasonable amount of memory, causing the process to crash.