CVE-2025-68656
Executive Summary
CVE-2025-68656 is a critical use-after-free vulnerability in the Espressif ESP-IDF USB Host HID (Human Interface Device) Driver. The flaw resides in the usb_class_request_get_descriptor() function, which improperly handles memory when an oversized descriptor is requested. The function frees and reallocates the hid_device->ctrl_xfer buffer but continues to use a stale local pointer, leading to an immediate use-after-free condition. An attacker with physical USB access or the ability to inject a malicious HID device can trigger this vulnerability by sending a crafted Report Descriptor length, potentially leading to arbitrary code execution or denial of service. The vulnerability affects all versions prior to 1.1.0, and the patch is available in version 1.1.0.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
This vulnerability is not related to NPM, PyPI, Go, or Ruby packages. It is a firmware-level issue in the Espressif ESP-IDF framework, specifically in the USB Host HID Driver component. Organizations using ESP32 or other Espressif chips with USB Host capabilities should verify their ESP-IDF version and apply the patch.
CVSS Breakdown & Threat Level
- CVSS Score: 6.8 (Medium)
- Attack Vector: Local (AV:L) – Requires physical USB access or a malicious HID device.
- Attack Complexity: Low (AC:L) – No special conditions required.
- Privileges Required: None (PR:N) – No authentication needed.
- User Interaction: Required (UI:R) – The user must connect the malicious HID device.
- Scope: Unchanged (S:U) – The vulnerability affects only the vulnerable component.
- Confidentiality Impact: High (C:H) – Potential for memory disclosure.
- Integrity Impact: High (I:H) – Potential for memory corruption.
- Availability Impact: High (A:H) – Potential for crash or denial of service.
Threat Level: Medium. While the CVSS score is 6.8, the requirement for physical USB access reduces the attack surface. However, in environments where USB devices are frequently connected (e.g., IoT hubs, kiosks), the risk is elevated.
Deep Dive & Mechanics
The vulnerability is in the usb_class_request_get_descriptor() function within the ESP-IDF USB Host HID Driver. When a HID device sends a request for a descriptor with an oversized length, the function performs the following flawed sequence:
- Initial Allocation: A buffer
hid_device->ctrl_xferis allocated to handle the control transfer. - Oversized Request: The function detects that the requested descriptor length exceeds the current buffer size.
- Free and Reallocate: The function frees the old
hid_device->ctrl_xferbuffer and allocates a new, larger one. - Stale Pointer Usage: The function continues to use a local pointer that still points to the old (freed) memory location. This pointer is used to process the incoming Report Descriptor data.
- Use-After-Free: Writing to the stale pointer corrupts freed memory, which can be reallocated by other parts of the system, leading to arbitrary code execution or a crash.
The attacker controls the Report Descriptor length, making this a trivially exploitable condition once a malicious HID device is connected.
Vulnerable vs. Patched Code
Vulnerable Code (pre-1.1.0):
// Simplified vulnerable code
void usb_class_request_get_descriptor(hid_device_t *hid_device, uint16_t length) {
uint8_t *local_ptr = hid_device->ctrl_xfer; // Stale pointer
if (length > HID_DESCRIPTOR_MAX_SIZE) {
free(hid_device->ctrl_xfer);
hid_device->ctrl_xfer = malloc(length);
// local_ptr still points to old freed memory
}
// Use local_ptr to write descriptor data
memcpy(local_ptr, descriptor_data, length); // Use-after-free
}
Patched Code (1.1.0):
// Simplified patched code
void usb_class_request_get_descriptor(hid_device_t *hid_device, uint16_t length) {
if (length > HID_DESCRIPTOR_MAX_SIZE) {
free(hid_device->ctrl_xfer);
hid_device->ctrl_xfer = malloc(length);
// Update local pointer after reallocation
}
uint8_t *local_ptr = hid_device->ctrl_xfer; // Safe pointer
memcpy(local_ptr, descriptor_data, length);
}
The fix ensures that the local pointer is updated after the reallocation, preventing the use-after-free.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- A physical USB device capable of acting as a HID device (e.g., a Raspberry Pi Pico or an Arduino with USB HID capabilities).
- The target device running ESP-IDF with the vulnerable USB Host HID Driver (version < 1.1.0).
Exploitation Steps:
- Craft Malicious HID Device: Program a microcontroller to act as a HID device that sends a descriptor request with an oversized length (e.g., 0xFFFF).
- Connect to Target: Plug the malicious HID device into the target's USB port.
- Trigger Vulnerability: The target's
usb_class_request_get_descriptor()function will free and reallocate the buffer, then write to the stale pointer. - Achieve Code Execution: By carefully controlling the heap layout, an attacker can overwrite function pointers or other critical data structures to gain arbitrary code execution.
Example Payload (Conceptual):
// Arduino sketch for a malicious HID device
void setup() {
// Initialize USB HID
// Send a descriptor request with oversized length
uint8_t descriptor_request[] = {0x80, 0x06, 0x00, 0x22, 0x00, 0x00, 0xFF, 0xFF};
// This triggers the use-after-free
}
Blue Team (Defense & Detection)
Detection:
- Monitor USB device enumeration logs for anomalous descriptor lengths.
- Use heap integrity checks (e.g., AddressSanitizer) during development.
- Implement runtime checks for buffer size consistency.
Mitigation:
- Update to ESP-IDF USB Host HID Driver version 1.1.0 or later.
- Restrict physical USB access to trusted devices only.
- Use USB port blockers or disable USB Host functionality if not needed.
Indicators of Compromise (IOCs)
- Network: No network-based IOCs; this is a local USB attack.
- Host:
- Unexpected crashes or reboots when connecting USB HID devices.
- Heap corruption errors in system logs.
- Unusual memory allocation patterns in the USB HID driver.
- File System: No specific file artifacts.
- Registry: Not applicable (embedded system).
Detection Engineering
YARA Rule
rule CVE_2025_68656_UseAfterFree {
meta:
description = "Detects use-after-free pattern in ESP-IDF USB HID driver"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2025-68656"
strings:
$code1 = "usb_class_request_get_descriptor" ascii
$code2 = "ctrl_xfer" ascii
$code3 = "free" ascii
$code4 = "malloc" ascii
condition:
all of ($code1, $code2, $code3, $code4) and #code3 > 1
}
Sigma Rule
title: CVE-2025-68656 Use-After-Free in ESP-IDF USB HID Driver
id: 8a9b3c4d-5e6f-7a8b-9c0d-1e2f3a4b5c6d
status: experimental
description: Detects potential exploitation of CVE-2025-68656 via anomalous USB descriptor requests
author: Valters IT
logsource:
product: embedded
service: usb
detection:
selection:
EventID: 1001 # Example USB event ID
DescriptorLength: "> 0xFFFF" # Oversized descriptor
condition: selection
falsepositives:
- Legitimate oversized descriptors (rare)
level: high
Suricata Rule
alert udp any any -> any any (msg:"CVE-2025-68656 Potential USB HID Exploit"; content:"|80 06 00 22 00 00 FF FF|"; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Update Firmware: Upgrade the ESP-IDF USB Host HID Driver to version 1.1.0 or later.
- Disable USB Host: If USB Host functionality is not required, disable it in the firmware configuration.
- Physical Security: Restrict physical access to USB ports on devices running vulnerable firmware.
Long-Term Measures:
- Implement code reviews focusing on memory management in USB drivers.
- Use static analysis tools to detect use-after-free vulnerabilities.
- Enable heap protection features (e.g., guard pages, canaries) in the RTOS.
Patch Verification:
- Check the version of
esp-idf-usb-host-hidin your project'sidf_component.ymlorCMakeLists.txt. - Ensure the version is >= 1.1.0.
Valters IT
DevSecOps & Cyber Threat Intelligence