diff mbox series

Bluetooth: protect le accept and resolv lists with hdev->lock

Message ID 20220422223116.70026-1-dossche.niels@gmail.com
State Accepted
Commit df50527dbc3280757c9f43d5e4e9ae71c3bc93a3
Headers show
Series Bluetooth: protect le accept and resolv lists with hdev->lock | expand

Commit Message

Niels Dossche April 22, 2022, 10:31 p.m. UTC
Concurrent operations from events on le_{accept,resolv}_list are
currently unprotected by hdev->lock.
Most existing code do already protect the lists with that lock.
This can be observed in hci_debugfs and hci_sync.
Add the protection for these events too.

Fixes: b950aa88638c ("Bluetooth: Add definitions and track LE resolve list modification")
Fixes: 0f36b589e4ee ("Bluetooth: Track LE white list modification via HCI commands")
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---

Note:
I am currently working on a static analyser to detect missing locks
using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know.
This was a reported case. I manually verified the report by looking
at the code, so that I do not send wrong information or patches.
After concluding that this seems to be a true positive, I created
this patch. This was compile-tested and runtime-tested on x86_64.
This issue was found on Linux v5.17.4.

 net/bluetooth/hci_event.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

bluez.test.bot@gmail.com April 23, 2022, 12:04 a.m. UTC | #1
This is automated email and please do not reply to this email!

Dear submitter,

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

---Test result---

Test Summary:
CheckPatch                    PASS      1.81 seconds
GitLint                       PASS      1.06 seconds
SubjectPrefix                 PASS      0.91 seconds
BuildKernel                   PASS      39.15 seconds
BuildKernel32                 PASS      35.25 seconds
Incremental Build with patchesPASS      47.65 seconds
TestRunner: Setup             PASS      588.43 seconds
TestRunner: l2cap-tester      PASS      21.02 seconds
TestRunner: bnep-tester       PASS      7.75 seconds
TestRunner: mgmt-tester       PASS      126.80 seconds
TestRunner: rfcomm-tester     PASS      11.60 seconds
TestRunner: sco-tester        PASS      11.37 seconds
TestRunner: smp-tester        PASS      11.30 seconds
TestRunner: userchan-tester   PASS      7.83 seconds



---
Regards,
Linux Bluetooth
patchwork-bot+bluetooth@kernel.org April 25, 2022, 2:30 p.m. UTC | #2
Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Marcel Holtmann <marcel@holtmann.org>:

On Sat, 23 Apr 2022 00:31:17 +0200 you wrote:
> Concurrent operations from events on le_{accept,resolv}_list are
> currently unprotected by hdev->lock.
> Most existing code do already protect the lists with that lock.
> This can be observed in hci_debugfs and hci_sync.
> Add the protection for these events too.
> 
> Fixes: b950aa88638c ("Bluetooth: Add definitions and track LE resolve list modification")
> Fixes: 0f36b589e4ee ("Bluetooth: Track LE white list modification via HCI commands")
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
> 
> [...]

Here is the summary with links:
  - Bluetooth: protect le accept and resolv lists with hdev->lock
    https://git.kernel.org/bluetooth/bluetooth-next/c/df50527dbc32

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index abaabfae19cc..f314eb0bf284 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1835,7 +1835,9 @@  static u8 hci_cc_le_clear_accept_list(struct hci_dev *hdev, void *data,
 	if (rp->status)
 		return rp->status;
 
+	hci_dev_lock(hdev);
 	hci_bdaddr_list_clear(&hdev->le_accept_list);
+	hci_dev_unlock(hdev);
 
 	return rp->status;
 }
@@ -1855,8 +1857,10 @@  static u8 hci_cc_le_add_to_accept_list(struct hci_dev *hdev, void *data,
 	if (!sent)
 		return rp->status;
 
+	hci_dev_lock(hdev);
 	hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr,
 			    sent->bdaddr_type);
+	hci_dev_unlock(hdev);
 
 	return rp->status;
 }
@@ -1876,8 +1880,10 @@  static u8 hci_cc_le_del_from_accept_list(struct hci_dev *hdev, void *data,
 	if (!sent)
 		return rp->status;
 
+	hci_dev_lock(hdev);
 	hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr,
 			    sent->bdaddr_type);
+	hci_dev_unlock(hdev);
 
 	return rp->status;
 }
@@ -1949,9 +1955,11 @@  static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data,
 	if (!sent)
 		return rp->status;
 
+	hci_dev_lock(hdev);
 	hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
 				sent->bdaddr_type, sent->peer_irk,
 				sent->local_irk);
+	hci_dev_unlock(hdev);
 
 	return rp->status;
 }
@@ -1971,8 +1979,10 @@  static u8 hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, void *data,
 	if (!sent)
 		return rp->status;
 
+	hci_dev_lock(hdev);
 	hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
 			    sent->bdaddr_type);
+	hci_dev_unlock(hdev);
 
 	return rp->status;
 }
@@ -1987,7 +1997,9 @@  static u8 hci_cc_le_clear_resolv_list(struct hci_dev *hdev, void *data,
 	if (rp->status)
 		return rp->status;
 
+	hci_dev_lock(hdev);
 	hci_bdaddr_list_clear(&hdev->le_resolv_list);
+	hci_dev_unlock(hdev);
 
 	return rp->status;
 }