diff mbox series

Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_add_adv_monitor()

Message ID 20230804111444.1.I43aa4bd799a3cf9102f9de8c365ccb3d8e53a9d1@changeid (mailing list archive)
State Accepted
Commit 34d241ece878b9df54d5f24afd43b7e7105e5395
Headers show
Series Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_add_adv_monitor() | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/SubjectPrefix success Gitlint PASS
tedd_an/BuildKernel success BuildKernel PASS
tedd_an/CheckAllWarning success CheckAllWarning PASS
tedd_an/CheckSparse success CheckSparse PASS
tedd_an/CheckSmatch success CheckSparse PASS
tedd_an/BuildKernel32 success BuildKernel32 PASS
tedd_an/TestRunnerSetup success TestRunnerSetup PASS
tedd_an/TestRunner_l2cap-tester success TestRunner PASS
tedd_an/TestRunner_iso-tester fail TestRunner_iso-tester: Total: 90, Passed: 85 (94.4%), Failed: 5, Not Run: 0
tedd_an/TestRunner_bnep-tester success TestRunner PASS
tedd_an/TestRunner_mgmt-tester fail TestRunner_mgmt-tester: Total: 497, Passed: 495 (99.6%), Failed: 2, Not Run: 0
tedd_an/TestRunner_rfcomm-tester success TestRunner PASS

Commit Message

Manish Mandlik Aug. 4, 2023, 6:14 p.m. UTC
KSAN reports use-after-free in hci_add_adv_monitor().

While adding an adv monitor,
    hci_add_adv_monitor() calls ->
    msft_add_monitor_pattern() calls ->
    msft_add_monitor_sync() calls ->
    msft_le_monitor_advertisement_cb() calls in an error case ->
    hci_free_adv_monitor() which frees the *moniter.

This is referenced by bt_dev_dbg() in hci_add_adv_monitor().

Fix the bt_dev_dbg() by using handle instead of monitor->handle.

Fixes: b747a83690c8 ("Bluetooth: hci_sync: Refactor add Adv Monitor")

Signed-off-by: Manish Mandlik <mmandlik@google.com>
---

 net/bluetooth/hci_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

patchwork-bot+bluetooth@kernel.org Aug. 7, 2023, 10:50 p.m. UTC | #1
Hello:

This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Fri,  4 Aug 2023 11:14:45 -0700 you wrote:
> KSAN reports use-after-free in hci_add_adv_monitor().
> 
> While adding an adv monitor,
>     hci_add_adv_monitor() calls ->
>     msft_add_monitor_pattern() calls ->
>     msft_add_monitor_sync() calls ->
>     msft_le_monitor_advertisement_cb() calls in an error case ->
>     hci_free_adv_monitor() which frees the *moniter.
> 
> [...]

Here is the summary with links:
  - Bluetooth: hci_sync: Avoid use-after-free in dbg for hci_add_adv_monitor()
    https://git.kernel.org/bluetooth/bluetooth-next/c/34d241ece878

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 0fefa6788911..c602cfb5be9e 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1957,7 +1957,7 @@  int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
 	case HCI_ADV_MONITOR_EXT_MSFT:
 		status = msft_add_monitor_pattern(hdev, monitor);
 		bt_dev_dbg(hdev, "add monitor %d msft status %d",
-			   monitor->handle, status);
+			   handle, status);
 		break;
 	}