Patch "mm, page_vma_mapped: Drop faulty pointer arithmetics in check_pte()" has been added to the 4.14-stable tree
Subsystems (4)
This is a note to let you know that I've just added the patch titled
mm, page_vma_mapped: Drop faulty pointer arithmetics in check_pte()
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-page_vma_mapped-drop-faulty-pointer-arithmetics-in-check_pte.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
0d665e7b109d512b7cae3ccef6e8654714887844Mon Sep 17 00:00:00 2001
From: "Kirill A. Shutemov" <[email protected]>
Date: Fri, 19 Jan 2018 15:49:24 +0300
Subject: mm, page_vma_mapped: Drop faulty pointer arithmetics in check_pte()
From: Kirill A. Shutemov <[email protected]>
commit 0d665e7b109d512b7cae3ccef6e8654714887844 upstream.
Tetsuo reported random crashes under memory pressure on 32-bit x86 system and tracked down to change that introduced page_vma_mapped_walk().
The root cause of the issue is the faulty pointer math in check_pte(). As ->pte may point to an arbitrary page we have to check that they are belong to the section before doing math. Otherwise it may lead to weird results.
It wasn't noticed until now as mem_map[] is virtually contiguous on flatmem or vmemmap sparsemem. Pointer arithmetic just works against all 'struct page' pointers. But with classic sparsemem, it doesn't because each section memap is allocated separately and so consecutive pfns crossing two sections might have struct pages at completely unrelated addresses.
Let's restructure code a bit and replace pointer arithmetic with operations on pfns.
--- include/linux/swapops.h | 21 ++++++++++++++++ mm/page_vma_mapped.c | 63 ++++++++++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 25 deletions(-)
include/linux/swapops.h +21 -0
@@ -124,6 +124,11 @@ static inline bool is_write_device_privareturn unlikely (swp_type (entry) ==SWP_DEVICE_WRITE ); } +static inline unsigned long device_private_entry_to_pfn (swp_entry_t entry) +{ +return swp_offset (entry); +} +static inline struct page *device_private_entry_to_page (swp_entry_t entry) {return pfn_to_page (swp_offset (entry));
@@ -154,6 +159,11 @@ static inline bool is_write_device_privareturn false; } +static inline unsigned long device_private_entry_to_pfn (swp_entry_t entry) +{ +return 0 ; +} +static inline struct page *device_private_entry_to_page (swp_entry_t entry) {return NULL ;
@@ -189,6 +199,11 @@ static inline int is_write_migration_entreturn unlikely (swp_type (entry) ==SWP_MIGRATION_WRITE ); } +static inline unsigned long migration_entry_to_pfn (swp_entry_t entry) +{ +return swp_offset (entry); +} +static inline struct page *migration_entry_to_page (swp_entry_t entry) {struct page *p =pfn_to_page (swp_offset (entry));
@@ -218,6 +233,12 @@ static inline int is_migration_entry(swp {return 0 ; } + +static inline unsigned long migration_entry_to_pfn (swp_entry_t entry) +{ +return 0 ; +} +static inline struct page *migration_entry_to_page (swp_entry_t entry) {return NULL ;
mm/page_vma_mapped.c +38 -25
85 lines not on this page · raw message
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/mm-page_vma_mapped-drop-faulty-pointer-arithmetics-in-check_pte.patch