В ядре Linux была устранена следующая уязвимость: KVM: x86/mmu: Consume заблокированное значение rmap в безблокировочном rmap walk __kvm_rmap_lock() намеренно убирает блокировку rmap при наблюдении пустого rmap. В этом случае kvm_rmap_lock_readonly() также повторно включает упреждение и возвращает ноль, поэтому вызывающий абонент не имеет ни блокировки rmap, ни ссылки на упреждение. Elision документирует инвариант, на который он опирается: * Elide блокировка, если rmap пуст, так как ходячим без блокировки (только для чтения * режим) не нужно (и не может) пройти пустую rmap, и они не могут добавлять * записи в rmap.
Т.е. единственные пути, которые обрабатывают пустые rmaps *, делают это, удерживая mmu_lock для записи, и являются взаимоисключающими. kvm_rmap_age_gfn_range() игнорирует возвращаемое значение и безоговорочно вводит for_each_rmap_spte_lockless(). Итератор начинался с rmap_get_first(), который пересчитывает rmap_head->val, а не использует значение, возвращаемое блокировкой. Если запись заполняет rmap между чтением замка и повторным чтением итератора, путь старения проходит недавно установленную rmap, не удерживая его блокировку.
Для KVM_RMAP_MANY rmap это оставляет ходока после цепочки pte_list_desc, которую он никогда не блокировал. Писатель, держащий mmu_lock для записи, может освободить эту цепочку (например, kvm_zap_all_rmap_sptes () на пути рециркуляции или любой rmap zap) через kmem_cache_free () во время прохождения, давая плиту use-after-free. Ничто не сериализует их: путь старения проходит без mmu_lock, когда CONFIG_KVM_MMU_LOCKLESS_AGING=y и блокировка rmap, которая в противном случае исключала бы запись, были удалены.
Поскольку пустой путь снова включает упреждение, интервал между двумя чтениями может охватывать произвольную задержку планирования. Исправьте класс ошибки, если при ходьбе без блокировки потребляете значение, возвращаемое блокировкой, вместо повторного чтения rmap. Разделите rmap_get_first() на __rmap_get_first(), который запускает итератор из уже прочитанного значения rmap, и заставьте for_each_rmap_spte_lockless() принять это значение и вызвать __rmap_get_first() напрямую. kvm_rmap_age_gfn_range() передает значение, возвращенное kvm_rmap_lock_readonly(): когда блокировка была удалена, значение равно нулю, __rmap_get_first() возвращает NULL, и ход пропущен.
Никакой lockless walker не перечитывает rmap, поэтому инвариант lock-elision не может быть нарушен, и никакой путь lock()-without-paired-unlock() не добавляется к коду старения.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: KVM: x86/mmu: Consume the locked rmap value in the lockless rmap walk __kvm_rmap_lock() deliberately elides the rmap lock when it observes an empty rmap. In that case kvm_rmap_lock_readonly() also re-enables preemption and returns zero, so the caller holds neither the rmap lock nor a preemption reference. The elision documents the invariant it relies on: * Elide the lock if the rmap is empty, as lockless walkers (read-only * mode) don't need to (and can't) walk an empty rmap, nor can they add * entries to the rmap. I.e. the only paths that process empty rmaps * do so while holding mmu_lock for write, and are mutually exclusive. kvm_rmap_age_gfn_range() ignores the returned value and unconditionally enters for_each_rmap_spte_lockless(). The iterator started with rmap_get_first(), which re-reads rmap_head->val rather than using the value returned by the lock. If a writer populates the rmap between the lock's read and the iterator's re-read, the aging path walks the newly installed rmap without holding its lock. For a KVM_RMAP_MANY rmap this leaves the walker following a pte_list_desc chain that it never locked. A writer holding mmu_lock for write may free that chain (e.g. kvm_zap_all_rmap_sptes() on the recycle path, or any rmap zap) via kmem_cache_free() while the walk is in progress, giving a slab use-after-free. Nothing serialises the two: the aging path runs without mmu_lock when CONFIG_KVM_MMU_LOCKLESS_AGING=y, and the rmap lock that would otherwise exclude the writer was elided. Because the empty path re-enables preemption, the interval between the two reads can span an arbitrary scheduling delay. Fix the class of bug by having the lockless walk consume the value returned by the lock instead of re-reading the rmap. Split rmap_get_first() into __rmap_get_first(), which starts an iterator from an already-read rmap value, and make for_each_rmap_spte_lockless() take that value and call __rmap_get_first() directly. kvm_rmap_age_gfn_range() passes the value returned by kvm_rmap_lock_readonly(): when the lock was elided the value is zero, __rmap_get_first() returns NULL, and the walk is skipped. No lockless walker re-reads the rmap, so the lock-elision invariant cannot be violated, and no lock()-without-paired-unlock() path is added to the aging code.
Характеристики атаки
Последствия
Строка CVSS v3.1