Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F7E43DC4D9 for ; Tue, 29 Sep 2026 15:42:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.156 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790696558; cv=none; b=Bj38+1lOJjPZ3QUDGlr9OeIDTAERCApSTS+cr+mLllu9Cv/JrHLvspqbo0Iv1t+M301hu8bn8wuIe5MmrbK7JFLX+xXjQNQ3Y9Dx7NdKmK2k91N0/OU7fdToOqgUG/8Q9KypGnTFTi+Q22nec8kCLopB3aPkEd8o/1p5hxKTA3k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790696558; c=relaxed/simple; bh=+VxFY7zsEvUuBflQhBlC5VAdTMtrSa8xzyhtAb44BU0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Hj4Z8w2lvfaPFR8PnTySD5LDNHRB845F0xHfXZ0nxIY74CIDpuBVIx4/w0TUYNL5kCBWCts4qsyidjIa+4iKbeBLMldjsjVyBu8Y/hmdY9PUkEKEKhiE/8b4MwmGYiGCmuMq7GooSqIYLHyUIVUfsJKQmQL0a2YgxOuD/l53mmE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fourdim.xyz; spf=pass smtp.mailfrom=fourdim.xyz; dkim=pass (2048-bit key) header.d=fourdim.xyz header.i=@fourdim.xyz header.b=wUT82xcM; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=o4vZB3yL; arc=none smtp.client-ip=103.168.172.156 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fourdim.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fourdim.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fourdim.xyz header.i=@fourdim.xyz header.b="wUT82xcM"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="o4vZB3yL" Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 32942140055B; Tue, 29 Sep 2026 11:42:35 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Tue, 29 Sep 2026 11:42:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fourdim.xyz; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to; s=fm3; t=1790696555; x=1790782955; bh=uujL3305SFGF2QBMhu1S5 KMeTIqR1AbsmSd5Dyz6Suw=; b=wUT82xcMETI55OwRKwInB1ZpOO7dwDJmAAfiN X35RyeFcuN1zvUmRP69DggMikbRCig+Vh6ZaTzNE7GvasM9J30owEy+lCAnpwEZU PuduShoAhHaKQDFoTFyFnEe1sEbM7EAljg7qkTHpaF/Vk4vD75gedvjmNMraTite tmLxYlJVgFyQ8g0nWZtGfLCO/1C7tZ8hj0WALLPBt2Vgp7uKeRSN5pm6zBpkFWdO uYqAkvgu8KlgvfobmgA6+z+U09j4VrG3ptyh2K839DkYw4y+WbxQzA522i5TnU9i 060pri2Zgwz5QBOKH1rXlE1WrghMM11K2lNs0DEJ8D+XElMXg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:message-id:mime-version:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1790696555; x=1790782955; bh=uujL3305SFGF2QBMhu1S5KMeTIqR1AbsmSd 5D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rRFbA X-ME-Proxy: Feedback-ID: if72e4b10:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 29 Sep 2026 11:42:34 -0400 (EDT) From: Siwei Zhang To: Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org, Siwei Zhang Subject: [PATCH v2] Bluetooth: L2CAP: Reject signalling responses in invalid states Date: Tue, 29 Sep 2026 11:42:09 -0400 Message-ID: <20260929154219.2366060-1-oss@fourdim.xyz> X-Mailer: git-send-email 2.55.0 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 in BT_CONNECT. Answer configuration requests in BT_CONNECT2, but defer our own request until BT_CONFIG so configuration cannot complete before the gate. Ignore configuration responses outside BT_CONFIG and BT_CONNECTED, and only complete configuration in BT_CONFIG. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang --- v2: - resolve the patch conflict v1: https://lore.kernel.org/linux-bluetooth/20260928173324.1837653-1-oss@fourdim.xyz/T/#t net/bluetooth/l2cap_core.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 49a998804908..cb4ec42f99e3 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -4438,6 +4438,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)) { @@ -4467,6 +4471,7 @@ static int l2cap_connect_create_rsp(struct l2cap_conn *conn, break; } +done: l2cap_chan_unlock(chan); l2cap_chan_put(chan); @@ -4604,7 +4609,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); @@ -4657,6 +4668,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); @@ -4724,6 +4739,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); -- 2.55.0