В ядре Linux устранена следующая уязвимость:
мм: исправлен неправильный адрес сброса при прямом восстановлении таблицы страниц. Когда zap_pte_range освобождает таблицу страниц, он делает:
pte_free_tlb(tlb, pmd_pgtable(pmdval), адрес);
и это безусловно неправильно: если этот код выполняется, addr *всегда*
указывает на одну точку дальше конца диапазона, указанного в таблице. Адрес
параметр используется для очистки TLB (на самом деле кэша структуры подкачки)
удалить ссылки на таблицу, подлежащую освобождению, и любую архитектуру, которая
заботится о параметре, сбрасывает неверный адрес. (Но они будут
все равно освободите правильную страницу).
Думаю, стоит задуматься, почему ядро вообще работает. Если мы попадем в ошибочную строку кода, мы сначала очистим запись PMD.
(строка 1954, zap_empty_pte_table), то мы выполним ожидающие сбросы, если
Force_flush установлен (tlb_flush_mmu_tlbonly(tlb)), то мы пропустим
повторите попытку в строке 1979 (уф!), и тогда мы сделаем нарушение
вызов pte_free_tlb. *Или* мы удалим запись PMD непосредственно перед
pte_free_tlb (строка 1983, zap_pte_table_if_empty). Если у нас есть какие-либо ожидающие сбросы (т. е. мы фактически удалили все
записи) в то время, когда мы очищаем запись PMD, тогда сброс действительно должен
сбросить все ссылки на таблицу (Линус, похоже, так думает
будет на всех архитектурах [0]).
Условие, при котором у нас нет накопленных флешей на момент
очистка очень сложна (вся функция zap_pte_range абсурдно
сложный поток управления). Если мы попадем в плохой случай, то в конечном итоге мы окажемся
очистка записи PMD после последней очистки диапазона, и любые
ЦП может кэшировать ссылку на (пустую) таблицу страниц. Если это
происходит из-за обычного чтения или записи, это приведет к сбою, поэтому будет
быть редким.
Но кэш также может быть заполнен спекулятивно. Тогда
мы сбросим неправильный адрес, а затем освободим и, возможно, повторно используем
стол. На x86 даже очистка неправильного адреса работает в системах Intel, отличных от KPTI.
потому что INVLPG очищает *все* кеши страничной структуры, а не только те, которые
для целевого адреса.
Но INVPCID нет, аlush_tlb_one_user
будет использовать INVPCID, если он доступен. И тогда мы поджарены. Системы AMD
более восприимчивы: мы устанавливаем бит EFER.TCE, что делает даже INVLPG
только очистить целевой адрес.
Я думаю, что это может решить проблему в ripgrep, о которой сообщается здесь:
https://github.com/BurntSushi/ripgrep/issues/3494
[0] https://lore.kernel.org/all/CA+55aFzBggoXtNXQeng5d_mRoDnaMBE5Y+URs+PHR67nUpMtaw@mail.gmail.com/T/#u
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: mm: fix incorrect flush address in direct page table reclaim When zap_pte_range reclaims a page table, it does: pte_free_tlb(tlb, pmd_pgtable(pmdval), addr); and this is unconditionally wrong: if this code executes, addr *always* points one past the end of the range covered by the table. The addr parameter is used to flush the TLB (really the paging-structure-cache) to drop references to the to-be-freed table, and any architecture that cares about the parameter will flush the wrong address. (But they'll still free the correct page). I think it's worth contemplating why the kernel works at all. If we hit the offending line of code, we will first clear the PMD entry (line 1954, zap_empty_pte_table), then we will issue pending flushes if force_flush is set (tlb_flush_mmu_tlbonly(tlb)), then we will skip the retry on line 1979 (phew!), and then we will do the offending pte_free_tlb call. *Or* we will clear the PMD entry immediately before pte_free_tlb (line 1983, zap_pte_table_if_empty). If we have any pending flushes (i.e. we actually zapped any last-level entries) at the time we clear the PMD entry, then the flush really ought to flush all references to the table (Linus certainly seems to think it will on all architectures [0]). The condition under which we have no accumulated flushes at the time of the clear is very complex (the whole zap_pte_range function has absurdly complex control flow). If we do hit the bad case, then we will end up clearing the PMD entry after the last time the range is flushed, and any CPU is free to cache a reference to the (empty) page table. If this happens due to an ordinary read or write, it would segfault, so it would be rare. But the cache could be speculatively filled as well. Then we'll flush the wrong address and then free and possibly reuse the table. On x86, even flushing the wrong address works on non-KPTI Intel systems because INVLPG flushes *all* paging-structure-caches, not just the ones for the target address. But INVPCID does not, and flush_tlb_one_user will use INVPCID if it's available. And then we're toast. AMD systems are more susceptible: we set the EFER.TCE bit, which makes even INVLPG only flush the target address. I think this might fix an issue in ripgrep reported here: https://github.com/BurntSushi/ripgrep/issues/3494 [0] https://lore.kernel.org/all/CA+55aFzBggoXtNXQeng5d_mRoDnaMBE5Y+URs+PHR67nUpMtaw@mail.gmail.com/T/#u
Характеристики атаки
Последствия
Строка CVSS v3.1