forked from mirrors/linux
		
	mm: mmap: fix fput in error path v2
Patch "495c10cc1c0c CHROMIUM: dma-buf: restore args..." adds a workaround for a bug in mmap_region. As the comment states ->mmap() callback can change vma->vm_file and so we might call fput() on the wrong file. Revert the workaround and proper fix this in mmap_region. v2: drop the extra if in dma_buf_mmap as well Signed-off-by: Christian König <christian.koenig@amd.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Acked-by: Andrew Morton <akpm@linux-foundation.org> Link: https://patchwork.freedesktop.org/patch/399359/
This commit is contained in:
		
							parent
							
								
									f9f92e7c58
								
							
						
					
					
						commit
						1527f926fd
					
				
					 2 changed files with 4 additions and 18 deletions
				
			
		| 
						 | 
					@ -1166,9 +1166,6 @@ EXPORT_SYMBOL_GPL(dma_buf_end_cpu_access);
 | 
				
			||||||
int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 | 
					int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 | 
				
			||||||
		 unsigned long pgoff)
 | 
							 unsigned long pgoff)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct file *oldfile;
 | 
					 | 
				
			||||||
	int ret;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (WARN_ON(!dmabuf || !vma))
 | 
						if (WARN_ON(!dmabuf || !vma))
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1186,22 +1183,11 @@ int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
 | 
				
			||||||
		return -EINVAL;
 | 
							return -EINVAL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* readjust the vma */
 | 
						/* readjust the vma */
 | 
				
			||||||
	get_file(dmabuf->file);
 | 
						fput(vma->vm_file);
 | 
				
			||||||
	oldfile = vma->vm_file;
 | 
						vma->vm_file = get_file(dmabuf->file);
 | 
				
			||||||
	vma->vm_file = dmabuf->file;
 | 
					 | 
				
			||||||
	vma->vm_pgoff = pgoff;
 | 
						vma->vm_pgoff = pgoff;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ret = dmabuf->ops->mmap(dmabuf, vma);
 | 
						return dmabuf->ops->mmap(dmabuf, vma);
 | 
				
			||||||
	if (ret) {
 | 
					 | 
				
			||||||
		/* restore old parameters on failure */
 | 
					 | 
				
			||||||
		vma->vm_file = oldfile;
 | 
					 | 
				
			||||||
		fput(dmabuf->file);
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		if (oldfile)
 | 
					 | 
				
			||||||
			fput(oldfile);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return ret;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL_GPL(dma_buf_mmap);
 | 
					EXPORT_SYMBOL_GPL(dma_buf_mmap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1899,8 +1899,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 | 
				
			||||||
	return addr;
 | 
						return addr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
unmap_and_free_vma:
 | 
					unmap_and_free_vma:
 | 
				
			||||||
 | 
						fput(vma->vm_file);
 | 
				
			||||||
	vma->vm_file = NULL;
 | 
						vma->vm_file = NULL;
 | 
				
			||||||
	fput(file);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Undo any partial mapping done by a device driver. */
 | 
						/* Undo any partial mapping done by a device driver. */
 | 
				
			||||||
	unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
 | 
						unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue