linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [media] videobuf-dma-contig: Use size of buffer in mmap not vma size
@ 2019-03-29 17:34 Andrew F. Davis
  2019-05-24  9:47 ` Sakari Ailus
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew F. Davis @ 2019-03-29 17:34 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: linux-media, linux-kernel, Andrew F . Davis

The size of the vma can be larger than the size of the backing buffer.
Use the buffer size over vma size to prevent exposing extra memory
to userspace.

Signed-off-by: Andrew F. Davis <afd@ti.com>
---
 drivers/media/v4l2-core/videobuf-dma-contig.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c
index e1bf50df4c70..65e2655d22b7 100644
--- a/drivers/media/v4l2-core/videobuf-dma-contig.c
+++ b/drivers/media/v4l2-core/videobuf-dma-contig.c
@@ -280,7 +280,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
 	struct videobuf_dma_contig_memory *mem;
 	struct videobuf_mapping *map;
 	int retval;
-	unsigned long size;
 
 	dev_dbg(q->dev, "%s\n", __func__);
 
@@ -303,7 +302,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
 		goto error;
 
 	/* Try to remap memory */
-	size = vma->vm_end - vma->vm_start;
 	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
 	/* the "vm_pgoff" is just used in v4l2 to find the
@@ -314,7 +312,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
 	 */
 	vma->vm_pgoff = 0;
 
-	retval = vm_iomap_memory(vma, mem->dma_handle, size);
+	retval = vm_iomap_memory(vma, mem->dma_handle, mem->size);
 	if (retval) {
 		dev_err(q->dev, "mmap: remap failed with error %d. ",
 			retval);
-- 
2.21.0


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

* Re: [PATCH] [media] videobuf-dma-contig: Use size of buffer in mmap not vma size
  2019-03-29 17:34 [PATCH] [media] videobuf-dma-contig: Use size of buffer in mmap not vma size Andrew F. Davis
@ 2019-05-24  9:47 ` Sakari Ailus
  0 siblings, 0 replies; 2+ messages in thread
From: Sakari Ailus @ 2019-05-24  9:47 UTC (permalink / raw)
  To: Andrew F. Davis; +Cc: Mauro Carvalho Chehab, linux-media, linux-kernel

On Fri, Mar 29, 2019 at 12:34:27PM -0500, Andrew F. Davis wrote:
> The size of the vma can be larger than the size of the backing buffer.
> Use the buffer size over vma size to prevent exposing extra memory
> to userspace.
> 
> Signed-off-by: Andrew F. Davis <afd@ti.com>

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

> ---
>  drivers/media/v4l2-core/videobuf-dma-contig.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/videobuf-dma-contig.c b/drivers/media/v4l2-core/videobuf-dma-contig.c
> index e1bf50df4c70..65e2655d22b7 100644
> --- a/drivers/media/v4l2-core/videobuf-dma-contig.c
> +++ b/drivers/media/v4l2-core/videobuf-dma-contig.c
> @@ -280,7 +280,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
>  	struct videobuf_dma_contig_memory *mem;
>  	struct videobuf_mapping *map;
>  	int retval;
> -	unsigned long size;
>  
>  	dev_dbg(q->dev, "%s\n", __func__);
>  
> @@ -303,7 +302,6 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
>  		goto error;
>  
>  	/* Try to remap memory */
> -	size = vma->vm_end - vma->vm_start;
>  	vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
>  
>  	/* the "vm_pgoff" is just used in v4l2 to find the
> @@ -314,7 +312,7 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
>  	 */
>  	vma->vm_pgoff = 0;
>  
> -	retval = vm_iomap_memory(vma, mem->dma_handle, size);
> +	retval = vm_iomap_memory(vma, mem->dma_handle, mem->size);
>  	if (retval) {
>  		dev_err(q->dev, "mmap: remap failed with error %d. ",
>  			retval);
> -- 
> 2.21.0
> 

-- 
Sakari Ailus

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

end of thread, other threads:[~2019-05-24  9:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 17:34 [PATCH] [media] videobuf-dma-contig: Use size of buffer in mmap not vma size Andrew F. Davis
2019-05-24  9:47 ` Sakari Ailus

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).