Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH bluetooth 0/4] Bluetooth: fix cmd_sync payload lifetimes on the cancel path
@ 2026-08-06 12:59 Linmao Li
  2026-08-06 12:59 ` [PATCH bluetooth 1/4] Bluetooth: hci_conn: fix the SCO setup context lifetime Linmao Li
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Linmao Li @ 2026-08-06 12:59 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz
  Cc: Brian Gix, linux-bluetooth, linux-kernel, Linmao Li

The cmd_sync worker calls entry->destroy() after running a command, and
_hci_cmd_sync_cancel_entry() does the same when an entry is cancelled --
but only if a destroy callback was supplied. Without one it frees the
work entry and leaves entry->data unreleased.

These four call sites pass a heap payload with a NULL destroy callback
and free it inside the sync function instead, so each of them leaks when
the entry is cancelled rather than run. hci_cmd_sync_clear() cancels
every pending entry when the controller is unregistered.

Patch 1 additionally holds the connection, as the payload stores a bare
hci_conn pointer. Patch 2 additionally frees the payload when queueing
fails, which it currently does not check for. Patches 3 and 4 also leak
the socket reference taken by mgmt_pending_new().

Each patch moves the release into a destroy callback; apart from holding
the connection in patch 1, no behaviour changes.

Found by inspection while reading the recent cmd_sync lifetime fixes.
Not tested on hardware: these paths need an adapter removal racing a
queued command, or allocation failure, to reach.

Linmao Li (4):
  Bluetooth: hci_conn: fix the SCO setup context lifetime
  Bluetooth: hci_sync: free the advertising instance on the failure and
    cancel paths
  Bluetooth: MGMT: free the mesh send cancel command when it is
    cancelled
  Bluetooth: MGMT: free the HCI command when it is cancelled

 net/bluetooth/hci_conn.c | 20 +++++++++++++++-----
 net/bluetooth/hci_sync.c | 12 +++++++++---
 net/bluetooth/mgmt.c     | 22 +++++++++++++++-------
 3 files changed, 39 insertions(+), 15 deletions(-)


base-commit: abd93c85c8667add738ee82aeab95dd9fc8265a2
-- 
2.25.1


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

end of thread, other threads:[~2026-08-06 19:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 12:59 [PATCH bluetooth 0/4] Bluetooth: fix cmd_sync payload lifetimes on the cancel path Linmao Li
2026-08-06 12:59 ` [PATCH bluetooth 1/4] Bluetooth: hci_conn: fix the SCO setup context lifetime Linmao Li
2026-08-06 14:15   ` Bluetooth: fix cmd_sync payload lifetimes on the cancel path bluez.test.bot
2026-08-06 12:59 ` [PATCH bluetooth 2/4] Bluetooth: hci_sync: free the advertising instance on the failure and cancel paths Linmao Li
2026-08-06 12:59 ` [PATCH bluetooth 3/4] Bluetooth: MGMT: free the mesh send cancel command when it is cancelled Linmao Li
2026-08-06 12:59 ` [PATCH bluetooth 4/4] Bluetooth: MGMT: free the HCI " Linmao Li
2026-08-06 19:54 ` [PATCH bluetooth 0/4] Bluetooth: fix cmd_sync payload lifetimes on the cancel path 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