In the Linux kernel, the following vulnerability has been resolved: net: phy: transfer phy_config_inband() locking responsibility to phylink Problem description =================== Lockdep reports a possible circular locking dependency (AB/BA) between &pl->state_mutex and &phy->lock, as follows. phylink_resolve() // acquires &pl->state_mutex -> phylink_major_config() -> phy_config_inband() // acquires &pl->phydev->lock whereas all the other call sites where &pl->state_mutex and &pl->phydev->lock have the locking scheme reversed. В других местах &pl->phydev->lock приобретается на верхнем уровне, а &pl->state_mutex — на нижнем. Ярким примером является phylink_bringup_phy().
Исключением является недавно введенный phy_config_inband (), а существующий порядок блокировки является правильным. Чтобы понять, почему это не может быть наоборот, достаточно рассмотреть phylink_phy_change(), обратный вызов phylink из виртуального метода PHY устройства phy->phy_link_change(), вызванный машиной состояния PHY. phy_link_up() и phy_link_down(), (косвенные) абоненты phylink_phy_change(), вызваны с &phydev->lock. Затем phylink_phy_change () приобретает свой собственный &pl->state_mutex, чтобы сериализировать изменения, внесенные в его pl->phy_state и pl->link_config.
Таким образом, все другие экземпляры &pl->state_mutex и &phydev->lock должны соответствовать этому порядку. Влияние проблемы Я думаю, что ядро имеет серьезный риск тупика, если существующий поток phylink_resolve (), который приводит к вызову phy_config_inband (), совпадает с вызовом phy_link_up () или phy_link_down (), который заблокирует &pl->state_mutex в phylink_phy_change (). Практически говоря, воздействие может быть ограничено медленной скоростью среднего протокола автопереговоров, что делает маловероятным, чтобы текущее состояние все еще оставалось нерешенным, когда обнаруживается новое, но я думаю, что проблема есть.
Тем не менее, проблема была обнаружена с помощью LockDep. Предлагаемое решение Practically говорит, что требование phy_config_inband () о приобретении phydev->lock должно быть передано вызывающему абоненту (phylink является единственным вызывающим абонентом). Там он должен пузыриться до тех пор, пока не будет приобретен &pl->state_mutex, в тех случаях, когда это происходит.
Solution details, considerations, notes ======================================= This is the phy_config_inband() call graph: sfp_upstream_ops :: connect_phy() | v phylink_sfp_connect_phy() | v phylink_sfp_config_phy() | | sfp_upstream_ops :: module_insert() | | | v | phylink_sfp_module_insert() | | | | sfp_upstream_ops :: module_start() | | | | | v | | phylink_sfp_module_start() | | | | v v | phylink_sfp_config_optical() phylink_start() | | | phylink_resume() v v | | phylink_sfp_set_config() | | | v v v phylink_mac_initial_config() | phylink_resolve() | | phylink_ethtool_ksettings_set() v v v phylink_major_config() | v phy_config_inband() phylink_major_config() caller #1, phylink_mac_initial_config(), does not acquire &pl->state_mutex nor do its callers. Он должен приобрести &pl->phydev->lock до вызова phylink_major_config(). phylink_major_config() caller 2, phylink_resolve() приобретает &pl->state_mutex, поэтому также должен приобрести &pl->phydev->lock. phylink_major_config() caller 3, phylink_ethtool_ksettings_set(), совершенно неинтересно, потому что он только вызывает --- усеченный----
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: net: phy: transfer phy_config_inband() locking responsibility to phylink Problem description =================== Lockdep reports a possible circular locking dependency (AB/BA) between &pl->state_mutex and &phy->lock, as follows. phylink_resolve() // acquires &pl->state_mutex -> phylink_major_config() -> phy_config_inband() // acquires &pl->phydev->lock whereas all the other call sites where &pl->state_mutex and &pl->phydev->lock have the locking scheme reversed. Everywhere else, &pl->phydev->lock is acquired at the top level, and &pl->state_mutex at the lower level. A clear example is phylink_bringup_phy(). The outlier is the newly introduced phy_config_inband() and the existing lock order is the correct one. To understand why it cannot be the other way around, it is sufficient to consider phylink_phy_change(), phylink's callback from the PHY device's phy->phy_link_change() virtual method, invoked by the PHY state machine. phy_link_up() and phy_link_down(), the (indirect) callers of phylink_phy_change(), are called with &phydev->lock acquired. Then phylink_phy_change() acquires its own &pl->state_mutex, to serialize changes made to its pl->phy_state and pl->link_config. So all other instances of &pl->state_mutex and &phydev->lock must be consistent with this order. Problem impact ============== I think the kernel runs a serious deadlock risk if an existing phylink_resolve() thread, which results in a phy_config_inband() call, is concurrent with a phy_link_up() or phy_link_down() call, which will deadlock on &pl->state_mutex in phylink_phy_change(). Practically speaking, the impact may be limited by the slow speed of the medium auto-negotiation protocol, which makes it unlikely for the current state to still be unresolved when a new one is detected, but I think the problem is there. Nonetheless, the problem was discovered using lockdep. Proposed solution ================= Practically speaking, the phy_config_inband() requirement of having phydev->lock acquired must transfer to the caller (phylink is the only caller). There, it must bubble up until immediately before &pl->state_mutex is acquired, for the cases where that takes place. Solution details, considerations, notes ======================================= This is the phy_config_inband() call graph: sfp_upstream_ops :: connect_phy() | v phylink_sfp_connect_phy() | v phylink_sfp_config_phy() | | sfp_upstream_ops :: module_insert() | | | v | phylink_sfp_module_insert() | | | | sfp_upstream_ops :: module_start() | | | | | v | | phylink_sfp_module_start() | | | | v v | phylink_sfp_config_optical() phylink_start() | | | phylink_resume() v v | | phylink_sfp_set_config() | | | v v v phylink_mac_initial_config() | phylink_resolve() | | phylink_ethtool_ksettings_set() v v v phylink_major_config() | v phy_config_inband() phylink_major_config() caller #1, phylink_mac_initial_config(), does not acquire &pl->state_mutex nor do its callers. It must acquire &pl->phydev->lock prior to calling phylink_major_config(). phylink_major_config() caller #2, phylink_resolve() acquires &pl->state_mutex, thus also needs to acquire &pl->phydev->lock. phylink_major_config() caller #3, phylink_ethtool_ksettings_set(), is completely uninteresting, because it only call ---truncated---
Характеристики атаки
Последствия
Строка CVSS v3.1
Тип уязвимости (CWE)
Уязвимые продукты 6
| Конфигурация | От (включительно) | До (исключительно) |
|---|---|---|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.14
|
6.16.8
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.17:rc1:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.17:rc2:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.17:rc3:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.17:rc4:*:*:*:*:*:*
|
— | — |
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:6.17:rc5:*:*:*:*:*:*
|
— | — |