From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380107; b=FaEN78K/WWDQrJdkAJ7izHnE5NjtqGkjhSQgNDaFcrzHC0GWJD0JcZ++WQyoO8whvdVS G79EazvBPxI5w83KT4weviruthTs+HfNgFFj6dDFEC43NG3O/xKgPfFeuND3wljGRTats 3lG3bU2LgI4kIEx3fmF05V+Y3ahV4UUH2CYPdeezlqYcBuz5FKSiwAhHowaBSnpnQFuRG blsaR3Me9+8RF5KI/yHdLWeOvEnWWU8SStxp0afru88bIOyadpKAC02kUjH6tYiDhbQ5a N7/Mu2stpBqr3s9nudgiKMiYf4YsjJET/7QMiqJEHp5avQcQgzhe/OBzhPpMQhsWvlA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380107; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=HR62u/Ii8CdKg58j1P3i564JY8/xLZZ7gpUYMG3gp3M=; b=yISzg8V4b5Bn3KP60/D7BduVdOOth7szxFw6EmAXhkw5T/EVdE43Xzlg0vTZgQnc/WEk tHxOlsS8RKQfPYRnKNAfFMSawYcZqRmsA5amu6lkOP5woCYaoMcIaInKHuYbA8Z8MgVNN 6mu8fXdKh00TPNEM5ot/FToc5ZYFo8advd8e90Wo4AykdPysJ97uA8mYbanVIV719rNnn DQVBVpHFhmmse1Hyauf2A6fIyx2kxCwPJkk1KF+DS5Btam598KKpxF46D/dj+n4W3+LqP zn6NfpUdg3ZgvYsDRc66TLzB96tukLrIV4aUGqM6bXTUtP0guVHkqvPg/D3ZdRXyVgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=AxNVRBKB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49A92606A683; Fri, 4 Dec 2026 10:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=AxNVRBKB Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5EB01F000CE; Fri, 4 Dec 2026 10:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380107; bh=HR62u/Ii8CdKg58j1P3i564JY8/xLZZ7gpUYMG3gp3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AxNVRBKBt0fn3GQOFJ8HJ69NtOXHx68CJEjJ8/4HavO0LD3mWWO0RPziacK/+RhVU dql2vUlb+JD8k3O8+uPpuyoxGx8pIFQ0Vp83CwmS9LXRpQ9qnWwXsUaGuUJVglqCRA YpZpq7axorHeON9p8lHBSboTsmFL22RCxWed+IA8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+9dc8780713b11155dd74@syzkaller.appspotmail.com, Nguyen Ngoc Thang , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 7.3 092/742] Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS Date: Fri, 4 Dec 2026 18:59:16 +0900 Message-ID: <20261204100637.556356922@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nguyen Ngoc Thang [ Upstream commit 06b6fbe05f5c81654815ec8d864d792a226cbdac ] 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 Assisted-by: OpenCode:claude-fable-5.2 Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- 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 b864d50bb5e59..9dc7fc5b2a275 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 eeeddb3ced8cd..59ae6ee4ff345 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -1022,9 +1022,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. @@ -6949,7 +6951,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) @@ -6967,21 +6968,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) -- 2.53.0