* [PATCH 0/2] Bluetooth: RFCOMM: Fix listener shutdown and TTY setup
@ 2026-11-25 15:22 Cen Zhang
2026-11-25 15:22 ` [PATCH 1/2] Bluetooth: RFCOMM: Reject listen after socket shutdown Cen Zhang
2026-11-25 15:22 ` [PATCH 2/2] Bluetooth: RFCOMM: Close DLC on TTY registration failure Cen Zhang
0 siblings, 2 replies; 3+ messages in thread
From: Cen Zhang @ 2026-11-25 15:22 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: linux-bluetooth, linux-kernel, stable, baijiaju1990, jjzuming, zzzccc427
Sashiko found that an RFCOMM socket can still start listening after
shutdown, allowing release to skip accept queue cleanup. Reject
listen after shutdown.
The review also found that failed TTY registration can leave a
transferred DLC open. Close the DLC before dropping the port
references and purge pending input when the port is destroyed. Use
the existing RFCOMM_CONNINFO locking to avoid waiting for the socket
lock while holding global locks during handoff.
Cen Zhang (2):
Bluetooth: RFCOMM: Reject listen after socket shutdown
Bluetooth: RFCOMM: Close DLC on TTY registration failure
net/bluetooth/rfcomm/sock.c | 2 +-
net/bluetooth/rfcomm/tty.c | 11 +++++------
2 files changed, 6 insertions(+), 7 deletions(-)
base-commit: f57f78086ab54f3b3122fbaeba2c842ba7bb6d00
---
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] Bluetooth: RFCOMM: Reject listen after socket shutdown
2026-11-25 15:22 [PATCH 0/2] Bluetooth: RFCOMM: Fix listener shutdown and TTY setup Cen Zhang
@ 2026-11-25 15:22 ` Cen Zhang
2026-11-25 15:22 ` [PATCH 2/2] Bluetooth: RFCOMM: Close DLC on TTY registration failure Cen Zhang
1 sibling, 0 replies; 3+ messages in thread
From: Cen Zhang @ 2026-11-25 15:22 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: linux-bluetooth, linux-kernel, stable, baijiaju1990, jjzuming, zzzccc427
RFCOMM drains a listener's accept queue on its first shutdown. A bound
socket can retain BT_BOUND after shutdown, however, and the listen
state check can admit it as a listener. Release then skips the accept
queue cleanup because sk_shutdown is already set. Queued children can
retain a pointer to the listener after it is freed.
Check sk_shutdown before entering BT_LISTEN. The socket lock serializes
this check with rfcomm_sock_shutdown() setting the flag.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://lkml.iu.edu/hypermail/linux/kernel/2611.2/24606.html
Cc: stable@vger.kernel.org
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
This patch was written with assistance from Codex (OpenAI).
net/bluetooth/rfcomm/sock.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 889e45dd5d04e..86a43dc0ab5e3 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -448,7 +448,7 @@ static int rfcomm_sock_listen(struct socket *sock, int backlog)
lock_sock(sk);
- if (sk->sk_state != BT_BOUND) {
+ if (sk->sk_state != BT_BOUND || sk->sk_shutdown) {
err = -EBADFD;
goto done;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] Bluetooth: RFCOMM: Close DLC on TTY registration failure
2026-11-25 15:22 [PATCH 0/2] Bluetooth: RFCOMM: Fix listener shutdown and TTY setup Cen Zhang
2026-11-25 15:22 ` [PATCH 1/2] Bluetooth: RFCOMM: Reject listen after socket shutdown Cen Zhang
@ 2026-11-25 15:22 ` Cen Zhang
1 sibling, 0 replies; 3+ messages in thread
From: Cen Zhang @ 2026-11-25 15:22 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: linux-bluetooth, linux-kernel, stable, baijiaju1990, jjzuming, zzzccc427
The TTY takes ownership of the DLC before tty_port_register_device().
If registration fails, dropping the port references detaches the device
but leaves the DLC open. In the reuse case the original socket is
already BT_CLOSED, so it will not close the DLC on release.
Start DLC teardown while the registration reference still pins the
port and its DLC. Purge any unconsumed receive data when the port is
finally destroyed, after detaching the device as the DLC owner.
Commit 77bc0f253ff9f ("Bluetooth: RFCOMM: serialize RFCOMM_CONNINFO
dlc->session dereference") moved session reads under rfcomm_mutex.
The handoff therefore no longer needs to wait on the socket lock for
RFCOMM_CONNINFO. Use WRITE_ONCE() to publish BT_CLOSED. The DLC lock
continues to serialize that update with the old socket state callback.
Fixes: 56bc551ef79c ("Bluetooth: RFCOMM: Close the socket before transferring its DLC")
Link: https://lkml.iu.edu/hypermail/linux/kernel/2611.2/24606.html
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
This patch was written with assistance from Codex (OpenAI).
net/bluetooth/rfcomm/tty.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index 745cf1e4bb2c3..43a03837e371b 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -96,6 +96,7 @@ static void rfcomm_dev_destruct(struct tty_port *port)
list_del(&dev->list);
mutex_unlock(&rfcomm_dev_lock);
+ skb_queue_purge(&dev->pending);
kfree(dev);
/* It's safe to call module_put() here because socket still
@@ -293,12 +294,8 @@ static struct rfcomm_dev *__rfcomm_dev_add(struct rfcomm_dev_req *req,
atomic_sub(skb->len, &sk->sk_rmem_alloc);
}
- /* Finish RFCOMM_CONNINFO before replacing the callback
- * which serializes session teardown with the socket.
- */
- lock_sock(sk);
- sk->sk_state = BT_CLOSED;
- release_sock(sk);
+ /* Serialize with the DLC state callback. */
+ WRITE_ONCE(sk->sk_state, BT_CLOSED);
}
dlc->data_ready = rfcomm_dev_data_ready;
@@ -347,6 +344,8 @@ static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
dev->id, NULL);
if (IS_ERR(tty)) {
err = PTR_ERR(tty);
+ /* Close the DLC while the port still pins it. */
+ rfcomm_dlc_close(dlc, 0);
if (!test_and_set_bit(RFCOMM_TTY_OWNED, &dev->status))
tty_port_put(&dev->port); /* Drop the initial reference. */
tty_port_put(&dev->port); /* Drop the registration reference. */
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-25 15:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-25 15:22 [PATCH 0/2] Bluetooth: RFCOMM: Fix listener shutdown and TTY setup Cen Zhang
2026-11-25 15:22 ` [PATCH 1/2] Bluetooth: RFCOMM: Reject listen after socket shutdown Cen Zhang
2026-11-25 15:22 ` [PATCH 2/2] Bluetooth: RFCOMM: Close DLC on TTY registration failure Cen Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®