* [PATCH v3] Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS
@ 2026-11-18 14:27 Luiz Augusto von Dentz
2026-11-18 16:10 ` patchwork-bot+bluetooth
0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2026-11-18 14:27 UTC (permalink / raw)
To: linux-bluetooth
From: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
L2CAP_LE_CREDITS has no response, so an ident taken from conn->tx_ida for
it is never released by l2cap_put_ident() and l2cap_chan_le_send_credits()
has to free it right away after sending, otherwise the range is exhausted
after 254 packets and credits would be sent with the invalid ident 0, which
some remote stacks ignore, stalling the channel.
tx_ida only exists to track requests awaiting a response, so a command
without one has no business in it: every credit update allocates and
frees an ident, and the ident is visible in tx_ida while the credits are
in flight, so an answer to them (a L2CAP_COMMAND_REJ) is processed by
l2cap_put_ident() like the answer to a request.
Using a counter that doesn't consult tx_ida is not an option either, it can
return the ident of a request still outstanding, and a reject of the
credits would then release that request's ident and close its channel in
l2cap_le_command_rej().
Reserve ident 255 for L2CAP_LE_CREDITS instead: l2cap_get_ident() never
returns it (the BR/EDR range already ends at 128), so it can't collide with
any request, it doesn't have to be tracked in conn->tx_ida, and a reject of
it matches no outstanding request.
Fixes: 6e1930ece855 ("Bluetooth: L2CAP: fix tx ident leak for commands without a response")
Reported-by: syzbot+9dc8780713b11155dd74@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=9dc8780713b11155dd74
Signed-off-by: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
Assisted-by: OpenCode:claude-fable-5.2
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
include/net/bluetooth/l2cap.h | 5 +++++
net/bluetooth/l2cap_core.c | 28 +++++++++++-----------------
2 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index cf5c2df68af8..72d9d56c6f2a 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -45,6 +45,11 @@
#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF
#define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */
#define L2CAP_LE_MIN_MTU 23
+
+/* Identifier used by L2CAP_LE_CREDITS, it has no response so it is not
+ * tracked in conn->tx_ida and is never allocated for any other command.
+ */
+#define L2CAP_IDENT_LE_CREDITS 255
#define L2CAP_ECRED_CONN_SCID_MAX 5
#define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 977b41229a7f..3ff40565a05f 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -1046,9 +1046,11 @@ static int l2cap_get_ident(struct l2cap_conn *conn)
u8 max;
int ident;
- /* LE link does not support tools like l2ping so use the full range */
+ /* LE link does not support tools like l2ping so use the full range,
+ * except for L2CAP_IDENT_LE_CREDITS which is reserved.
+ */
if (conn->hcon->type == LE_LINK)
- max = 255;
+ max = L2CAP_IDENT_LE_CREDITS - 1;
/* Get next available identificator.
* 1 - 128 are used by kernel.
* 129 - 199 are reserved.
@@ -7204,7 +7206,6 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan)
struct l2cap_conn *conn = chan->conn;
struct l2cap_le_credits pkt;
u16 return_credits = l2cap_le_rx_credits(chan);
- int ident;
if (chan->mode != L2CAP_MODE_LE_FLOWCTL &&
chan->mode != L2CAP_MODE_EXT_FLOWCTL)
@@ -7222,21 +7223,14 @@ static void l2cap_chan_le_send_credits(struct l2cap_chan *chan)
pkt.cid = cpu_to_le16(chan->scid);
pkt.credits = cpu_to_le16(return_credits);
- /* Keeps l2cap_put_ident() from releasing ident before we do */
- lockdep_assert_held(&conn->lock);
-
- ident = l2cap_get_ident(conn);
-
- l2cap_send_cmd(conn, ident, L2CAP_LE_CREDITS, sizeof(pkt), &pkt);
-
- /* L2CAP_LE_CREDITS has no response so the ident is never released by
- * l2cap_put_ident() - release it right away, otherwise the tx_ida
- * range is exhausted after 254 packets and from then on credits are
- * sent with the invalid ident 0, which some remote stacks ignore,
- * stalling the channel.
+ /* L2CAP_LE_CREDITS has no response so it uses the reserved ident rather
+ * than one from conn->tx_ida, which would have to be released right
+ * away or would be exhausted after 254 packets, and could otherwise
+ * collide with the ident of a request still outstanding. A reject of it
+ * can't match any request either.
*/
- if (ident > 0)
- ida_free(&conn->tx_ida, ident);
+ l2cap_send_cmd(conn, L2CAP_IDENT_LE_CREDITS, L2CAP_LE_CREDITS,
+ sizeof(pkt), &pkt);
}
void l2cap_chan_rx_avail(struct l2cap_chan *chan, ssize_t rx_avail)
base-commit: f42f5cae154b90a0cb6d8232dc84c7614ca2e6a0
--
2.56.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS
2026-11-18 14:27 [PATCH v3] Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS Luiz Augusto von Dentz
@ 2026-11-18 16:10 ` patchwork-bot+bluetooth
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+bluetooth @ 2026-11-18 16:10 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hello:
This patch was applied to bluetooth/bluetooth-next.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Wed, 18 Nov 2026 09:27:32 -0500 you wrote:
> From: Nguyen Ngoc Thang <ngocthang2710.1999@gmail.com>
>
> L2CAP_LE_CREDITS has no response, so an ident taken from conn->tx_ida for
> it is never released by l2cap_put_ident() and l2cap_chan_le_send_credits()
> has to free it right away after sending, otherwise the range is exhausted
> after 254 packets and credits would be sent with the invalid ident 0, which
> some remote stacks ignore, stalling the channel.
>
> [...]
Here is the summary with links:
- [v3] Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS
https://git.kernel.org/bluetooth/bluetooth-next/c/06b6fbe05f5c
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-11-18 16:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 14:27 [PATCH v3] Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS Luiz Augusto von Dentz
2026-11-18 16:10 ` 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