From: Sasha Levin Date: Sat, 17 May 2014 13:19:30 +0000 (+1000) Subject: mm: remap_file_pages: grab file ref to prevent race while mmaping X-Git-Tag: next-20140519~3^2~14 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=d391cbb06dcf54321078cd5b9b3f56c80f221d09;p=karo-tx-linux.git mm: remap_file_pages: grab file ref to prevent race while mmaping A file reference should be held while a file is mmaped, otherwise it might be freed while being used. Signed-off-by: Sasha Levin Suggested-by: Hugh Dickins Acked-by: Kirill A. Shutemov Signed-off-by: Andrew Morton --- diff --git a/mm/mmap.c b/mm/mmap.c index 2a0e0a8337b6..da3c21224757 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)