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=1796380081; b=v7ag5+Yelfft6THJaXcPFOxdaPm7t0t7nzPh76oRv1DUeHtkgWV2UGaxJocXYFm3r00/ ZIy6BQLzy/+W2uPAtfj5+vbgmaI+uyV8XpEcpmgNqps/2wZZcB6R/hpUZ4Euw5ZwwJBXf uepnTEi+CaYExMr0yAhN/BcolMMv8CnORyGmr2RaE4BVzjbLgf11j3oEHYAyFBV7ZhQVL wffREY1IGGFiQVVmz3dlwRJ1Lh3P0Sap6hX5gaxMFth11VwXYSRUQ+GCdeRVk2y0BGY/H JsMENbcOuc4oLZNRQT1fJAoCE5JSoxBEnuYWxjXQtJb7iUcsGy7h0E0WCn4VJvc0a9w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380081; 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=fSCMC/2fd1Hu705GSTraPsB9GbqAFcaPLXowswfUrHA=; b=MEwviL7QOL59bUmywEIPQ0An6wtaYFunvMAow7KD0ZVavEcNcBBy9k8rM1AjCFy8XaWo l+1Di9LU/afCPz6WdiCsfh/PPlWWKxeCMqdG+7ullGHY4go5lHgysA5bwpIuIBRvIWNTk V+HIWKY0F4W2n3An58Mi6HXTTQiOswCERk79ClZ1A3tyhrsBoopK5EAQXbL9AZeyypp01 WSTtXwtET+IgiOnovDIY6eypKdulzmGJKgUf1Y7pMt/CYYV9fMS/bQCLQ17ARFb5Y1/G5 ueYt/+yxoHAn7JIP4YYxvu6HqOkuQEzln7/lTut+v40upFX6fH8yGxldbCLPbHFNY6w== 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=AUqXF84z; 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 26E47606A322; Fri, 4 Dec 2026 10:28:01 +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=AUqXF84z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BC501F000C2; Fri, 4 Dec 2026 10:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380081; bh=fSCMC/2fd1Hu705GSTraPsB9GbqAFcaPLXowswfUrHA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AUqXF84z49Mm/QaC5huWy9NyjT0Dlw0PqfAgo8AXlUpoUpvWvjoXa4WjanX+W8Y2m CseljlNLlbPvRYPHlnsPX1cnCIM74mAXEi0BmUly1HaIFMMtoR9ClRBeuemEROYiBQ vN1Dj9EGxpDOVzTX1yjSeZtSwYvan5vVLf86b85A= 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 091/742] Bluetooth: L2CAP: return LE credits from recvmsg under the conn lock Date: Fri, 4 Dec 2026 18:59:15 +0900 Message-ID: <20261204100637.529298905@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: stable@vger.kernel.org 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 5beb86f98c3d45f6d64be5b6d6c77480487b41b4 ] l2cap_chan_le_send_credits() allocates an ident from conn->tx_ida, sends L2CAP_LE_CREDITS and frees the ident right away, since the command has no response. The RX path frees idents in l2cap_put_ident() under conn->lock. That only works if the credits path holds conn->lock too, so that no response can be processed between the allocation and the free. The RX path does, but l2cap_sock_recvmsg() calls l2cap_publish_rx_avail() -> l2cap_chan_rx_avail() -> l2cap_chan_le_send_credits() with only the socket lock held. If the remote answers the credits packet with L2CAP_COMMAND_REJ, l2cap_put_ident() can free the ident first, and the credits path then frees it again: ida_free called for id=3 which is not allocated. WARNING: lib/idr.c:594 at ida_free+0x24c/0x2d4 lib/idr.c:594 Call trace: ida_free+0x24c/0x2d4 lib/idr.c:594 l2cap_chan_le_send_credits+0x17c/0x29c net/bluetooth/l2cap_core.c:7113 l2cap_chan_rx_avail+0xb4/0x134 net/bluetooth/l2cap_core.c:7126 l2cap_publish_rx_avail+0x110/0x168 net/bluetooth/l2cap_sock.c l2cap_sock_recvmsg+0x280/0x7b8 net/bluetooth/l2cap_sock.c:1317 The same unlocked call also updates chan->rx_credits and reads chan->sdu concurrently with the RX path. Publish rx_avail from recvmsg under conn->lock and chan->lock, taken with l2cap_chan_lock_conn() as l2cap_sock_defer() already does, before taking the socket lock to keep the conn->lock -> chan->lock -> sk_lock order. Assert conn->lock in l2cap_chan_le_send_credits() so that an unlocked caller is caught by lockdep. 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 Signed-off-by: Luiz Augusto von Dentz Stable-dep-of: 06b6fbe05f5c ("Bluetooth: L2CAP: Use a reserved ident for L2CAP_LE_CREDITS") Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_core.c | 3 +++ net/bluetooth/l2cap_sock.c | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 7ac5dd0fb6fe4..eeeddb3ced8cd 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -6967,6 +6967,9 @@ 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); diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index f413e5beab9e4..c7fe12445df42 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1292,6 +1292,7 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, { struct sock *sk = sock->sk; struct l2cap_pinfo *pi = l2cap_pi(sk); + bool have_conn; int err; if (unlikely(flags & MSG_ERRQUEUE)) @@ -1312,9 +1313,12 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, pi->chan->mode != L2CAP_MODE_EXT_FLOWCTL) return err; - lock_sock(sk); - + /* Returning credits must be serialized with the RX path */ + have_conn = l2cap_chan_lock_conn(pi->chan); l2cap_publish_rx_avail(pi->chan); + l2cap_chan_unlock_conn(pi->chan, have_conn); + + lock_sock(sk); /* Attempt to put pending rx data in the socket buffer */ while (!list_empty(&pi->rx_busy)) { -- 2.53.0