В ядре Linux была устранена следующая уязвимость: ocfs2/dlm: serialize migration MLE clearup on failure Миграция MLE имеет базовую ссылку на мастеринг-ответ и ссылку на использование, удерживаемую dlm_migrate_lockres(). Окончательное утверждение потребляет базовую ссылку, но ошибка миграции снова отбрасывает ее, не проверяя, использовало ли уже это утверждение. Цель ставит в очередь своего работника по миграции, прежде чем он признает пакет ALL_DONE, поэтому его окончательное утверждение может быть обработано, пока отправитель все еще ждет статуса.
If the connection fails before the status arrives, dlm_send_one_lockres() returns an error for a migration that the target has already completed: Old-master sender Finishing assertion ----------------- ------------------- publish MLE; take in-use reference send ALL_DONE; wait for status take lookup reference unlink MLE put lookup and base references send returns a connection error put base reference again; free MLE put in-use reference; access freed MLE dlm_assert_master_handler() holds dlm->spinlock from the MLE lookup to the final puts, and it takes dlm->master_lock around the unlink and the puts. Решите под теми же блокировками: если MLE уже невосприимчив, утверждение потребляет базовую ссылку, поэтому оставьте только ссылку на использование отправителя. В противном случае отсоедините его перед использованием базовой ссылки, чтобы более позднее утверждение больше не находило его.
Утверждение, которое попало туда первым, также сделало целью владельца и очистило DLM_LOCK_RES_MIGRATING. Обработка попытки как неудачная в этот момент оставит шлюзы, принадлежащие цели, в то время как этот узел все еще удерживает блокировки других узлов и биты refmap, поэтому он не может быть ни очищен, ни мигрировал снова. Вместо этого завершите нашу сторону, как это делает завершенная миграция: отбросьте эти блокировки под res->spinlock, если цель все еще владеет блокировками, и пересчитайте их использование.
Используйте ту же очистку для предпосылочного отказа, отказа отправки и путей отказа цели-смерти. Ссылка на отправителя сохраняет MLE живым до тех пор, пока он не будет окончательно выведен за пределы вложенных замков. Успешная миграция сохраняет свой существующий in-use-only.
Цель, которая умерла, не может утверждать после того, как отправитель увидел свою смерть. Обратный вызов o2net выполняется до DLM; он отключает узел и смывает рабочий запрос, который запускает обработчики сообщений, поэтому утверждение, уже полученное, было обработано к тому времени, когда DLM удаляет узел с карты домена. Узел, который покидает домен, отправляет свое сообщение о выходе только после ответа на его утверждения.
Два окна самой передачи остаются такими, какие они есть: обработчик переключает владельца, а отправитель сбрасывает блокировки других узлов несколько минут спустя, а утверждение из живой цели, которое приходит после того, как отправитель сдался, все еще встречает проверку владельца в обработчике. Ожидание цели, прежде чем сдаться, только растянет первое окно в то время, когда восстановление цели может наблюдать за ней. KASAN отчет, только соответствующие кадры сохраняются: BUG: KASAN: slab-use-after-free в dlm_put_mle_inuse+0xce/0xe0 Read размера 8 в addr ffff8881190e3c20 по задаче umount/593 Call Trace: <TASK> dlm_put_mle_inuse+0xce/0xe0 dlm_migrate_lockres+0x16af/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/0x110 ocfs2_cluster_disconnect+0x73/0xc0 ocfs2_dlm_shutdown+0x311/0x440 ocfs2_dismount_volume+0x696/0x940 generic_shutdown_super+0x15f/0x490 kill_block_super+0x40/0xa0 deactivate_locked_super+0xae/0x120 deactivate_super+0xa2/0xc0 cleanup_mnt+0x217/0x450 task_work_run+0x144/0x230 </TASK> Allocated по задаче 593: kmem_cache_alloc_noprof+0x20b/0x5c0 dlm_migrate_lockres+0x20e/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/ ---cruncated----
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: ocfs2/dlm: serialize migration MLE cleanup on failure A migration MLE has a base reference for the mastering answer and an in-use reference held by dlm_migrate_lockres(). The finishing assertion consumes the base reference, but migration failure drops it again without checking whether the assertion already consumed it. The target queues its migration worker before it acknowledges the ALL_DONE packet, so its finishing assertion can be handled while the sender still waits for the status. If the connection fails before the status arrives, dlm_send_one_lockres() returns an error for a migration that the target has already completed: Old-master sender Finishing assertion ----------------- ------------------- publish MLE; take in-use reference send ALL_DONE; wait for status take lookup reference unlink MLE put lookup and base references send returns a connection error put base reference again; free MLE put in-use reference; access freed MLE dlm_assert_master_handler() holds dlm->spinlock from the MLE lookup to the final puts, and it takes dlm->master_lock around the unlink and the puts. Decide under the same locks: if the MLE is already unhashed, the assertion consumed the base reference, so drop only the sender's in-use reference. Otherwise unlink it before consuming the base reference so a later assertion no longer finds it. An assertion that got there first has also made the target the owner and cleared DLM_LOCK_RES_MIGRATING. Treating the attempt as failed at that point would leave the lockres owned by the target while this node still holds the other nodes' locks and refmap bits, so it could neither be purged nor migrated again. Finish our side as a completed migration does instead: drop those locks under res->spinlock if the target still owns the lockres, and recalculate its usage. Use the same cleanup for the pre-send failure, the send failure and the target-death failure paths. The sender's in-use reference keeps the MLE alive until its final put outside the nested locks. Successful migration retains its existing in-use-only put. A target that has died cannot assert after the sender has seen its death. The o2net node-down callback runs before the DLM one; it disconnects the node and flushes the workqueue that runs the message handlers, so an assertion already received has been handled by the time the DLM removes the node from the domain map. A node that leaves the domain cleanly sends its exit message only after its assertions have been answered. Two windows of the hand-over itself are left as they are: the handler switches the owner and the sender drops the other nodes' locks moments later, and an assertion from a live target that arrives after the sender has given up still meets the owner check in the handler. Waiting for the target before giving up would only stretch the first window into the time in which recovery of the target can observe it. KASAN report, only the relevant frames are kept: BUG: KASAN: slab-use-after-free in dlm_put_mle_inuse+0xce/0xe0 Read of size 8 at addr ffff8881190e3c20 by task umount/593 Call Trace: <TASK> dlm_put_mle_inuse+0xce/0xe0 dlm_migrate_lockres+0x16af/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/0x110 ocfs2_cluster_disconnect+0x73/0xc0 ocfs2_dlm_shutdown+0x311/0x440 ocfs2_dismount_volume+0x696/0x940 generic_shutdown_super+0x15f/0x490 kill_block_super+0x40/0xa0 deactivate_locked_super+0xae/0x120 deactivate_super+0xa2/0xc0 cleanup_mnt+0x217/0x450 task_work_run+0x144/0x230 </TASK> Allocated by task 593: kmem_cache_alloc_noprof+0x20b/0x5c0 dlm_migrate_lockres+0x20e/0x20d0 dlm_empty_lockres+0x60a/0xbd0 dlm_unregister_domain+0x53b/0x11d0 o2cb_cluster_disconnect+0xa5/ ---truncated---