Bluetooth: Fixes for issues reported by sashiko.dev
Subsystems (2)
Luiz Augusto von Dentz
maintainercover Bluetooth: Fixes for issues reported by sashiko.dev
From: Luiz Augusto von Dentz <[email protected]>
This series fixes issues reported by sashiko.dev against the Bluetooth core, each patch carries the identifier of the report(s) it addresses in its Reported-by tag.
Missing locking around shared state:
- Patch 2 takes hci_req_sync_lock around hci_powered_update_sync() in hci_power_on().
- Patches 3 and 4 look up advertising instances under hdev->lock in hci_disable_ext_adv_instance_sync() and hci_schedule_adv_instance_sync().
- Patch 5 serializes the writers of hdev->link_keys. smp_notify_keys() runs with the l2cap channel lock held, which is ordered after hdev->lock, so this adds a dedicated hdev->link_keys_lock instead of taking hdev->lock there.
- Patch 13 protects the MSFT event prefix with hdev->lock.
- Patch 15 holds hdev->lock while looking up and freeing advertisement monitors.
- Patch 16 serializes the reparenting of the RFCOMM tty device.
Lifetime issues:
- Patch 11 reworks the mesh transmission handling: mesh_pending and the advertising instances are accessed under hdev->lock, the cmd_sync entries carry the transmission handle rather than a pointer to it, and Mesh Send Cancel and mgmt_cleanup() cancel a transmission the same way, stopping the done timer if it is the one in progress.
- Patch 12 reads the pending Set Powered command under mgmt_pending_lock in mgmt_powering_down().
Missing validation:
- Patch 1 sizes the Read Index List reply from all the controllers.
- Patch 6 checks hdev->smp_data before using SMP_DEV().
- Patch 8 validates the length of the sent LE Set Extended Advertising Enable command before parsing it.
- Patch 9 rejects a zero multi advertising rotation duration.
- Patch 10 only uses the EFS option in l2cap_parse_conf_rsp() if the response carried one.
debugfs:
- Patch 7 stops force_bredr_smp from creating the BR/EDR SMP channel while SMP is not registered.
- Patch 14 sets/clears the debugfs controlled flags explicitly rather than toggling them, and serializes the writers.
Known limitation: in patch 11, if the done timer has already fired when a transmission is cancelled, mesh_send_done_sync() can still complete the next transmission early.
Testing: an earlier revision of the series was run with KASAN and lockdep enabled through the BlueZ testers (mgmt, mesh, smp, l2cap, rfcomm, iso, ...) and test-functional. This revision, rebased on top of bluetooth-next with patch 11 reworked, has only been build tested (W=1, each patch).
Luiz Augusto von Dentz (16):
Bluetooth: mgmt: Fix read_index_list() buffer overflow
Bluetooth: hci_core: Take req_sync lock in hci_power_on()
Bluetooth: hci_sync: Lock the lookup in
hci_disable_ext_adv_instance_sync()
Bluetooth: hci_sync: Hold hdev->lock in
hci_schedule_adv_instance_sync()
Bluetooth: SMP: Serialize link key updates from smp_notify_keys()
Bluetooth: SMP: Check smp_data before using SMP_DEV()
Bluetooth: SMP: Don't create the BR/EDR channel while unregistered
Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv
Enable
Bluetooth: mgmt: Reject zero multi advertising rotation duration
Bluetooth: L2CAP: Don't use uninitialized EFS in
l2cap_parse_conf_rsp()
Bluetooth: mgmt: Fix mesh transmission locking and lifetime
Bluetooth: MGMT: Fix use-after-free in mgmt_powering_down()
Bluetooth: MSFT: Protect the event prefix with hdev->lock
Bluetooth: hci_debugfs: Fix racy toggling of debugfs controlled flags
Bluetooth: hci_core: Hold hdev->lock when removing advertisement
monitors
Bluetooth: RFCOMM: Serialize tty device reparenting
include/net/bluetooth/hci_core.h | 4 + net/bluetooth/hci_core.c | 54 ++++++- net/bluetooth/hci_debugfs.c | 30 +++- net/bluetooth/hci_event.c | 9 +- net/bluetooth/hci_sync.c | 24 ++- net/bluetooth/l2cap_core.c | 5 +- net/bluetooth/mgmt.c | 262 +++++++++++++++++++++++++------ net/bluetooth/mgmt_config.c | 6 + net/bluetooth/msft.c | 29 ++-- net/bluetooth/rfcomm/tty.c | 21 ++- net/bluetooth/smp.c | 58 +++++-- 11 files changed, 406 insertions(+), 96 deletions(-)
base-commit: 3c5963d23d64972385786e0be47be16d89ff4434
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 1/16 Bluetooth: mgmt: Fix read_index_list() buffer overflow
From: Luiz Augusto von Dentz <[email protected]>
The first pass counts only configured controllers, but HCI_UNCONFIGURED can change before the second pass, which may then write more entries than were allocated. Size the buffer from the total number of controllers as read_unconf_index_list() already does.
--- net/bluetooth/mgmt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
net/bluetooth/mgmt.c +2 -4
@@ -444,10 +444,8 @@ static int read_index_list(struct sock *sk, struct hci_dev *hdev, void *data,read_lock (&hci_dev_list_lock); count =0 ; -list_for_each_entry (d, &hci_dev_list, list) { -if (!hci_dev_test_flag (d,HCI_UNCONFIGURED )) - count++; - } +list_for_each_entry (d, &hci_dev_list, list) + count++; rp_len =sizeof (*rp) + (2 * count); rp =kmalloc (rp_len,GFP_ATOMIC );
Signature · 1 line
2.56.0
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/series/1214200/
---Test result---
Test Summary:
CheckPatch FAIL 6.95 seconds VerifyFixes PASS 0.05 seconds VerifySignedoff PASS 0.06 seconds GitLint FAIL 2.62 seconds SubjectPrefix PASS 0.81 seconds BuildKernel PASS 20.07 seconds CheckAllWarning PASS 23.47 seconds CheckSparse WARNING 25.04 seconds BuildKernel32 PASS 20.33 seconds CheckKernelLLVM PASS 20.77 seconds TestRunnerSetup PASS 479.13 seconds TestRunner_l2cap-tester PASS 16.07 seconds TestRunner_iso-tester PASS 11.73 seconds TestRunner_bnep-tester PASS 3.12 seconds TestRunner_mgmt-tester PASS 84.64 seconds TestRunner_rfcomm-tester PASS 4.37 seconds TestRunner_sco-tester PASS 5.42 seconds TestRunner_ioctl-tester PASS 4.49 seconds TestRunner_mesh-tester PASS 4.41 seconds TestRunner_smp-tester PASS 4.30 seconds TestRunner_userchan-tester PASS 3.20 seconds TestRunner_6lowpan-tester PASS 4.37 seconds IncrementalBuild PASS 56.39 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v1,01/16] Bluetooth: mgmt: Fix read_index_list() buffer overflow
ERROR: Unrecognized email address: 'sashiko.dev (linux-7841362e-9b8f-465f-aa22-e99c315231e2)' #127:
Reported-by: sashiko.dev (linux-7841362e-9b8f-465f-aa22-e99c315231e2)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #127:
WARNING: Non-standard signature: Assisted-by:
#129:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #129:
total: 2 errors, 2 warnings, 0 checks, 12 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994489.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,02/16] Bluetooth: hci_core: Take req_sync lock in hci_power_on()
ERROR: Unrecognized email address: 'sashiko.dev (linux-1baf7393-3aeb-4fa5-806f-19cea743b9f3)' #125:
Reported-by: sashiko.dev (linux-1baf7393-3aeb-4fa5-806f-19cea743b9f3)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #125:
WARNING: Non-standard signature: Assisted-by:
#127:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #127:
total: 2 errors, 2 warnings, 0 checks, 9 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994488.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,03/16] Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync()
ERROR: Unrecognized email address: 'sashiko.dev (linux-a364929c-cd00-492a-a83c-5425d042b09f)' #127:
Reported-by: sashiko.dev (linux-a364929c-cd00-492a-a83c-5425d042b09f)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #127:
WARNING: Non-standard signature: Assisted-by:
#129:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #129:
total: 2 errors, 2 warnings, 0 checks, 36 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994490.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,04/16] Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync()
ERROR: Unrecognized email address: 'sashiko.dev (linux-616b1f8e-06ec-4634-a907-5eb4e82f66df)' #125:
Reported-by: sashiko.dev (linux-616b1f8e-06ec-4634-a907-5eb4e82f66df)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #125:
WARNING: Non-standard signature: Assisted-by:
#127:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #127:
total: 2 errors, 2 warnings, 0 checks, 22 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994491.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,05/16] Bluetooth: SMP: Serialize link key updates from smp_notify_keys()
ERROR: Unrecognized email address: 'sashiko.dev (linux-7482a666-d2a0-44a4-9e0d-05354860a5fa)' #133:
Reported-by: sashiko.dev (linux-7482a666-d2a0-44a4-9e0d-05354860a5fa)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #133:
WARNING: Non-standard signature: Assisted-by:
#135:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #135:
total: 2 errors, 2 warnings, 0 checks, 134 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994492.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,06/16] Bluetooth: SMP: Check smp_data before using SMP_DEV()
ERROR: Unrecognized email address: 'sashiko.dev (linux-9bc9da90-02a8-4a87-a603-87d0a4cf464c)' #126:
Reported-by: sashiko.dev (linux-9bc9da90-02a8-4a87-a603-87d0a4cf464c)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #126:
WARNING: Non-standard signature: Assisted-by:
#128:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #128:
total: 2 errors, 2 warnings, 0 checks, 18 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994493.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,07/16] Bluetooth: SMP: Don't create the BR/EDR channel while unregistered
ERROR: Unrecognized email address: 'sashiko.dev (linux-a921c99c-0b41-485c-91a4-1c6e54b45b0b)' #128:
Reported-by: sashiko.dev (linux-a921c99c-0b41-485c-91a4-1c6e54b45b0b)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #128:
WARNING: Non-standard signature: Assisted-by:
#130:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #130:
total: 2 errors, 2 warnings, 0 checks, 34 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994494.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,08/16] Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable
ERROR: Unrecognized email address: 'sashiko.dev (linux-42bcc244-62e6-4295-802c-f9a512ca49a3)' #125:
Reported-by: sashiko.dev (linux-42bcc244-62e6-4295-802c-f9a512ca49a3)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #125:
WARNING: Non-standard signature: Assisted-by:
#127:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #127:
total: 2 errors, 2 warnings, 0 checks, 18 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994495.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,09/16] Bluetooth: mgmt: Reject zero multi advertising rotation duration
ERROR: Unrecognized email address: 'sashiko.dev (linux-24ecb695-0c5c-408a-a016-a980c3115e95)' #126:
Reported-by: sashiko.dev (linux-24ecb695-0c5c-408a-a016-a980c3115e95)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #126:
WARNING: Non-standard signature: Assisted-by:
#128:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #128:
total: 2 errors, 2 warnings, 0 checks, 12 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994496.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,10/16] Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp()
ERROR: Unrecognized email address: 'sashiko.dev (linux-089f015e-6251-4fea-85ef-7d6761e8c457)' #125:
Reported-by: sashiko.dev (linux-089f015e-6251-4fea-85ef-7d6761e8c457)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #125:
WARNING: Non-standard signature: Assisted-by:
#127:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #127:
total: 2 errors, 2 warnings, 0 checks, 23 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994497.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,11/16] Bluetooth: mgmt: Fix mesh transmission locking and lifetime
ERROR: Unrecognized email address: 'sashiko.dev (linux-4ab89465-fc27-4d91-a870-a8ed49b22e91)' #147:
Reported-by: sashiko.dev (linux-4ab89465-fc27-4d91-a870-a8ed49b22e91)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #147:
Reported-by: sashiko.dev (linux-4ab89465-fc27-4d91-a870-a8ed49b22e91)
Reported-by: sashiko.dev (linux-93ef41e7-8b48-4483-aa5d-d21f1e27c104)
ERROR: Unrecognized email address: 'sashiko.dev (linux-93ef41e7-8b48-4483-aa5d-d21f1e27c104)' #148:
Reported-by: sashiko.dev (linux-93ef41e7-8b48-4483-aa5d-d21f1e27c104)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #148:
Reported-by: sashiko.dev (linux-93ef41e7-8b48-4483-aa5d-d21f1e27c104)
Reported-by: sashiko.dev (linux-ab941894-dbe1-49da-8bac-c52efda6eaee)
ERROR: Unrecognized email address: 'sashiko.dev (linux-ab941894-dbe1-49da-8bac-c52efda6eaee)' #149:
Reported-by: sashiko.dev (linux-ab941894-dbe1-49da-8bac-c52efda6eaee)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #149:
Reported-by: sashiko.dev (linux-ab941894-dbe1-49da-8bac-c52efda6eaee)
Reported-by: sashiko.dev (linux-4016f774-7ac7-4b8a-916f-587ec9d597d4)
ERROR: Unrecognized email address: 'sashiko.dev (linux-4016f774-7ac7-4b8a-916f-587ec9d597d4)' #150:
Reported-by: sashiko.dev (linux-4016f774-7ac7-4b8a-916f-587ec9d597d4)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #150:
WARNING: Non-standard signature: Assisted-by:
#152:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #152:
total: 5 errors, 5 warnings, 0 checks, 365 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994498.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,12/16] Bluetooth: MGMT: Fix use-after-free in mgmt_powering_down()
ERROR: Unrecognized email address: 'sashiko.dev (linux-e45413fa-48a6-43f1-90be-638841567534)' #127:
Reported-by: sashiko.dev (linux-e45413fa-48a6-43f1-90be-638841567534)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #127:
WARNING: Non-standard signature: Assisted-by:
#129:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #129:
total: 2 errors, 2 warnings, 0 checks, 34 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994499.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,13/16] Bluetooth: MSFT: Protect the event prefix with hdev->lock
ERROR: Unrecognized email address: 'sashiko.dev (linux-246df501-f32c-46fd-8779-7fa755ed7f9d)' #128:
Reported-by: sashiko.dev (linux-246df501-f32c-46fd-8779-7fa755ed7f9d)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #128:
WARNING: Non-standard signature: Assisted-by:
#130:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #130:
total: 2 errors, 2 warnings, 0 checks, 88 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994500.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,14/16] Bluetooth: hci_debugfs: Fix racy toggling of debugfs controlled flags
ERROR: Unrecognized email address: 'sashiko.dev (linux-442108d5-76ce-44a1-a84d-16b44d6a26a6)' #132:
Reported-by: sashiko.dev (linux-442108d5-76ce-44a1-a84d-16b44d6a26a6)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #132:
WARNING: Non-standard signature: Assisted-by:
#134:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #134:
total: 2 errors, 2 warnings, 0 checks, 102 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994501.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,15/16] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors
ERROR: Unrecognized email address: 'sashiko.dev (linux-8b358899-5ac9-4687-af16-58420a4d9bba)' #129:
Reported-by: sashiko.dev (linux-8b358899-5ac9-4687-af16-58420a4d9bba)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #129:
WARNING: Non-standard signature: Assisted-by:
#131:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #131:
total: 2 errors, 2 warnings, 0 checks, 32 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994502.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
[v1,16/16] Bluetooth: RFCOMM: Serialize tty device reparenting
ERROR: Unrecognized email address: 'sashiko.dev (linux-cd8016c2-2358-40f0-b65c-091f6a957f67)' #127:
Reported-by: sashiko.dev (linux-cd8016c2-2358-40f0-b65c-091f6a957f67)
WARNING: Reported-by: should be immediately followed by Closes: or Link: with a URL to the report #127:
WARNING: Non-standard signature: Assisted-by:
#129:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #129:
total: 2 errors, 2 warnings, 0 checks, 38 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
/home/runner/work/bluetooth-next/bluetooth-next/src/patch/14994503.patch has style problems, please review.
NOTE: Ignored message types: UNKNOWN_COMMIT_ID
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[v1,03/16] Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync()
1: T1 Title exceeds max length (86>80): "[v1,03/16] Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync()" [v1,04/16] Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync()
1: T1 Title exceeds max length (83>80): "[v1,04/16] Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync()" [v1,08/16] Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable
1: T1 Title exceeds max length (86>80): "[v1,08/16] Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable" [v1,10/16] Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp()
1: T1 Title exceeds max length (82>80): "[v1,10/16] Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp()" [v1,15/16] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors
1: T1 Title exceeds max length (84>80): "[v1,15/16] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors"
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
https://github.com/bluez/bluetooth-next/pull/1144
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerPATCH 2/16 Bluetooth: hci_core: Take req_sync lock in hci_power_on()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
hci_powered_update_sync() issues synchronous HCI commands but was called without hci_req_sync_lock(), racing with other request users.
--- net/bluetooth/hci_core.c | 2 ++ 1 file changed, 2 insertions(+)
net/bluetooth/hci_core.c +2 -0
@@ -1010,7 +1010,9 @@ static void hci_power_on(struct work_struct *work) hci_dev_test_flag(hdev, HCI_MGMT) && hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) {cancel_delayed_work (&hdev->power_off); +hci_req_sync_lock (hdev); err =hci_powered_update_sync (hdev); +hci_req_sync_unlock (hdev);mgmt_power_on (hdev, err);return ; }
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 3/16 Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
hci_disable_ext_adv_instance_sync() calls hci_find_adv_instance() and dereferences the instance without hdev->lock, racing with the removal of the instance. Look the instance up under the lock and only use the values copied while it is held.
--- net/bluetooth/hci_sync.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
net/bluetooth/hci_sync.c +13 -3
@@ -1226,16 +1226,26 @@ static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance)struct hci_cp_ext_adv_set *set;u8 data[sizeof (*cp) +sizeof (*set) *1 ];u8 size; -struct adv_info *adv =NULL ; +u8 handle = instance;/* If request specifies an instance that doesn't exist, fail */ if (instance >0 ) { +struct adv_info *adv; +bool enabled = false; + +hci_dev_lock (hdev); adv =hci_find_adv_instance (hdev, instance); +if (adv) { + enabled = adv->enabled; + handle = adv->handle; + } +hci_dev_unlock (hdev); +if (!adv)return -EINVAL ;/* If not enabled there is nothing to do */ -if (!adv->enabled) +if (!enabled)return 0 ; }
@@ -1248,7 +1258,7 @@ static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) cp->num_of_sets = !!instance; cp->enable =0x00 ; - set->handle = adv ? adv->handle : instance; + set->handle = handle; size =sizeof (*cp) +sizeof (*set) * cp->num_of_sets;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 4/16 Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The advertising instance returned by hci_find_adv_instance() was dereferenced without hdev->lock and could be freed concurrently.
--- net/bluetooth/hci_sync.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/bluetooth/hci_sync.c +7 -1
@@ -2207,9 +2207,13 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance,if (hdev->adv_instance_timeout)return -EBUSY ; +hci_dev_lock (hdev); + adv =hci_find_adv_instance (hdev, instance); -if (!adv) +if (!adv) { +hci_dev_unlock (hdev);return -ENOENT ; + }/* A zero timeout means unlimited advertising. As long as there is * only one instance, duration should be ignored. We still set a timeout
@@ -2239,6 +2243,8 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, secs_to_jiffies(timeout)); } +hci_dev_unlock (hdev); +/* If we're just re-scheduling the same instance again then do not * execute any HCI commands. This happens when a single instance is * being advertised.
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 5/16 Bluetooth: SMP: Serialize link key updates from smp_notify_keys()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
smp_notify_keys() runs from the L2CAP RX path without hdev->lock, yet hci_add_link_key() and the debug key removal modify hdev->link_keys and dereference entries returned by hci_find_link_key(), so a concurrent unpair or Load Link Keys can free the entry being updated.
hdev->lock can't be taken there since it is ordered before the l2cap channel lock held by the SMP receive path (see smp_user_confirm_reply()). Add a dedicated link_keys_lock protecting the writers of hdev->link_keys (add, remove and clear), keep the returned key under RCU in SMP and remove debug keys by address through hci_remove_link_key().
--- include/net/bluetooth/hci_core.h | 4 ++++ net/bluetooth/hci_core.c | 40 ++++++++++++++++++++++++++++---- net/bluetooth/hci_event.c | 3 +-- net/bluetooth/smp.c | 11 +++++++-- 4 files changed, 50 insertions(+), 8 deletions(-)
include/net/bluetooth/hci_core.h +4 -0
@@ -575,6 +575,7 @@ struct hci_dev {struct list_head accept_list;struct list_head uuids;struct list_head link_keys; +struct mutex link_keys_lock;struct list_head long_term_keys;struct list_head identity_resolving_keys;struct mutex remote_oob_lock;
@@ -1943,6 +1944,9 @@ struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,void hci_uuids_clear (struct hci_dev *hdev);void hci_link_keys_clear (struct hci_dev *hdev); +struct link_key *__hci_add_link_key (struct hci_dev *hdev,struct hci_conn *conn, +bdaddr_t *bdaddr,u8 *val,u8 type, +u8 pin_len,bool *persistent);u8 *hci_conn_key_enc_size (struct hci_conn *conn);struct link_key *hci_find_link_key (struct hci_dev *hdev,bdaddr_t *bdaddr); struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
net/bluetooth/hci_core.c +36 -4
@@ -1112,10 +1112,14 @@ void hci_link_keys_clear(struct hci_dev *hdev) {struct link_key *key, *tmp; +mutex_lock (&hdev->link_keys_lock); +list_for_each_entry_safe (key, tmp, &hdev->link_keys, list) {list_del_rcu (&key->list);kfree_rcu (key, rcu); } + +mutex_unlock (&hdev->link_keys_lock); }void hci_smp_ltks_clear (struct hci_dev *hdev)
@@ -1332,13 +1336,16 @@ struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,return irk_to_return; } -struct link_key *hci_add_link_key (struct hci_dev *hdev,struct hci_conn *conn, -bdaddr_t *bdaddr,u8 *val,u8 type, -u8 pin_len,bool *persistent) +/* This function requires the caller holds hdev->link_keys_lock */ +struct link_key *__hci_add_link_key (struct hci_dev *hdev,struct hci_conn *conn, +bdaddr_t *bdaddr,u8 *val,u8 type, +u8 pin_len,bool *persistent) {struct link_key *key, *old_key;u8 old_key_type; +lockdep_assert_held (&hdev->link_keys_lock); + old_key =hci_find_link_key (hdev, bdaddr);if (old_key) { old_key_type = old_key->type;
@@ -1381,6 +1388,24 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,return key; } +/* Can be called without hdev->lock (e.g. from SMP, where it can't be taken +* after the l2cap channel lock), the writers of hdev->link_keys are +* serialized with their own lock. +*/ +struct link_key *hci_add_link_key (struct hci_dev *hdev,struct hci_conn *conn, +bdaddr_t *bdaddr,u8 *val,u8 type, +u8 pin_len,bool *persistent) +{ +struct link_key *key; + +mutex_lock (&hdev->link_keys_lock); + key =__hci_add_link_key (hdev, conn, bdaddr, val, type, pin_len, + persistent); +mutex_unlock (&hdev->link_keys_lock); + +return key; +} +struct smp_ltk *hci_add_ltk (struct hci_dev *hdev,bdaddr_t *bdaddr,u8 addr_type,u8 type,u8 authenticated,u8 tk[16 ],u8 enc_size,__le16 ediv,__le64 rand)
@@ -1442,15 +1467,21 @@ int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) {struct link_key *key; +mutex_lock (&hdev->link_keys_lock); + key =hci_find_link_key (hdev, bdaddr); -if (!key) +if (!key) { +mutex_unlock (&hdev->link_keys_lock);return -ENOENT ; + }BT_DBG ("%s removing %pMR" , hdev->name, bdaddr);list_del_rcu (&key->list);kfree_rcu (key, rcu); +mutex_unlock (&hdev->link_keys_lock); +return 0 ; }
@@ -2606,6 +2637,7 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv) hdev->def_page_scan_window =0x0012 ;mutex_init (&hdev->lock); +mutex_init (&hdev->link_keys_lock);mutex_init (&hdev->req_lock);mutex_init (&hdev->mgmt_pending_lock);mutex_init (&hdev->remote_oob_lock);
net/bluetooth/hci_event.c +1 -2
@@ -5336,8 +5336,7 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data,*/ if (key->type ==HCI_LK_DEBUG_COMBINATION && !hci_dev_test_flag (hdev,HCI_KEEP_DEBUG_KEYS )) { -list_del_rcu (&key->list); -kfree_rcu (key, rcu); +hci_remove_link_key (hdev, &ev->bdaddr); goto unlock; }
net/bluetooth/smp.c +9 -2
@@ -1097,8 +1097,13 @@ static void smp_notify_keys(struct l2cap_conn *conn)else type =HCI_LK_UNAUTH_COMBINATION_P256 ; - key =hci_add_link_key (hdev, smp->conn->hcon, &hcon->dst, - smp->link_key, type,0 , &persistent); +/* hdev->lock can't be taken here since it is ordered before +* the l2cap channel lock held by the caller. +*/ +mutex_lock (&hdev->link_keys_lock); + + key =__hci_add_link_key (hdev, smp->conn->hcon, &hcon->dst, + smp->link_key, type,0 , &persistent);if (key) {mgmt_new_link_key (hdev, key, persistent);
@@ -1111,6 +1116,8 @@ static void smp_notify_keys(struct l2cap_conn *conn)kfree_rcu (key, rcu); } } + +mutex_unlock (&hdev->link_keys_lock); } }
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 6/16 Bluetooth: SMP: Check smp_data before using SMP_DEV()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
hdev->smp_data is NULL when the SMP channel could not be registered, so receiving a Pairing Request/Response with the OOB flag set would dereference NULL through SMP_DEV().
--- net/bluetooth/smp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/smp.c +4 -2
@@ -1766,7 +1766,8 @@ static u8 smp_cmd_pairing_req(struct l2cap_conn *conn, struct sk_buff *skb)* successfully received our local OOB data - therefore set the * flag to indicate that local OOB is in use. */ -if (req->oob_flag ==SMP_OOB_PRESENT &&SMP_DEV (hdev)->local_oob) +if (req->oob_flag ==SMP_OOB_PRESENT && hdev->smp_data && +SMP_DEV (hdev)->local_oob)set_bit (SMP_FLAG_LOCAL_OOB , &smp->flags);/* SMP over BR/EDR requires special treatment */
@@ -1962,7 +1963,8 @@ static u8 smp_cmd_pairing_rsp(struct l2cap_conn *conn, struct sk_buff *skb)* successfully received our local OOB data - therefore set the * flag to indicate that local OOB is in use. */ -if (rsp->oob_flag ==SMP_OOB_PRESENT &&SMP_DEV (hdev)->local_oob) +if (rsp->oob_flag ==SMP_OOB_PRESENT && hdev->smp_data && +SMP_DEV (hdev)->local_oob)set_bit (SMP_FLAG_LOCAL_OOB , &smp->flags); smp->prsp[0 ] =SMP_CMD_PAIRING_RSP ;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 7/16 Bluetooth: SMP: Don't create the BR/EDR channel while unregistered
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
smp_force_bredr() created a BR/EDR SMP channel even when the controller was powered off or not LE capable, leaving a stale channel that smp_register() later warns about and leaks. Only create it when SMP is registered and guard the removal; smp_register() creates it on power on if the flag is set.
--- net/bluetooth/smp.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
net/bluetooth/smp.c +14 -6
@@ -3441,20 +3441,28 @@ int smp_force_bredr(struct hci_dev *hdev, bool enable)if (enable ==hci_dev_test_flag (hdev,HCI_FORCE_BREDR_SMP ))return -EALREADY ; +/* The channels are only registered while the controller is powered +* and LE capable. Otherwise just record the flag, smp_register() will +* create the BR/EDR channel on the next power on. +*/ if (enable) {struct l2cap_chan *chan; - chan =smp_add_cid (hdev,L2CAP_CID_SMP_BREDR ); -if (IS_ERR (chan)) -return PTR_ERR (chan); +if (hdev->smp_data && !hdev->smp_bredr_data) { + chan =smp_add_cid (hdev,L2CAP_CID_SMP_BREDR ); +if (IS_ERR (chan)) +return PTR_ERR (chan); - hdev->smp_bredr_data = chan; + hdev->smp_bredr_data = chan; + } }else {struct l2cap_chan *chan; chan = hdev->smp_bredr_data; - hdev->smp_bredr_data =NULL ; -smp_del_chan (chan); +if (chan) { + hdev->smp_bredr_data =NULL ; +smp_del_chan (chan); + } }hci_dev_change_flag (hdev,HCI_FORCE_BREDR_SMP );
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 8/16 Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
hci_cc_le_set_ext_adv_enable() read num_of_sets and the set entries from the last sent command without checking its length.
--- net/bluetooth/hci_event.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/bluetooth/hci_event.c +4 -2
@@ -1685,14 +1685,16 @@ static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data,struct hci_cp_ext_adv_set *set;struct adv_info *adv =NULL , *n;struct hci_ev_status *rp = data; +size_t len;bt_dev_dbg (hdev,"status 0x%2.2x" , rp->status);if (rp->status)return rp->status; - cp =hci_sent_cmd_data (hdev,HCI_OP_LE_SET_EXT_ADV_ENABLE ); -if (!cp) + cp =hci_sent_cmd_data_len (hdev,HCI_OP_LE_SET_EXT_ADV_ENABLE , &len); +if (!cp || len <sizeof (*cp) || + len <sizeof (*cp) + cp->num_of_sets *sizeof (*set))return rp->status; set = (void *)cp->data;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 9/16 Bluetooth: mgmt: Reject zero multi advertising rotation duration
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
A zero def_multi_adv_rotation_duration makes hci_schedule_adv_instance_sync() requeue itself with no delay, spinning the request workqueue. Reject it in Set Default System Configuration.
--- net/bluetooth/mgmt_config.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bluetooth/mgmt_config.c +6 -0
@@ -281,6 +281,12 @@ int set_def_system_config(struct sock *sk, struct hci_dev *hdev, void *data,* (32 bits), the one of the GFSK PHYs. */ switch (type) { +case 0x000c : +/* A zero rotation duration would make the advertising +* instance scheduler requeue itself with no delay. +*/ + invalid = !TLV_GET_LE16 (buffer); +break ;case 0x0021 : invalid =TLV_GET_U8 (buffer) !=0x01 &&TLV_GET_U8 (buffer) !=0x02 ;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 10/16 Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The local EFS values were copied from an on-stack struct even when the response carried no EFS option. Track whether it was received.
--- net/bluetooth/l2cap_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +4 -1
@@ -3892,6 +3892,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,unsigned long val;struct l2cap_conf_rfc rfc = { .mode =L2CAP_MODE_BASIC };struct l2cap_conf_efs efs; +bool remote_efs = false;BT_DBG ("chan %p, rsp %p, len %d, req %p" , chan, rsp, len, data);
@@ -3947,6 +3948,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,if (olen !=sizeof (efs))break ;memcpy (&efs, (void *)val, olen); + remote_efs = true;if (chan->local_stype !=L2CAP_SERV_NOTRAFIC && efs.stype !=L2CAP_SERV_NOTRAFIC && efs.stype != chan->local_stype)
@@ -3985,7 +3987,8 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, chan->ack_win =min_t (u16, chan->ack_win, rfc.txwin_size); -if (test_bit (FLAG_EFS_ENABLE , &chan->flags)) { +if (remote_efs && +test_bit (FLAG_EFS_ENABLE , &chan->flags)) { chan->local_msdu =le16_to_cpu (efs.msdu); chan->local_sdu_itime =le32_to_cpu (efs.sdu_itime);
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 11/16 Bluetooth: mgmt: Fix mesh transmission locking and lifetime
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The mesh_pending list is modified under hdev->lock by Mesh Send, but the cmd_sync callbacks, Mesh Send Cancel and mgmt_cleanup() add/remove entries and touch hdev->adv_instances without it, which corrupts the list and the advertising instances. In addition the queued mesh_send_sync entry holds a raw pointer to the mesh_tx which mgmt_cleanup() (socket close) or a cancel of the running transmission can free, leading to use-after-free.
Fix this by:
- taking hdev->lock around every mesh_pending/adv_instances access in the cmd_sync callbacks, send_cancel() and mgmt_cleanup(), but never across HCI commands;
- queueing the cmd_sync entries with the transmission handle and looking it up under the lock instead of passing the pointer;
- cancelling a transmission the same way from Mesh Send Cancel and mgmt_cleanup(): dequeue its entry, stop the done timer if it is the one in progress so the timer doesn't complete an unrelated transmission, then resume with the next one. mgmt_cleanup() takes references on the controllers instead of holding hci_dev_list_lock for this;
- not taking hdev->lock from callbacks invoked with -ECANCELED since those run with the cmd_sync lock held, the transmission is removed by whoever cancelled the entry;
- removing the transmissions left when the index is removed, nothing would send or free them afterwards;
- removing the transmission if queueing fails in Mesh Send.
--- net/bluetooth/mgmt.c | 234 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 196 insertions(+), 38 deletions(-)
net/bluetooth/mgmt.c +196 -38
@@ -1087,6 +1087,7 @@ static void discov_off(struct work_struct *work)static int send_settings_rsp (struct sock *sk,u16 opcode,struct hci_dev *hdev); +/* This function requires the caller holds hdev->lock */ static void mesh_send_complete (struct hci_dev *hdev,struct mgmt_mesh_tx *mesh_tx,bool silent) {
@@ -1102,34 +1103,65 @@ static void mesh_send_complete(struct hci_dev *hdev,static int mesh_send_done_sync (struct hci_dev *hdev,void *data) {struct mgmt_mesh_tx *mesh_tx; +bool disable;hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); -if (list_empty (&hdev->adv_instances)) + +hci_dev_lock (hdev); + disable =list_empty (&hdev->adv_instances); +hci_dev_unlock (hdev); + +if (disable)hci_disable_advertising_sync (hdev); + +hci_dev_lock (hdev); mesh_tx =mgmt_mesh_next (hdev,NULL );if (mesh_tx)mesh_send_complete (hdev, mesh_tx, false); +hci_dev_unlock (hdev);return 0 ; } +/* The cmd_sync entries identify the transmission by handle rather than by +* pointer since the mesh_tx can be removed while the entry is queued or +* running. +*/ +#define MESH_TX_DATA (_handle) ((void *)(unsigned long)(_handle)) +#define MESH_TX_HANDLE (_data) ((u8)(unsigned long)(_data)) +static int mesh_send_sync (struct hci_dev *hdev,void *data);static void mesh_send_start_complete (struct hci_dev *hdev,void *data,int err);static void mesh_next (struct hci_dev *hdev,void *data,int err) { -struct mgmt_mesh_tx *mesh_tx =mgmt_mesh_next (hdev,NULL ); +struct mgmt_mesh_tx *mesh_tx; -if (!mesh_tx) +/* The entry is being cancelled with the cmd_sync lock held, which +* can't be taken before hdev->lock. +*/ +if (err == -ECANCELED )return ; - err =hci_cmd_sync_queue (hdev, mesh_send_sync, mesh_tx, +hci_dev_lock (hdev); + +/* Only start the next transmission if there is none in progress */ + mesh_tx =mgmt_mesh_next (hdev,NULL ); +if (!mesh_tx ||hci_dev_test_flag (hdev,HCI_MESH_SENDING )) { +hci_dev_unlock (hdev); +return ; + } + + err =hci_cmd_sync_queue (hdev, mesh_send_sync, +MESH_TX_DATA (mesh_tx->handle), mesh_send_start_complete);if (err <0 )mesh_send_complete (hdev, mesh_tx, false);else hci_dev_set_flag (hdev,HCI_MESH_SENDING ); + +hci_dev_unlock (hdev); }static void mesh_send_done (struct work_struct *work)
@@ -2310,38 +2342,73 @@ static int set_mesh(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)static void mesh_send_start_complete (struct hci_dev *hdev,void *data,int err) { -struct mgmt_mesh_tx *mesh_tx = data; -struct mgmt_cp_mesh_send *send = (void *)mesh_tx->param; +struct mgmt_mesh_tx *mesh_tx; +struct mgmt_cp_mesh_send *send;unsigned long mesh_send_interval;u8 mgmt_err =mgmt_status (err); +/* The entry is being cancelled with the cmd_sync lock held, which +* can't be taken before hdev->lock, so leave the removal of the +* transmission to whoever cancelled it. +*/ +if (err == -ECANCELED ) { +hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); +return ; + } + +hci_dev_lock (hdev); + + mesh_tx =mgmt_mesh_find (hdev,MESH_TX_HANDLE (data)); +if (!mesh_tx) { +/* Removed while being sent (e.g. its socket was closed) */ +hci_dev_unlock (hdev); +hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); +mesh_next (hdev,NULL ,0 ); +return ; + } +/* Report any errors here, but don't report completion */ if (mgmt_err) {hci_dev_clear_flag (hdev,HCI_MESH_SENDING );/* Send Complete Error Code for handle */ mesh_send_complete (hdev, mesh_tx, false); -if (err != -ECANCELED ) -mesh_next (hdev,NULL ,0 ); +hci_dev_unlock (hdev); +mesh_next (hdev,NULL ,0 );return ; } + send = (void *)mesh_tx->param; mesh_send_interval =msecs_to_jiffies ((send->cnt) *25 ); +hci_dev_unlock (hdev); +queue_delayed_work (hdev->req_workqueue, &hdev->mesh_send_done, mesh_send_interval); }static int mesh_send_sync (struct hci_dev *hdev,void *data) { -struct mgmt_mesh_tx *mesh_tx = data; -struct mgmt_cp_mesh_send *send = (void *)mesh_tx->param; +struct mgmt_mesh_tx *mesh_tx; +struct mgmt_cp_mesh_send *send;struct adv_info *adv, *next_instance;u8 instance = hdev->le_num_of_adv_sets +1 ;u16 timeout, duration;int err =0 ; -if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) +hci_dev_lock (hdev); + + mesh_tx =mgmt_mesh_find (hdev,MESH_TX_HANDLE (data)); +if (!mesh_tx) { +hci_dev_unlock (hdev); +return -ENOENT ; + } + + send = (void *)mesh_tx->param; + +if (hdev->le_num_of_adv_sets <= hdev->adv_instance_cnt) { +hci_dev_unlock (hdev);return MGMT_STATUS_BUSY ; + } timeout =1000 ; duration = send->cnt *INTERVAL_TO_MS (hdev->le_adv_max_interval);
@@ -2379,6 +2446,8 @@ static int mesh_send_sync(struct hci_dev *hdev, void *data) instance =0 ; } +hci_dev_unlock (hdev); +if (instance)return hci_schedule_adv_instance_sync (hdev, instance, true);
@@ -2422,37 +2491,67 @@ static int mesh_features(struct sock *sk, struct hci_dev *hdev,return 0 ; } +/* Cancel a single transmission, the handle is looked up again after the +* entry has been dequeued since it may be gone or have completed meanwhile. +*/ +static void mesh_cancel_tx (struct hci_dev *hdev,u8 handle,bool silent) +{ +struct mgmt_mesh_tx *mesh_tx; + +hci_cmd_sync_dequeue (hdev, mesh_send_sync,MESH_TX_DATA (handle),NULL ); + +hci_dev_lock (hdev); + + mesh_tx =mgmt_mesh_find (hdev, handle); +if (mesh_tx) { +/* If it is the transmission in progress make sure the timer +* doesn't complete the next one in its place. +*/ +if (hci_dev_test_flag (hdev,HCI_MESH_SENDING ) && + mesh_tx ==mgmt_mesh_next (hdev,NULL )) { +cancel_delayed_work (&hdev->mesh_send_done); +hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); + } + +mesh_send_complete (hdev, mesh_tx, silent); + } + +hci_dev_unlock (hdev); +} +static int send_cancel (struct hci_dev *hdev,void *data) {struct mgmt_pending_cmd *cmd = data;struct mgmt_cp_mesh_send_cancel *cancel = (void *)cmd->param;struct mgmt_mesh_tx *mesh_tx; +u8 handle;if (!cancel->handle) { -do { +for (;;) { +hci_dev_lock (hdev); mesh_tx =mgmt_mesh_next (hdev, cmd->sk); + handle = mesh_tx ? mesh_tx->handle :0 ; +hci_dev_unlock (hdev); -if (mesh_tx) { -if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, - mesh_tx,NULL )) -mesh_send_complete (hdev, mesh_tx, false); - } - }while (mesh_tx); +if (!mesh_tx) +break ; + +mesh_cancel_tx (hdev, handle, false); + } }else { +hci_dev_lock (hdev); mesh_tx =mgmt_mesh_find (hdev, cancel->handle); + handle = mesh_tx && mesh_tx->sk == cmd->sk ? mesh_tx->handle :0 ; +hci_dev_unlock (hdev); -if (mesh_tx && mesh_tx->sk == cmd->sk) { -if (!hci_cmd_sync_dequeue (hdev, mesh_send_sync, - mesh_tx,NULL )) -mesh_send_complete (hdev, mesh_tx, false); - } +if (handle) +mesh_cancel_tx (hdev, handle, false); }mgmt_cmd_complete (cmd->sk, hdev->id,MGMT_OP_MESH_SEND_CANCEL ,0 ,NULL ,0 ); -if (!hci_dev_test_flag (hdev,HCI_MESH_SENDING )) -mesh_next (hdev,NULL ,0 ); +mesh_next (hdev,NULL ,0 );return 0 ; }
@@ -2542,7 +2641,8 @@ static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)if (!mesh_tx) err = -ENOMEM ;else if (!sending) - err =hci_cmd_sync_queue (hdev, mesh_send_sync, mesh_tx, + err =hci_cmd_sync_queue (hdev, mesh_send_sync, +MESH_TX_DATA (mesh_tx->handle), mesh_send_start_complete);if (err <0 ) {
@@ -2550,10 +2650,8 @@ static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) err =mgmt_cmd_status (sk, hdev->id,MGMT_OP_MESH_SEND ,MGMT_STATUS_FAILED ); -if (mesh_tx) { -if (sending) -mgmt_mesh_remove (mesh_tx); - } +if (mesh_tx) +mgmt_mesh_remove (mesh_tx); }else {hci_dev_set_flag (hdev,HCI_MESH_SENDING );
@@ -9892,6 +9990,7 @@ void mgmt_index_added(struct hci_dev *hdev)void mgmt_index_removed (struct hci_dev *hdev) {struct mgmt_ev_ext_index ev; +struct mgmt_mesh_tx *mesh_tx;struct cmd_lookup match = {NULL , hdev,MGMT_STATUS_INVALID_INDEX };if (hci_test_quirk (hdev,HCI_QUIRK_RAW_DEVICE ))
@@ -9921,6 +10020,10 @@ void mgmt_index_removed(struct hci_dev *hdev)cancel_delayed_work_sync (&hdev->service_cache);cancel_delayed_work_sync (&hdev->rpa_expired);cancel_delayed_work_sync (&hdev->mesh_send_done); + +/* Nothing is going to send or complete the transmissions left */ +while ((mesh_tx =mgmt_mesh_next (hdev,NULL ))) +mesh_send_complete (hdev, mesh_tx, true); }void mgmt_power_on (struct hci_dev *hdev,int err)
@@ -11103,19 +11206,74 @@ void mgmt_exit(void)void mgmt_cleanup (struct sock *sk) { -struct mgmt_mesh_tx *mesh_tx; +struct hci_dev **hdevs;struct hci_dev *hdev; +int i, n, count; -read_lock (&hci_dev_list_lock); +/* hci_dev_list_lock can't be held while taking hdev->lock so take +* references on the controllers first. +*/ +for (;;) { +bool more = false; + +read_lock (&hci_dev_list_lock); + count =0 ; +list_for_each_entry (hdev, &hci_dev_list, list) + count++; +read_unlock (&hci_dev_list_lock); + +if (!count) +return ; + + hdevs =kcalloc (count,sizeof (*hdevs),GFP_KERNEL ); +if (!hdevs) +return ; + + n =0 ; +read_lock (&hci_dev_list_lock); +list_for_each_entry (hdev, &hci_dev_list, list) { +if (n == count) { + more = true; +break ; + } + hdevs[n++] =hci_dev_hold (hdev); + } +read_unlock (&hci_dev_list_lock); + +if (!more) +break ; -list_for_each_entry (hdev, &hci_dev_list, list) { -do { +/* The list grew meanwhile, retry */ +for (i =0 ; i < n; i++) +hci_dev_put (hdevs[i]); +kfree (hdevs); + } + +for (i =0 ; i < n; i++) { +struct mgmt_mesh_tx *mesh_tx; +u8 handle; + + hdev = hdevs[i]; + +for (;;) { +hci_dev_lock (hdev); mesh_tx =mgmt_mesh_next (hdev, sk); + handle = mesh_tx ? mesh_tx->handle :0 ; +hci_dev_unlock (hdev); + +if (!mesh_tx) +break ; -if (mesh_tx) -mesh_send_complete (hdev, mesh_tx, true); - }while (mesh_tx); +mesh_cancel_tx (hdev, handle, true); + } + +/* Resume the transmissions of the other sockets in case the +* one in progress was removed. +*/ +mesh_next (hdev,NULL ,0 ); + +hci_dev_put (hdev); } -read_unlock (&hci_dev_list_lock); +kfree (hdevs); }
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 12/16 Bluetooth: MGMT: Fix use-after-free in mgmt_powering_down()
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
mgmt_powering_down() looked up the Set Powered command and read its parameters after mgmt_pending_find() dropped mgmt_pending_lock, so the command could be unlinked and freed in between. Do the lookup and read the parameters while holding the lock.
--- net/bluetooth/mgmt.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-)
net/bluetooth/mgmt.c +15 -7
@@ -10325,19 +10325,27 @@ bool mgmt_powering_down(struct hci_dev *hdev) {struct mgmt_pending_cmd *cmd;struct mgmt_mode *cp; +bool powering_down = false;if (hci_dev_test_flag (hdev,HCI_POWERING_DOWN ))return true; - cmd =pending_find (MGMT_OP_SET_POWERED , hdev); -if (!cmd) -return false; +mutex_lock (&hdev->mgmt_pending_lock); - cp = cmd->param; -if (!cp->val) -return true; +list_for_each_entry (cmd, &hdev->mgmt_pending, list) { +if (hci_sock_get_channel (cmd->sk) !=HCI_CHANNEL_CONTROL || + cmd->opcode !=MGMT_OP_SET_POWERED ) +continue ; -return false; +/* cmd can only be freed after it is unlinked under the lock */ + cp = cmd->param; + powering_down = !cp->val; +break ; + } + +mutex_unlock (&hdev->mgmt_pending_lock); + +return powering_down; }u8 hci_to_mgmt_reason (u8 err)
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 13/16 Bluetooth: MSFT: Protect the event prefix with hdev->lock
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
msft_vendor_evt() read msft->evt_prefix_len and compared evt_prefix before taking hdev->lock, while msft_do_open() (and the supported features reply) free and reallocate the prefix without it, so an event received while the controller is being opened could access freed memory. Take hdev->lock for the whole event processing and while updating the prefix.
--- net/bluetooth/msft.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-)
net/bluetooth/msft.c +20 -9
@@ -170,11 +170,16 @@ static bool read_supported_features(struct hci_dev *hdev, goto failed; } +/* The event prefix is used by msft_vendor_evt() with hdev->lock held */ +hci_dev_lock (hdev); +if (rp->evt_prefix_len >0 ) { msft->evt_prefix =kmemdup (rp->evt_prefix, rp->evt_prefix_len,GFP_KERNEL ); -if (!msft->evt_prefix) +if (!msft->evt_prefix) { +hci_dev_unlock (hdev); goto failed; + } } msft->evt_prefix_len = rp->evt_prefix_len;
@@ -183,6 +188,8 @@ static bool read_supported_features(struct hci_dev *hdev,if (msft->features &MSFT_FEATURE_MASK_CURVE_VALIDITY ) hdev->msft_curve_validity = true; +hci_dev_unlock (hdev); +kfree_skb (skb);return true;
@@ -648,10 +655,12 @@ void msft_do_open(struct hci_dev *hdev)bt_dev_dbg (hdev,"Initialize MSFT extension" );/* Reset existing MSFT data before re-reading */ +hci_dev_lock (hdev);kfree (msft->evt_prefix); msft->evt_prefix =NULL ; msft->evt_prefix_len =0 ; msft->features =0 ; +hci_dev_unlock (hdev);if (!read_supported_features (hdev, msft)) {hci_dev_lock (hdev);
@@ -1078,12 +1087,15 @@ static void msft_monitor_device_evt(struct hci_dev *hdev, struct sk_buff *skb)void msft_vendor_evt (struct hci_dev *hdev,void *data,struct sk_buff *skb) { -struct msft_data *msft = hdev->msft_data; +struct msft_data *msft;u8 *evt_prefix;u8 *evt; +hci_dev_lock (hdev); + + msft = hdev->msft_data;if (!msft) -return ; + goto unlock;/* When the extension has defined an event prefix, check that it * matches, and otherwise just return.
@@ -1091,23 +1103,21 @@ void msft_vendor_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb)if (msft->evt_prefix_len >0 ) { evt_prefix =msft_skb_pull (hdev, skb,0 , msft->evt_prefix_len);if (!evt_prefix) -return ; + goto unlock;if (memcmp (evt_prefix, msft->evt_prefix, msft->evt_prefix_len)) -return ; + goto unlock; }/* Every event starts at least with an event code and the rest of * the data is variable and depends on the event code. */ if (skb->len <1 ) -return ; + goto unlock; evt =msft_skb_pull (hdev, skb,0 ,sizeof (*evt));if (!evt) -return ; - -hci_dev_lock (hdev); + goto unlock;switch (*evt) {case MSFT_EV_LE_MONITOR_DEVICE :
@@ -1121,6 +1131,7 @@ void msft_vendor_evt(struct hci_dev *hdev, void *data, struct sk_buff *skb)break ; } +unlock:hci_dev_unlock (hdev); }
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 14/16 Bluetooth: hci_debugfs: Fix racy toggling of debugfs controlled flags
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The debugfs writers checked the current state of the flag, then blindly inverted it with hci_dev_change_flag(). Two concurrent writers both pass the check and the second inversion undoes the first one, leaving the flag out of sync with the actual controller/SMP channel state (e.g. DUT mode flag vs controller, or the BR/EDR SMP channel being leaked or removed twice).
Set or clear the flag explicitly instead, redo the dut_mode check under hci_req_sync_lock() and serialize smp_force_bredr() with hdev->lock.
--- net/bluetooth/hci_debugfs.c | 30 ++++++++++++++++++++++++------ net/bluetooth/smp.c | 25 +++++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-)
net/bluetooth/hci_debugfs.c +24 -6
@@ -777,7 +777,10 @@ static ssize_t force_static_address_write(struct file *file,if (enable ==hci_dev_test_flag (hdev,HCI_FORCE_STATIC_ADDR ))return -EALREADY ; -hci_dev_change_flag (hdev,HCI_FORCE_STATIC_ADDR ); +if (enable) +hci_dev_set_flag (hdev,HCI_FORCE_STATIC_ADDR ); +else +hci_dev_clear_flag (hdev,HCI_FORCE_STATIC_ADDR );return count; }
@@ -1177,7 +1180,10 @@ static ssize_t force_no_mitm_write(struct file *file,if (enable ==hci_dev_test_flag (hdev,HCI_FORCE_NO_MITM ))return -EALREADY ; -hci_dev_change_flag (hdev,HCI_FORCE_NO_MITM ); +if (enable) +hci_dev_set_flag (hdev,HCI_FORCE_NO_MITM ); +else +hci_dev_clear_flag (hdev,HCI_FORCE_NO_MITM );return count; }
@@ -1303,20 +1309,32 @@ static ssize_t dut_mode_write(struct file *file, const char __user *user_buf,return -EALREADY ;hci_req_sync_lock (hdev); + +/* Check again now that concurrent writers are excluded */ +if (enable ==hci_dev_test_flag (hdev,HCI_DUT_MODE )) { +hci_req_sync_unlock (hdev); +return -EALREADY ; + } +if (enable) skb =__hci_cmd_sync (hdev,HCI_OP_ENABLE_DUT_MODE ,0 ,NULL ,HCI_CMD_TIMEOUT );else skb =__hci_cmd_sync (hdev,HCI_OP_RESET ,0 ,NULL ,HCI_CMD_TIMEOUT ); -hci_req_sync_unlock (hdev); - -if (IS_ERR (skb)) +if (IS_ERR (skb)) { +hci_req_sync_unlock (hdev);return PTR_ERR (skb); + }kfree_skb (skb); -hci_dev_change_flag (hdev,HCI_DUT_MODE ); +if (enable) +hci_dev_set_flag (hdev,HCI_DUT_MODE ); +else +hci_dev_clear_flag (hdev,HCI_DUT_MODE ); + +hci_req_sync_unlock (hdev);return count; }
net/bluetooth/smp.c +19 -6
@@ -3438,8 +3438,14 @@ static void smp_del_chan(struct l2cap_chan *chan)int smp_force_bredr (struct hci_dev *hdev,bool enable) { -if (enable ==hci_dev_test_flag (hdev,HCI_FORCE_BREDR_SMP )) -return -EALREADY ; +int err =0 ; + +hci_dev_lock (hdev); + +if (enable ==hci_dev_test_flag (hdev,HCI_FORCE_BREDR_SMP )) { + err = -EALREADY ; + goto unlock; + }/* The channels are only registered while the controller is powered * and LE capable. Otherwise just record the flag, smp_register() will
@@ -3450,8 +3456,10 @@ int smp_force_bredr(struct hci_dev *hdev, bool enable)if (hdev->smp_data && !hdev->smp_bredr_data) { chan =smp_add_cid (hdev,L2CAP_CID_SMP_BREDR ); -if (IS_ERR (chan)) -return PTR_ERR (chan); +if (IS_ERR (chan)) { + err =PTR_ERR (chan); + goto unlock; + } hdev->smp_bredr_data = chan; }
@@ -3465,9 +3473,14 @@ int smp_force_bredr(struct hci_dev *hdev, bool enable) } } -hci_dev_change_flag (hdev,HCI_FORCE_BREDR_SMP ); +if (enable) +hci_dev_set_flag (hdev,HCI_FORCE_BREDR_SMP ); +else +hci_dev_clear_flag (hdev,HCI_FORCE_BREDR_SMP ); -return 0 ; +unlock: +hci_dev_unlock (hdev); +return err; }int smp_register (struct hci_dev *hdev)
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 15/16 Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
hci_remove_single_adv_monitor() and hci_remove_all_adv_monitor() only require hci_req_sync_lock, yet they look up and free monitors, modifying hdev->adv_monitors_idr and adv_monitors_cnt, which Read Advertisement Monitor Features iterates under hdev->lock. Take hdev->lock around the IDR accesses and the freeing, but not across the HCI commands sent to the controller.
--- net/bluetooth/hci_core.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
net/bluetooth/hci_core.c +11 -1
@@ -2107,7 +2107,10 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,if (status == -ENOENT )bt_dev_warn (hdev,"Removing monitor with no matching handle %d" , monitor->handle); + +hci_dev_lock (hdev);hci_free_adv_monitor (hdev, monitor); +hci_dev_unlock (hdev);return status; }
@@ -2115,7 +2118,11 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,/* This function requires the caller holds hci_req_sync_lock */ int hci_remove_single_adv_monitor (struct hci_dev *hdev,u16 handle) { -struct adv_monitor *monitor =idr_find (&hdev->adv_monitors_idr, handle); +struct adv_monitor *monitor; + +hci_dev_lock (hdev); + monitor =idr_find (&hdev->adv_monitors_idr, handle); +hci_dev_unlock (hdev);if (!monitor)return -EINVAL ;
@@ -2131,7 +2138,10 @@ int hci_remove_all_adv_monitor(struct hci_dev *hdev)int status =0 ;while (1 ) { +hci_dev_lock (hdev); monitor =idr_get_next (&hdev->adv_monitors_idr, &idr_next_id); +hci_dev_unlock (hdev); +if (!monitor)break ;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH 16/16 Bluetooth: RFCOMM: Serialize tty device reparenting
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
rfcomm_dev_shutdown() and rfcomm_reparent_device() both move the tty device to a new parent with device_move() without any synchronization between them, and shutdown tests dev->tty_dev->parent before moving, so a concurrent reparent can race with that check and the move itself. Serialize the moves with a mutex and perform the parent check under it.
--- net/bluetooth/rfcomm/tty.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-)
net/bluetooth/rfcomm/tty.c +17 -4
@@ -123,13 +123,22 @@ static bool rfcomm_dev_carrier_raised(struct tty_port *port)return (dev->dlc->state ==BT_CONNECTED ); } +/* Serializes reparenting of the tty devices, device_move() doesn't protect +* the parent from concurrent moves of the same device. +*/ +static DEFINE_MUTEX (rfcomm_move_lock); +/* device-specific cleanup: close the dlc */ static void rfcomm_dev_shutdown (struct tty_port *port) { struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port); -if (dev->tty_dev && dev->tty_dev->parent) -device_move (dev->tty_dev,NULL ,DPM_ORDER_DEV_LAST ); +if (dev->tty_dev) { +mutex_lock (&rfcomm_move_lock); +if (dev->tty_dev->parent) +device_move (dev->tty_dev,NULL ,DPM_ORDER_DEV_LAST ); +mutex_unlock (&rfcomm_move_lock); + }/* close the dlc */ rfcomm_dlc_close (dev->dlc,0 );
@@ -187,8 +196,12 @@ static void rfcomm_reparent_device(struct rfcomm_dev *dev)/* Just because the acl link is in the hash table is no * guarantee the sysfs device has been added ... */ -if (conn &&device_is_registered (&conn->dev)) -device_move (dev->tty_dev, &conn->dev,DPM_ORDER_DEV_AFTER_PARENT ); +if (conn &&device_is_registered (&conn->dev)) { +mutex_lock (&rfcomm_move_lock); +device_move (dev->tty_dev, &conn->dev, +DPM_ORDER_DEV_AFTER_PARENT ); +mutex_unlock (&rfcomm_move_lock); + }hci_dev_unlock (hdev);hci_dev_put (hdev);
Signature · 1 line
2.56.0