В ядре Linux устранена следующая уязвимость:
net: dsa: улучшить последовательность завершения работы
Александр Свердлин представляет 2 проблемы во время остановки с
драйвер lan9303. Один специфичен для lan9303, а другой просто случается.
воспроизвести там. Первая проблема заключается в том, что lan9303 уникален среди драйверов DSA, поскольку он
вызывает dev_get_drvdata() в «произвольное время выполнения» (не проверка, не завершение работы,
не удалять):
phy_state_machine()
-> ...
-> dsa_user_phy_read()
-> ds->ops->phy_read()
-> lan9303_phy_read()
-> чип->ops->phy_read()
-> lan9303_mdio_phy_read()
-> dev_get_drvdata()
Но мы никогда не останавливаем функцию phy_state_machine(), поэтому она может продолжать работать.
после dsa_switch_shutdown().
Наш общий шаблон во всех драйверах DSA:
установить для drvdata значение NULL, чтобы подавить метод удаления(), который может появиться
потом. Но в данном случае это приведет к NPD. Вторая проблема заключается в том, что способ, которым мы устанавливаем
dp->conduit->dsa_ptr = NULL; одновременно с получением пакета
обработка. dsa_switch_rcv() проверяет один раз, имеет ли dev->dsa_ptr значение NULL,
но впоследствии, вместо того, чтобы продолжать использовать это значение, отличное от NULL,
dev->dsa_ptr разыменовывается снова и снова без проверки NULL:
dsa_conduit_find_user() и во многих других местах.
Между разыменованиями
нет блокировки, гарантирующей, что то, что было действительным однажды, продолжает оставаться действительным
действительный. Обе проблемы имеют общий аспект: закрытие интерфейса канала
решает их. В первом случае dev_close(conduit) запускает NETDEV_GOING_DOWN.
событие в dsa_user_netdevice_event(), которое также закрывает пользовательские порты.
dsa_port_disable_rt() вызывает phylink_stop(), который синхронно останавливает
конечный автомат phylink, и ds->ops->phy_read() больше не будет
после этого момента вызовите водителя.
Во втором случае это должен сделать dev_close(conduit) согласно
Документация/сеть/driver.rst:
| Покой
| ----------
|
| После вызова процедуры ndo_stop аппаратное обеспечение должно
| не получать и не передавать какие-либо данные. Все пакеты в полете должны
| быть прервано. При необходимости проведите опрос или дождитесь завершения
| любые команды сброса.
Поэтому этого должно быть достаточно, чтобы гарантировать, что позже, когда мы обнулим
conduit->dsa_ptr, одновременный вызов dsa_switch_rcv() не будет
на этом трубопроводе. Добавление функции netif_device_detach() призвано гарантировать, что
ioctls, rtnetlinks и запросы ethtool на пользовательских портах больше не используются.
распространяться до драйвера — мы больше не готовы их обрабатывать. Состояние гонки на самом деле не существовало при фиксации 0650bf52b31f
(«net: dsa: быть совместим с мастерами, которые отменяют регистрацию при выключении»)
впервые представил dsa_switch_shutdown().
Он был создан позже, когда мы перестали отменять регистрацию пользовательских интерфейсов в плохом месте, и мы просто заменил эту последовательность грубым обнулением conduit->dsa_ptr (тот, который не гарантирует, что интерфейсы не работают).
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: net: dsa: improve shutdown sequence Alexander Sverdlin presents 2 problems during shutdown with the lan9303 driver. One is specific to lan9303 and the other just happens to reproduce there. The first problem is that lan9303 is unique among DSA drivers in that it calls dev_get_drvdata() at "arbitrary runtime" (not probe, not shutdown, not remove): phy_state_machine() -> ... -> dsa_user_phy_read() -> ds->ops->phy_read() -> lan9303_phy_read() -> chip->ops->phy_read() -> lan9303_mdio_phy_read() -> dev_get_drvdata() But we never stop the phy_state_machine(), so it may continue to run after dsa_switch_shutdown(). Our common pattern in all DSA drivers is to set drvdata to NULL to suppress the remove() method that may come afterwards. But in this case it will result in an NPD. The second problem is that the way in which we set dp->conduit->dsa_ptr = NULL; is concurrent with receive packet processing. dsa_switch_rcv() checks once whether dev->dsa_ptr is NULL, but afterwards, rather than continuing to use that non-NULL value, dev->dsa_ptr is dereferenced again and again without NULL checks: dsa_conduit_find_user() and many other places. In between dereferences, there is no locking to ensure that what was valid once continues to be valid. Both problems have the common aspect that closing the conduit interface solves them. In the first case, dev_close(conduit) triggers the NETDEV_GOING_DOWN event in dsa_user_netdevice_event() which closes user ports as well. dsa_port_disable_rt() calls phylink_stop(), which synchronously stops the phylink state machine, and ds->ops->phy_read() will thus no longer call into the driver after this point. In the second case, dev_close(conduit) should do this, as per Documentation/networking/driver.rst: | Quiescence | ---------- | | After the ndo_stop routine has been called, the hardware must | not receive or transmit any data. All in flight packets must | be aborted. If necessary, poll or wait for completion of | any reset commands. So it should be sufficient to ensure that later, when we zeroize conduit->dsa_ptr, there will be no concurrent dsa_switch_rcv() call on this conduit. The addition of the netif_device_detach() function is to ensure that ioctls, rtnetlinks and ethtool requests on the user ports no longer propagate down to the driver - we're no longer prepared to handle them. The race condition actually did not exist when commit 0650bf52b31f ("net: dsa: be compatible with masters which unregister on shutdown") first introduced dsa_switch_shutdown(). It was created later, when we stopped unregistering the user interfaces from a bad spot, and we just replaced that sequence with a racy zeroization of conduit->dsa_ptr (one which doesn't ensure that the interfaces aren't up).
Характеристики атаки
Последствия
Строка CVSS v3.1
Тип уязвимости (CWE)
Уязвимые продукты 5
| Конфигурация | От (включительно) | До (исключительно) |
|---|---|---|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
5.15.155
|
5.16
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
5.16.10
|
5.17
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
5.17
|
6.10.14
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.11
|
6.11.3
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.12:rc1:*:*:*:*:*:*
|
— | — |