In the Linux kernel, the following vulnerability has been resolved: mm/hugetlb: fix mremap deadlock when PMD sharing is possible move_hugetlb_page_tables() holds the mapping's i_mmap_rwsem for write while moving hugetlb PTEs. Это предотвращает гонки с усечением и защищает huge_pmd_unshare(), но цикл перемещения не должен вызывать помощников, которые могут получить тот же rwsem для чтения. huge_pte_alloc() может сделать это, когда получатель может использовать совместное использование PMD: он может вызвать huge_pmd_share(), который принимает i_mmap_rwsem для чтения при поиске совместно используемой таблицы PMD. Вызов его, в то время как путь перемещения уже содержит i_mmap_rwsem для записи может зайти в тупик.
Избегайте этого пути для карт размером с PMD, которые могут использовать совместное использование PMD. Вместо того, чтобы распределять или делиться таблицей страниц назначения во время перемещения, перейдите к диапазону источников и позвольте пути ошибок назначения заполнять или делиться PMD лениво. Повторно используйте огромную логику unmap для zap на стороне источника, выделив контур ядра из __unmap_hugepage_range().
Обёртка сохраняет существующее поведение tlb_start_vma(), tlb_end_vma() и huge_pmd_unshare_flush(), в то время как move_hugetlb_page_tables() может повторно использовать цикл unmap с его существующим mmu_gather.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: mm/hugetlb: fix mremap deadlock when PMD sharing is possible move_hugetlb_page_tables() holds the mapping's i_mmap_rwsem for write while moving hugetlb PTEs. This prevents races with truncation and protects huge_pmd_unshare(), but the move loop must not call helpers that can acquire the same rwsem for read. huge_pte_alloc() can do that when the destination can use PMD sharing: it may call huge_pmd_share(), which takes i_mmap_rwsem for read while searching for a shareable PMD table. Calling it while the move path already holds i_mmap_rwsem for write can deadlock. Avoid that path for PMD-sized hugetlb mappings that can use PMD sharing. Instead of allocating or sharing the destination page table while moving, zap the source range and let the destination fault path populate or share the PMD lazily. Reuse the hugetlb unmap logic for the source-side zap by splitting the core loop out of __unmap_hugepage_range(). The wrapper keeps the existing tlb_start_vma(), tlb_end_vma() and huge_pmd_unshare_flush() behavior, while move_hugetlb_page_tables() can reuse the unmap loop with its existing mmu_gather.