linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	Oleg Nesterov <oleg@redhat.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	"Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>
Subject: [PATCH 3/5] mm: make sure all file VMAs have ->vm_ops set
Date: Mon, 13 Jul 2015 13:54:10 +0300	[thread overview]
Message-ID: <1436784852-144369-4-git-send-email-kirill.shutemov@linux.intel.com> (raw)
In-Reply-To: <1436784852-144369-1-git-send-email-kirill.shutemov@linux.intel.com>

We rely on vma->vm_ops == NULL to detect anonymous VMA: see
vma_is_anonymous(), but some drivers doesn't set ->vm_ops.

As result we can end up with anonymous page in private file mapping.
That's should not lead to serious misbehaviour, but nevertheless is
wrong.

Let's fix by setting up dummy ->vm_ops for file mmapping if f_op->mmap()
didn't set its own.

The patch also adds sanity check into __vma_link_rb(). It will help
catch broken VMAs which inserted directly into mm_struct via
insert_vm_struct().

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
---
 mm/mmap.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/mm/mmap.c b/mm/mmap.c
index 30904c16b7d3..4ce7a6f33db0 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -612,6 +612,8 @@ static unsigned long count_vma_pages_range(struct mm_struct *mm,
 void __vma_link_rb(struct mm_struct *mm, struct vm_area_struct *vma,
 		struct rb_node **rb_link, struct rb_node *rb_parent)
 {
+	WARN_ONCE(vma->vm_file && !vma->vm_ops, "missing vma->vm_ops");
+
 	/* Update tracking information for the gap following the new vma. */
 	if (vma->vm_next)
 		vma_gap_update(vma->vm_next);
@@ -1638,6 +1640,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
 		 */
 		WARN_ON_ONCE(addr != vma->vm_start);
 
+		/* All file mapping must have ->vm_ops set */
+		if (!vma->vm_ops) {
+			static const struct vm_operations_struct dummy_ops = {};
+			vma->vm_ops = &dummy_ops;
+		}
+
 		addr = vma->vm_start;
 		vm_flags = vma->vm_flags;
 	} else if (vm_flags & VM_SHARED) {
-- 
2.1.4

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

  parent reply	other threads:[~2015-07-13 10:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-13 10:54 [PATCH 0/5] Make vma_is_anonymous() reliable Kirill A. Shutemov
2015-07-13 10:54 ` [PATCH 1/5] mm: mark most vm_operations_struct const Kirill A. Shutemov
2015-07-13 10:54 ` [PATCH 2/5] x86, mpx: do not set ->vm_ops on mpx VMAs Kirill A. Shutemov
2015-07-13 12:06   ` Leon Romanovsky
2015-07-13 12:29     ` Kirill A. Shutemov
2015-07-13 12:42       ` Leon Romanovsky
2015-07-13 16:53   ` Oleg Nesterov
2015-07-13 17:05     ` Dave Hansen
2015-07-16 11:05       ` Kirill A. Shutemov
2015-07-16 15:53         ` Dave Hansen
2015-07-16 16:09           ` Kirill A. Shutemov
2015-07-16 22:26             ` [PATCH 0/1] mm, mpx: add "vm_flags_t vm_flags" arg to do_mmap_pgoff() Oleg Nesterov
2015-07-16 22:26               ` [PATCH 1/1] " Oleg Nesterov
2015-07-24 14:39                 ` Paul Gortmaker
2015-07-27 19:34                   ` Mark Salter
2015-07-13 10:54 ` Kirill A. Shutemov [this message]
2015-07-13 10:54 ` [PATCH 4/5] mm, madvise: use vma_is_anonymous() to check for anon VMA Kirill A. Shutemov
2015-07-15 23:50   ` Minchan Kim
2015-07-13 10:54 ` [PATCH 5/5] mm, memcontrol: " Kirill A. Shutemov
2015-07-13 13:08   ` Johannes Weiner
2015-07-13 13:20     ` 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=1436784852-144369-4-git-send-email-kirill.shutemov@linux.intel.com \
    --to=kirill.shutemov@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=oleg@redhat.com \
    /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 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).