Экспериментальный хост-стек USB выделяет буфер конфигурации-дескриптора для каждого устройства, udev->cfg_desc, из выделенного usb_device_heap в usbh_device_set_configuration() (subsys/usb/host/usbh_device.c). На трех путях отказа — неудачное чтение полноразмерного GET_DESCRIPTOR(CONFIGURATION), несоответствие между коротким и полным дескрипторами и отклоненный дескриптор в parse_configuration_descriptor() — буфер был выпущен с k_heap_free(), но указатель остался висеть. Очистка в usbh_device_free() охраняется только в том случае, если (udev->cfg_desc ! NULL), поэтому он освобождает тот же блок во второй раз.
Путь полностью управляется подключенным периферийным устройством: usbh_device_connect() вызывает usbh_device_init(), который заканчивается на usbh_device_set_configuration(), а при отказе usbh_device_connect() вызывает usbh_device_free(). На v4.4.x это происходит во время одного и того же перечисления, без необходимости отключения; на v4.1.0–v4.3.x второй свободный вместо этого прибывает через dev_removed_handler()/dev_connected_handler() в subsys/usb/host/usbh_core.c, поэтому после неудачного перечисления требуется событие удаления или дублирования подключения — последовательность, которую полностью контролирует подключенное устройство. Злонамеренное или неправильно сформированное устройство USB должно ответить на первый 9-байтовый запрос конфигурационного дескриптора только хорошо сформированным заголовком, а затем выполнить любую из трех проверок, например, путем возврата полного дескриптора, количество интерфейсов которого не совпадает с bNumInterfaces, или путем ответа на второе чтение с различными байтами.
Результатом является двойной свободный на usb_device_heap. На сборках, где lib/heap hardening активен (текущий CONFIG_SYS_HEAP_HARDENING_BASIC), sys_heap_free() обнаруживает уже свободный кусок и вызывает k_panic(), давая детерминированный, периферийный отказ в обслуживании хоста USB. На сборках без этого обнаружения - более ранние выпуски или CONFIG_SYS_HEAP_HARDENING_NONE - второй свободный манипулирует куском уже в свободном списке, повреждая свободный список кучи, чтобы более поздние выделения могли возвращать перекрывающиеся или недействительные блоки.
Эксплуатация помимо отказа в обслуживании ограничена тем фактом, что usb_device_heap представляет собой небольшую выделенную кучу (CONFIG_USBH_USB_DEVICE_HEAP, по умолчанию 1024 байта), единственным клиентом которой является этот буфер дескриптора, а CONFIG_USB_HOST_STACK по умолчанию помечается как экспериментальный и отключенный. Исправление устанавливает udev->cfg_desc NULL после каждого k_heap_free (), делая звук защиты очистки.
Показать оригинальное описание (EN)
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.
Характеристики атаки
Последствия
Строка CVSS v3.1