The patch titled Subject: mm: khugepaged: close use-after-free race during shmem collapsing has been added to the -mm tree. Its filename is mm-khugepaged-close-use-after-free-race-during-shmem-collapsing.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/mm-khugepaged-close-use-after-free-race-during-shmem-collapsing.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/mm-khugepaged-close-use-after-free-race-during-shmem-collapsing.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Johannes Weiner <hannes@xxxxxxxxxxx> Subject: mm: khugepaged: close use-after-free race during shmem collapsing Patch series "mm: workingset: radix tree subtleties & single-page file refaults", v3. This is another revision of the radix tree / workingset patches based on feedback from Jan and Kirill. This is a follow-up to d3798ae8c6f3 ("mm: filemap: don't plant shadow entries without radix tree node"). That patch fixed an issue that was caused mainly by the page cache sneaking special shadow page entries into the radix tree and relying on subtleties in the radix tree code to make that work. The fix also had to stop tracking refaults for single-page files because shadow pages stored as direct pointers in radix_tree_root->rnode weren't properly handled during tree extension. These patches make the radix tree code explicitely support and track such special entries, to eliminate the subtleties and to restore the thrash detection for single-page files. This patch (of 9): When a radix tree iteration drops the tree lock, another thread might swoop in and free the node holding the current slot. The iteration needs to do another tree lookup from the current index to continue. [kirill.shutemov@xxxxxxxxxxxxxxx: re-lookup for replacement] Fixes: f3f0e1d2150b ("khugepaged: add support of collapse for tmpfs/shmem pages") Link: http://lkml.kernel.org/r/20161117191138.22769-2-hannes@xxxxxxxxxxx Signed-off-by: Johannes Weiner <hannes@xxxxxxxxxxx> Acked-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx> Reviewed-by: Jan Kara <jack@xxxxxxx> Cc: Hugh Dickins <hughd@xxxxxxxxxx> Cc: Matthew Wilcox <mawilcox@xxxxxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/khugepaged.c | 5 +++++ 1 file changed, 5 insertions(+) diff -puN mm/khugepaged.c~mm-khugepaged-close-use-after-free-race-during-shmem-collapsing mm/khugepaged.c --- a/mm/khugepaged.c~mm-khugepaged-close-use-after-free-race-during-shmem-collapsing +++ a/mm/khugepaged.c @@ -1403,6 +1403,9 @@ static void collapse_shmem(struct mm_str spin_lock_irq(&mapping->tree_lock); + slot = radix_tree_lookup_slot(&mapping->page_tree, index); + VM_BUG_ON_PAGE(page != radix_tree_deref_slot_protected(slot, + &mapping->tree_lock), page); VM_BUG_ON_PAGE(page_mapped(page), page); /* @@ -1426,6 +1429,7 @@ static void collapse_shmem(struct mm_str radix_tree_replace_slot(slot, new_page + (index % HPAGE_PMD_NR)); + slot = radix_tree_iter_next(&iter); index++; continue; out_lru: @@ -1537,6 +1541,7 @@ tree_unlocked: putback_lru_page(page); unlock_page(page); spin_lock_irq(&mapping->tree_lock); + slot = radix_tree_iter_next(&iter); } VM_BUG_ON(nr_none); spin_unlock_irq(&mapping->tree_lock); _ Patches currently in -mm which might be from hannes@xxxxxxxxxxx are mm-khugepaged-close-use-after-free-race-during-shmem-collapsing.patch mm-khugepaged-fix-radix-tree-node-leak-in-shmem-collapse-error-path.patch mm-workingset-turn-shadow-node-shrinker-bugs-into-warnings.patch lib-radix-tree-native-accounting-of-exceptional-entries.patch lib-radix-tree-check-accounting-of-existing-slot-replacement-users.patch lib-radix-tree-add-entry-deletion-support-to-__radix_tree_replace.patch lib-radix-tree-update-callback-for-changing-leaf-nodes.patch mm-workingset-move-shadow-entry-tracking-to-radix-tree-exceptional-tracking.patch mm-workingset-restore-refault-tracking-for-single-page-files.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html