]> git.baikalelectronics.ru Git - kernel.git/commit
mm, page_vma_mapped: Drop faulty pointer arithmetics in check_pte()
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Fri, 19 Jan 2018 12:49:24 +0000 (15:49 +0300)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 22 Jan 2018 01:44:47 +0000 (17:44 -0800)
commit0df8c49129525404dc600f6e2fa66a6e387e5b23
treee6ebae5cd32b4f9008d06592a5301937c0be5875
parent2b23a9c245cfc108176dfba01dfd13469304b872
mm, page_vma_mapped: Drop faulty pointer arithmetics in check_pte()

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.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reported-and-tested-by: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Acked-by: Michal Hocko <mhocko@suse.com>
Fixes: a975ae39a50d ("mm: introduce page_vma_mapped_walk()")
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/swapops.h
mm/page_vma_mapped.c