Skip to content

Bluetooth: Fix advertising instance accesses without hdev->lock

Cen Zhang linux-bluetooth lkml 2 versions – In review

Get series with b4
b4 am pm-bluetooth-objects-candidate-0245-v14-e37270232af59a877004-0@gmail.com

Versions newest first · linked by author and title

  1. v2 Latest2 patches 1 replyIn review
  2. v12 patches 2 repliesSuperseded 1 of 2 applied

Changes in v2 from the cover letter

- Address the advertising snapshot allocation and timeout/handle concerns raised by Sashiko:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/pm-bluetooth-objects-candidate-0245-v9-6b34bc036455ad3dd4ea-0%40gmail.com
- Use a 255-byte stack array in list order, and widen and clamp the duration conversion.
- Add a separate periodic/BIG/transfer handle mapping fix; retain the remove-set and random-address fixes already in next.
- Drop the former patch 2, Initialize advertising RPA work only once, because it is already applied upstream.
- Rebase onto bluetooth-next f42f5cae154b; preserve the connection-work shutdown changes.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2Bluetooth: hci_sync: Fix remaining advertising instance UAFsnet/bluetooth/hci_sync.c net/bluetooth/mgmt.c+229 -761 reply
2/2Bluetooth: hci_sync: Use controller handles for periodic advertisingnet/bluetooth/hci_sync.c+63 -90 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] Bluetooth: Fix advertising instance accesses without hdev->lock

Snapshot advertising instance data under hdev->lock and keep instance numbers, rather than list pointers, while waiting for controller commands (patch 1). The resume and power-on walks use a 255-byte stack array in list order, covering every nonzero u8 instance ID without an allocation failure after the pause state has been consumed. Widen the timeout conversion before converting to 10 ms units and clamp to U16_MAX.

Translate management instance numbers to controller handles in the remaining periodic advertising, BIG creation and advertising set transfer commands. For the shared handle 0, update the intended instance after the command succeeds, since the completion has no instance number (patch 2). The remove-set and random-address paths have already been fixed in the current tree and keep those implementations.

The former patch 2, "Bluetooth: hci_core: Initialize advertising RPA work only once", is already applied upstream and is not included again.

Validation: GCC modular and Clang built-in Bluetooth builds, including Clang context analysis; every prefix of both revised series and their combined tree build on bluetooth-next f42f5cae154b.
No new kernel runtime test was run; the quoted report is from the earlier instrumented test kernel.

I used Codex (OpenAI) to help write these patches.

Cen Zhang (2):
Bluetooth: hci_sync: Fix remaining advertising instance UAFs
Bluetooth: hci_sync: Use controller handles for periodic advertising

 net/bluetooth/hci_sync.c | 343 ++++++++++++++++++++++++++++++---------
 net/bluetooth/mgmt.c     |  34 +++-
 2 files changed, 292 insertions(+), 85 deletions(-)

---
Changes in v2:
- Address the advertising snapshot allocation and timeout/handle concerns raised by Sashiko:
https://netdev-ai.bots.linux.dev/sashiko/#/patchset/pm-bluetooth-objects-candidate-0245-v9-6b34bc036455ad3dd4ea-0%40gmail.com
- Use a 255-byte stack array in list order, and widen and clamp the duration conversion.
- Add a separate periodic/BIG/transfer handle mapping fix; retain the remove-set and random-address fixes already in next.
- Drop the former patch 2, Initialize advertising RPA work only once, because it is already applied upstream.
- Rebase onto bluetooth-next f42f5cae154b; preserve the connection-work shutdown changes.

Link to v1: https://lore.kernel.org/r/pm-bluetooth-objects-candidate-0245-v9-6b34bc036455ad3dd4ea-0@gmail.com