2024-04-11 15:20:21

by Vasiliy Kovalev

[permalink] [raw]
Subject: [PATCH net] Bluetooth: hci_event: fix possible multiple drops by marked conn->state after hci_disconnect()

From: Vasiliy Kovalev <[email protected]>

When returning from the hci_disconnect() function, the conn->state
continues to be set to BT_CONNECTED and hci_conn_drop() is executed,
which decrements the conn->refcnt.

Syzkaller has generated a reproducer that results in multiple calls to
hci_encrypt_change_evt() of the same conn object.
--
hci_encrypt_change_evt(){
// conn->state == BT_CONNECTED
hci_disconnect(){
hci_abort_conn();
}
hci_conn_drop();
// conn->state == BT_CONNECTED
}
--
This behavior can cause the conn->refcnt to go far into negative values
and cause problems. To get around this, you need to change the conn->state,
namely to BT_DISCONN, as it was before.

Fixes: a13f316e90fd ("Bluetooth: hci_conn: Consolidate code for aborting connections")
Cc: [email protected]
Signed-off-by: Vasiliy Kovalev <[email protected]>
---
net/bluetooth/hci_event.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 64477e1bde7cec..e0477021183f9b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -2989,6 +2989,7 @@ static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)

hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
hci_conn_drop(conn);
+ conn->state = BT_DISCONN;

unlock:
hci_dev_unlock(hdev);
@@ -3654,6 +3655,7 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
hci_encrypt_cfm(conn, ev->status);
hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
hci_conn_drop(conn);
+ conn->state = BT_DISCONN;
goto unlock;
}

@@ -5248,6 +5250,7 @@ static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data,
if (ev->status && conn->state == BT_CONNECTED) {
hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE);
hci_conn_drop(conn);
+ conn->state = BT_DISCONN;
goto unlock;
}

--
2.33.8



2024-04-11 17:28:10

by bluez.test.bot

[permalink] [raw]
Subject: RE: [net] Bluetooth: hci_event: fix possible multiple drops by marked conn->state after hci_disconnect()

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

---Test result---

Test Summary:
CheckPatch PASS 0.46 seconds
GitLint FAIL 0.48 seconds
SubjectPrefix PASS 0.06 seconds
BuildKernel PASS 29.79 seconds
CheckAllWarning PASS 32.96 seconds
CheckSparse WARNING 38.28 seconds
CheckSmatch FAIL 36.34 seconds
BuildKernel32 PASS 28.93 seconds
TestRunnerSetup PASS 521.35 seconds
TestRunner_l2cap-tester PASS 18.31 seconds
TestRunner_iso-tester FAIL 31.19 seconds
TestRunner_bnep-tester PASS 4.63 seconds
TestRunner_mgmt-tester PASS 109.11 seconds
TestRunner_rfcomm-tester PASS 7.20 seconds
TestRunner_sco-tester PASS 14.96 seconds
TestRunner_ioctl-tester PASS 7.62 seconds
TestRunner_mesh-tester FAIL 6.01 seconds
TestRunner_smp-tester PASS 6.80 seconds
TestRunner_userchan-tester PASS 4.87 seconds
IncrementalBuild PASS 27.76 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[net] Bluetooth: hci_event: fix possible multiple drops by marked conn->state after hci_disconnect()

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
1: T1 Title exceeds max length (100>80): "[net] Bluetooth: hci_event: fix possible multiple drops by marked conn->state after hci_disconnect()"
13: B3 Line contains hard tab characters (\t): " // conn->state == BT_CONNECTED"
14: B3 Line contains hard tab characters (\t): " hci_disconnect(){"
15: B3 Line contains hard tab characters (\t): " hci_abort_conn();"
16: B3 Line contains hard tab characters (\t): " }"
17: B3 Line contains hard tab characters (\t): " hci_conn_drop();"
18: B3 Line contains hard tab characters (\t): " // conn->state == BT_CONNECTED"
##############################
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):
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: net/bluetooth/hci_core.o] Error 139
make[4]: *** Deleting file 'net/bluetooth/hci_core.o'
make[3]: *** [scripts/Makefile.build:485: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: net] Error 2
make[2]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bcm203x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bcm203x.o'
make[4]: *** Waiting for unfinished jobs....
Segmentation fault (core dumped)
make[4]: *** [scripts/Makefile.build:244: drivers/bluetooth/bpa10x.o] Error 139
make[4]: *** Deleting file 'drivers/bluetooth/bpa10x.o'
make[3]: *** [scripts/Makefile.build:485: drivers/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:485: drivers] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1919: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: TestRunner_iso-tester - FAIL
Desc: Run iso-tester with test-runner
Output:
Total: 122, Passed: 121 (99.2%), Failed: 1, Not Run: 0

Failed Test Cases
ISO Connect2 Suspend - Success Failed 4.236 seconds
##############################
Test: TestRunner_mesh-tester - FAIL
Desc: Run mesh-tester with test-runner
Output:
Total: 10, Passed: 9 (90.0%), Failed: 1, Not Run: 0

Failed Test Cases
Mesh - Send cancel - 2 Failed 0.091 seconds


---
Regards,
Linux Bluetooth