aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorKirill A. Shutemov <kirill.shutemov@linux.intel.com>2013-12-20 15:10:03 +0200
committerSimon Shields <keepcalm444@gmail.com>2016-03-15 18:13:20 +1100
commitb6e29030f9325ccc841ad02e4687dedf6d9bba08 (patch)
tree22e94e358a2a3a06b4d63a8e682df3b9b6b1f1ec /include
parent9c6b633d3414bf49bb75a641a4f028bf0acf2254 (diff)
downloadkernel_samsung_smdk4412-b6e29030f9325ccc841ad02e4687dedf6d9bba08.tar.gz
kernel_samsung_smdk4412-b6e29030f9325ccc841ad02e4687dedf6d9bba08.tar.bz2
kernel_samsung_smdk4412-b6e29030f9325ccc841ad02e4687dedf6d9bba08.zip
mm: Fix NULL pointer dereference in madvise(MADV_WILLNEED) support
Sasha Levin found a NULL pointer dereference that is due to a missing page table lock, which in turn is due to the pmd entry in question being a transparent huge-table entry. The code - introduced in commit 1998cc048901 ("mm: make madvise(MADV_WILLNEED) support swap file prefetch") - correctly checks for this situation using pmd_none_or_trans_huge_or_clear_bad(), but it turns out that that function doesn't work correctly. pmd_none_or_trans_huge_or_clear_bad() expected that pmd_bad() would trigger if the transparent hugepage bit was set, but it doesn't do that if pmd_numa() is also set. Note that the NUMA bit only gets set on real NUMA machines, so people trying to reproduce this on most normal development systems would never actually trigger this. Fix it by removing the very subtle (and subtly incorrect) expectation, and instead just checking pmd_trans_huge() explicitly. Reported-by: Sasha Levin <sasha.levin@oracle.com> Acked-by: Andrea Arcangeli <aarcange@redhat.com> [ Additionally remove the now stale test for pmd_trans_huge() inside the pmd_bad() case - Linus ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Change-Id: I3f3763f236ef102de735297cd175cf514d40d28f
Diffstat (limited to 'include')
-rw-r--r--include/asm-generic/pgtable.h5
1 files changed, 2 insertions, 3 deletions
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 831924a1bbd..2fda790a338 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -488,11 +488,10 @@ static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
barrier();
#endif
- if (pmd_none(pmdval))
+ if (pmd_none(pmdval) || pmd_trans_huge(pmdval))
return 1;
if (unlikely(pmd_bad(pmdval))) {
- if (!pmd_trans_huge(pmdval))
- pmd_clear_bad(pmd);
+ pmd_clear_bad(pmd);
return 1;
}
return 0;