Skip to content

[PW_SID:1150937] [v5] Bluetooth: hci_sync: wait for directed advertising completion - #644

Open
BluezTestBot wants to merge 6 commits into
workflowfrom
1150937
Open

[PW_SID:1150937] [v5] Bluetooth: hci_sync: wait for directed advertising completion#644
BluezTestBot wants to merge 6 commits into
workflowfrom
1150937

Conversation

@BluezTestBot

Copy link
Copy Markdown

le_conn_timeout is embedded in struct hci_conn, but queuing the work does
not hold a reference to the connection. hci_conn_del() uses
cancel_delayed_work() because synchronous cancellation would deadlock when
le_conn_timeout() itself calls hci_conn_del() while holding hdev->lock.

This leaves the following interleaving possible:

CPU 0 CPU 1
le_conn_timeout()
hci_conn_del()
cancel_delayed_work() = false
hci_conn_cleanup()
put_device()
kfree(conn)
hci_conn_failed(conn, ...)

The callback then dereferences the released connection. KASAN reported:

BUG: KASAN: slab-use-after-free in hci_conn_failed+0x232/0x250
Read of size 8 at addr ffff8881180e8e20 by task kworker/u33:1/111
Workqueue: hci0 le_conn_timeout
Call Trace:
hci_conn_failed+0x232/0x250
le_conn_timeout+0x23e/0x2c0
process_one_work+0x61b/0xf50
worker_thread+0x45b/0xd10

Remove le_conn_timeout instead of adding another connection reference.
Have the directed-advertising enable commands complete normally, then wait
for the appropriate LE Connection Complete event with HCI_OP_NOP, matching
other Command Complete then later-event sequences such as PAST. The
command-sync entry already holds a connection reference until its
completion callback returns.

LE Set Advertising Enable and LE Set Extended Advertising Enable return
Command Complete rather than Command Status, so the later event cannot be
attached to the enable command itself without changing generic command
completion. Waiting with HCI_OP_NOP keeps that completion path unchanged.

Mark directed advertising as an in-flight connection attempt so teardown
can cancel the wait. Disable advertising synchronously when that wait
fails, and preserve HCI_ERROR_ADVERTISING_TIMEOUT for a software timeout.
Clear the instance-0 extended advertising state when advertising is stopped
or a connection completes so resuming paused advertising does not restart
the directed advertising instance.

There is then no delayed callback that can race with connection deletion.

Fixes: 980ffc0 ("Bluetooth: Fix LE connection timeout deadlock")
Cc: stable@vger.kernel.org
Suggested-by: Luiz Augusto von Dentz luiz.dentz@gmail.com
Signed-off-by: Chengfeng Ye nicoyip.dev@gmail.com

Changes in v5:

  • Drop the generic hci_cmd_complete_evt() change from v3/v4. Keeping a
    request pending on successful Command Complete when a later event was
    requested broke BlueZ CI PAST, Read Exp Feature, and Mesh Send cancel.
  • Wait for directed advertising completion with HCI_OP_NOP after the
    enable command completes, matching PAST, instead of changing generic
    command-complete semantics.

Changes in v4:

  • Rebase onto bluetooth-next/master so the patch applies to current
    Bluetooth CI HEAD.

Changes in v3:

  • Keep command-sync requests pending on successful Command Complete when
    the caller requested a later event, matching the existing Command Status
    behavior and fixing the first Sashiko/Luiz report.
  • Clear HCI_LE_ADV_0 when all extended advertising instances are disabled
    and when LE connection complete implicitly stops advertising, fixing the
    second Sashiko report about resuming stale directed advertising.

Changes in v2:

  • Remove le_conn_timeout instead of adding references around delayed work.
  • Wait for LE Connection Complete from both directed-advertising enable paths.
  • Make the wait cancellable and disable advertising after a failed wait.

Link: https://lore.kernel.org/linux-bluetooth/20260821172441.3020751-1-nicoyip.dev@gmail.com/ [v4]
Link: https://lore.kernel.org/linux-bluetooth/20260821164512.2842464-1-nicoyip.dev@gmail.com/ [v3]
Link: https://lore.kernel.org/linux-bluetooth/20260801145430.3560911-1-nicoyip.dev@gmail.com/ [v2]
Link: https://lore.kernel.org/linux-bluetooth/20260730104103.2080325-1-nicoyip.dev@gmail.com/ [v1]
Link: https://sashiko.dev/#/patchset/20260801145430.3560911-1-nicoyip.dev%40gmail.com

include/net/bluetooth/hci_core.h | 1 -
net/bluetooth/hci_conn.c | 45 --------------------------------
net/bluetooth/hci_event.c | 33 +++++------------------
net/bluetooth/hci_sync.c | 38 ++++++++++++++++++++++-----
4 files changed, 38 insertions(+), 79 deletions(-)

tedd-an and others added 6 commits August 21, 2026 20:12
This patch adds workflow files for ci:

[sync.yml]
 - The workflow file for scheduled work
 - Sync the repo with upstream repo and rebase the workflow branch
 - Review the patches in the patchwork and creates the PR if needed

[ci.yml]
 - The workflow file for CI tasks
 - Run CI tests when PR is created

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
This replaces the bzcafe action with bluez/action-ci so we can maintain
everything in the github bluez organization

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This attempts to sync every 5 minutes instead of 30.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
bluez/action-ci uses master as default branch for workflow which is
incorrect for kernel

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
The CI action now creates individual GitHub Check Runs per test, which
requires 'checks: write' permission on the GITHUB_TOKEN. Also make the
pull_request trigger types explicit to include 'reopened', allowing CI
to be retriggered by closing and reopening a PR.
le_conn_timeout is embedded in struct hci_conn, but queuing the work does
not hold a reference to the connection.  hci_conn_del() uses
cancel_delayed_work() because synchronous cancellation would deadlock when
le_conn_timeout() itself calls hci_conn_del() while holding hdev->lock.

This leaves the following interleaving possible:

  CPU 0                               CPU 1
  le_conn_timeout()
                                      hci_conn_del()
                                        cancel_delayed_work() = false
                                        hci_conn_cleanup()
                                          put_device()
                                            kfree(conn)
  hci_conn_failed(conn, ...)

The callback then dereferences the released connection.  KASAN reported:

  BUG: KASAN: slab-use-after-free in hci_conn_failed+0x232/0x250
  Read of size 8 at addr ffff8881180e8e20 by task kworker/u33:1/111
  Workqueue: hci0 le_conn_timeout
  Call Trace:
   hci_conn_failed+0x232/0x250
   le_conn_timeout+0x23e/0x2c0
   process_one_work+0x61b/0xf50
   worker_thread+0x45b/0xd10

Remove le_conn_timeout instead of adding another connection reference.
Have the directed-advertising enable commands complete normally, then wait
for the appropriate LE Connection Complete event with HCI_OP_NOP, matching
other Command Complete then later-event sequences such as PAST.  The
command-sync entry already holds a connection reference until its
completion callback returns.

LE Set Advertising Enable and LE Set Extended Advertising Enable return
Command Complete rather than Command Status, so the later event cannot be
attached to the enable command itself without changing generic command
completion.  Waiting with HCI_OP_NOP keeps that completion path unchanged.

Mark directed advertising as an in-flight connection attempt so teardown
can cancel the wait.  Disable advertising synchronously when that wait
fails, and preserve HCI_ERROR_ADVERTISING_TIMEOUT for a software timeout.
Clear the instance-0 extended advertising state when advertising is stopped
or a connection completes so resuming paused advertising does not restart
the directed advertising instance.

There is then no delayed callback that can race with connection deletion.

Fixes: 980ffc0 ("Bluetooth: Fix LE connection timeout deadlock")
Cc: stable@vger.kernel.org
Suggested-by: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Signed-off-by: Chengfeng Ye <nicoyip.dev@gmail.com>
@github-actions

Copy link
Copy Markdown

CheckPatch
Desc: Run checkpatch.pl script
Duration: 1.14 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

VerifyFixes
Desc: Verify Fixes tag format and validity
Duration: 0.07 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

VerifySignedoff
Desc: Verify Signed-off-by chain
Duration: 0.07 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

GitLint
Desc: Run gitlint
Duration: 0.20 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

SubjectPrefix
Desc: Check subject contains "Bluetooth" prefix
Duration: 0.06 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

BuildKernel
Desc: Build Kernel for Bluetooth
Duration: 24.41 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

CheckAllWarning
Desc: Run linux kernel with all warning enabled
Duration: 27.42 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

CheckSparse
Desc: Run sparse tool with linux kernel
Duration: 24.44 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

BuildKernel32
Desc: Build 32bit Kernel for Bluetooth
Duration: 28.23 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

CheckKernelLLVM
Desc: Build kernel with LLVM + context analysis
Duration: 0.00 seconds
Result: SKIP
Output:

Clang not found

@github-actions

Copy link
Copy Markdown

TestRunnerSetup
Desc: Setup kernel and bluez for test-runner
Duration: 427.64 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_l2cap-tester
Desc: Run l2cap-tester with test-runner
Duration: 62.80 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_iso-tester
Desc: Run iso-tester with test-runner
Duration: 92.02 seconds
Result: FAIL
Output:

Total: 141, Passed: 136 (96.5%), Failed: 5, Not Run: 0

Failed Test Cases
ISO Broadcaster PAST Info - Success                  Timed out    2.680 seconds
ISO Broadcaster PAST Info RPA - Success              Timed out    1.987 seconds
ISO Broadcaster PAST Sender - Success                Timed out    2.006 seconds
ISO Broadcaster PAST Receiver - Success              Timed out    2.811 seconds
ISO Broadcaster PAST Receiver Sync Lost - Success    Timed out    2.525 seconds

@github-actions

Copy link
Copy Markdown

TestRunner_bnep-tester
Desc: Run bnep-tester with test-runner
Duration: 17.87 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_mgmt-tester
Desc: Run mgmt-tester with test-runner
Duration: 206.09 seconds
Result: FAIL
Output:

Total: 501, Passed: 496 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.236 seconds

@github-actions

Copy link
Copy Markdown

TestRunner_rfcomm-tester
Desc: Run rfcomm-tester with test-runner
Duration: 23.10 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_sco-tester
Desc: Run sco-tester with test-runner
Duration: 27.28 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_ioctl-tester
Desc: Run ioctl-tester with test-runner
Duration: 23.03 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_mesh-tester
Desc: Run mesh-tester with test-runner
Duration: 23.68 seconds
Result: FAIL
Output:

Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    2.545 seconds
Mesh - Send cancel - 2                               Timed out    1.992 seconds

@github-actions

Copy link
Copy Markdown

TestRunner_smp-tester
Desc: Run smp-tester with test-runner
Duration: 21.01 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_userchan-tester
Desc: Run userchan-tester with test-runner
Duration: 18.25 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

TestRunner_6lowpan-tester
Desc: Run 6lowpan-tester with test-runner
Duration: 21.11 seconds
Result: PASS

@github-actions

Copy link
Copy Markdown

IncrementalBuild
Desc: Incremental build with the patches in the series
Duration: 22.13 seconds
Result: PASS

@github-actions
github-actions Bot force-pushed the workflow branch 2 times, most recently from 5774a29 to 616126a Compare August 28, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants