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=1796388046; b=cSrzA4azsAVii49MOSJNJzjNquamAKF9dLTW2T3zRsRNKB9xk9Yh7O1mgw692FMelEbC Yn/hNgGSDAkmf0KW54W9TfuD60fIgN38wH5/0myepF/BgZ3ttUV5Zt1MuKQ/hfqZIEFGe t/fquJuUwTepAY2U0kZO0Rtvp5E8Ssn9IkB4CueajxC3gSYl2zze/41kRrJNWPtJw8djP xhKyIIfxNwRz5EhBEEx6VoiesU/CSEW1OF+puKbTsMGsQY4pd4V8RtDew3OwsIO1nJO0h MJxmt1KkbS9fs4tWFn/tqloXni91frJJIh+jqGRuHBsVChs4ituhawPHib5w+ZcZ5Kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388046; 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=UYwqrvQ5+6vlolq3uBys6RQWi+Q+jarUE3btVZhvClY=; b=fvgMm6dMaKu1KxNq64kL9JaDdXODi8XGfmKce1JuyaODu3kZWJR/0i0ykvwHH6dHYKAN us4Bdm3Gp+gGnM6RnWIIeAzG4drRWcyut5aaeGe1jZdmBsdaEfETQLufJw4lJ0K64e6xK cegsb4C9oeVwQf8H637VZxbI4kNADs2WQNOQ9EVBCNGk7ugK39svlzqUt57BUEMzUEa3M 6Mfx+TdnemBmsfJNrRlC2XGqXAEuF7H/dvmGTr85y3gTMrjZedMLGzcM9bBsUFoGOv12w N2cnxTc9r5vV6KsLP1bIDXxux/u0YFY730g8hCHOwMd7mBZndETP4L7PPjfiWM5ILMQ== 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="VSMrXKm/"; 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 F0DE6606A32D; Fri, 4 Dec 2026 12:40:45 +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=VSMrXKm/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 654C11F000C2; Fri, 4 Dec 2026 12:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388045; bh=UYwqrvQ5+6vlolq3uBys6RQWi+Q+jarUE3btVZhvClY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VSMrXKm/+mbUHszb5DnQYpWXNHNQi44QnkbpqAlJSfdHHqzvSYw7ttCfDOB9x0nEN NvmQq4ubGsgvGVhNtMomD8knyYxacspeMpDgKW08KY3e4XJRxTUatWIn8/3OEP9kAc e3utYH2yRwilX9YM5uDcf5x1UnDGaBV/0qEtyWk8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pauli Virtanen , Eulgyu Kim , Jaeyoung Chung , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.1 0464/1059] Bluetooth: L2CAP: take chan->lock for l2cap_chan_add/ready/del Date: Fri, 4 Dec 2026 18:59:55 +0900 Message-ID: <20261204100656.286201933@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pauli Virtanen [ Upstream commit 385c0829e09e7a6380ae67998ac6ef6f4dfd5303 ] chan->lock must be held for __l2cap_chan_add as eg. calls to l2cap_chan_close assume chan->conn writes are guarded by it. It must be held for l2cap_chan_del() due to l2cap_sock.c:l2cap_chan_conn, l2cap_monitor_timeout, etc. Similarly it should be held for l2cap_ops::ready (assumed in 6lowpan.c). Also teardown usually has chan->lock held, it should always have it held to have the same locking context. The lock is not correctly held by l2cap_core in several places. Add the missing locks for l2cap_chan_del/add/ready(), except in l2cap_ecred_rsp_defer() which needs separate fix as it needs lock nesting. Fixes: 6fef032af009 ("Bluetooth: L2CAP: Fix use-after-free in l2cap_sock_new_connection_cb()") Signed-off-by: Pauli Virtanen Reported-by: Eulgyu Kim Reported-by: Jaeyoung Chung Signed-off-by: Luiz Augusto von Dentz [ sashal: Used conn->chan_lock instead of upstream's conn->lock in l2cap_chan_add() when adding the chan->lock take/release around __l2cap_chan_add(). ] Signed-off-by: Sasha Levin --- include/net/bluetooth/l2cap.h | 3 ++- net/bluetooth/l2cap_core.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index b317c89935e90..b15ab4ead3bc3 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -967,7 +967,8 @@ int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator); void l2cap_chan_set_defaults(struct l2cap_chan *chan, struct l2cap_chan *pchan); int l2cap_ertm_init(struct l2cap_chan *chan); void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); -void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); +void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) + __must_hold(&chan->lock); typedef void (*l2cap_chan_func_t)(struct l2cap_chan *chan, void *data); void l2cap_chan_list(struct l2cap_conn *conn, l2cap_chan_func_t func, void *data); diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 86e229a593f83..c6231c630ad50 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -711,7 +711,9 @@ void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan) { mutex_lock(&conn->chan_lock); + l2cap_chan_lock(chan); __l2cap_chan_add(conn, chan); + l2cap_chan_unlock(chan); mutex_unlock(&conn->chan_lock); } @@ -4113,6 +4115,8 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, if (!chan) return NULL; + l2cap_chan_lock(chan); + l2cap_chan_set_defaults(chan, pchan); chan->ops = pchan->ops; @@ -4121,10 +4125,13 @@ static struct l2cap_chan *l2cap_new_connection(struct l2cap_conn *conn, if (pchan->ops->new_connection && pchan->ops->new_connection(pchan, chan) < 0) { l2cap_chan_del(chan, 0); + l2cap_chan_unlock(chan); l2cap_chan_put(chan); return NULL; } + l2cap_chan_unlock(chan); + return chan; } @@ -5151,6 +5158,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, goto response_unlock; } + l2cap_chan_lock(chan); + bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->dst, &conn->hcon->dst); chan->src_type = bdaddr_src_type(conn->hcon); @@ -5184,6 +5193,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn, result = L2CAP_CR_LE_SUCCESS; } + l2cap_chan_unlock(chan); + response_unlock: l2cap_chan_unlock(pchan); mutex_unlock(&conn->chan_lock); @@ -5377,6 +5388,8 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, continue; } + l2cap_chan_lock(chan); + bacpy(&chan->src, &conn->hcon->src); bacpy(&chan->dst, &conn->hcon->dst); chan->src_type = bdaddr_src_type(conn->hcon); @@ -5409,6 +5422,8 @@ static inline int l2cap_ecred_conn_req(struct l2cap_conn *conn, } else { l2cap_chan_ready(chan); } + + l2cap_chan_unlock(chan); } unlock: -- 2.53.0