В ядре Linux устранена следующая уязвимость:
net: stmmac: TSO: исправлено несбалансированное отображение/отключение DMA для невыгружаемых данных SKB. В случае, если невыгружаемые данные SKB содержат заголовок протокола и протокол
полезная нагрузка должна быть передана на определенную платформу, которая имеет адрес DMA AXI.
ширина настроена на 40/48 бит или размер невыгружаемых данных.
больше, чем TSO_MAX_BUFF_SIZE на определенной платформе, которую DMA AXI
ширина адреса настроена на 32-битную, то для этого СКБ требуется как минимум
два дескриптора передачи DMA для его обслуживания. Например, для разделения одного буфера DMA выделяются три дескриптора.
сопоставлено из одного фрагмента невыгружаемых данных:
dma_desc[N + 0],
dma_desc[N + 1],
dma_desc[N + 2].
Тогда три элемента tx_q->tx_skbuff_dma[] будут выделены для хранения
дополнительная информация для повторного использования в stmmac_tx_clean():
tx_q->tx_skbuff_dma[N + 0],
tx_q->tx_skbuff_dma[N + 1],
tx_q->tx_skbuff_dma[N + 2]. Теперь мы сосредоточимся на tx_q->tx_skbuff_dma[entry].buf, который является буфером DMA.
адрес, возвращаемый вызовом сопоставления DMA. stmmac_tx_clean() попытается
отключить буфер DMA _ONLY_IF_ tx_q->tx_skbuff_dma[entry].buf
является действительным адресом буфера. Ожидаемое поведение, при котором сохраняется адрес буфера DMA этого невыгружаемого
данные в tx_q->tx_skbuff_dma[entry].buf:
tx_q->tx_skbuff_dma[N + 0].buf = NULL;
tx_q->tx_skbuff_dma[N + 1].buf = NULL;
tx_q->tx_skbuff_dma[N + 2].buf = dma_map_single();
К сожалению, текущий код ведет себя следующим образом:
tx_q->tx_skbuff_dma[N + 0].buf = dma_map_single();
tx_q->tx_skbuff_dma[N + 1].buf = NULL;
tx_q->tx_skbuff_dma[N + 2].buf = NULL;
На стороне stmmac_tx_clean(), когда dma_desc[N + 0] закрывается функцией
Механизм DMA, tx_q->tx_skbuff_dma[N + 0].buf — действительный адрес буфера
очевидно, что тогда буфер DMA будет немедленно отключен.
В редких случаях механизм DMA не завершает работу.
ожидается dma_desc[N + 1], dma_desc[N + 2]. Теперь дела пойдут
ужасно неправильно, DMA собирается получить доступ к неотображенной/неиспользуемой памяти
регионе будут переданы поврежденные данные или возникнет ошибка iommu.
сработало :(
Напротив, цикл for, отображающий фрагменты SKB, ведет себя идеально.
как и ожидалось, и именно так драйвер должен поступать как для невыгружаемых
данные и выгружаемые фрагменты на самом деле. Этот патч исправляет последовательности отображения/отмены отображения DMA, исправляя индекс массива.
для tx_q->tx_skbuff_dma[entry].buf при назначении адреса буфера DMA.
Протестировано и проверено на DWXGMAC CORE 3.20a.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data In case the non-paged data of a SKB carries protocol header and protocol payload to be transmitted on a certain platform that the DMA AXI address width is configured to 40-bit/48-bit, or the size of the non-paged data is bigger than TSO_MAX_BUFF_SIZE on a certain platform that the DMA AXI address width is configured to 32-bit, then this SKB requires at least two DMA transmit descriptors to serve it. For example, three descriptors are allocated to split one DMA buffer mapped from one piece of non-paged data: dma_desc[N + 0], dma_desc[N + 1], dma_desc[N + 2]. Then three elements of tx_q->tx_skbuff_dma[] will be allocated to hold extra information to be reused in stmmac_tx_clean(): tx_q->tx_skbuff_dma[N + 0], tx_q->tx_skbuff_dma[N + 1], tx_q->tx_skbuff_dma[N + 2]. Now we focus on tx_q->tx_skbuff_dma[entry].buf, which is the DMA buffer address returned by DMA mapping call. stmmac_tx_clean() will try to unmap the DMA buffer _ONLY_IF_ tx_q->tx_skbuff_dma[entry].buf is a valid buffer address. The expected behavior that saves DMA buffer address of this non-paged data to tx_q->tx_skbuff_dma[entry].buf is: tx_q->tx_skbuff_dma[N + 0].buf = NULL; tx_q->tx_skbuff_dma[N + 1].buf = NULL; tx_q->tx_skbuff_dma[N + 2].buf = dma_map_single(); Unfortunately, the current code misbehaves like this: tx_q->tx_skbuff_dma[N + 0].buf = dma_map_single(); tx_q->tx_skbuff_dma[N + 1].buf = NULL; tx_q->tx_skbuff_dma[N + 2].buf = NULL; On the stmmac_tx_clean() side, when dma_desc[N + 0] is closed by the DMA engine, tx_q->tx_skbuff_dma[N + 0].buf is a valid buffer address obviously, then the DMA buffer will be unmapped immediately. There may be a rare case that the DMA engine does not finish the pending dma_desc[N + 1], dma_desc[N + 2] yet. Now things will go horribly wrong, DMA is going to access a unmapped/unreferenced memory region, corrupted data will be transmited or iommu fault will be triggered :( In contrast, the for-loop that maps SKB fragments behaves perfectly as expected, and that is how the driver should do for both non-paged data and paged frags actually. This patch corrects DMA map/unmap sequences by fixing the array index for tx_q->tx_skbuff_dma[entry].buf when assigning DMA buffer address. Tested and verified on DWXGMAC CORE 3.20a
Характеристики атаки
Последствия
Строка CVSS v3.1
Уязвимые продукты 9
| Конфигурация | От (включительно) | До (исключительно) |
|---|---|---|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
4.7
|
5.15.171
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
5.16
|
6.1.116
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.2
|
6.6.60
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.7
|
6.11.7
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.12:rc1:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.12:rc2:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.12:rc3:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.12:rc4:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.12:rc5:*:*:*:*:*:*
|
— | — |