From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v8 3/5] Bluetooth: L2CAP: Fix leaking sockets released before their channel is deleted
Date: Mon, 30 Nov 2026 14:56:52 -0500 [thread overview]
Message-ID: <20261130195654.560637-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261130195654.560637-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When a socket without an owner is closed while its channel is still
around, l2cap_sock_kill() doesn't kill it since it is not flagged
SOCK_ZAPPED yet, which only chan->ops->teardown() does. This happens
with deferred Enhanced Credit Based channels refused while other
channels of the same request are still waiting to be authorized, either
by userspace releasing the socket or, for the ones never accepted, by
the listener being closed.
The channels that are deleted by something else afterwards, like
l2cap_ecred_rsp_defer() does once it sends the response that includes
them, don't call chan->ops->close() either, so nobody kills the
orphaned socket anymore and it is leaked along with the references it
holds.
Fix this by calling l2cap_sock_kill() from l2cap_sock_teardown_cb()
once the socket is flagged SOCK_ZAPPED, which only kills it if it has
no owner. The ones closing the channel afterwards do nothing since the
socket is no longer linked to it.
Fixes: 9aa9d9473f15 ("Bluetooth: L2CAP: Fix responding with wrong PDU type")
Assisted-by: OpenCode:claude-fable-5.2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
net/bluetooth/l2cap_sock.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index d5663a4642a9..ec5d25067bc5 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1800,6 +1800,16 @@ static void l2cap_sock_teardown_cb(struct l2cap_chan *chan, int err)
/* Only zap after cleanup to avoid use after free race */
sock_set_flag(sk, SOCK_ZAPPED);
+ /* A socket without an owner, either because it was released while the
+ * channel was still around or because it was never accepted, can't be
+ * killed before it is zapped, and nobody else will once the channel is
+ * deleted by something else, e.g. the response of a request that
+ * included it, so do it now. l2cap_sock_kill() does nothing if the
+ * socket still has an owner, and the ones that close the channel
+ * afterwards do nothing either since the socket is no longer linked
+ * to it.
+ */
+ l2cap_sock_kill(sk);
}
static void l2cap_sock_state_change_cb(struct l2cap_chan *chan, int state,
--
2.56.0
next prev parent reply other threads:[~2026-11-30 19:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 19:56 [PATCH v8 0/5] L2CAP: Fix channels being established with insufficient security Luiz Augusto von Dentz
2026-11-30 19:56 ` [PATCH v8 1/5] Bluetooth: hci_event: Disconnect if the encryption key size is not valid Luiz Augusto von Dentz
2026-11-30 19:56 ` [PATCH v8 2/5] Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Luiz Augusto von Dentz
2026-11-30 19:56 ` Luiz Augusto von Dentz [this message]
2026-11-30 19:56 ` [PATCH v8 4/5] Bluetooth: L2CAP: Fix accepting channels with insufficient security Luiz Augusto von Dentz
2026-11-30 19:56 ` [PATCH v8 5/5] Bluetooth: L2CAP: Don't offer deferred channels before security is met Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130195654.560637-4-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox