Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1203544

[PATCH 3.14 01/29] mm: avoid setting up anonymous pages into file mapping

From Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Newsgroups linux.kernel
Subject [PATCH 3.14 01/29] mm: avoid setting up anonymous pages into file mapping
Date 2015-08-09 00:50 +0200
Message-ID <pVl6d-45c-75@gated-at.bofh.it> (permalink)
References <pVktr-3jX-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


3.14-stable review patch.  If anyone has any objections, please let me know.

------------------

From: "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>

commit 6b7339f4c31ad69c8e9c0b2859276e22cf72176d upstream.

Reading page fault handler code I've noticed that under right
circumstances kernel would map anonymous pages into file mappings: if
the VMA doesn't have vm_ops->fault() and the VMA wasn't fully populated
on ->mmap(), kernel would handle page fault to not populated pte with
do_anonymous_page().

Let's change page fault handler to use do_anonymous_page() only on
anonymous VMA (->vm_ops == NULL) and make sure that the VMA is not
shared.

For file mappings without vm_ops->fault() or shred VMA without vm_ops,
page fault on pte_none() entry would lead to SIGBUS.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Willy Tarreau <w@1wt.eu>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


---
 mm/memory.c |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3234,6 +3234,10 @@ static int do_anonymous_page(struct mm_s
 
 	pte_unmap(page_table);
 
+	/* File mapping without ->vm_ops ? */
+	if (vma->vm_flags & VM_SHARED)
+		return VM_FAULT_SIGBUS;
+
 	/* Check if we need to add a guard page to the stack */
 	if (check_stack_guard_page(vma, address) < 0)
 		return VM_FAULT_SIGSEGV;
@@ -3502,6 +3506,9 @@ static int do_linear_fault(struct mm_str
 			- vma->vm_start) >> PAGE_SHIFT) + vma->vm_pgoff;
 
 	pte_unmap(page_table);
+	/* The VMA was not fully populated on mmap() or missing VM_DONTEXPAND */
+	if (!vma->vm_ops->fault)
+		return VM_FAULT_SIGBUS;
 	return __do_fault(mm, vma, address, pmd, pgoff, flags, orig_pte);
 }
 
@@ -3650,11 +3657,9 @@ static int handle_pte_fault(struct mm_st
 	entry = ACCESS_ONCE(*pte);
 	if (!pte_present(entry)) {
 		if (pte_none(entry)) {
-			if (vma->vm_ops) {
-				if (likely(vma->vm_ops->fault))
-					return do_linear_fault(mm, vma, address,
+			if (vma->vm_ops)
+				return do_linear_fault(mm, vma, address,
 						pte, pmd, flags, entry);
-			}
 			return do_anonymous_page(mm, vma, address,
 						 pte, pmd, flags);
 		}


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 3.14 00/29] 3.14.50-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 11/29] mmc: sdhci-esdhc: Make 8BIT bus work Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 04/29] ARC: make sure instruction_pointer() returns unsigned value Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 26/29] avr32: handle NULL as a valid clock object Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 07/29] ALSA: usb-audio: add dB range mapping for some devices Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 15/29] Input: usbtouchscreen - avoid unresponsive TSC-30 touch screen Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 16/29] blkcg: fix gendisk reference leak in blkg_conf_prep() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 17/29] ata: pmp: add quirk for Marvell 4140 SATA PMP Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 24/29] rds: rds_ib_device.refcount overflow Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 23/29] x86/efi: Use all 64 bit of efi_memmap in setup_e820() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 20/29] xhci: report U3 when link is in resume state Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 10/29] mac80211: clear subdir_stations when removing debugfs Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 19/29] xhci: Calculate old endpoints correctly on device reset Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 03/29] s390/sclp: clear upper register halves in _sclp_print_early Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 27/29] iscsi-target: Fix use-after-free during TPG session shutdown Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 02/29] freeing unlinked file indefinitely delayed Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  [PATCH 3.14 01/29] mm: avoid setting up anonymous pages into file mapping Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-09 00:50 +0200
  Re: [PATCH 3.14 00/29] 3.14.50-stable review Guenter Roeck <linux@roeck-us.net> - 2015-08-09 05:20 +0200
    Re: [PATCH 3.14 00/29] 3.14.50-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2015-08-10 21:20 +0200
  Re: [PATCH 3.14 00/29] 3.14.50-stable review Sudip Mukherjee <sudipm.mukherjee@gmail.com> - 2015-08-10 07:10 +0200

csiph-web