🇰🇷 한글 설명
실험적 USB 호스트 스택에서 디바이스 구성 디스크립터 버퍼가 실패 경로에서 해제된 후 포인터가 NULL로 초기화되지 않아, 정리 단계에서 동일 블록이 두 번 해제되는 이중 해제(double free) 취약점입니다. 악의적이거나 잘못된 USB 장치가 열거 과정에서 특정 조건을 유발하면 서비스 거부 또는 힙 손상이 발생할 수 있습니다.
💡 쉬운 설명
USB 장치를 연결하는 과정에서 이미 해제된 메모리를 다시 해제하는 오류가 있습니다. 악의적인 USB 장치가 이를 유발하면 USB 호스트 기능이 멈추거나 메모리가 손상될 수 있습니다.
🇺🇸 원문 (English)
The experimental USB host stack allocates a per-device configuration-descriptor buffer, udev->cfg_desc, from the dedicated usb_device_heap in usbh_device_set_configuration() (subsys/usb/host/usbh_device.c). On three failure paths — a failed full-length GET_DESCRIPTOR(CONFIGURATION) read, a mismatch between the short and full descriptor reads, and a rejected descriptor in parse_configuration_descriptor() — the buffer was released with k_heap_free() but the pointer was left dangling. The cleanup in usbh_device_free() is guarded only by if (udev->cfg_desc != NULL), so it frees the same block a second time.
The path is driven entirely by the attached peripheral: usbh_device_connect() calls usbh_device_init(), which ends in usbh_device_set_configuration(), and on failure usbh_device_connect() calls usbh_device_free(). On v4.4.x this happens during the same enumeration, with no unplug required; on v4.1.0–v4.3.x the second free instead arrives via dev_removed_handler()/dev_connected_handler() in subsys/usb/host/usbh_core.c, so it requires a removal or duplicate-connect event after the failed enumeration — a sequence the attached device fully controls. A malicious or malformed USB device only has to answer the first 9-byte configuration-descriptor request with a well-formed header and then fail any of the three checks, for example by returning a full descriptor whose interface count disagrees with bNumInterfaces, or by answering the second read with different bytes.
The result is a double free on usb_device_heap. On builds where lib/heap hardening is active (the current default CONFIG_SYS_HEAP_HARDENING_BASIC), sys_heap_free() detects the already-free chunk and calls k_panic(), giving a deterministic, peripheral-triggered denial of service of the USB host. On builds without that detection — earlier releases, or CONFIG_SYS_HEAP_HARDENING_NONE — the second free manipulates a chunk already on the free list, corrupting the heap's free list so that later allocations can return overlapping or invalid blocks.
Exploitation beyond denial of service is bounded by the fact that usb_device_heap is a small dedicated heap (CONFIG_USBH_USB_DEVICE_HEAP, default 1024 bytes) whose only client is this descriptor buffer, and by CONFIG_USB_HOST_STACK being marked experimental and disabled by default. The fix sets udev->cfg_desc = NULL after every k_heap_free(), making the cleanup guard sound.
📍 영향받는 시스템
Zephyr RTOS의 실험적 USB 호스트 스택(CONFIG_USB_HOST_STACK 활성화 시), v4.1.0 이상 일부 버전 및 v4.4.x 등
⚔️ 공격 벡터
물리적으로 연결된 악의적 USB 장치가 구성 디스크립터 요청에 잘못된 응답을 보내 실패 경로를 유도
🛡️ 대응 방법
Zephyr를 수정된 버전으로 업데이트하거나, 해제 후 udev->cfg_desc = NULL 설정이 포함된 패치를 적용하고, 실험적 USB 호스트 스택을 비활성화
🔧 검증 코드
k_heap_free 호출 직후 cfg_desc = NULL 대입이 있으면 패치 적용된 것이고, free 직후 대입이 없으면 취약한 상태입니다. 결과가 없으면 해당 소스가 설치되지 않은 것입니다.
grep -rn "cfg_desc" $(find / -path '*/subsys/usb/host/usbh_device.c' 2>/dev/null | head -1) | grep -i 'k_heap_free' -A1