All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Sasha Levin <sasha.levin@oracle.com>
Cc: linux-mm@kvack.org, kirill.shutemov@linux.intel.com,
	davej@redhat.com, linux-kernel@vger.kernel.org,
	viro@zeniv.linux.org.uk, peterz@infradead.org, mingo@kernel.org
Subject: Re: [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping
Date: Wed, 14 May 2014 12:15:46 +0300	[thread overview]
Message-ID: <20140514091546.GA29388@node.dhcp.inet.fi> (raw)
In-Reply-To: <1400038542-9705-1-git-send-email-sasha.levin@oracle.com>

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

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: "Kirill A. Shutemov" <kirill@shutemov.name>
To: Sasha Levin <sasha.levin@oracle.com>
Cc: linux-mm@kvack.org, kirill.shutemov@linux.intel.com,
	davej@redhat.com, linux-kernel@vger.kernel.org,
	viro@zeniv.linux.org.uk, peterz@infradead.org, mingo@kernel.org
Subject: Re: [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping
Date: Wed, 14 May 2014 12:15:46 +0300	[thread overview]
Message-ID: <20140514091546.GA29388@node.dhcp.inet.fi> (raw)
In-Reply-To: <1400038542-9705-1-git-send-email-sasha.levin@oracle.com>

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

  reply	other threads:[~2014-05-14  9:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-14  3:35 [PATCH] mm: remap_file_pages: grab file ref to prevent race while mmaping Sasha Levin
2014-05-14  3:35 ` Sasha Levin
2014-05-14  9:15 ` Kirill A. Shutemov [this message]
2014-05-14  9:15   ` Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140514091546.GA29388@node.dhcp.inet.fi \
    --to=kirill@shutemov.name \
    --cc=davej@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sasha.levin@oracle.com \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.