Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v4 00/17] Bluetooth: Fixes for issues reported by sashiko.dev
Date: Wed, 18 Nov 2026 10:58:57 -0500	[thread overview]
Message-ID: <20261118155914.178050-1-luiz.dentz@gmail.com> (raw)

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 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 was build tested (W=1, each patch) and
run with the same configuration: 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). Earlier runs had rfcomm-tester
report a possible circular locking dependency (rfcomm_mutex,
hci_cb_list_lock, hdev->lock and the flush of the hci0 workqueue in
hci_release_dev()), which doesn't involve any lock of this series and
happens on the base kernel too.

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             | 325 ++++++++++++++++++++++++-------
 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, 502 insertions(+), 136 deletions(-)


base-commit: f42f5cae154b90a0cb6d8232dc84c7614ca2e6a0
-- 
2.56.0


             reply	other threads:[~2026-11-18 15:59 UTC|newest]

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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118155914.178050-1-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox