linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] swiotlb: Fix uninitialized pointer on DMA ops
@ 2018-08-18 19:04 Esteban Zamora
  2018-08-19 12:57 ` Konrad Rzeszutek Wilk
  2018-08-20 10:00 ` Robin Murphy
  0 siblings, 2 replies; 3+ messages in thread
From: Esteban Zamora @ 2018-08-18 19:04 UTC (permalink / raw)
  To: estebanzacr.20
  Cc: Konrad Rzeszutek Wilk, Christoph Hellwig, Marek Szyprowski,
	Robin Murphy, iommu, linux-kernel

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.

Signed-off-by: Esteban Zamora <estebanzacr.20@gmail.com>
---
 kernel/dma/swiotlb.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
index 4f8a6db..9a7718c 100644
--- a/kernel/dma/swiotlb.c
+++ b/kernel/dma/swiotlb.c
@@ -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);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] swiotlb: Fix uninitialized pointer on DMA ops
  2018-08-18 19:04 [PATCH] swiotlb: Fix uninitialized pointer on DMA ops Esteban Zamora
@ 2018-08-19 12:57 ` Konrad Rzeszutek Wilk
  2018-08-20 10:00 ` Robin Murphy
  1 sibling, 0 replies; 3+ messages in thread
From: Konrad Rzeszutek Wilk @ 2018-08-19 12:57 UTC (permalink / raw)
  To: Esteban Zamora, estebanzacr.20
  Cc: Christoph Hellwig, Marek Szyprowski, Robin Murphy, iommu, linux-kernel

On August 18, 2018 3:04:51 PM EDT, Esteban Zamora <estebanzacr.20@gmail.com> wrote:
>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.


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.


>
>Signed-off-by: Esteban Zamora <estebanzacr.20@gmail.com>
>---
> kernel/dma/swiotlb.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
>index 4f8a6db..9a7718c 100644
>--- a/kernel/dma/swiotlb.c
>+++ b/kernel/dma/swiotlb.c
>@@ -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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] swiotlb: Fix uninitialized pointer on DMA ops
  2018-08-18 19:04 [PATCH] swiotlb: Fix uninitialized pointer on DMA ops Esteban Zamora
  2018-08-19 12:57 ` Konrad Rzeszutek Wilk
@ 2018-08-20 10:00 ` Robin Murphy
  1 sibling, 0 replies; 3+ messages in thread
From: Robin Murphy @ 2018-08-20 10:00 UTC (permalink / raw)
  To: Esteban Zamora
  Cc: Konrad Rzeszutek Wilk, Christoph Hellwig, Marek Szyprowski,
	iommu, linux-kernel

On 18/08/18 20:04, Esteban Zamora wrote:
> 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.

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

> Set this pointer to NULL in order to fix the issue.
> 
> Signed-off-by: Esteban Zamora <estebanzacr.20@gmail.com>
> ---
>   kernel/dma/swiotlb.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
> index 4f8a6db..9a7718c 100644
> --- a/kernel/dma/swiotlb.c
> +++ b/kernel/dma/swiotlb.c
> @@ -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);
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-20 10:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-18 19:04 [PATCH] swiotlb: Fix uninitialized pointer on DMA ops Esteban Zamora
2018-08-19 12:57 ` Konrad Rzeszutek Wilk
2018-08-20 10:00 ` Robin Murphy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).