FAILED: patch "[PATCH] Bluetooth: L2CAP: Reject signalling responses in invalid states" failed to apply to 6.1-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x 6320736af7dcb90da6ee9fd651ecc11c564d45b7
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 6320736af7dcb90da6ee9fd651ecc11c564d45b7 Mon Sep 17 00:00:00 2001
From: Siwei Zhang <[email protected]>
Date: Tue, 13 Oct 2026 11:36:34 -0400
Subject: [PATCH] Bluetooth: L2CAP: Reject signalling responses in invalid
states
A peer can send configuration messages while an incoming channel is in BT_CONNECT2, before the security or deferred accept gate has completed. A configuration response can then promote the channel to BT_CONNECTED. Configuration responses can also act on channels that are closing, and a late connection response can move a disconnecting channel back to BT_CONFIG.
Accept connection responses only while waiting inBT_CONNECT. Answer configuration requests inBT_CONNECT2, but defer our own request untilBT_CONFIG so configuration cannot complete before
the gate. Ignore configuration responses outsideBT_CONFIG and BT_CONNECTED, and only complete
configuration in BT_CONFIG.
--- net/bluetooth/l2cap_core.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +19 -1
@@ -4442,6 +4442,10 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,lockdep_assert_held (&chan->conn->lock); +/* Ignore a late response after the channel has left BT_CONNECT. */ +if (chan->state !=BT_CONNECT ) + goto done; +switch (result) {case L2CAP_CR_SUCCESS :if (__l2cap_get_chan_by_dcid (conn, dcid)) {
@@ -4471,6 +4475,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,break ; } +done:l2cap_chan_unlock (chan);l2cap_chan_put (chan);
@@ -4608,7 +4613,13 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, goto unlock; } -if (!test_and_set_bit (CONF_REQ_SENT , &chan->conf_state)) { +/* A channel in BT_CONNECT2 has not passed security or userspace +* accept yet. Answer the peer's request, but hold our own until +* the channel reaches BT_CONFIG: the CONNECT2 -> CONFIG sites send +* it. Connected channels may also need to reconfigure. +*/ +if ((chan->state ==BT_CONFIG || chan->state ==BT_CONNECTED ) && + !test_and_set_bit (CONF_REQ_SENT , &chan->conf_state)) {u8 buf[64 ];l2cap_send_cmd (conn,l2cap_get_ident (conn),L2CAP_CONF_REQ ,l2cap_build_conf_req (chan, buf,sizeof (buf)), buf);
@@ -4661,6 +4672,10 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,lockdep_assert_held (&chan->conn->lock); +/* Connected channels may also receive reconfiguration responses. */ +if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECTED ) + goto done; +switch (result) {case L2CAP_CONF_SUCCESS :l2cap_conf_rfc_get (chan, rsp->data, len);
@@ -4728,6 +4743,9 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,if (test_bit (CONF_OUTPUT_DONE , &chan->conf_state)) {set_default_fcs (chan); +if (chan->state !=BT_CONFIG ) + goto done; +if (chan->mode ==L2CAP_MODE_ERTM || chan->mode ==L2CAP_MODE_STREAMING ) err =l2cap_ertm_init (chan);
Signature · 1 line
2.53.0
cover Bluetooth: L2CAP: signalling response fixes
Backports of
6320736af7dc ("Bluetooth: L2CAP: Reject signalling responses in invalid states") a518b9a9ef6e ("Bluetooth: L2CAP: Only accept connection responses to outstanding requests")
which failed to apply to the 6.1-stable tree:
https://lore.kernel.org/stable/[email protected]/
https://lore.kernel.org/stable/[email protected]/
Patch 3 is a9f9eeb5344f ("Bluetooth: L2CAP: Ignore connection responses with wrong ident"), which tightens the check added by patch 2 and only applies on top of it.
The series goes on top of the three L2CAP patches already queued for 6.1.y:
c1398cf11b31 ("Bluetooth: L2CAP: Reject mode changes on connected channels") c5ebb0245fe9 ("Bluetooth: L2CAP: Reject invalid TxWindow in configuration requests") 226fa3b676cb ("Bluetooth: L2CAP: Use default TxWindow for zero socket option")
Jinwang Li (1):
Bluetooth: L2CAP: Ignore connection responses with wrong ident
Siwei Zhang (2):
Bluetooth: L2CAP: Reject signalling responses in invalid states
Bluetooth: L2CAP: Only accept connection responses to outstanding
requests
net/bluetooth/l2cap_core.c | 47 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-)
Signature · 1 line
2.56.0
PATCH 1/3 Bluetooth: L2CAP: Reject signalling responses in invalid states
commit 6320736af7dcb90da6ee9fd651ecc11c564d45b7 upstream.
Adjusted context as stable does not have the lockdep_assert_held() calls, and l2cap_get_chan_by_scid() still returns the channel locked, so l2cap_config_rsp() does not lock it again.
A peer can send configuration messages while an incoming channel is in BT_CONNECT2, before the security or deferred accept gate has completed. A configuration response can then promote the channel to BT_CONNECTED. Configuration responses can also act on channels that are closing, and a late connection response can move a disconnecting channel back to BT_CONFIG.
Accept connection responses only while waiting inBT_CONNECT. Answer configuration requests inBT_CONNECT2, but defer our own request untilBT_CONFIG so configuration cannot complete before
the gate. Ignore configuration responses outsideBT_CONFIG and BT_CONNECTED, and only complete
configuration in BT_CONFIG.
--- net/bluetooth/l2cap_core.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-)
net/bluetooth/l2cap_core.c +19 -1
@@ -4297,6 +4297,10 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,l2cap_chan_lock (chan); +/* Ignore a late response after the channel has left BT_CONNECT. */ +if (chan->state !=BT_CONNECT ) + goto done; +switch (result) {case L2CAP_CR_SUCCESS :if (__l2cap_get_chan_by_dcid (conn, dcid)) {
@@ -4326,6 +4330,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,break ; } +done:l2cap_chan_unlock (chan);l2cap_chan_put (chan);
@@ -4461,7 +4466,13 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, goto unlock; } -if (!test_and_set_bit (CONF_REQ_SENT , &chan->conf_state)) { +/* A channel in BT_CONNECT2 has not passed security or userspace +* accept yet. Answer the peer's request, but hold our own until +* the channel reaches BT_CONFIG: the CONNECT2 -> CONFIG sites send +* it. Connected channels may also need to reconfigure. +*/ +if ((chan->state ==BT_CONFIG || chan->state ==BT_CONNECTED ) && + !test_and_set_bit (CONF_REQ_SENT , &chan->conf_state)) {u8 buf[64 ];l2cap_send_cmd (conn,l2cap_get_ident (conn),L2CAP_CONF_REQ ,l2cap_build_conf_req (chan, buf,sizeof (buf)), buf);
@@ -4509,6 +4520,10 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,if (!chan)return 0 ; +/* Connected channels may also receive reconfiguration responses. */ +if (chan->state !=BT_CONFIG && chan->state !=BT_CONNECTED ) + goto done; +switch (result) {case L2CAP_CONF_SUCCESS :l2cap_conf_rfc_get (chan, rsp->data, len);
@@ -4576,6 +4591,9 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,if (test_bit (CONF_OUTPUT_DONE , &chan->conf_state)) {set_default_fcs (chan); +if (chan->state !=BT_CONFIG ) + goto done; +if (chan->mode ==L2CAP_MODE_ERTM || chan->mode ==L2CAP_MODE_STREAMING ) err =l2cap_ertm_init (chan);
Signature · 1 line
2.56.0
PATCH 2/3 Bluetooth: L2CAP: Only accept connection responses to outstanding requests
In reply to Siwei Zhangcommit a518b9a9ef6ee3b18ecdf6ba5360c608aaf969e9 upstream.
Adjusted context as stable does not have the lockdep_assert_held() call and the __must_hold() context analysis annotations, and l2cap_connect_create_rsp() still holds conn->chan_lock and returns through the unlock label when the channel lookup fails.
An outgoing channel waits in BT_CONNECT until security and the feature mask exchange complete, and only then sends its connection request. A peer can answer it before that with a connection response matching our source CID. The channel then moves to BT_CONFIG, completes configuration and becomes connected before security has completed. If security then fails, l2cap_security_cfm() leaves the connected channel alone, so it stays up on a link that did not reach the required security level.
A connection response with a zero source CID is matched by identifier. Another channel can hold the same identifier for a response it still has to send, so the lookup can pick the wrong channel.
Only accept a connection response while our request is outstanding, and only look at such channels when matching by identifier.
--- net/bluetooth/l2cap_core.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-)
net/bluetooth/l2cap_core.c +28 -3
@@ -165,6 +165,28 @@ static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn,return NULL ; } +/* Our connection request has been sent and is still outstanding */ +static bool l2cap_chan_connect_pending (struct l2cap_chan *chan) +{ +return chan->state ==BT_CONNECT && +test_bit (CONF_CONNECT_PEND , &chan->conf_state); +} + +/* Other channels may hold the same ident for a response they still have +* to send, so only look at channels waiting for a connection response. +*/ +static struct l2cap_chan *__l2cap_get_connect_chan_by_ident (struct l2cap_conn *conn, +u8 ident) +{ +struct l2cap_chan *c; + +list_for_each_entry (c, &conn->chan_l, list) { +if (c->ident == ident &&l2cap_chan_connect_pending (c)) +return c; + } +return NULL ; +} +static struct l2cap_chan *__l2cap_global_chan_by_addr (__le16 psm,bdaddr_t *src,u8 src_type) {
@@ -4280,7 +4302,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, goto unlock; } }else { - chan =__l2cap_get_chan_by_ident (conn, cmd->ident); + chan =__l2cap_get_connect_chan_by_ident (conn, cmd->ident);if (!chan) { err = -EBADSLT ; goto unlock;
@@ -4297,8 +4319,11 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,l2cap_chan_lock (chan); -/* Ignore a late response after the channel has left BT_CONNECT. */ -if (chan->state !=BT_CONNECT ) +/* Only accept a response to a connection request we sent and that +* is still outstanding. A channel waiting in BT_CONNECT for security +* or the feature mask has not sent one yet. +*/ +if (!l2cap_chan_connect_pending (chan)) goto done;switch (result) {
Signature · 1 line
2.56.0
PATCH 3/3 Bluetooth: L2CAP: Ignore connection responses with wrong ident
In reply to Siwei ZhangFrom: Jinwang Li <[email protected]>
commit a9f9eeb5344fc7dc625e5700ccf09891bc2603b5 upstream.
Adjusted context as stable does not have the lockdep_assert_held() call in l2cap_connect_create_rsp().
L2CAP/COS/CED/BI-28-C requires the IUT to ignore a Connection Response that carries an invalid Identifier.
l2cap_connect_create_rsp() only checks that a connection request is outstanding, not that the response answers it. Add an ident check against the pending request so that a mismatched response is dropped.
--- net/bluetooth/l2cap_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/bluetooth/l2cap_core.c +4 -4
@@ -4319,11 +4319,11 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn,l2cap_chan_lock (chan); -/* Only accept a response to a connection request we sent and that -* is still outstanding. A channel waiting in BT_CONNECT for security -* or the feature mask has not sent one yet. +/* Only accept a response matching a connection request we sent and +* that is still outstanding. A channel waiting in BT_CONNECT for +* security or the feature mask has not sent one yet. */ -if (!l2cap_chan_connect_pending (chan)) +if (!l2cap_chan_connect_pending (chan) || chan->ident != cmd->ident) goto done;switch (result) {
Signature · 1 line
2.56.0