Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v5 00/17] Bluetooth: Fixes for issues reported by sashiko.dev
@ 2026-11-18 19:11 Luiz Augusto von Dentz
  2026-11-18 19:11 ` [PATCH v5 01/17] Bluetooth: mgmt: Fix read_index_list() buffer overflow Luiz Augusto von Dentz
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-18 19:11 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This series fixes issues reported by sashiko.dev against the Bluetooth
core, each patch carries the identifier of the report(s) it addresses in
its Reported-by tag.

Missing locking around shared state:
 - Patch 2 takes hci_req_sync_lock around hci_powered_update_sync() in
   hci_power_on().
 - Patches 3 and 4 look up advertising instances under hdev->lock in
   hci_disable_ext_adv_instance_sync() and
   hci_schedule_adv_instance_sync().
 - Patch 5 serializes the writers of hdev->link_keys. smp_notify_keys()
   runs with the l2cap channel lock held, which is ordered after
   hdev->lock, so this adds a dedicated hdev->link_keys_lock instead of
   taking hdev->lock there.
 - Patch 13 protects the MSFT event prefix with hdev->lock.
 - Patch 15 holds hdev->lock while looking up and freeing advertisement
   monitors.

Lifetime issues:
 - Patch 11 reworks the mesh transmission handling: mesh_pending and the
   advertising instances are accessed under hdev->lock, the cmd_sync
   entries carry the transmission handle rather than a pointer to it, the
   first transmission is always the one being sent, cancelling one stops
   the done timer or dequeues its done entry if it is the one in
   progress, and the transmissions left are flushed when the controller
   is powered off.
 - Patch 12 reads the pending Set Powered command under
   mgmt_pending_lock in mgmt_powering_down().
 - Patch 16 frees the response of the MSFT add/remove monitor commands and
   initializes the RSSI fields of the handle data when it is created.
 - Patch 17 doesn't fail removing a monitor the controller doesn't know.

Missing validation:
 - Patch 1 sizes the Read Index List reply from all the controllers.
 - Patch 6 checks hdev->smp_data before using SMP_DEV().
 - Patch 8 validates the length of the sent LE Set Extended Advertising
   Enable command before parsing it.
 - Patch 9 rejects a zero multi advertising rotation duration.
 - Patch 10 only uses the EFS option in l2cap_parse_conf_rsp() if the
   response carried one.

debugfs:
 - Patch 7 stops force_bredr_smp from creating the BR/EDR SMP channel
   while SMP is not registered, and serializes smp_register() with it.
 - Patch 14 sets/clears the debugfs controlled flags and quirks
   explicitly rather than toggling them, and serializes the writers.

Changes in v5 (addressing the sashiko.dev review of v4), in patch 11:
 - mesh_flush() clears HCI_MESH_SENDING and stops the done timer before
   dequeuing the queued entries, otherwise a timer that already passed its
   HCI_MESH_SENDING check (it runs without hdev->lock) could queue
   mesh_send_done_sync behind the dequeue and have it complete a
   transmission started after the controller is powered on again.

Changes in v4 (addressing the sashiko.dev review of v3), all in patch 11:
 - The transmissions left are flushed when the controller is closed, also
   when it is auto powered off, not only from __mgmt_power_off(), and the
   entries still queued for them (mesh_send_sync and mesh_send_done_sync)
   are dequeued so they can't act on the transmissions started after the
   controller is powered on again.
 - Mesh Send is rejected with Not Powered when the controller isn't
   powered, serialized with the flush by hdev->lock, so it can't queue a
   transmission that nothing is going to send.
 - mgmt_mesh_add() doesn't reuse the handle of a transmission still pending
   when the counter wraps around, now that the handle is what identifies a
   transmission, otherwise Mesh Send Cancel could cancel the transmission
   of another socket.

Changes in v3 (addressing the sashiko.dev review of v2):
 - Patch 11: the cancel callback no longer clears HCI_MESH_SENDING, which
   let Mesh Send requeue a cancelled transmission still at the head of
   the list, the canceller clears it together with the removal. The
   transmissions left are now flushed, and the flag cleared, when the
   controller is powered off too, not only on index removal, and Mesh Send
   no longer reports the completion of a transmission whose handle
   userspace wasn't told about because queueing it failed.
 - Patch 16: also initialize the RSSI fields of the MSFT handle data when
   it is created rather than once the command completed.
 - Patch 17: fixed the Fixes tag, it is 7cf5c2978f23.

Changes in v2 (addressing the sashiko.dev review of v1):
 - Dropped "Bluetooth: RFCOMM: Serialize tty device reparenting", the
   review found that it is incomplete (hci_conn_del_sysfs() also moves the
   device, and shutdown moves it before closing the DLC), a proper fix
   needs a shared lock with hci_sysfs.c.
 - Dropped "hci_sync: Take req_sync lock in interleave_scan_work()" and the
   change to hci_abort_conn_sync() from the earlier revisions, they were
   not correct (the former can deadlock with cancel_interleave_scan()).
 - Patch 4: fixed the Fixes tag, it is cba6b758711c.
 - Patch 5: debug keys are removed by reference with hci_del_link_key()
   since a lookup by address skips blocked keys and would leak them, and
   the comment and commit message about which callers may use the
   returned key were corrected.
 - Patch 7: smp_register() is now called with hdev->lock so it can't race
   with smp_unregister() and smp_force_bredr().
 - Patch 11: restored mgmt_cleanup(), the previous change could sleep in
   atomic context (it runs from the socket destructor) and can't run for a
   socket with pending transmissions anyway since they hold a reference to
   it. HCI_MESH_SENDING is now only cleared together with the removal of
   the transmission, the first transmission is the one queued, a failed
   queue no longer strands the remaining ones, a done entry already queued
   is dequeued on cancel, and the index removal clears the flag.
 - Patch 14: also use assign_bit() instead of change_bit() for the quirk
   attributes.
 - New patches 16 and 17, found by the review.

Not addressed by this series, also reported by the reviews and left for
follow ups: the unlocked LTK/IRK accesses in smp_notify_keys() and
hci_add_irk(), the unlocked advertising instance lookups in the callees of
hci_start_adv_sync(), hci_enable_ext_advertising_sync(),
hci_remove_advertising_sync() and hci_enable_advertising_sync(), the
cur_adv_instance race, the double list_del() of an MSFT address filter and
the RFCOMM lock ordering and device_move() races.

Testing: v1 was run with KASAN and lockdep enabled through the BlueZ
testers (mgmt, mesh, smp, l2cap, rfcomm, iso, ...) and test-functional
(which found the lock ordering problem with hdev->lock in patch 5 that
led to hdev->link_keys_lock). v4 passed the whole test-functional run
(67 passed, 1 skipped and 1 xfailed, the expected failures of mesh-tester,
whose "Send cancel" tests are flaky and pass, or not, with or without this
series). v5 only changes the order of the calls in mesh_flush(), it was
build tested (W=1, each patch) and mesh-tester and mgmt-tester were run
again with the same configuration, with no warnings.

Luiz Augusto von Dentz (17):
  Bluetooth: mgmt: Fix read_index_list() buffer overflow
  Bluetooth: hci_core: Take req_sync lock in hci_power_on()
  Bluetooth: hci_sync: Lock the lookup in
    hci_disable_ext_adv_instance_sync()
  Bluetooth: hci_sync: Hold hdev->lock in
    hci_schedule_adv_instance_sync()
  Bluetooth: SMP: Serialize link key updates from smp_notify_keys()
  Bluetooth: SMP: Check smp_data before using SMP_DEV()
  Bluetooth: SMP: Don't create the BR/EDR channel while unregistered
  Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv
    Enable
  Bluetooth: mgmt: Reject zero multi advertising rotation duration
  Bluetooth: L2CAP: Don't use uninitialized EFS in
    l2cap_parse_conf_rsp()
  Bluetooth: mgmt: Fix mesh transmission locking and lifetime
  Bluetooth: MGMT: Fix use-after-free in mgmt_powering_down()
  Bluetooth: MSFT: Protect the event prefix with hdev->lock
  Bluetooth: hci_debugfs: Fix racy toggling of debugfs controlled flags
  Bluetooth: hci_core: Hold hdev->lock when removing advertisement
    monitors
  Bluetooth: MSFT: Free the response of the monitor commands
  Bluetooth: hci_core: Don't fail removing a monitor unknown to the
    controller

 include/net/bluetooth/hci_core.h |   7 +
 net/bluetooth/hci_core.c         |  81 +++++++-
 net/bluetooth/hci_debugfs.c      |  32 ++-
 net/bluetooth/hci_event.c        |   9 +-
 net/bluetooth/hci_sync.c         |  31 ++-
 net/bluetooth/l2cap_core.c       |   5 +-
 net/bluetooth/mgmt.c             | 329 ++++++++++++++++++++++++-------
 net/bluetooth/mgmt_config.c      |   6 +
 net/bluetooth/mgmt_util.c        |  23 ++-
 net/bluetooth/msft.c             |  61 +++---
 net/bluetooth/smp.c              |  58 ++++--
 11 files changed, 506 insertions(+), 136 deletions(-)


base-commit: f42f5cae154b90a0cb6d8232dc84c7614ca2e6a0
-- 
2.56.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-11-19 17:30 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 19:11 [PATCH v5 00/17] Bluetooth: Fixes for issues reported by sashiko.dev Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 01/17] Bluetooth: mgmt: Fix read_index_list() buffer overflow Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 02/17] Bluetooth: hci_core: Take req_sync lock in hci_power_on() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 03/17] Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 04/17] Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 05/17] Bluetooth: SMP: Serialize link key updates from smp_notify_keys() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 06/17] Bluetooth: SMP: Check smp_data before using SMP_DEV() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 07/17] Bluetooth: SMP: Don't create the BR/EDR channel while unregistered Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 08/17] Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 09/17] Bluetooth: mgmt: Reject zero multi advertising rotation duration Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 10/17] Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 11/17] Bluetooth: mgmt: Fix mesh transmission locking and lifetime Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 12/17] Bluetooth: MGMT: Fix use-after-free in mgmt_powering_down() Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 13/17] Bluetooth: MSFT: Protect the event prefix with hdev->lock Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 14/17] Bluetooth: hci_debugfs: Fix racy toggling of debugfs controlled flags Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 15/17] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 16/17] Bluetooth: MSFT: Free the response of the monitor commands Luiz Augusto von Dentz
2026-11-18 19:11 ` [PATCH v5 17/17] Bluetooth: hci_core: Don't fail removing a monitor unknown to the controller Luiz Augusto von Dentz
2026-11-19 17:30 ` [PATCH v5 00/17] Bluetooth: Fixes for issues reported by sashiko.dev patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox