Skip to contentSkip to conversation

Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release

PATCH Applied Luiz Augusto von Dentz 3 participants 4 messages Sep 13, 2022 – Sep 15, 2022

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release

From: Luiz Augusto von Dentz <[email protected]>

Due to change to switch to use lock_sock inside rfcomm_sk_state_change the socket shutdown/release procedure can cause a deadlock:

    rfcomm_sock_shutdown():
      lock_sock();
      __rfcomm_sock_close():
        rfcomm_dlc_close():
          __rfcomm_dlc_close():
            rfcomm_dlc_lock();
            rfcomm_sk_state_change():
              lock_sock();

To fix this when the call __rfcomm_sock_close is now done without holding the lock_sock since rfcomm_dlc_lock exists to protect the dlc data there is no need to use lock_sock in that code path.

---
 net/bluetooth/rfcomm/sock.c | 3 +++
 1 file changed, 3 insertions(+)
net/bluetooth/rfcomm/sock.c +3 -0
index 4bf4ea6cbb5e..21e24da4847f 100644
@@ -902,7 +902,10 @@ static int rfcomm_sock_shutdown(struct socket *sock, int how)
 	lock_sock(sk);
 	if (!sk->sk_shutdown) {
 		sk->sk_shutdown = SHUTDOWN_MASK;
+
+		release_sock(sk);
 		__rfcomm_sock_close(sk);
+		lock_sock(sk);
 
 		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
 		    !(current->flags & PF_EXITING))
Signature · 1 line
2.37.3
#1 lore raw

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

---Test result---

Test Summary:

CheckPatch                    PASS      0.92 seconds
GitLint                       FAIL      0.47 seconds
SubjectPrefix                 PASS      0.31 seconds
BuildKernel                   PASS      45.45 seconds
BuildKernel32                 PASS      40.12 seconds
Incremental Build with patchesPASS      59.47 seconds
TestRunner: Setup             PASS      667.48 seconds
TestRunner: l2cap-tester      PASS      20.48 seconds
TestRunner: iso-tester        PASS      20.45 seconds
TestRunner: bnep-tester       PASS      7.74 seconds
TestRunner: mgmt-tester       PASS      127.19 seconds
TestRunner: rfcomm-tester     PASS      12.53 seconds
TestRunner: sco-tester        PASS      11.90 seconds
TestRunner: smp-tester        PASS      11.79 seconds
TestRunner: userchan-tester   PASS      8.35 seconds

Details
##############################
Test: GitLint - FAIL - 0.47 seconds
Run gitlint with rule in .gitlint
Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release
21: B1 Line exceeds max length (101>80): "Link: https://lore.kernel.org/all/CAD+dNTsbuU4w+Y_P7o+VEN7BYCAbZuwZx2+tH+OTzCdcZF82YA@mail.gmail.com/"

---
Regards,
Linux Bluetooth

author maintainer
#2 lore raw

Hi,

Quoted 28 lines · On Tue, Sep 13, 2022 at 5:13 PM <[email protected]> wrote:

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

---Test result---

Test Summary:

CheckPatch                    PASS      0.92 seconds
GitLint                       FAIL      0.47 seconds
SubjectPrefix                 PASS      0.31 seconds
BuildKernel                   PASS      45.45 seconds
BuildKernel32                 PASS      40.12 seconds
Incremental Build with patchesPASS      59.47 seconds
TestRunner: Setup             PASS      667.48 seconds
TestRunner: l2cap-tester      PASS      20.48 seconds
TestRunner: iso-tester        PASS      20.45 seconds
TestRunner: bnep-tester       PASS      7.74 seconds
TestRunner: mgmt-tester       PASS      127.19 seconds
TestRunner: rfcomm-tester     PASS      12.53 seconds
TestRunner: sco-tester        PASS      11.90 seconds
TestRunner: smp-tester        PASS      11.79 seconds
TestRunner: userchan-tester   PASS      8.35 seconds
Quoted 6 lines

Details
##############################
Test: GitLint - FAIL - 0.47 seconds
Run gitlint with rule in .gitlint
Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release
21: B1 Line exceeds max length (101>80): "Link: https://lore.kernel.org/all/CAD+dNTsbuU4w+Y_P7o+VEN7BYCAbZuwZx2+tH+OTzCdcZF82YA@mail.gmail.com/"

Let me know if this fixes the problems you are are having, note that I did add a test for rfcomm-tester to verify the deadlock is fixed:

https://patchwork.kernel.org/project/bluetooth/patch/[email protected]/

Signature · 1 line
Luiz Augusto von Dentz
#3 lore raw
In reply to Luiz Augusto von Dentz
This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluetooth-next.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 14 lines · On Tue, 13 Sep 2022 16:31:57 -0700 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

Due to change to switch to use lock_sock inside rfcomm_sk_state_change the socket shutdown/release procedure can cause a deadlock:

    rfcomm_sock_shutdown():
      lock_sock();
      __rfcomm_sock_close():
        rfcomm_dlc_close():
          __rfcomm_dlc_close():
            rfcomm_dlc_lock();
            rfcomm_sk_state_change():
              lock_sock();
Quoted 1 line

[...]

Here is the summary with links:
- Bluetooth: RFCOMM: Fix possible deadlock on socket shutdown/release

    https://git.kernel.org/bluetooth/bluetooth-next/c/812e92b824c1

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html