UBUNTU-CVE-2024-49998
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).
02 / AFFECTED SOFTWARE
Affected packages
4 explicit affected versions
7 explicit affected versions
12 explicit affected versions
1 explicit affected versions
13 explicit affected versions
10 explicit affected versions
10 explicit affected versions
54 explicit affected versions
10 explicit affected versions
8 explicit affected versions
26 explicit affected versions
5 explicit affected versions
8 explicit affected versions
10 explicit affected versions
12 explicit affected versions
15 explicit affected versions
11 explicit affected versions
7 explicit affected versions
15 explicit affected versions
11 explicit affected versions
43 explicit affected versions
59 explicit affected versions
60 explicit affected versions
50 explicit affected versions
6 explicit affected versions
12 explicit affected versions
19 explicit affected versions
6 explicit affected versions
69 explicit affected versions
17 explicit affected versions
54 explicit affected versions
62 explicit affected versions
55 explicit affected versions
10 explicit affected versions
12 explicit affected versions
11 explicit affected versions
17 explicit affected versions
61 explicit affected versions
7 explicit affected versions
13 explicit affected versions
14 explicit affected versions
35 explicit affected versions
21 explicit affected versions
19 explicit affected versions
18 explicit affected versions
20 explicit affected versions
64 explicit affected versions
17 explicit affected versions
13 explicit affected versions
23 explicit affected versions
22 explicit affected versions
21 explicit affected versions
16 explicit affected versions
10 explicit affected versions
18 explicit affected versions
1 explicit affected versions
52 explicit affected versions
12 explicit affected versions
14 explicit affected versions
7 explicit affected versions
12 explicit affected versions
12 explicit affected versions
12 explicit affected versions
15 explicit affected versions
11 explicit affected versions
4 explicit affected versions
37 explicit affected versions
26 explicit affected versions
13 explicit affected versions
12 explicit affected versions
29 explicit affected versions
13 explicit affected versions
66 explicit affected versions
11 explicit affected versions
12 explicit affected versions
61 explicit affected versions
24 explicit affected versions
33 explicit affected versions
23 explicit affected versions
10 explicit affected versions
1 explicit affected versions
11 explicit affected versions
12 explicit affected versions
7 explicit affected versions
12 explicit affected versions
52 explicit affected versions
46 explicit affected versions
62 explicit affected versions
10 explicit affected versions
26 explicit affected versions
18 explicit affected versions
10 explicit affected versions
20 explicit affected versions
13 explicit affected versions
19 explicit affected versions
16 explicit affected versions
63 explicit affected versions
20 explicit affected versions
53 explicit affected versions
3 explicit affected versions
1 explicit affected versions
51 explicit affected versions
7 explicit affected versions
17 explicit affected versions
12 explicit affected versions
49 explicit affected versions
27 explicit affected versions
36 explicit affected versions
13 explicit affected versions
16 explicit affected versions
13 explicit affected versions
13 explicit affected versions
7 explicit affected versions
2 explicit affected versions
44 explicit affected versions
16 explicit affected versions
3 explicit affected versions
13 explicit affected versions
26 explicit affected versions
45 explicit affected versions
37 explicit affected versions
21 explicit affected versions
14 explicit affected versions
38 explicit affected versions
53 explicit affected versions
9 explicit affected versions
51 explicit affected versions
11 explicit affected versions
62 explicit affected versions
7 explicit affected versions
33 explicit affected versions
4 explicit affected versions
1 explicit affected versions
60 explicit affected versions
13 explicit affected versions
43 explicit affected versions
10 explicit affected versions
8 explicit affected versions
14 explicit affected versions
4 explicit affected versions
11 explicit affected versions
1 explicit affected versions
12 explicit affected versions
03 / CONNECTIONS
Connected vulnerabilities
04 / EVIDENCE
Source records
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).
05 / REFERENCES
Further evidence
- https://git.kernel.org/linus/6c24a03a61a245fe34d47582898331fa034b6ccd
- https://git.kernel.org/stable/c/6c24a03a61a245fe34d47582898331fa034b6ccd
- https://git.kernel.org/stable/c/ab5d3420a1120950703dbdc33698b28a6ebc3d23
- https://git.kernel.org/stable/c/b4a65d479213fe84ecb14e328271251eebe69492
- https://ubuntu.com/security/CVE-2024-49998
- https://ubuntu.com/security/notices/USN-7276-1
- https://ubuntu.com/security/notices/USN-7277-1
- https://ubuntu.com/security/notices/USN-7301-1
- https://ubuntu.com/security/notices/USN-7303-1
- https://ubuntu.com/security/notices/USN-7303-2
- https://ubuntu.com/security/notices/USN-7303-3
- https://ubuntu.com/security/notices/USN-7304-1
- https://ubuntu.com/security/notices/USN-7310-1
- https://ubuntu.com/security/notices/USN-7311-1
- https://ubuntu.com/security/notices/USN-7384-1
- https://ubuntu.com/security/notices/USN-7384-2
- https://ubuntu.com/security/notices/USN-7385-1
- https://ubuntu.com/security/notices/USN-7386-1
- https://ubuntu.com/security/notices/USN-7387-1
- https://ubuntu.com/security/notices/USN-7387-2
- https://ubuntu.com/security/notices/USN-7387-3
- https://ubuntu.com/security/notices/USN-7388-1
- https://ubuntu.com/security/notices/USN-7389-1
- https://ubuntu.com/security/notices/USN-7390-1
- https://ubuntu.com/security/notices/USN-7403-1
- https://ubuntu.com/security/notices/USN-7407-1
- https://ubuntu.com/security/notices/USN-7421-1
- https://ubuntu.com/security/notices/USN-7458-1
- https://ubuntu.com/security/notices/USN-7459-1
- https://ubuntu.com/security/notices/USN-7459-2
- https://ubuntu.com/security/notices/USN-7468-1
- https://www.cve.org/CVERecord?id=CVE-2024-49998