В ядре Linux была устранена следующая уязвимость: can: protect the receive lists with a per-device lock Списки приёма устройства CAN находятся в устройстве can_ml_priv и перемещаются вместе с устройством при его перемещении в другое пространство имен сети. Но они защищены per-netns rcvlists_lock. Таким образом, can_rx_unregister() нуждается в dev_net(dev), чтобы выбрать правильный замок и тихо возвращается, когда пройденное пространство имен больше не соответствует dev_net(dev). isotp_release() и bcm_release() покидают свой список уведомителей, прежде чем они возьмут любой замок, который сериализуется против уведомителя netdev, который работает под RTNL. isotp_release() передает пространство имен сокета, которое больше не соответствует dev_net(dev). bcm_rx_unreg() передает dev_net(dev), который can_rx_unregister() снова читает для своей проверки, поэтому изменение пространства имен между двумя чтениями делает проверку также неудачной.
В обоих случаях can_rx_unregister () тихо возвращается. Поскольку can_rx_register() хранит rcv->sk без ссылки, остальные получатели указывают на свободный сокет (isotp) или свободный op (bcm): BUG: KASAN: use-after-free в isotp_rcv+0x1570/0x24d0 Read размера 1 в addr ffff888118130552 задачей isotp_ns_uaf/578 can_rcv_filter+0x4af/0x8c0 can_receive+0x28d/0x3c0 can_rcv+0x2a9/0x310 __netif_receive_skb_one_core+0x21a/0x260 process_backlog+0x210/0x760 Besides это, списки устройства защищены rcvlists_lock пространства имен, которое передается в. Звонящие, которые проходят dev_net(dev), читают его в разное время, поэтому одни и те же списки могут быть изменены под замками разных пространств имен во время перемещения устройства.
Использование RTNL на этих путях выпуска не является вариантом: raw_bind(), raw_setsockopt() и raw_release() уже поддерживают RTNL, добавляя и удаляя до фильтров CAN_RAW_FILTER_MAX на сокет, которые непривилегированные пользователи могут активировать неоднократно, что делает RTNL глобальным узким местом. Вместо этого исправьте первопричину и добавьте spinlock в struct can_dev_rcv_lists, который защищает списки получения устройства CAN или списки устройств any' CAN пространства имен. Он инициализируется в can_set_ml_priv(), который используется всеми сетевыми устройствами CAN.
При этом can_rx_unregister() находит подписку независимо от текущего пространства имен устройства. Протоколы сохраняют устройство действительным со своими отслеживаемыми ссылками. rcvlists_lock больше защищает только статистику списка получателей, а CAN_RAW, CAN_BCM и CAN_ISOTP передают пространство имен, которое использовалось для can_rx_register(). Таким образом, isotp_release() и bcm_release() теперь правильно удаляют свои фильтры без RTNL, а raw_release(), raw_setsockopt(), raw_bind() и isotp_bind() больше не нуждаются в RTNL и добавляют и удаляют свои фильтры под lock_sock().
Для сериализации bind() с NETDEV_UNREGISTER, bind() публикует устройство внутри раздела RCU своего поиска, а raw_notify() и isotp_notify() перепроверяют связанное устройство под lock_sock(). Поскольку RTNL больше не держит NETDEV_DOWN вне bind(), bind() проверяет IFF_UP после публикации связанного устройства, с барьерной парой против raw_notify() и isotp_notify(), поэтому нисходящий переход во время bind() по-прежнему сообщается с ENETDOWN.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: can: protect the receive lists with a per-device lock The receive lists of a CAN device are located in the device's can_ml_priv and travel with the device when it is moved to another network namespace. But they are protected by the per-netns rcvlists_lock. So can_rx_unregister() needs dev_net(dev) to pick the right lock and silently returns when the passed namespace does not match dev_net(dev) anymore. isotp_release() and bcm_release() leave their notifier list before they take any lock that serializes against the netdev notifier, which runs under RTNL. When the bound device is moved to another namespace in this window, the notifier skips the socket and the release path has to remove the filters itself. isotp_release() passes the socket's namespace, which does not match dev_net(dev) anymore. bcm_rx_unreg() passes dev_net(dev), which can_rx_unregister() reads again for its check, so a namespace change between both reads makes the check fail as well. In both cases can_rx_unregister() silently returns. As can_rx_register() stores rcv->sk without a reference, the remaining receivers point to the freed socket (isotp) or the freed op (bcm): BUG: KASAN: use-after-free in isotp_rcv+0x1570/0x24d0 Read of size 1 at addr ffff888118130552 by task isotp_ns_uaf/578 can_rcv_filter+0x4af/0x8c0 can_receive+0x28d/0x3c0 can_rcv+0x2a9/0x310 __netif_receive_skb_one_core+0x21a/0x260 process_backlog+0x210/0x760 Besides this, the lists of a device are protected by the rcvlists_lock of the namespace that is passed in. Callers which pass dev_net(dev) read it at different times, so the same lists may be modified under the locks of different namespaces while the device is moved. Taking RTNL in these release paths is no option: raw_bind(), raw_setsockopt() and raw_release() already hold RTNL while adding and removing up to CAN_RAW_FILTER_MAX filters per socket, which unprivileged users can trigger repeatedly and which makes RTNL a global bottleneck. Instead fix the root cause and add a spinlock to struct can_dev_rcv_lists, which protects the receive lists of a CAN device or the 'any' CAN device lists of a namespace. It is initialized in can_set_ml_priv(), which is used by all CAN network devices. With this, can_rx_unregister() finds the subscription independently of the current namespace of the device. The protocols keep the device valid with their tracked references. The per-netns rcvlists_lock only protects the receive list statistics anymore, and CAN_RAW, CAN_BCM and CAN_ISOTP pass the namespace that has been used for can_rx_register(). So isotp_release() and bcm_release() now remove their filters correctly without RTNL, and raw_release(), raw_setsockopt(), raw_bind() and isotp_bind() do not need RTNL anymore and add and remove their filters under lock_sock(). To serialize bind() with NETDEV_UNREGISTER, bind() publishes the device inside the RCU section of its lookup, and raw_notify() and isotp_notify() recheck the bound device under lock_sock(). As RTNL does not keep NETDEV_DOWN out of bind() anymore, bind() checks IFF_UP after publishing the bound device, with a barrier pair against raw_notify() and isotp_notify(), so a down transition during bind() is still reported with ENETDOWN.
Характеристики атаки
Последствия
Строка CVSS v3.1