Skip to contentSkip to conversation

Bluetooth: ISO: Fix not handling shutdown condition

PATCH Applied Luiz Augusto von Dentz 3 participants 3 messages Aug 19, 2022

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 Bluetooth: ISO: Fix not handling shutdown condition

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

In order to properly handle shutdown syscall the code shall not assume that the how argument is always SHUT_RDWR resulting in SHUTDOWN_MASK as that would result in poll to immediatelly report EPOLLHUP instead of properly waiting for disconnect_cfm (Disconnect Complete) which is rather important for the likes of BAP as the CIG may need to be reprogrammed.

Fixes ccf74f2390d6 ("Bluetooth: Add BTPROTO_ISO socket type")
---
 net/bluetooth/iso.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
net/bluetooth/iso.c +24 -9
index ced8ad4fed4f..b50a69064fee 100644
@@ -1317,17 +1317,32 @@ static int iso_sock_shutdown(struct socket *sock, int how)
 	sock_hold(sk);
 	lock_sock(sk);
 
-	if (!sk->sk_shutdown) {
-		sk->sk_shutdown = SHUTDOWN_MASK;
-		iso_sock_clear_timer(sk);
-		__iso_sock_close(sk);
-
-		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
-		    !(current->flags & PF_EXITING))
-			err = bt_sock_wait_state(sk, BT_CLOSED,
-						 sk->sk_lingertime);
+	switch (how) {
+	case SHUT_RD:
+		if (sk->sk_shutdown & RCV_SHUTDOWN)
+			goto unlock;
+		sk->sk_shutdown |= RCV_SHUTDOWN;
+		break;
+	case SHUT_WR:
+		if (sk->sk_shutdown & SEND_SHUTDOWN)
+			goto unlock;
+		sk->sk_shutdown |= SEND_SHUTDOWN;
+		break;
+	case SHUT_RDWR:
+		if (sk->sk_shutdown & SHUTDOWN_MASK)
+			goto unlock;
+		sk->sk_shutdown |= SHUTDOWN_MASK;
+		break;
 	}
 
+	iso_sock_clear_timer(sk);
+	__iso_sock_close(sk);
+
+	if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
+	    !(current->flags & PF_EXITING))
+		err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
+
+unlock:
 	release_sock(sk);
 	sock_put(sk);
 
Signature · 1 line
2.37.2
#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=669308

---Test result---

Test Summary:

CheckPatch                    FAIL      1.87 seconds
GitLint                       PASS      0.98 seconds
SubjectPrefix                 PASS      0.74 seconds
BuildKernel                   PASS      32.56 seconds
BuildKernel32                 PASS      28.57 seconds
Incremental Build with patchesPASS      42.90 seconds
TestRunner: Setup             PASS      478.43 seconds
TestRunner: l2cap-tester      PASS      16.66 seconds
TestRunner: bnep-tester       PASS      6.19 seconds
TestRunner: mgmt-tester       PASS      98.28 seconds
TestRunner: rfcomm-tester     PASS      9.50 seconds
TestRunner: sco-tester        PASS      9.29 seconds
TestRunner: smp-tester        PASS      9.25 seconds
TestRunner: userchan-tester   PASS      6.44 seconds

Details
##############################
Test: CheckPatch - FAIL - 1.87 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
Bluetooth: ISO: Fix not handling shutdown condition\WARNING:TYPO_SPELLING: 'immediatelly' may be misspelled - perhaps 'immediately'? #82:
that would result in poll to immediatelly report EPOLLHUP instead of

                             ^^^^^^^^^^^^

total: 0 errors, 1 warnings, 0 checks, 41 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12949086.patch has style problems, please review.

NOTE: Ignored message types: UNKNOWN_COMMIT_ID

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

---
Regards,
Linux Bluetooth

#2 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 10 lines · On Fri, 19 Aug 2022 11:46:33 -0700 you wrote:

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

In order to properly handle shutdown syscall the code shall not assume that the how argument is always SHUT_RDWR resulting in SHUTDOWN_MASK as that would result in poll to immediatelly report EPOLLHUP instead of properly waiting for disconnect_cfm (Disconnect Complete) which is rather important for the likes of BAP as the CIG may need to be reprogrammed.

[...]

Here is the summary with links:
- Bluetooth: ISO: Fix not handling shutdown condition

    https://git.kernel.org/bluetooth/bluetooth-next/c/a89e4b749aab

You are awesome, thank you!

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