* [PATCH v2] Bluetooth: RFCOMM: free the skb when the DLC has no owner
@ 2026-09-15 7:00 Maxim Skokov
2026-09-28 17:30 ` patchwork-bot+bluetooth
0 siblings, 1 reply; 2+ messages in thread
From: Maxim Skokov @ 2026-09-15 7:00 UTC (permalink / raw)
To: marcel, luiz.dentz
Cc: linux-bluetooth, linux-kernel, mikhail.v.gavrilov, Maxim Skokov,
stable
rfcomm_recv_data() hands the skb to d->data_ready() and returns 0
without freeing it, so the callback owns the skb from that point on.
The tty implementation frees it when the DLC has been detached from its
device:
static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc,
struct sk_buff *skb)
{
struct rfcomm_dev *dev = dlc->owner;
if (!dev) {
kfree_skb(skb);
return;
}
The socket implementation returns without freeing it, and the skb is
leaked.
A connected DLC can have no owner: rfcomm_sock_destruct() clears
d->owner, while the DLC itself stays on the session until it is closed.
Data frames that arrive in that window still find d->state ==
BT_CONNECTED in rfcomm_recv_data() and are handed to the callback, one
leaked skb each.
The leak does not stop on its own either. The remote runs out of
credits only once RFCOMM_RX_THROTTLED is set, and for a socket the only
place that sets it is rfcomm_sk_data_ready() itself, below the return.
rfcomm_process_dlcs() keeps granting credits, so the remote keeps
sending and the leak keeps growing.
Free the skb, as the tty side does.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: Mikhail Gavrilov <mikhail.v.gavrilov@gmail.com>
Closes: https://lore.kernel.org/linux-bluetooth/CABXGCsPe5wykd8Aj-hm+SJ7SGQyb8yoGNnx3XDpPmBathj+EGg@mail.gmail.com/
Cc: stable@vger.kernel.org
Signed-off-by: Maxim Skokov <skokovmaksimevg@gmail.com>
Assisted-by: Claude:claude-opus-5
---
Notes:
Noticed in the v3 thread of "Bluetooth: RFCOMM: connect the session
socket without rfcomm_mutex", where the same leak is described.
Found by inspection. I did not manage to produce an orphaned connected
DLC on hardware: it needs the socket to be destroyed while the remote is
still sending on the DLC. A kprobe on rfcomm_sk_data_ready() over an
HFP session (RTL8851BE, btusb) counted 31 frames delivered to a live
socket and one rfcomm_sock_destruct(), so the window does open in normal
use; no frame happened to arrive inside it.
Built and loaded on 7.3.0-rc1 with KASAN, UBSAN, PROVE_LOCKING and
DEBUG_OBJECTS; HFP and A2DP sessions behave as before, and none of the
sanitizers reported anything on the RFCOMM paths.
v2: no code change. Removed the trailing whitespace on the blank lines of
this section, which git format-patch --notes adds and gitlint rejected.
v1: https://lore.kernel.org/linux-bluetooth/20260914173044.5249-1-skokovmaksimevg@gmail.com/
net/bluetooth/rfcomm/sock.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 958081adb9..82aa38715c 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -48,8 +48,11 @@ static void rfcomm_sock_kill(struct sock *sk);
static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb)
{
struct sock *sk = d->owner;
- if (!sk)
+
+ if (!sk) {
+ kfree_skb(skb);
return;
+ }
atomic_add(skb->len, &sk->sk_rmem_alloc);
skb_queue_tail(&sk->sk_receive_queue, skb);
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v2] Bluetooth: RFCOMM: free the skb when the DLC has no owner
2026-09-15 7:00 [PATCH v2] Bluetooth: RFCOMM: free the skb when the DLC has no owner Maxim Skokov
@ 2026-09-28 17:30 ` patchwork-bot+bluetooth
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+bluetooth @ 2026-09-28 17:30 UTC (permalink / raw)
To: Maxim Skokov
Cc: marcel, luiz.dentz, linux-bluetooth, linux-kernel,
mikhail.v.gavrilov, stable
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Tue, 15 Sep 2026 10:00:46 +0300 you wrote:
> rfcomm_recv_data() hands the skb to d->data_ready() and returns 0
> without freeing it, so the callback owns the skb from that point on.
> The tty implementation frees it when the DLC has been detached from its
> device:
>
> static void rfcomm_dev_data_ready(struct rfcomm_dlc *dlc,
> struct sk_buff *skb)
> {
> struct rfcomm_dev *dev = dlc->owner;
>
> [...]
Here is the summary with links:
- [v2] Bluetooth: RFCOMM: free the skb when the DLC has no owner
https://git.kernel.org/bluetooth/bluetooth-next/c/9d1afbf60ed5
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-28 17:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-15 7:00 [PATCH v2] Bluetooth: RFCOMM: free the skb when the DLC has no owner Maxim Skokov
2026-09-28 17:30 ` patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox