В ядре Linux устранена следующая уязвимость:
Bluetooth: SCO: дайте сокету собственную ссылку sco_conn.
sco_conn_del() удаляет ссылку, которой он не владеет. Требуется один переходный процесс
ссылку через sco_conn_hold_unless_zero() и освобождает ее с помощью
sco_conn_put(), следующий за sco_sock_hold(); дополнительный вклад в
Ветка !sk выпускает вторую:
conn = sco_conn_hold_unless_zero (conn);
...
ск = sco_sock_hold (подключение);
sco_conn_unlock (подключение);
sco_conn_put (подключение);
если (!sk) {
sco_conn_put (подключение);
возвращаться;
}
Когда close() завершает отключение контроллера, sco_chan_del()
очищает conn->sk и удаляет ссылку на сокет, пока sco_conn_del()
бег. sco_conn_del() затем видит sk == NULL, его собственный метод put удаляет счетчик
обнуляется и освобождает конн, а второй пут записывает в освобожденный креф:
ОШИБКА: KASAN: slab-use-after-free в sco_conn_put.part.0+0x1a/0x190
Запись размера 4 по адресу ffff8881099dec74 с помощью задачи kworker/u17:3/413. Рабочая очередь: hci1 hci_rx_work
Отслеживание вызова:
sco_conn_put.part.0+0x1a/0x190
hci_disconn_complete_evt+0x1ee/0x3e0
hci_event_packet+0x54a/0x650
hci_rx_work+0x321/0x3d0
Выделено задачей 413:
sco_conn_add+0x72/0x1a0
sco_connect_cfm+0x88/0x670
Освобожден заданием 413:
sco_conn_del.isra.0+0x3f/0xf0
hci_disconn_complete_evt+0x1ee/0x3e0
refcount_t: опустошение; использовать после бесплатно.
Основная причина заключается в том, что сокет сохраняет соединение, не удерживая
ссылка своя. __sco_chan_add() выполняет:
sco_pi(sk)->conn = conn;
поэтому сокет заимствует любую ссылку, которую имел вызывающий объект, и
коллеры скрывают это с помощью специальных удержаний и путов. Дайте розетке
вместо этого подсчитывается ссылка: __sco_chan_add() принимает одну и высвобождается.
вместе с каналом (sco_chan_del()) и в sco_sock_destruct(). Поскольку сокет содержит собственную ссылку, sco_conn_del() больше не требуется.
дополнительный ввод и избыточное удержание в sco_conn_ready() исчезнут.
Если сокет станет владельцем своей ссылки, это означает, что соединение теперь фактически установлено.
освобожден на путях ошибок sco_connect(), где раньше происходила утечка, что в
очередь запускает sco_conn_free() и его hci_conn_drop(conn->hcon). Чтобы сохранить
Учет hci_conn сбалансирован, также укажите явное владение:
sco_conn_add() использует одну ссылку hci_conn, и sco_conn владеет ею в течение
срок его службы. sco_connect() передает ссылку, возвращенную
hci_connect_sco() и больше не отбрасывает его на пути ошибок;
sco_connect_cfm(), которому не дана ссылка, принимает ее с помощью
hci_conn_hold() перед передачей его в sco_conn_add() (и снова удаляет его, если
распределение не удалось); и явный hci_conn_hold() в sco_conn_ready()
удаляется. Таким образом, каждая ссылка имеет одного четкого владельца.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: Bluetooth: SCO: give the socket its own sco_conn reference sco_conn_del() drops a reference it does not own. It takes one transient reference via sco_conn_hold_unless_zero() and releases it with the sco_conn_put() that follows sco_sock_hold(); the additional put in the !sk branch releases a second one: conn = sco_conn_hold_unless_zero(conn); ... sk = sco_sock_hold(conn); sco_conn_unlock(conn); sco_conn_put(conn); if (!sk) { sco_conn_put(conn); return; } When close() races the controller's Disconnection Complete, sco_chan_del() clears conn->sk and drops the socket's reference while sco_conn_del() is running. sco_conn_del() then sees sk == NULL, its own put drops the count to zero and frees the conn, and the second put writes to the freed kref: BUG: KASAN: slab-use-after-free in sco_conn_put.part.0+0x1a/0x190 Write of size 4 at addr ffff8881099dec74 by task kworker/u17:3/413 Workqueue: hci1 hci_rx_work Call Trace: sco_conn_put.part.0+0x1a/0x190 hci_disconn_complete_evt+0x1ee/0x3e0 hci_event_packet+0x54a/0x650 hci_rx_work+0x321/0x3d0 Allocated by task 413: sco_conn_add+0x72/0x1a0 sco_connect_cfm+0x88/0x670 Freed by task 413: sco_conn_del.isra.0+0x3f/0xf0 hci_disconn_complete_evt+0x1ee/0x3e0 refcount_t: underflow; use-after-free. The root cause is that the socket stores the connection without holding a reference of its own. __sco_chan_add() does: sco_pi(sk)->conn = conn; so the socket borrows whatever reference its caller happened to hold, and the callers paper over that with ad-hoc holds and puts. Give the socket a counted reference instead: __sco_chan_add() takes one and it is released together with the channel (sco_chan_del()) and in sco_sock_destruct(). With the socket holding its own reference, sco_conn_del() no longer needs the extra put and the redundant hold in sco_conn_ready() goes away. Making the socket own its reference means the connection is now actually freed on the error paths of sco_connect() where it used to leak, which in turn runs sco_conn_free() and its hci_conn_drop(conn->hcon). To keep the hci_conn accounting balanced, make that ownership explicit as well: sco_conn_add() consumes one hci_conn reference and the sco_conn owns it for its lifetime. sco_connect() hands over the reference returned by hci_connect_sco() and no longer drops it on the error paths; sco_connect_cfm(), which is not given a reference, takes one with hci_conn_hold() before handing it to sco_conn_add() (and drops it again if the allocation fails); and the explicit hci_conn_hold() in sco_conn_ready() is removed. Every reference then has a single, clear owner.
Характеристики атаки
Последствия
Строка CVSS v3.1