В ядре Linux была устранена следующая уязвимость: mm/rmap: don't exjoy lendyfree THPs at PMD level __discard_anon_folio_pmd_locked() очищает PMD от lendyfree THP, прежде чем определит, можно ли отбросить фолио, и восстанавливает его, если фолио грязное или имеет дополнительные ссылки. Это делается только под замком PMD и считывающим замком anon_vma внутри try_to_unmap_one(), и замок mmap не удерживается. PMD не вызывает UAF.
Параллельная munmap() или mremap() должна сериализироваться с ней на блокировке PMD, но zap_pmd_range() (вызывается munmap()) и move_page_tables() (вызывается mremap()) не берут блокировку, когда они видят временно отсутствующий PMD и пропускают PMD. There is no more page table walk after the none PMD is restored: - munmap(): free_pgtables() waits in unlink_anon_vmas() for the anon_vma lock, then free_pmd_range() drops the restored PMD as bad without removing the rmap, so the folio keeps a stale mapcount. - whole-VMA MREMAP_DONTUNMAP: dontunmap_complete() unlinks the source VMA from its anon_vma while the restored PMD still maps the folio. - plain mremap(): the THP is not moved but unmapped, so the THP's data is lost. В первых двух случаях фолио остается на карте, но нет VMA, который отображает его, связан с его anon_vma.
Когда anon_vma освобожден, он все еще доступен, когда один rmap ходит по фолио. Гонки без лени против MREMAP_DONTUNMAP, когда непривилегированный пользователь воспроизводит KASAN use-after-free в folio_lock_anon_vma_read (), как сообщается в ссылке Closes. Одно из решений состоит в том, чтобы использовать недействительный PMD вместо очищенного до тех пор, пока не будет совершен отказ, но сначала ему нужно исправить дугу. 1.
GUP-fast по-прежнему следует за недействительным PMD на riscv, LoongArch и s390. 2. sparc64 пересчитывает thp_pte_count, когда недействительный PMD снова установлен или очищен. To keep the fix simple for backport, stop discarding lazyfree THPs at PMD level instead. try_to_unmap_one() splits the PMD and discards the folio at PTE level. unmap_huge_pmd_locked() and __discard_anon_folio_pmd_locked() are left in place, unused, to minimize this fix for backport and the invalidated PMD approach is planned as a follow-up series to use them again.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: mm/rmap: don't discard lazyfree THPs at PMD level __discard_anon_folio_pmd_locked() clears a lazyfree THP's PMD before it determines whether the folio can be discarded, and restores it if the folio is dirty or has extra references. It is done under only the PMD lock and the anon_vma read lock inside try_to_unmap_one() and no mmap lock is held. The temporarily none PMD causes UAF. A parallel munmap() or mremap() is supposed to serialize with it on the PMD lock, but zap_pmd_range() (called by munmap()) and move_page_tables() (called by mremap()) do not take the lock when they see the temporarily none PMD and skip the PMD. There is no more page table walk after the none PMD is restored: - munmap(): free_pgtables() waits in unlink_anon_vmas() for the anon_vma lock, then free_pmd_range() drops the restored PMD as bad without removing the rmap, so the folio keeps a stale mapcount. - whole-VMA MREMAP_DONTUNMAP: dontunmap_complete() unlinks the source VMA from its anon_vma while the restored PMD still maps the folio. - plain mremap(): the THP is not moved but unmapped, so the THP's data is lost. In the first two cases, the folio stays mapped, but no VMA that maps it is linked to its anon_vma. When the anon_vma is freed, it is still reachable when one rmap walks the folio. Racing lazyfree reclaim against MREMAP_DONTUNMAP as an unprivileged user reproduces a KASAN use-after-free in folio_lock_anon_vma_read() as reported in the Closes link. One solution is to use an invalidated PMD instead of a cleared one until the discard is committed, but it needs arch fixes first. 1. GUP-fast still follows an invalidated PMD on riscv, LoongArch and s390. 2. sparc64 miscounts thp_pte_count when an invalidated PMD is set again or cleared. To keep the fix simple for backport, stop discarding lazyfree THPs at PMD level instead. try_to_unmap_one() splits the PMD and discards the folio at PTE level. unmap_huge_pmd_locked() and __discard_anon_folio_pmd_locked() are left in place, unused, to minimize this fix for backport and the invalidated PMD approach is planned as a follow-up series to use them again.
Характеристики атаки
Последствия
Строка CVSS v3.1