Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Kirill A. Shutemov and committed by
Linus Torvalds
ee53664b 4203d0eb

+2 -3
+2 -3
include/asm-generic/pgtable.h
··· 599 599 #ifdef CONFIG_TRANSPARENT_HUGEPAGE 600 600 barrier(); 601 601 #endif 602 - if (pmd_none(pmdval)) 602 + if (pmd_none(pmdval) || pmd_trans_huge(pmdval)) 603 603 return 1; 604 604 if (unlikely(pmd_bad(pmdval))) { 605 - if (!pmd_trans_huge(pmdval)) 606 - pmd_clear_bad(pmd); 605 + pmd_clear_bad(pmd); 607 606 return 1; 608 607 } 609 608 return 0;