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 TSOMAXBUFF_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: dmadesc[N + 0], dmadesc[N + 1], dmadesc[N + 2]. Then three elements of txq->txskbuffdma[] will be allocated to hold extra information to be reused in stmmactxclean(): txq->txskbuffdma[N + 0], txq->txskbuffdma[N + 1], txq->txskbuffdma[N + 2]. Now we focus on txq->txskbuffdma[entry].buf, which is the DMA buffer address returned by DMA mapping call. stmmactxclean() will try to unmap the DMA buffer ONLYIF_ txq->txskbuff_dma[entry].buf is a valid buffer address.
The expected behavior that saves DMA buffer address of this non-paged data to txq->txskbuffdma[entry].buf is: txq->txskbuffdma[N + 0].buf = NULL; txq->txskbuffdma[N + 1].buf = NULL; txq->txskbuffdma[N + 2].buf = dmamapsingle(); Unfortunately, the current code misbehaves like this: txq->txskbuffdma[N + 0].buf = dmamapsingle(); txq->txskbuffdma[N + 1].buf = NULL; txq->txskbuff_dma[N + 2].buf = NULL;
On the stmmactxclean() side, when dmadesc[N + 0] is closed by the DMA engine, txq->txskbuffdma[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 dmadesc[N + 1], dmadesc[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 txq->txskbuff_dma[entry].buf when assigning DMA buffer address.
Tested and verified on DWXGMAC CORE 3.20a
[
{
"signature_type": "Line",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@07c9c26e37542486e34d767505e842f48f29c3f6",
"digest": {
"line_hashes": [
"64958028584199366525939969834863455857",
"243013063416257151169145137134166306061",
"60338359714974264037962354358941993660",
"78345809640895673170698213500978075631",
"30452921626733742997995271074889854849",
"287691572177283357774860018069920563074",
"44809084751446968389946006427772663630",
"27802284724466234259208450488545446119",
"159531192577894061317567017480472283550",
"99794715846091348705667485768948300546"
],
"threshold": 0.9
},
"id": "CVE-2024-53058-1b07ba01"
},
{
"signature_type": "Function",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"function": "stmmac_tso_xmit"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@07c9c26e37542486e34d767505e842f48f29c3f6",
"digest": {
"length": 5399.0,
"function_hash": "150063212099831640874226795132407411220"
},
"id": "CVE-2024-53058-82b5d17a"
},
{
"signature_type": "Function",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"function": "stmmac_tso_xmit"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@66600fac7a984dea4ae095411f644770b2561ede",
"digest": {
"length": 5442.0,
"function_hash": "42590299588475704450246807166090020377"
},
"id": "CVE-2024-53058-b51ad7ea"
},
{
"signature_type": "Line",
"deprecated": false,
"signature_version": "v1",
"target": {
"file": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c"
},
"source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@66600fac7a984dea4ae095411f644770b2561ede",
"digest": {
"line_hashes": [
"64958028584199366525939969834863455857",
"243013063416257151169145137134166306061",
"60338359714974264037962354358941993660",
"78345809640895673170698213500978075631",
"30452921626733742997995271074889854849",
"287691572177283357774860018069920563074",
"44809084751446968389946006427772663630",
"27802284724466234259208450488545446119",
"159531192577894061317567017480472283550",
"99794715846091348705667485768948300546"
],
"threshold": 0.9
},
"id": "CVE-2024-53058-cbd13f93"
}
]