swiotlb: Fix uninitialized pointer on DMA ops
PATCH 1/1 swiotlb: Fix uninitialized pointer on DMA ops
The mmap function pointer on swiotlb_dma_ops struct is uninitialized, which causes a random crash when calling the dma_mmap_coherent function on platforms where no DMA address translation hardware is available.
Set this pointer to NULL in order to fix the issue.
--- kernel/dma/swiotlb.c | 1 + 1 file changed, 1 insertion(+)
kernel/dma/swiotlb.c +1 -0
@@ -1082,5 +1082,6 @@ const struct dma_map_ops swiotlb_dma_ops = { .map_page = swiotlb_map_page, .unmap_page = swiotlb_unmap_page, .dma_supported = dma_direct_supported, + .mmap = NULL, };EXPORT_SYMBOL (swiotlb_dma_ops);
Signature · 1 line
2.7.4
Quoted 6 lines · Esteban Zamora
The mmap function pointer on
swiotlb_dma_opsstruct is uninitialized, which causes a random crash when calling thedma_mmap_coherentfunction on platforms where no DMA address translation hardware is available.Set this pointer to NULL in order to fix the issue.
By default unused entries in .rodata structure (like this one) are zero - meaning they are NULL if not set by the complier.
You should be able to verify this by looking at the objdump of the kernel and find this structure.
Quoted 17 lines
Signed-off-by Esteban Zamora <[email protected]>---
kernel/dma/swiotlb.c| 1 +1 file changed, 1 insertion(+)kernel/dma/swiotlb.c +1
-0@@ -1082,5 +1082,6 @@ const struct dma_map_ops swiotlb_dma_ops = { .map_page = swiotlb_map_page, .unmap_page = swiotlb_unmap_page, .dma_supported = dma_direct_supported, + .mmap = NULL, };EXPORT_SYMBOL (swiotlb_dma_ops);
Robin Murphy
reviewerQuoted 4 lines · Esteban Zamora
The mmap function pointer on
swiotlb_dma_opsstruct is uninitialized, which causes a random crash when calling thedma_mmap_coherentfunction on platforms where no DMA address translation hardware is available.
Can you share any kernel logs with details of those crashes? As Konrad mentions, the rules for partial structure initialisation in C are well-defined, even with designated initialisers[1], and if this commit message were true then half of the subsystems in the kernel would be crashing left right and centre.
Robin.
[1] https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html#Designated-Inits
Quoted 19 lines
Set this pointer to NULL in order to fix the issue.
Signed-off-by Esteban Zamora <[email protected]>--- kernel/dma/swiotlb.c | 1 + 1 file changed, 1 insertion(+)kernel/dma/swiotlb.c +1
-0@@ -1082,5 +1082,6 @@ const struct dma_map_ops swiotlb_dma_ops = { .map_page = swiotlb_map_page, .unmap_page = swiotlb_unmap_page, .dma_supported = dma_direct_supported, + .mmap = NULL, };EXPORT_SYMBOL (swiotlb_dma_ops);