REDHAT-BUG-2576881: Use After Free
In the Linux kernel, the following vulnerability has been resolved:
fs/proc/taskmmu: pin mmusers in dopagemapscan()
The PAGEMAPSCAN ioctl takes mmapreadlock() on an mm obtained from /proc/<pid>/pagemap without holding a reference to mmusers.
procmemopen() deliberately grabs only mmcount, so a consumer that touches the address space has to call mmgetnotzero() first. Every other consumer in this file does -- mstart(), doprocmapquery(), showsmapsrollup() and pagemapread() -- but dopagemapscan() does not.
Without that reference the target can reach exitmmap() concurrently, and exitmmap() calls unmapvmas() while holding mmaplock only for reading, which does not exclude the scanner. For ordinary VMAs this is harmless, as freepgtables() and removevma() run afterwards under mmapwritelock. A shared hugetlb VMA is different: hugetlbzapend() frees the VMA's hugetlbvmalock inside the read-locked phase.
walkhugetlbrange() can therefore load vma->vmprivatedata, have the lock freed underneath it, and then downread() a freed rwsemaphore. The load happens before the freeing side clears the pointer, so this is a use-after-free and not a NULL dereference. Any unprivileged user can reach it with no huge pages configured, as hugetlbreservepages() allocates the lock before the VMNORESERVE early return.
Pin mmusers across the scan, the way the other consumers do. mmput() from the exiting task can then no longer reach exitmmap() while a walk is in progress.
[akpm: remove unneeded & undesirable test for !mm]
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Operational
In do_pagemap_scan(), call mmget_not_zero() to pin mm_users before scanning, hold the reference for the duration of the scan, and release it with mmput().
Event History
Frequently Asked Questions
Which kernel interface is involved in reaching the vulnerable code path?
The affected path is the PAGEMAP_SCAN ioctl used through /proc/<pid>/pagemap. The scanner operates on another process's memory map while that process can concurrently exit its address space.
Are all memory mappings equally exposed to the use-after-free condition?
No. The described use-after-free depends on a shared hugetlb VMA, where teardown can free the hugetlb_vma_lock during the read-locked phase. Ordinary VMAs are described as harmless in this race because their relevant cleanup occurs later under mmap_write_lock.