From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v7 2/4] Bluetooth: L2CAP: Fix leaking the socket of refused Enhanced Credit channels
Date: Wed, 25 Nov 2026 16:12:08 -0500 [thread overview]
Message-ID: <20261125211210.1955598-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261125211210.1955598-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When a deferred Enhanced Credit Based channel is refused, e.g. because
userspace closed it, while other channels of the same request are still
waiting to be authorized, the channel is kept in BT_DISCONN until the
response is sent so it can be included in it.
l2cap_sock_release() then calls l2cap_sock_kill(), but that does
nothing for a socket that is not flagged SOCK_ZAPPED yet, which only
chan->ops->teardown() does, and when the channel is deleted later by
the response nobody kills the socket anymore, leaking it along with the
references it holds.
Fix this by calling chan->ops->teardown() when the channel is refused
and not deleted right away, so its socket can be killed by its owner
once it is closed. Deleting the channel afterwards has nothing left to
do for its socket.
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_core.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index a15ffcdd1330..d39d8b8c47be 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -841,6 +841,14 @@ static void l2cap_chan_ecred_connect_reject(struct l2cap_chan *chan)
l2cap_state_change(chan, BT_DISCONN);
__l2cap_ecred_conn_rsp_defer(chan);
+
+ /* The response is only sent once the other channels of the request are
+ * authorized or refused, so the channel is kept until then to be
+ * included in it, but its socket has to be released now so it can be
+ * freed when its owner closes it.
+ */
+ if (!test_bit(FLAG_DEL, &chan->flags))
+ chan->ops->teardown(chan, ECONNREFUSED);
}
static void l2cap_chan_connect_reject(struct l2cap_chan *chan)
--
2.56.0
next prev parent reply other threads:[~2026-11-25 21:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 21:12 [PATCH v7 0/4] L2CAP: Fix channels being established with insufficient security Luiz Augusto von Dentz
2026-11-25 21:12 ` [PATCH v7 1/4] Bluetooth: L2CAP: Fix rejecting all Enhanced Credit channels if one is refused Luiz Augusto von Dentz
2026-11-26 3:44 ` L2CAP: Fix channels being established with insufficient security bluez.test.bot
2026-11-25 21:12 ` Luiz Augusto von Dentz [this message]
2026-11-25 21:12 ` [PATCH v7 3/4] Bluetooth: L2CAP: Fix accepting channels " Luiz Augusto von Dentz
2026-11-25 21:12 ` [PATCH v7 4/4] 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=20261125211210.1955598-3-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