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=1794063396; b=UjYKSTN+jk8hRgfOSRxXiHiQbC7HaTRZ45brOnjHKaPpezvGpCkCXmBWjT1nH9urw63U tMzw7hmyuKkQAldXE58g8wqOV4HcjJgNWvxhvTSf4+8n7Ruz0MBIf0mkgu/eSL53LPZKW G0AlLeXJ80PS3g88AX4SO+vs70SeTSVa5GJuYUlDgbSCKACI6JyeSXD3YOK6V0c+cWU1C drJJnu2gNMTd7vdrgrfSQ0iKBuP2oK+k9yN732jAK9xzS+SHzdHxXGOvRoBC4wbx+PJdg Wm2Wm/m5Iwq4Ap0je6LuitwAcYOpmc2DVRr1u9KZ1nx7GsPXYVgcZ9JoPToVuOrVQag== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794063396; 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=YWdyp7xOED/dDbxs0rD0R6k4b2c/1pNLUZv6aabgscU=; b=XbnmkiW8UdaJ7U2blg8fF/NsLLZ9OzlJFeGz+++uCIoUyaArWSd5kFfxeSmyjDPztpN6 u1Xx9yqZ0rLsQib9qIdgDWhcq+PckU4PBT74y4NuN6UCRbwF2K6E8WYm79f10XnIPLfBe BC1LVwtYS51aTt4sNvYiipaYIehHhLsZHyd76kQnB46cKvfCNOQxjlOrxDVjtyKEHLxP/ iIMXm4uJ7OR7hBzfQZGpmdnE1PsP+jIZw+d3707kCOqpS1wBWVdaSKY9Frl7fBI+X19rx FIbhtT0Y22hx+PGNTJ+c1YUB3264zO7f3Cp4FLNWZ10ZLhWsQIocRdHh+jpmbyjvStg== 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=SytRhjqV; 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 0338C606A333; Sat, 7 Nov 2026 14:56:35 +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=SytRhjqV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6FCFB1F0089F; Sat, 7 Nov 2026 14:56:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794063395; bh=YWdyp7xOED/dDbxs0rD0R6k4b2c/1pNLUZv6aabgscU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SytRhjqV5IhGQSh1oCknEVH055/HEMqEJm/49pk9Gn/fXNnMyzoXrybHeA4cCEfhA +L7/d5mmvIpVP9VIRdLzV71q355o8YHXOufxnwwOg3UZhX2F76isJCCxp7Sv/07RoZ jxLtPD3Jst0sZOKswIjmg+P5utGTVee99mXQYRqU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Siwei Zhang , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 6.18 568/869] Bluetooth: L2CAP: Reject invalid TxWindow in configuration requests Date: Sat, 7 Nov 2026 08:54:10 -0500 Message-ID: <20261107134912.519355811@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134852.069646174@linuxfoundation.org> References: <20261107134852.069646174@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Siwei Zhang [ Upstream commit c5ebb0245fe927cf5fa33510a9cb2799c4a2dd01 ] A peer can send an ERTM RFC option with a TxWindow of zero, which is out of spec. It is stored in remote_tx_win unchanged and later passed to l2cap_seq_list_init(), where roundup_pow_of_two(0) is undefined. On some architectures this results in a ZERO_SIZE_PTR list and a remote kernel oops. A TxWindow above 63 is out of spec as well. With 6-bit sequence numbers we would then send more unacknowledged frames than the sequence space can tell apart. Reply with L2CAP_CONF_UNACCEPT and propose the default TxWindow instead of accepting the value, so remote_tx_win always stays within 1 to 63. Keep the parameters of an earlier request then, and do not treat the request as done because an earlier one was. Also refuse a zero size in l2cap_seq_list_init(), so any other path that reaches it with a zero TxWindow fails the channel instead of the kernel. Fixes: f2fcfcd67025 ("Bluetooth: Add configuration support for ERTM and Streaming mode") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Siwei Zhang Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/l2cap_core.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 4e1c21f05e54e..0ba7b1ea435cc 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -323,6 +323,10 @@ static int l2cap_seq_list_init(struct l2cap_seq_list *seq_list, u16 size) { size_t alloc_size, i; + /* roundup_pow_of_two(0) is undefined */ + if (!size) + return -EINVAL; + /* Allocated size is a power of 2 to map sequence numbers * (which may be up to 14 bits) in to a smaller array that is * sized for the negotiated ERTM transmit windows. @@ -3648,18 +3652,33 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data, size_t data break; case L2CAP_MODE_ERTM: - if (!test_bit(CONF_EWS_RECV, &chan->conf_state)) - chan->remote_tx_win = rfc.txwin_size; - else - rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; - - chan->remote_max_tx = rfc.max_transmit; - size = min_t(u16, le16_to_cpu(rfc.max_pdu_size), chan->conn->mtu - L2CAP_EXT_HDR_SIZE - L2CAP_SDULEN_SIZE - L2CAP_FCS_SIZE); rfc.max_pdu_size = cpu_to_le16(size); - chan->remote_mps = size; + + /* The TxWindow must be within 1 to 63, otherwise + * propose the default one and keep the parameters of + * an earlier request. This overrides a PENDING result + * from the EFS check above, so the request is no + * longer pending, nor done if an earlier one was. + */ + if (!rfc.txwin_size || + rfc.txwin_size > L2CAP_DEFAULT_TX_WINDOW) { + result = L2CAP_CONF_UNACCEPT; + clear_bit(CONF_LOC_CONF_PEND, &chan->conf_state); + clear_bit(CONF_OUTPUT_DONE, &chan->conf_state); + rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; + remote_efs = 0; + } else { + if (!test_bit(CONF_EWS_RECV, &chan->conf_state)) + chan->remote_tx_win = rfc.txwin_size; + else + rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; + + chan->remote_max_tx = rfc.max_transmit; + chan->remote_mps = size; + } __l2cap_set_ertm_timeouts(chan, &rfc); -- 2.53.0