linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping
@ 2014-05-14  3:35 Sasha Levin
  2014-05-14  9:15 ` Kirill A. Shutemov
  0 siblings, 1 reply; 2+ messages in thread
From: Sasha Levin @ 2014-05-14  3:35 UTC (permalink / raw)
  To: linux-mm
  Cc: kirill.shutemov, davej, linux-kernel, viro, peterz, mingo, Sasha Levin

A file reference should be held while a file is mmaped, otherwise it might
be freed while being used.

Suggested-by: Hugh Dickins <hughd@google.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 mm/mmap.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index 2a0e0a8..da3c212 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -2593,6 +2593,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 	struct vm_area_struct *vma;
 	unsigned long populate = 0;
 	unsigned long ret = -EINVAL;
+	struct file *file;
 
 	pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
 			"See Documentation/vm/remap_file_pages.txt.\n",
@@ -2636,8 +2637,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
 		munlock_vma_pages_range(vma, start, start + size);
 	}
 
+	file = get_file(vma->vm_file);
 	ret = do_mmap_pgoff(vma->vm_file, start, size,
 			prot, flags, pgoff, &populate);
+	fput(file);
 out:
 	up_write(&mm->mmap_sem);
 	if (populate)
-- 
1.7.10.4


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

* Re: [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping
  2014-05-14  3:35 [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping Sasha Levin
@ 2014-05-14  9:15 ` Kirill A. Shutemov
  0 siblings, 0 replies; 2+ messages in thread
From: Kirill A. Shutemov @ 2014-05-14  9:15 UTC (permalink / raw)
  To: Sasha Levin
  Cc: linux-mm, kirill.shutemov, davej, linux-kernel, viro, peterz, mingo

On Tue, May 13, 2014 at 11:35:42PM -0400, Sasha Levin wrote:
> A file reference should be held while a file is mmaped, otherwise it might
> be freed while being used.
> 
> Suggested-by: Hugh Dickins <hughd@google.com>
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>

Sorry, again. :-/

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

> ---
>  mm/mmap.c |    3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2a0e0a8..da3c212 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -2593,6 +2593,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
>  	struct vm_area_struct *vma;
>  	unsigned long populate = 0;
>  	unsigned long ret = -EINVAL;
> +	struct file *file;
>  
>  	pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
>  			"See Documentation/vm/remap_file_pages.txt.\n",
> @@ -2636,8 +2637,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
>  		munlock_vma_pages_range(vma, start, start + size);
>  	}
>  
> +	file = get_file(vma->vm_file);
>  	ret = do_mmap_pgoff(vma->vm_file, start, size,
>  			prot, flags, pgoff, &populate);
> +	fput(file);
>  out:
>  	up_write(&mm->mmap_sem);
>  	if (populate)
> -- 
> 1.7.10.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
 Kirill A. Shutemov

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

end of thread, other threads:[~2014-05-14  9:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-14  3:35 [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping Sasha Levin
2014-05-14  9:15 ` Kirill A. Shutemov

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