Skip to contentSkip to conversation

Bluetooth: btintel: serialize hw error recovery with req_lock

PATCH In review Cen Zhang 2 participants 2 messages Dec 9, 2025 Bluetooth drivers

lore
Share & tools
lore

Cen Zhang

author
#0 lore raw

PATCH 1/1 Bluetooth: btintel: serialize hw error recovery with req_lock

btintel_hw_error() issues two __hci_cmd_sync() calls to reset the controller and fetch the Intel exception report. Unlike the shutdown path, this helper ran without hci_req_sync_lock(), so it could race against hci_dev_do_close() and both sides would manipulate hdev->req_status/req_rsp concurrently.When the close path freed the shared response buffer first, the still running hw_error path hit a slab-use-after-free inside kfree_skb() (skb_unref → atomic_read) and KASAN reported the crash in the trace.

Acquire hci_req_sync_lock() around the hw_error recovery sequence and make sure all error/cleanup paths release it. This serializes the Intel handler with every other synchronous command issuer and prevents the req_* bookkeeping from being double-touched.

Below is the data race report and the kasan report:

BUG: data-race in __hci_cmd_sync_sk / btintel_shutdown_combined

read of hdev->req_rsp at net/bluetooth/hci_sync.c:199 by task kworker/u17:1/83 write/free of same SKB at drivers/bluetooth/btintel.c:3660 by task ioctl/22580

Call Trace (reader):

  __hci_cmd_sync_sk+0x12f2/0x1c30 net/bluetooth/hci_sync.c:200
  __hci_cmd_sync+0x55/0x80 net/bluetooth/hci_sync.c:223
  btintel_hw_error+0x114/0x670 drivers/bluetooth/btintel.c:254
  hci_error_reset+0x348/0xa30 net/bluetooth/hci_core.c:1030
  ...

Call Trace (writer):

  btintel_shutdown_combined+0xd0/0x360 drivers/bluetooth/btintel.c:3648
  hci_dev_close_sync+0x9ae/0x2c10 net/bluetooth/hci_sync.c:5246
  hci_dev_do_close+0x232/0x460 net/bluetooth/hci_core.c:526
  ...

BUG: KASAN: slab-use-after-free in sk_skb_reason_drop+0x43/0x380 net/core/skbuff.c:1202
Read of size 4 at addr ffff888144a738dc by task kworker/u17:1/83

Call Trace:
  __hci_cmd_sync_sk+0x12f2/0x1c30 net/bluetooth/hci_sync.c:200
  __hci_cmd_sync+0x55/0x80 net/bluetooth/hci_sync.c:223
  btintel_hw_error+0x186/0x670 drivers/bluetooth/btintel.c:260
  ...

Allocated by task 84:
  skb_clone+0x212/0x3a0 net/core/skbuff.c:2049
  hci_event_packet+0x66c/0x2da0 net/bluetooth/hci_event.c:7614
  ...

Freed by task 22580:
  btintel_shutdown_combined+0xd0/0x360 drivers/bluetooth/btintel.c:3648
  hci_dev_close_sync+0x9ae/0x2c10 net/bluetooth/hci_sync.c:5246
  hci_dev_do_close+0x232/0x460 net/bluetooth/hci_core.c:526
  ...
---
 drivers/bluetooth/btintel.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/bluetooth/btintel.c +6 -0
index 9d29ab811..baa3ee510 100644
@@ -251,10 +251,12 @@ void btintel_hw_error(struct hci_dev *hdev, u8 code)
 
 	bt_dev_err(hdev, "Hardware error 0x%2.2x", code);
 
+	hci_req_sync_lock(hdev);
 	skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
 	if (IS_ERR(skb)) {
 		bt_dev_err(hdev, "Reset after hardware error failed (%ld)",
 			   PTR_ERR(skb));
+		hci_req_sync_unlock(hdev);
 		return;
 	}
 	kfree_skb(skb);
@@ -263,18 +265,22 @@ void btintel_hw_error(struct hci_dev *hdev, u8 code)
 	if (IS_ERR(skb)) {
 		bt_dev_err(hdev, "Retrieving Intel exception info failed (%ld)",
 			   PTR_ERR(skb));
+		hci_req_sync_unlock(hdev);
 		return;
 	}
 
 	if (skb->len != 13) {
 		bt_dev_err(hdev, "Exception info size mismatch");
 		kfree_skb(skb);
+		hci_req_sync_unlock(hdev);
 		return;
 	}
 
 	bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1));
 
 	kfree_skb(skb);
+
+	hci_req_sync_unlock(hdev);
 }
 EXPORT_SYMBOL_GPL(btintel_hw_error);
 
Signature · 1 line
2.34.1
#1 lore raw

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=1031579

---Test result---

Test Summary:

CheckPatch                    PENDING   0.32 seconds
GitLint                       PENDING   0.34 seconds
SubjectPrefix                 PASS      0.09 seconds
BuildKernel                   PASS      25.47 seconds
CheckAllWarning               PASS      27.48 seconds
CheckSparse                   PASS      30.42 seconds
BuildKernel32                 PASS      24.77 seconds
TestRunnerSetup               PASS      558.28 seconds
TestRunner_l2cap-tester       PASS      24.90 seconds
TestRunner_iso-tester         FAIL      57.49 seconds
TestRunner_bnep-tester        PASS      6.39 seconds
TestRunner_mgmt-tester        FAIL      127.02 seconds
TestRunner_rfcomm-tester      PASS      9.67 seconds
TestRunner_sco-tester         FAIL      14.68 seconds
TestRunner_ioctl-tester       PASS      10.38 seconds
TestRunner_mesh-tester        FAIL      11.52 seconds
TestRunner_smp-tester         PASS      8.78 seconds
TestRunner_userchan-tester    PASS      6.69 seconds
IncrementalBuild              PENDING   0.44 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
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
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 494, Passed: 487 (98.6%), Failed: 3, Not Run: 4

Failed Test Cases

Read Exp Feature - Success                           Failed       0.107 seconds
LL Privacy - Add Device 2 (2 Devices to AL)          Failed       0.179 seconds
LL Privacy - Set Flags 2 (Enable RL)                 Failed       0.160 seconds

##############################
Test: TestRunner_sco-tester - FAIL
Desc: Run sco-tester with test-runner
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
##############################
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    1.793 seconds
Mesh - Send cancel - 2                               Timed out    1.997 seconds

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series Output:

---
Regards,
Linux Bluetooth