public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: l2cap: Add missing chan lock in l2cap_ecred_reconf_rsp
@ 2026-04-03  2:35 Dudu Lu
  2026-04-03  5:03 ` bluez.test.bot
  0 siblings, 1 reply; 4+ messages in thread
From: Dudu Lu @ 2026-04-03  2:35 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, luiz.dentz, Dudu Lu

l2cap_ecred_reconf_rsp() calls l2cap_chan_del() without first acquiring
the channel lock or holding a reference on the channel. All other call
sites of l2cap_chan_del() in l2cap_core.c (e.g., l2cap_disconnect_req,
l2cap_ecred_conn_rsp) properly hold the channel lock and a reference.

Without the lock, concurrent operations on the same channel can lead to
list corruption or use-after-free. Fix by adding l2cap_chan_hold +
l2cap_chan_lock before the deletion and the corresponding unlock + put
after, matching the established pattern.

Fixes: 15f02b910562 ("Bluetooth: L2CAP: Add L2CAP_ECRED_RECONF support")
Signed-off-by: Dudu Lu <phx0fer@gmail.com>
---
 net/bluetooth/l2cap_core.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index XXXXXXX..XXXXXXX 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5472,7 +5472,15 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn,
 		if (chan->ident != cmd->ident)
 			continue;

-		l2cap_chan_del(chan, ECONNRESET);
+		l2cap_chan_hold(chan);
+		l2cap_chan_lock(chan);
+
+		l2cap_chan_del(chan, ECONNRESET);
+
+		l2cap_chan_unlock(chan);
+		l2cap_chan_put(chan);
 	}

 	return 0;

^ permalink raw reply	[flat|nested] 4+ messages in thread
* [PATCH] Bluetooth: l2cap: Add missing chan lock in l2cap_ecred_reconf_rsp
@ 2026-04-05 15:47 Dudu Lu
  2026-04-05 16:16 ` bluez.test.bot
  0 siblings, 1 reply; 4+ messages in thread
From: Dudu Lu @ 2026-04-05 15:47 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, luiz.dentz, Dudu Lu

l2cap_ecred_reconf_rsp() calls l2cap_chan_del() without holding
l2cap_chan_lock(). Every other l2cap_chan_del() caller in the file
acquires the lock first. A remote BLE device can send a crafted
L2CAP ECRED reconfiguration response to corrupt the channel list
while another thread is iterating it.

Add l2cap_chan_hold() and l2cap_chan_lock() before l2cap_chan_del(),
and l2cap_chan_unlock() and l2cap_chan_put() after, matching the
pattern used in l2cap_ecred_conn_rsp() and l2cap_conn_del().

Fixes: 15f02b910562 ("Bluetooth: L2CAP: Add L2CAP_ECRED_RECONF support")
Signed-off-by: Dudu Lu <phx0fer@gmail.com>
---
 net/bluetooth/l2cap_core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 95c65fece39b..82989c1319c4 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -5473,7 +5473,13 @@ static inline int l2cap_ecred_reconf_rsp(struct l2cap_conn *conn,
 		if (chan->ident != cmd->ident)
 			continue;
 
+		l2cap_chan_hold(chan);
+		l2cap_chan_lock(chan);
+
 		l2cap_chan_del(chan, ECONNRESET);
+
+		l2cap_chan_unlock(chan);
+		l2cap_chan_put(chan);
 	}
 
 	return 0;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-05 16:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-03  2:35 [PATCH] Bluetooth: l2cap: Add missing chan lock in l2cap_ecred_reconf_rsp Dudu Lu
2026-04-03  5:03 ` bluez.test.bot
2026-04-03 16:19   ` Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2026-04-05 15:47 [PATCH] " Dudu Lu
2026-04-05 16:16 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox