Skip to content

Conversation

@BluezTestBot
Copy link
Owner

Concurrent sco_sock_connect() calls could race on the same socket since the
state checks (BT_OPEN/BT_BOUND) were done without holding the socket lock.
This allowed two parallel connects to proceed and end up binding two
separate sco_conn objects to the same sk. Later, when sk->conn had been
updated to point to the second conn, closing the socket could free the
second conn and the socket, while the first conn's connect confirm path
still referenced the stale sk/conn, triggering a KASAN use-after-free.

Fix by taking lock_sock(sk) before checking sk->sk_state and sk->sk_type,
performing the destination address assignment under the lock, and releasing
it before invoking sco_connect() (which will acquire the lock as needed).
This serializes concurrent connect attempts for the same sk and prevents the
interleaving that caused the double-attachment and subsequent UAF.

Thread 1: Thread 2: Thread3:
check sk_state check sk_state
sco_sock_connect(sk) sco_sock_connect(sk) sco_connect_cfm(sk->conn)
conn1->sk = sk
conn2->sk = sk
sk->conn = conn1
sk->conn = conn2
sco_sock_release
free conn2 and sk
sco_connect_cfm
sco_conn_del
sco_conn_free
UAF on sk

The representative KASAN report excerpt:

BUG: KASAN: slab-use-after-free in sco_conn_free net/bluetooth/sco.c:94
...
Write of size 8 at addr ffff88810d2be350 by task kworker/u25:1/88
...
Call Trace:
sco_conn_free net/bluetooth/sco.c:94 [inline]
kref_put include/linux/kref.h:65 [inline]
sco_conn_put+0x49d/0xfc0 net/bluetooth/sco.c:115
sco_conn_del+0x46d/0x8d0 net/bluetooth/sco.c:280
sco_connect_cfm+0x83d/0x1ee0 net/bluetooth/sco.c:1468
hci_connect_cfm include/net/bluetooth/hci_core.h:2082 [inline]
...
Allocated by task 294:
...
sco_sock_create+0x22d/0xc00 net/bluetooth/sco.c:616
...
Freed by task 295:
__sk_destruct+0x4b0/0x630 net/core/sock.c:2373
sock_put include/net/sock.h:1962 [inline]
sco_sock_kill+0x64d/0x9b0 net/bluetooth/sco.c:526
sco_sock_release+0x770/0xa50 net/bluetooth/sco.c:1359
...


v2: Try to resolve the issue of incorrect lock usage.

Signed-off-by: Cen Zhang zzzccc427@gmail.com

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

tedd-an and others added 2 commits December 3, 2025 20:30
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>
Concurrent sco_sock_connect() calls could race on the same socket since the
state checks (BT_OPEN/BT_BOUND) were done without holding the socket lock.
This allowed two parallel connects to proceed and end up binding two
separate sco_conn objects to the same sk. Later, when sk->conn had been
updated to point to the second conn, closing the socket could free the
second conn and the socket, while the first conn's connect confirm path
still referenced the stale sk/conn, triggering a KASAN use-after-free.

Fix by taking lock_sock(sk) before checking sk->sk_state and sk->sk_type,
performing the destination address assignment under the lock, and releasing
it before invoking sco_connect() (which will acquire the lock as needed).
This serializes concurrent connect attempts for the same sk and prevents the
interleaving that caused the double-attachment and subsequent UAF.

Thread 1:               Thread 2:               Thread3:
check sk_state          check sk_state
sco_sock_connect(sk)    sco_sock_connect(sk)    sco_connect_cfm(sk->conn)
conn1->sk = sk
                        conn2->sk = sk
sk->conn = conn1
                        sk->conn = conn2
                        sco_sock_release
                        free conn2 and sk
                                                sco_connect_cfm
                                                sco_conn_del
                                                sco_conn_free
                                                UAF on sk

The representative KASAN report excerpt:

  BUG: KASAN: slab-use-after-free in sco_conn_free net/bluetooth/sco.c:94
  ...
  Write of size 8 at addr ffff88810d2be350 by task kworker/u25:1/88
  ...
  Call Trace:
  sco_conn_free net/bluetooth/sco.c:94 [inline]
  kref_put include/linux/kref.h:65 [inline]
  sco_conn_put+0x49d/0xfc0 net/bluetooth/sco.c:115
  sco_conn_del+0x46d/0x8d0 net/bluetooth/sco.c:280
  sco_connect_cfm+0x83d/0x1ee0 net/bluetooth/sco.c:1468
  hci_connect_cfm include/net/bluetooth/hci_core.h:2082 [inline]
  ...
  Allocated by task 294:
  ...
  sco_sock_create+0x22d/0xc00 net/bluetooth/sco.c:616
  ...
  Freed by task 295:
  __sk_destruct+0x4b0/0x630 net/core/sock.c:2373
  sock_put include/net/sock.h:1962 [inline]
  sco_sock_kill+0x64d/0x9b0 net/bluetooth/sco.c:526
  sco_sock_release+0x770/0xa50 net/bluetooth/sco.c:1359
  ...
@github-actions
Copy link

github-actions bot commented Dec 9, 2025

CheckPatch
Desc: Run checkpatch.pl script
Duration: 0.30 seconds
Result: PENDING

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

GitLint
Desc: Run gitlint
Duration: 0.25 seconds
Result: PENDING

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

CheckSparse
Desc: Run sparse tool with linux kernel
Duration: 31.53 seconds
Result: WARNING
Output:

net/bluetooth/sco.c: note: in included file:./include/net/bluetooth/hci_core.h:153:35: warning: array of flexible structures

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

BUG: KASAN: slab-use-after-free in le_read_features_complete+0x7e/0x2b0
Total: 141, Passed: 141 (100.0%), Failed: 0, Not Run: 0

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

Total: 494, Passed: 489 (99.0%), Failed: 1, Not Run: 4

Failed Test Cases
Read Exp Feature - Success                           Failed       0.106 seconds

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

TestRunner_sco-tester
Desc: Run sco-tester with test-runner
Duration: 14.50 seconds
Result: FAIL
Output:

WARNING: possible circular locking dependency detected
BUG: sleeping function called from invalid context at net/core/sock.c:3782
Total: 30, Passed: 30 (100.0%), Failed: 0, Not Run: 0

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

TestRunner_mesh-tester
Desc: Run mesh-tester with test-runner
Duration: 12.46 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.696 seconds
Mesh - Send cancel - 2                               Timed out    1.997 seconds

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

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

@github-actions
Copy link

github-actions bot commented Dec 9, 2025

IncrementalBuild
Desc: Incremental build with the patches in the series
Duration: 0.66 seconds
Result: PENDING

@github-actions github-actions bot force-pushed the workflow branch 4 times, most recently from dbdc24e to 7b93eea Compare December 15, 2025 18:36
@github-actions github-actions bot force-pushed the workflow branch 5 times, most recently from 8eabaf6 to b7ba526 Compare December 22, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants