Skip to content

Commit 655548b

Browse files
kiryltorvalds
authored andcommitted
thp: fix corner case of munlock() of PTE-mapped THPs
The following program triggers BUG() in munlock_vma_pages_range(): // autogenerated by syzkaller (http://github.com/google/syzkaller) #include <sys/mman.h> int main() { mmap((void*)0x20105000ul, 0xc00000ul, 0x2ul, 0x2172ul, -1, 0); mremap((void*)0x201fd000ul, 0x4000ul, 0xc00000ul, 0x3ul, 0x203f0000ul); return 0; } The test-case constructs the situation when munlock_vma_pages_range() finds PTE-mapped THP-head in the middle of page table and, by mistake, skips HPAGE_PMD_NR pages after that. As result, on the next iteration it hits the middle of PMD-mapped THP and gets upset seeing mlocked tail page. The solution is only skip HPAGE_PMD_NR pages if the THP was mlocked during munlock_vma_page(). It would guarantee that the page is PMD-mapped as we never mlock PTE-mapeed THPs. Fixes: e90309c ("thp: allow mlocked THP again") Link: http://lkml.kernel.org/r/20161115132703.7s7rrgmwttegcdh4@black.fi.intel.com Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Reported-by: Dmitry Vyukov <dvyukov@google.com> Cc: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: syzkaller <syzkaller@googlegroups.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: <stable@vger.kernel.org> [4.5+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent e1465d1 commit 655548b

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎mm/mlock.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,13 @@ unsigned int munlock_vma_page(struct page *page)
190190
*/
191191
spin_lock_irq(zone_lru_lock(zone));
192192

193-
nr_pages = hpage_nr_pages(page);
194-
if (!TestClearPageMlocked(page))
193+
if (!TestClearPageMlocked(page)) {
194+
/* Potentially, PTE-mapped THP: do not skip the rest PTEs */
195+
nr_pages = 1;
195196
goto unlock_out;
197+
}
196198

199+
nr_pages = hpage_nr_pages(page);
197200
__mod_zone_page_state(zone, NR_MLOCK, -nr_pages);
198201

199202
if (__munlock_isolate_lru_page(page, true)) {

0 commit comments

Comments
 (0)