Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751990AbbGMKzf (ORCPT ); Mon, 13 Jul 2015 06:55:35 -0400 Received: from mga03.intel.com ([134.134.136.65]:16288 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751174AbbGMKyR (ORCPT ); Mon, 13 Jul 2015 06:54:17 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,462,1432623600"; d="scan'208";a="746062283" From: "Kirill A. Shutemov" To: Andrew Morton , Oleg Nesterov Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 3/5] mm: make sure all file VMAs have ->vm_ops set Date: Mon, 13 Jul 2015 13:54:10 +0300 Message-Id: <1436784852-144369-4-git-send-email-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1436784852-144369-1-git-send-email-kirill.shutemov@linux.intel.com> References: <1436784852-144369-1-git-send-email-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1806 Lines: 53 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 --- 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 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/