2024-04-03 14:31:22

by Dmitry Antipov

[permalink] [raw]
Subject: [PATCH] [RFC] Bluetooth: fix race condition in sco_connect()

This patch is intended to fix the race condition between two
'sco_connect()' calls, where two instances of 'struct sco_conn'
are erroneously set up to share the pointer to the same 'struct
sock'. When one of the connections goes away, it destroys an
underlying socket as well, leaving dangling pointer to destroyed
socket within another. Next, if the latter (alive) connection
enters 'sco_sock_timeout()', an attempt to do 'lock_sock()' on
a destroyed socket causes use-after-free write reported by KASAN
at https://syzkaller.appspot.com/bug?extid=4c0d0c4cde787116d465.

Signed-off-by: Dmitry Antipov <[email protected]>
---
net/bluetooth/sco.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 43daf965a01e..f8e5e4c3420f 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -228,7 +228,7 @@ static int sco_chan_add(struct sco_conn *conn, struct sock *sk,
int err = 0;

sco_conn_lock(conn);
- if (conn->sk)
+ if (conn->sk || sco_pi(sk)->conn)
err = -EBUSY;
else
__sco_chan_add(conn, sk, parent);
--
2.44.0



2024-04-03 14:56:54

by bluez.test.bot

[permalink] [raw]
Subject: RE: [RFC] Bluetooth: fix race condition in sco_connect()

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

---Test result---

Test Summary:
CheckPatch PASS 0.66 seconds
GitLint PASS 0.32 seconds
SubjectPrefix PASS 0.12 seconds
BuildKernel PASS 29.73 seconds
CheckAllWarning PASS 32.06 seconds
CheckSparse WARNING 39.63 seconds
CheckSmatch FAIL 34.58 seconds
BuildKernel32 PASS 28.85 seconds
TestRunnerSetup PASS 541.12 seconds
TestRunner_l2cap-tester PASS 24.53 seconds
TestRunner_iso-tester PASS 31.28 seconds
TestRunner_bnep-tester PASS 4.85 seconds
TestRunner_mgmt-tester FAIL 113.37 seconds
TestRunner_rfcomm-tester PASS 7.55 seconds
TestRunner_sco-tester PASS 15.03 seconds
TestRunner_ioctl-tester PASS 7.91 seconds
TestRunner_mesh-tester PASS 5.98 seconds
TestRunner_smp-tester PASS 6.95 seconds
TestRunner_userchan-tester PASS 5.05 seconds
IncrementalBuild PASS 28.88 seconds

Details
##############################
Test: CheckSparse - WARNING
Desc: Run sparse tool with linux kernel
Output:
net/bluetooth/sco.c: note: in included file:./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
##############################
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....
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_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 492, Passed: 488 (99.2%), Failed: 2, Not Run: 2

Failed Test Cases
LL Privacy - Add Device 5 (2 Devices to RL) Failed 0.167 seconds
LL Privacy - Add Device 6 (RL is full) Failed 0.186 seconds


---
Regards,
Linux Bluetooth