Bluetooth: Fixes for issues reported by sashiko.dev
Subsystems (2)
Luiz Augusto von Dentz
maintainerv2 cover 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.
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, the first transmission is always the one being sent, and cancelling one stops the done timer or dequeues its done entry if it is the one in progress.
- Patch 12 reads the pending Set Powered command under mgmt_pending_lock in mgmt_powering_down().
- Patch 16 frees the response of the MSFT add/remove monitor commands.
- Patch 17 doesn't fail removing a monitor the controller doesn't know.
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, and serializes smp_register() with it.
- Patch 14 sets/clears the debugfs controlled flags and quirks explicitly rather than toggling them, and serializes the writers.
Changes in v2 (addressing the sashiko.dev review of v1):
- Dropped "Bluetooth: RFCOMM: Serialize tty device reparenting", the review found that it is incomplete (hci_conn_del_sysfs() also moves the device, and shutdown moves it before closing the DLC), a proper fix needs a shared lock with hci_sysfs.c.
- Dropped "hci_sync: Take req_sync lock in interleave_scan_work()" and the change to hci_abort_conn_sync() from the earlier revisions, they were not correct (the former can deadlock with cancel_interleave_scan()).
- Patch 4: fixed the Fixes tag, it is cba6b758711c.
- Patch 5: debug keys are removed by reference with hci_del_link_key() since a lookup by address skips blocked keys and would leak them, and the comment and commit message about which callers may use the returned key were corrected.
- Patch 7: smp_register() is now called with hdev->lock so it can't race with smp_unregister() and smp_force_bredr().
- Patch 11: restored mgmt_cleanup(), the previous change could sleep in atomic context (it runs from the socket destructor) and can't run for a socket with pending transmissions anyway since they hold a reference to it. HCI_MESH_SENDING is now only cleared together with the removal of the transmission, the first transmission is the one queued, a failed queue no longer strands the remaining ones, a done entry already queued is dequeued on cancel, and the index removal clears the flag.
- Patch 14: also use assign_bit() instead of change_bit() for the quirk attributes.
- New patches 16 and 17, found by the review.
Not addressed by this series, also reported by the review and left for follow ups: the unlocked LTK/IRK accesses in smp_notify_keys() and hci_add_irk(), the callees of hci_start_adv_sync() and cur_adv_instance without hdev->lock, the double list_del() of an MSFT address filter and the RFCOMM lock ordering and device_move() races.
Testing: v1 was run with KASAN and lockdep enabled through the BlueZ testers (mgmt, mesh, smp, l2cap, rfcomm, iso, ...) and test-functional (which found the lock ordering problem with hdev->lock in patch 5 that led to hdev->link_keys_lock). v2 has been build tested (W=1, each patch) and test-functional was run with the same configuration: 68 passed, 1 skipped and 1 error. The error is rfcomm-tester reporting a possible circular locking dependency (rfcomm_mutex, hci_cb_list_lock, hdev->lock and the flush of the hci0 workqueue in hci_release_dev()), none of the locks touched by this series are part of it. It is not caused by it: the same kernel testers run on the base (without the series) failed the same way in one of two runs.
Luiz Augusto von Dentz (17):
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: MSFT: Free the response of the monitor commands
Bluetooth: hci_core: Don't fail removing a monitor unknown to the
controller
include/net/bluetooth/hci_core.h | 6 + net/bluetooth/hci_core.c | 81 ++++++++- net/bluetooth/hci_debugfs.c | 32 +++- net/bluetooth/hci_event.c | 9 +- net/bluetooth/hci_sync.c | 26 ++- net/bluetooth/l2cap_core.c | 5 +- net/bluetooth/mgmt.c | 285 +++++++++++++++++++++++-------- net/bluetooth/mgmt_config.c | 6 + net/bluetooth/msft.c | 48 ++++-- net/bluetooth/smp.c | 58 +++++-- 10 files changed, 439 insertions(+), 117 deletions(-)
base-commit: f42f5cae154b90a0cb6d8232dc84c7614ca2e6a0
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH v2 1/17 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/1214259/
---Test result---
Test Summary:
CheckPatch FAIL 14.35 seconds VerifyFixes PASS 0.13 seconds VerifySignedoff PASS 0.13 seconds GitLint FAIL 5.88 seconds SubjectPrefix PASS 2.16 seconds BuildKernel PASS 31.33 seconds CheckAllWarning PASS 35.12 seconds CheckSparse WARNING 39.84 seconds BuildKernel32 PASS 31.32 seconds CheckKernelLLVM PASS 34.60 seconds TestRunnerSetup PASS 749.61 seconds TestRunner_l2cap-tester PASS 14.87 seconds TestRunner_iso-tester PASS 13.20 seconds TestRunner_bnep-tester PASS 3.20 seconds TestRunner_mgmt-tester PASS 88.83 seconds TestRunner_rfcomm-tester PASS 4.50 seconds TestRunner_sco-tester PASS 5.67 seconds TestRunner_ioctl-tester PASS 4.72 seconds TestRunner_mesh-tester PASS 4.53 seconds TestRunner_smp-tester PASS 4.42 seconds TestRunner_userchan-tester PASS 3.25 seconds TestRunner_6lowpan-tester PASS 4.43 seconds IncrementalBuild PASS 91.15 seconds
Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[v2,01/17] 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/14994716.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.
[v2,02/17] 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/14994717.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.
[v2,03/17] 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/14994718.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.
[v2,04/17] 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/14994719.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.
[v2,05/17] Bluetooth: SMP: Serialize link key updates from smp_notify_keys()
ERROR: Unrecognized email address: 'sashiko.dev (linux-7482a666-d2a0-44a4-9e0d-05354860a5fa)' #136:
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 #136:
WARNING: Non-standard signature: Assisted-by:
#138:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #138:
total: 2 errors, 2 warnings, 0 checks, 161 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/14994720.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.
[v2,06/17] 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/14994721.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.
[v2,07/17] Bluetooth: SMP: Don't create the BR/EDR channel while unregistered
ERROR: Unrecognized email address: 'sashiko.dev (linux-a921c99c-0b41-485c-91a4-1c6e54b45b0b)' #130:
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 #130:
WARNING: Non-standard signature: Assisted-by:
#132:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #132:
total: 2 errors, 2 warnings, 0 checks, 43 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/14994722.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.
[v2,08/17] 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/14994723.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.
[v2,09/17] 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/14994724.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.
[v2,10/17] 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/14994725.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.
[v2,11/17] 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-ab941894-dbe1-49da-8bac-c52efda6eaee)
ERROR: Unrecognized email address: 'sashiko.dev (linux-ab941894-dbe1-49da-8bac-c52efda6eaee)' #148:
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 #148:
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)' #149:
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 #149:
WARNING: Non-standard signature: Assisted-by:
#151:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #151:
total: 4 errors, 4 warnings, 0 checks, 369 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/14994726.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.
[v2,12/17] 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/14994727.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.
[v2,13/17] 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/14994728.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.
[v2,14/17] Bluetooth: hci_debugfs: Fix racy toggling of debugfs controlled flags
ERROR: Unrecognized email address: 'sashiko.dev (linux-442108d5-76ce-44a1-a84d-16b44d6a26a6)' #133:
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 #133:
WARNING: Non-standard signature: Assisted-by:
#136:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #136:
total: 2 errors, 2 warnings, 0 checks, 110 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/14994729.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.
[v2,15/17] 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/14994732.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.
[v2,16/17] Bluetooth: MSFT: Free the response of the monitor commands
WARNING: Non-standard signature: Assisted-by:
#133:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #133:
total: 1 errors, 1 warnings, 0 checks, 56 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/14994730.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.
[v2,17/17] Bluetooth: hci_core: Don't fail removing a monitor unknown to the controller
WARNING: Non-standard signature: Assisted-by:
#130:
ERROR: Unrecognized email address: 'OpenCode:claude-fable-5.2' #130:
total: 1 errors, 1 warnings, 0 checks, 11 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/14994731.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:
[v2,03/17] Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync()
1: T1 Title exceeds max length (86>80): "[v2,03/17] Bluetooth: hci_sync: Lock the lookup in hci_disable_ext_adv_instance_sync()" [v2,04/17] Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync()
1: T1 Title exceeds max length (83>80): "[v2,04/17] Bluetooth: hci_sync: Hold hdev->lock in hci_schedule_adv_instance_sync()" [v2,08/17] Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable
1: T1 Title exceeds max length (86>80): "[v2,08/17] Bluetooth: hci_event: Validate sent command length in LE Set Ext Adv Enable" [v2,10/17] Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp()
1: T1 Title exceeds max length (82>80): "[v2,10/17] Bluetooth: L2CAP: Don't use uninitialized EFS in l2cap_parse_conf_rsp()" [v2,15/17] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors
1: T1 Title exceeds max length (84>80): "[v2,15/17] Bluetooth: hci_core: Hold hdev->lock when removing advertisement monitors" [v2,17/17] Bluetooth: hci_core: Don't fail removing a monitor unknown to the controller
1: T1 Title exceeds max length (87>80): "[v2,17/17] Bluetooth: hci_core: Don't fail removing a monitor unknown to the controller"
##############################
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/1145
---
Regards,
Linux Bluetooth
Luiz Augusto von Dentz
maintainerPATCH v2 2/17 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 v2 3/17 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 v2 4/17 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 v2 5/17 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). SMP holds it while it adds the key, notifies mgmt and removes a debug key, so the key can't go away meanwhile, and the debug key removed by hci_link_key_notify_evt() is deleted by reference with hci_del_link_key() since a lookup by address skips the keys that are blocked.
--- include/net/bluetooth/hci_core.h | 6 ++++ net/bluetooth/hci_core.c | 62 +++++++++++++++++++++++++++++--- net/bluetooth/hci_event.c | 3 +- net/bluetooth/smp.c | 11 ++++-- 4 files changed, 74 insertions(+), 8 deletions(-)
include/net/bluetooth/hci_core.h +6 -0
@@ -575,6 +575,8 @@ struct hci_dev {struct list_head accept_list;struct list_head uuids;struct list_head link_keys; +/* Serializes the writers of link_keys, see hci_add_link_key() */ +struct mutex link_keys_lock;struct list_head long_term_keys;struct list_head identity_resolving_keys;struct mutex remote_oob_lock;
@@ -1943,6 +1945,10 @@ 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); +void hci_del_link_key (struct hci_dev *hdev,struct link_key *key);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 +58 -4
111 lines not on this page · raw message
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_del_link_key (hdev, key); 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 v2 6/17 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 v2 7/17 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. Since smp_unregister() runs with hdev->lock take it around smp_register() as well so they can't race with each other nor with smp_force_bredr().
--- net/bluetooth/hci_sync.c | 2 ++ net/bluetooth/smp.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-)
net/bluetooth/hci_sync.c +2 -0
@@ -3892,7 +3892,9 @@ int hci_powered_update_sync(struct hci_dev *hdev)* registration is required so that LE SMP can clearly decide if * the public address or static address is used. */ +hci_dev_lock (hdev);smp_register (hdev); +hci_dev_unlock (hdev); err =hci_write_ssp_mode_sync (hdev,0x01 );if (err)
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 v2 8/17 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 v2 9/17 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 v2 10/17 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 v2 11/17 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 and Mesh Send Cancel 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 a cancel of the transmission can free while the entry is running, leading to use-after-free.
Fix this by:
- taking hdev->lock around every mesh_pending/adv_instances access in the cmd_sync callbacks and Mesh Send Cancel, 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;
- always sending the first transmission, tracked by HCI_MESH_SENDING which is only cleared together with the removal of the transmission so Mesh Send can't start another one in between, and making sure none is left stranded if queueing fails;
- cancelling a transmission by dequeuing its entry, and the done entry if it is the one in progress, stopping the done timer, which is queued with hdev->lock held so a cancel can't miss it;
- 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 and clearing HCI_MESH_SENDING when the index is removed.
--- net/bluetooth/mgmt.c | 257 +++++++++++++++++++++++++++++++++---------- 1 file changed, 199 insertions(+), 58 deletions(-)
net/bluetooth/mgmt.c +199 -58
@@ -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) {
@@ -1099,37 +1100,92 @@ static void mesh_send_complete(struct hci_dev *hdev,mgmt_mesh_remove (mesh_tx); } -static int mesh_send_done_sync (struct hci_dev *hdev,void *data) +/* 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); + +/* Start sending the first transmission unless one is already in progress, +* HCI_MESH_SENDING is set while the first transmission is being sent. +* +* This function requires the caller holds hdev->lock. +*/ +static void __mesh_next (struct hci_dev *hdev) {struct mgmt_mesh_tx *mesh_tx; +int err; -hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); -if (list_empty (&hdev->adv_instances)) -hci_disable_advertising_sync (hdev); - mesh_tx =mgmt_mesh_next (hdev,NULL ); - -if (mesh_tx) -mesh_send_complete (hdev, mesh_tx, false); +while (!hci_dev_test_flag (hdev,HCI_MESH_SENDING )) { + mesh_tx =mgmt_mesh_next (hdev,NULL ); +if (!mesh_tx) +return ; -return 0 ; + 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 ); + } } -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 ); - -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, - mesh_send_start_complete); +hci_dev_lock (hdev); +__mesh_next (hdev); +hci_dev_unlock (hdev); +} + +static int mesh_send_done_sync (struct hci_dev *hdev,void *data) +{ +struct mgmt_mesh_tx *mesh_tx; +u8 handle; +bool disable; -if (err <0 ) +hci_dev_lock (hdev); + + mesh_tx =mgmt_mesh_next (hdev,NULL ); +if (!mesh_tx || !hci_dev_test_flag (hdev,HCI_MESH_SENDING )) { +hci_dev_unlock (hdev); +return 0 ; + } + + handle = mesh_tx->handle; + disable =list_empty (&hdev->adv_instances); + +hci_dev_unlock (hdev); + +if (disable) +hci_disable_advertising_sync (hdev); + +hci_dev_lock (hdev); + +/* The transmission can be cancelled meanwhile, in which case whoever +* did so already moved on to the next one. HCI_MESH_SENDING is only +* cleared with the transmission removed so Mesh Send doesn't start +* another one in between. +*/ + mesh_tx =mgmt_mesh_find (hdev, handle); +if (mesh_tx) {mesh_send_complete (hdev, mesh_tx, false); -else -hci_dev_set_flag (hdev,HCI_MESH_SENDING ); +hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); + } + +hci_dev_unlock (hdev); + +return 0 ; }static void mesh_send_done (struct work_struct *work)
@@ -2310,38 +2366,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; -unsigned long mesh_send_interval; +struct mgmt_mesh_tx *mesh_tx; +struct mgmt_cp_mesh_send *send;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 the controller is going +* down nothing is being sent anymore though. +*/ +if (err == -ECANCELED ) { +hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); +return ; + } + +hci_dev_lock (hdev); + +/* Cancelled while the entry was running, whoever did so already moved +* on to the next transmission. +*/ + mesh_tx =mgmt_mesh_find (hdev,MESH_TX_HANDLE (data)); +if (!mesh_tx) { +hci_dev_unlock (hdev); +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_clear_flag (hdev,HCI_MESH_SENDING ); +__mesh_next (hdev); +hci_dev_unlock (hdev);return ; } - mesh_send_interval =msecs_to_jiffies ((send->cnt) *25 ); +/* Queued with hdev->lock held so a cancel can't miss it */ + send = (void *)mesh_tx->param;queue_delayed_work (hdev->req_workqueue, &hdev->mesh_send_done, - mesh_send_interval); +msecs_to_jiffies ((send->cnt) *25 )); + +hci_dev_unlock (hdev); }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 +2470,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 +2515,80 @@ 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) +{ +struct mgmt_mesh_tx *mesh_tx; +bool in_progress; + +hci_cmd_sync_dequeue (hdev, mesh_send_sync,MESH_TX_DATA (handle),NULL ); + +hci_dev_lock (hdev); + mesh_tx =mgmt_mesh_find (hdev, handle); + in_progress = mesh_tx &&hci_dev_test_flag (hdev,HCI_MESH_SENDING ) && + mesh_tx ==mgmt_mesh_next (hdev,NULL ); +hci_dev_unlock (hdev); + +/* The done timer may have fired already and be waiting to complete +* the transmission in progress, which is being cancelled. +*/ +if (in_progress) +hci_cmd_sync_dequeue (hdev, mesh_send_done_sync,NULL ,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, false); + } + +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); + } }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); }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 ; }
@@ -2503,7 +2639,6 @@ static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len)struct mgmt_cp_mesh_send *send = data;struct mgmt_rp_mesh_read_features rp;u16 expected_len; -bool sending;int err =0 ; if (!lmp_le_capable(hdev) ||
@@ -2536,27 +2671,27 @@ static int mesh_send(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) goto done; } - sending =hci_dev_test_flag (hdev,HCI_MESH_SENDING ); mesh_tx =mgmt_mesh_add (sk, hdev, send, len); - -if (!mesh_tx) +if (!mesh_tx) { err = -ENOMEM ; -else if (!sending) - err =hci_cmd_sync_queue (hdev, mesh_send_sync, mesh_tx, - mesh_send_start_complete); + }else { +u8 handle = mesh_tx->handle; + +/* The first transmission is the one queued, which may not be +* the one just added. +*/ +__mesh_next (hdev); + +/* Queueing failed, the transmission was removed */ +if (!mgmt_mesh_find (hdev, handle)) + err = -EIO ; + }if (err <0 ) {bt_dev_err (hdev,"Send Mesh Failed %d" , err); err =mgmt_cmd_status (sk, hdev->id,MGMT_OP_MESH_SEND ,MGMT_STATUS_FAILED ); - -if (mesh_tx) { -if (sending) -mgmt_mesh_remove (mesh_tx); - } }else { -hci_dev_set_flag (hdev,HCI_MESH_SENDING ); -mgmt_cmd_complete (sk, hdev->id,MGMT_OP_MESH_SEND ,0 , &mesh_tx->handle,1 ); }
@@ -9892,6 +10027,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 +10057,11 @@ 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 */ +hci_dev_clear_flag (hdev,HCI_MESH_SENDING ); +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)
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH v2 12/17 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
@@ -10363,19 +10363,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 v2 13/17 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 v2 14/17 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. The same applies to the quirk attributes.
--- net/bluetooth/hci_debugfs.c | 32 +++++++++++++++++++++++++------- net/bluetooth/smp.c | 25 +++++++++++++++++++------ 2 files changed, 44 insertions(+), 13 deletions(-)
net/bluetooth/hci_debugfs.c +25 -7
@@ -59,7 +59,7 @@ static ssize_t __name ## _write(struct file *file, \if (enable ==test_bit (__quirk, hdev->quirk_flags)) \return -EALREADY ; \ \ -change_bit (__quirk, hdev->quirk_flags); \ +assign_bit (__quirk, hdev->quirk_flags, enable); \ \return count; \ } \
@@ -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 v2 15/17 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
@@ -2129,7 +2129,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; }
@@ -2137,7 +2140,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 ;
@@ -2153,7 +2160,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 v2 16/17 Bluetooth: MSFT: Free the response of the monitor commands
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
msft_add_monitor_sync() and msft_remove_monitor_sync() send the MSFT command with __hci_cmd_sync() and pass the returned skb to the callbacks, which only parse it, so it is never freed. Free it once the callback returns.
While at it do the handle map lookups with hdev->lock held, as the callbacks modify the handle map under it.
Found by the sashiko.dev review of the previous patch in this series.
--- net/bluetooth/msft.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
net/bluetooth/msft.c +16 -3
@@ -438,23 +438,30 @@ static int msft_remove_monitor_sync(struct hci_dev *hdev,struct msft_cp_le_cancel_monitor_advertisement cp;struct msft_monitor_advertisement_handle_data *handle_data;struct sk_buff *skb; +int err; +hci_dev_lock (hdev); handle_data =msft_find_handle_data (hdev, monitor->handle, true); +if (handle_data) + cp.handle = handle_data->msft_handle; +hci_dev_unlock (hdev);/* If no matched handle, just remove without telling controller */ if (!handle_data)return -ENOENT ; cp.sub_opcode =MSFT_OP_LE_CANCEL_MONITOR_ADVERTISEMENT ; - cp.handle = handle_data->msft_handle; skb =__hci_cmd_sync (hdev, hdev->msft_opcode,sizeof (cp), &cp,HCI_CMD_TIMEOUT );if (IS_ERR (skb))return PTR_ERR (skb); -return msft_le_cancel_monitor_advertisement_cb (hdev, hdev->msft_opcode, - monitor, skb); + err =msft_le_cancel_monitor_advertisement_cb (hdev, hdev->msft_opcode, + monitor, skb); +kfree_skb (skb); + +return err; }/* This function requires the caller holds hci_req_sync_lock */
@@ -571,11 +578,15 @@ static int msft_add_monitor_sync(struct hci_dev *hdev, err =msft_le_monitor_advertisement_cb (hdev, hdev->msft_opcode, monitor, skb); +kfree_skb (skb);if (err) goto out_free; +hci_dev_lock (hdev); + handle_data =msft_find_handle_data (hdev, monitor->handle, true);if (!handle_data) { +hci_dev_unlock (hdev); err = -ENODATA ; goto out_free; }
@@ -585,6 +596,8 @@ static int msft_add_monitor_sync(struct hci_dev *hdev, handle_data->rssi_low_interval = cp->rssi_low_interval; handle_data->rssi_sampling_period = cp->rssi_sampling_period; +hci_dev_unlock (hdev); + out_free:kfree (cp);return err;
Signature · 1 line
2.56.0
Luiz Augusto von Dentz
maintainerPATCH v2 17/17 Bluetooth: hci_core: Don't fail removing a monitor unknown to the controller
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
hci_remove_adv_monitor() frees the monitor when the controller has no matching handle for it but still returned -ENOENT, so callers took it for a failure of a monitor that is gone, and hci_remove_all_adv_monitor() stopped at the first one leaving the others behind. Return success since the monitor was removed.
Found by the sashiko.dev review of the previous patch in this series.
--- net/bluetooth/hci_core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bluetooth/hci_core.c +4 -1
@@ -2134,7 +2134,10 @@ static int hci_remove_adv_monitor(struct hci_dev *hdev,hci_free_adv_monitor (hdev, monitor);hci_dev_unlock (hdev); -return status; +/* The monitor is gone, not having been known by the controller is not +* an error for the caller. +*/ +return status == -ENOENT ?0 : status; }/* This function requires the caller holds hci_req_sync_lock */
Signature · 1 line
2.56.0