Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: do not leak an hci_conn when a second LE connect is rejected
@ 2026-08-24 10:24 Radek Podgorny
  2026-08-24 10:49 ` bluez.test.bot
  2026-08-24 11:00 ` [PATCH v2] " Radek Podgorny
  0 siblings, 2 replies; 5+ messages in thread
From: Radek Podgorny @ 2026-08-24 10:24 UTC (permalink / raw)
  To: Marcel Holtmann, Luiz Augusto von Dentz; +Cc: linux-bluetooth, linux-kernel

create_le_conn_complete() decides whether the failed connection is
still pending by comparing it against hci_lookup_le_connect(), which
returns the first LE connection in BT_CONNECT. That is the same
connection only while at most one is pending.

Two can be pending. Connections created on the passive scan path sit
in BT_CONNECT with HCI_CONN_SCANNING set and are invisible to
hci_lookup_le_connect() until hci_le_create_conn_sync() clears the
flag when their command is issued, so the -EBUSY guard in
hci_connect_le() does not prevent a second connection from being
queued while the first is still on the scan path. Whenever two
connections are in BT_CONNECT at once, the lookup may return one
connection while create_le_conn_complete() is reporting the failure
of the other; the early exit then drops the error and hci_conn_failed()
never runs on the connection that failed.

The controller also rejects a second HCI_OP_LE_CREATE_CONN issued
while another connection creation is still outstanding, per Core Spec
Vol 4, Part E. The spec calls for Command Disallowed there; the
bcm43438 observed here answers with an LMP/LL error code instead,
which bt_to_errno() maps to the -EPROTO (-71) in the log below.

The leaked connection stays in BT_CONNECT forever, and because
hci_connect_le() refuses to dial while hci_lookup_le_connect() finds
anything, every subsequent attempt to reach any peer fails with
-EBUSY and no command reaches the controller at all.

Seen on a bcm43438 with two BLE peers polled on the same interval
(state 5 is BT_CONNECT; both handles are UNSET ones, allocated from
the ida above HCI_CONN_HANDLE_MAX):

  Bluetooth: hci1: Opcode 0x2013 failed: -71

  # hcitool con
          < LE 14:9C:EF:03:68:81 handle 3840 state 5 lm CENTRAL
          < LE C4:D3:6A:8C:B5:38 handle 3841 state 5 lm CENTRAL

A btmon capture across the next ten minutes of connect attempts
contains no HCI_OP_LE_CREATE_CONN at all; outgoing LE connections
do not recover until the adapter is reset. With this change the same
scenario fails the rejected connection cleanly and further connects
to both peers go through.

Ask about the connection itself instead of about the device.

Fixes: c9f73a2178c1 ("Bluetooth: hci_conn: Fix hci_connect_le_sync")
Signed-off-by: Radek Podgorny <radek@podgorny.cz>
---
 net/bluetooth/hci_sync.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 7150037a864b..24eeb76f7207 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -7279,8 +7279,13 @@ static void create_le_conn_complete(struct
hci_dev *hdev, void *data, int err)
 		goto unlock;
 	}
 -	/* Check if connection is still pending */
-	if (conn != hci_lookup_le_connect(hdev))
+	/* Check if this connection is still pending.
+	 *
+	 * hci_lookup_le_connect() returns only the first LE connection
+	 * in BT_CONNECT, which is not necessarily this one when two are
+	 * pending at once, so ask the connection itself.
+	 */
+	if (conn->state != BT_CONNECT)
 		goto unlock;
  	/* Flush to make sure we send create conn cancel command if needed */
-- 
2.47.3

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

* RE: Bluetooth: do not leak an hci_conn when a second LE connect is rejected
  2026-08-24 10:24 [PATCH] Bluetooth: do not leak an hci_conn when a second LE connect is rejected Radek Podgorny
@ 2026-08-24 10:49 ` bluez.test.bot
  2026-08-24 11:00 ` [PATCH v2] " Radek Podgorny
  1 sibling, 0 replies; 5+ messages in thread
From: bluez.test.bot @ 2026-08-24 10:49 UTC (permalink / raw)
  To: linux-bluetooth, radek

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----

error: corrupt patch at line 12
hint: Use 'git am --show-current-patch' to see the failed patch

Please resolve the issue and submit the patches again.


---
Regards,
Linux Bluetooth


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

* [PATCH v2] Bluetooth: do not leak an hci_conn when a second LE connect is rejected
  2026-08-24 10:24 [PATCH] Bluetooth: do not leak an hci_conn when a second LE connect is rejected Radek Podgorny
  2026-08-24 10:49 ` bluez.test.bot
@ 2026-08-24 11:00 ` Radek Podgorny
  2026-08-24 11:49   ` [v2] " bluez.test.bot
  2026-08-24 16:50   ` [PATCH v2] " patchwork-bot+bluetooth
  1 sibling, 2 replies; 5+ messages in thread
From: Radek Podgorny @ 2026-08-24 11:00 UTC (permalink / raw)
  To: marcel, luiz.dentz; +Cc: linux-bluetooth, linux-kernel, Radek Podgorny

create_le_conn_complete() decides whether the failed connection is
still pending by comparing it against hci_lookup_le_connect(), which
returns the first LE connection in BT_CONNECT. That is the same
connection only while at most one is pending.

Two can be pending. Connections created on the passive scan path sit
in BT_CONNECT with HCI_CONN_SCANNING set and are invisible to
hci_lookup_le_connect() until hci_le_create_conn_sync() clears the
flag when their command is issued, so the -EBUSY guard in
hci_connect_le() does not prevent a second connection from being
queued while the first is still on the scan path. Whenever two
connections are in BT_CONNECT at once, the lookup may return one
connection while create_le_conn_complete() is reporting the failure
of the other; the early exit then drops the error and hci_conn_failed()
never runs on the connection that failed.

The controller also rejects a second HCI_OP_LE_CREATE_CONN issued
while another connection creation is still outstanding, per Core Spec
Vol 4, Part E. The spec calls for Command Disallowed there; the
bcm43438 observed here answers with an LMP/LL error code instead,
which bt_to_errno() maps to the -EPROTO (-71) in the log below.

The leaked connection stays in BT_CONNECT forever, and because
hci_connect_le() refuses to dial while hci_lookup_le_connect() finds
anything, every subsequent attempt to reach any peer fails with
-EBUSY and no command reaches the controller at all.

Seen on a bcm43438 with two BLE peers polled on the same interval
(state 5 is BT_CONNECT; both handles are UNSET ones, allocated from
the ida above HCI_CONN_HANDLE_MAX):

  Bluetooth: hci1: Opcode 0x2013 failed: -71

  # hcitool con
          < LE 14:9C:EF:03:68:81 handle 3840 state 5 lm CENTRAL
          < LE C4:D3:6A:8C:B5:38 handle 3841 state 5 lm CENTRAL

A btmon capture across the next ten minutes of connect attempts
contains no HCI_OP_LE_CREATE_CONN at all; outgoing LE connections
do not recover until the adapter is reset. With this change the same
scenario fails the rejected connection cleanly and further connects
to both peers go through.

Ask about the connection itself instead of about the device.

Fixes: c9f73a2178c1 ("Bluetooth: hci_conn: Fix hci_connect_le_sync")
Signed-off-by: Radek Podgorny <radek@podgorny.cz>
---

Changes in v2:

- Resend with git send-email; both previous submissions were mangled
  by the mail client and never applied. No change to the patch itself.

 net/bluetooth/hci_sync.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 7150037a864b..24eeb76f7207 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -7279,8 +7279,13 @@ static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err)
 		goto unlock;
 	}
 
-	/* Check if connection is still pending */
-	if (conn != hci_lookup_le_connect(hdev))
+	/* Check if this connection is still pending.
+	 *
+	 * hci_lookup_le_connect() returns only the first LE connection
+	 * in BT_CONNECT, which is not necessarily this one when two are
+	 * pending at once, so ask the connection itself.
+	 */
+	if (conn->state != BT_CONNECT)
 		goto unlock;
 
 	/* Flush to make sure we send create conn cancel command if needed */
-- 
2.47.3


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

* RE: [v2] Bluetooth: do not leak an hci_conn when a second LE connect is rejected
  2026-08-24 11:00 ` [PATCH v2] " Radek Podgorny
@ 2026-08-24 11:49   ` bluez.test.bot
  2026-08-24 16:50   ` [PATCH v2] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 5+ messages in thread
From: bluez.test.bot @ 2026-08-24 11:49 UTC (permalink / raw)
  To: linux-bluetooth, radek

[-- Attachment #1: Type: text/plain, Size: 2389 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=1150809

---Test result---

Test Summary:
CheckPatch                    PASS      0.56 seconds
VerifyFixes                   PASS      0.10 seconds
VerifySignedoff               PASS      0.16 seconds
GitLint                       PASS      0.25 seconds
SubjectPrefix                 PASS      5.56 seconds
BuildKernel                   PASS      20.96 seconds
CheckAllWarning               PASS      23.54 seconds
CheckSparse                   PASS      22.26 seconds
BuildKernel32                 PASS      20.13 seconds
CheckKernelLLVM               SKIP      0.00 seconds
TestRunnerSetup               PASS      369.28 seconds
TestRunner_l2cap-tester       PASS      56.83 seconds
TestRunner_iso-tester         PASS      71.09 seconds
TestRunner_bnep-tester        PASS      15.61 seconds
TestRunner_mgmt-tester        FAIL      198.21 seconds
TestRunner_rfcomm-tester      PASS      21.10 seconds
TestRunner_sco-tester         PASS      27.74 seconds
TestRunner_ioctl-tester       PASS      22.17 seconds
TestRunner_mesh-tester        FAIL      22.58 seconds
TestRunner_smp-tester         PASS      19.29 seconds
TestRunner_userchan-tester    PASS      16.47 seconds
TestRunner_6lowpan-tester     PASS      18.98 seconds
IncrementalBuild              PASS      20.07 seconds

Details
##############################
Test: CheckKernelLLVM - SKIP
Desc: Build kernel with LLVM + context analysis
Output:
Clang not found
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 501, Passed: 496 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.217 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 8 (80.0%), Failed: 2, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 1                               Timed out    2.497 seconds
Mesh - Send cancel - 2                               Timed out    1.993 seconds


https://github.com/bluez/bluetooth-next/pull/643

---
Regards,
Linux Bluetooth


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

* Re: [PATCH v2] Bluetooth: do not leak an hci_conn when a second LE connect is rejected
  2026-08-24 11:00 ` [PATCH v2] " Radek Podgorny
  2026-08-24 11:49   ` [v2] " bluez.test.bot
@ 2026-08-24 16:50   ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2026-08-24 16:50 UTC (permalink / raw)
  To: Radek Podgorny; +Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 24 Aug 2026 13:00:20 +0200 you wrote:
> create_le_conn_complete() decides whether the failed connection is
> still pending by comparing it against hci_lookup_le_connect(), which
> returns the first LE connection in BT_CONNECT. That is the same
> connection only while at most one is pending.
> 
> Two can be pending. Connections created on the passive scan path sit
> in BT_CONNECT with HCI_CONN_SCANNING set and are invisible to
> hci_lookup_le_connect() until hci_le_create_conn_sync() clears the
> flag when their command is issued, so the -EBUSY guard in
> hci_connect_le() does not prevent a second connection from being
> queued while the first is still on the scan path. Whenever two
> connections are in BT_CONNECT at once, the lookup may return one
> connection while create_le_conn_complete() is reporting the failure
> of the other; the early exit then drops the error and hci_conn_failed()
> never runs on the connection that failed.
> 
> [...]

Here is the summary with links:
  - [v2] Bluetooth: do not leak an hci_conn when a second LE connect is rejected
    https://git.kernel.org/bluetooth/bluetooth-next/c/aadb3cd4bbb4

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-08-24 16:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-24 10:24 [PATCH] Bluetooth: do not leak an hci_conn when a second LE connect is rejected Radek Podgorny
2026-08-24 10:49 ` bluez.test.bot
2026-08-24 11:00 ` [PATCH v2] " Radek Podgorny
2026-08-24 11:49   ` [v2] " bluez.test.bot
2026-08-24 16:50   ` [PATCH v2] " 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