Skip to contentSkip to conversation

vb2: Fix dma_dir setting for dma-contig mem type

PATCH In review Sakari Ailus 3 participants 3 messages Feb 13, 2015 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vb2: Fix dma_dir setting for dma-contig mem type

The last argument of vb2_dc_get_user_pages() is of type enum dma_data_direction, but the caller, vb2_dc_get_userptr() passes a value which is the result of comparison dma_dir == DMA_FROM_DEVICE. This results in the write parameter to get_user_pages() being zero in all cases, i.e. that the caller has no intent to write there.

This was broken by patch "vb2: replace 'write' by 'dma_dir'".

---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/v4l2-core/videobuf2-dma-contig.c +1 -2
index b481d20..69e0483 100644
@@ -632,8 +632,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr,
 	}
 
 	/* extract page list from userspace mapping */
-	ret = vb2_dc_get_user_pages(start, pages, n_pages, vma,
-				    dma_dir == DMA_FROM_DEVICE);
+	ret = vb2_dc_get_user_pages(start, pages, n_pages, vma, dma_dir);
 	if (ret) {
 		unsigned long pfn;
 		if (vb2_dc_get_user_pfn(start, n_pages, vma, &pfn) == 0) {
Signature · 1 line
2.1.0.231.g7484e3b
#1 lore raw
Quoted 9 lines · Sakari Ailus

The last argument of vb2_dc_get_user_pages() is of type enum dma_data_direction, but the caller, vb2_dc_get_userptr() passes a value which is the result of comparison dma_dir == DMA_FROM_DEVICE. This results in the write parameter to get_user_pages() being zero in all cases, i.e. that the caller has no intent to write there.

This was broken by patch "vb2: replace 'write' by 'dma_dir'".

Well, v3.19 is out so this is material for the stable branch. I'll submit a pull request once I get some acks.

This is quite bad indeed, as writing somewhere you're not expected to write may well lead to memory corruption, which is exactly the case here.

Signature · 2 lines
Sakari Ailus
e-mail: [email protected]	XMPP: [email protected]
Acked-by on v1 1/1
#2 lore raw
In reply to Sakari Ailus
Quoted 9 lines · Sakari Ailus

The last argument of vb2_dc_get_user_pages() is of type enum dma_data_direction, but the caller, vb2_dc_get_userptr() passes a value which is the result of comparison dma_dir == DMA_FROM_DEVICE. This results in the write parameter to get_user_pages() being zero in all cases, i.e. that the caller has no intent to write there.

This was broken by patch "vb2: replace 'write' by 'dma_dir'".

Yuck.

Regards,

Hans

Quoted 19 lines
---
 drivers/media/v4l2-core/videobuf2-dma-contig.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/v4l2-core/videobuf2-dma-contig.c +1 -2
index b481d20..69e0483 100644
@@ -632,8 +632,7 @@ static void *vb2_dc_get_userptr(void *alloc_ctx, unsigned long vaddr,
 	}
 
 	/* extract page list from userspace mapping */
-	ret = vb2_dc_get_user_pages(start, pages, n_pages, vma,
-				    dma_dir == DMA_FROM_DEVICE);
+	ret = vb2_dc_get_user_pages(start, pages, n_pages, vma, dma_dir);
 	if (ret) {
 		unsigned long pfn;
 		if (vb2_dc_get_user_pfn(start, n_pages, vma, &pfn) == 0) {