From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796029863; b=Cz6Tuc5mRvEHesEwDxgY6KiMxRmGhXmxj5wKHGNQOa+6s5uGjL3Z0ksL4SB40SAlC/r6 lXOijC/2cZbzQ3qz5jiQdg/eyxdtjwGd/blx789qUvXPuPaAIGdWrId2o/rOuxcGm85Ce 1gWKH0DIKMepxaj2xWsX/jkjY8xQtolktrjNp0BGjseSwNETXbTelcYDpWrkd1snk43Wk nfgLEWr/nMuMwyVBgw2KIOrDwN6JKZnq6ooR7hMP+prZBqFz3MMsitvdw9m3bYu+XoENd LRSs+UiB8Z0JrpBIP3Gi9+bmgw8OiD6grJBEE9KUMf9zWEPuvyPybkkD9kzb+P8nS7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796029863; h=DMARC-Filter:DKIM-Signature:Received:From:To:Subject:Date:Message-ID: X-Mailer:In-Reply-To:References:MIME-Version:Content-Type: Content-Transfer-Encoding; bh=1fMSkyRTpVZHvcoGKrBb/5wodSGCkerzOwgDxeWqTjo=; b=SBbgpzHbWV4fFe0/tKaUrXKRCoxT21V7aaXv/OLxkktqDyvid7QNCFZX+HcNNTp2VbVI GTS5jhw6piTVz9S6nOLfE+nwugzIH1lfnB7J/JqWgvJvGJu91OF7tEip2/xOejpCbT8TU n19WCwtW3AmCsQiZG02r4t2+ho/cg2mdsAtQuKRPBp520Tr7XSD9b6RZPB/WgsfumlNLG Eb7PA7/vTbrao377A8huhTIdLcx1YgV4iqQY8MBY5DYQPm3ERch7zmF+eYMRL+vM4Amhd K6j+e5l0VgGqPITNQ/I/5Y7TsSj02u9VpAZmvl7LYuhdKn37goImO5quG6fKdYBspqg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=lERv7qYc; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 D815E606A33B for ; Mon, 30 Nov 2026 09:11:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D815E606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=lERv7qYc DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796029859; bh=EY0L8Qw5XijdeH6YZ96IpdjgiO5oUnD7wuMjJ3XLJ20=; h=From:To:Subject:Date:In-Reply-To:References:From; b=lERv7qYcdHZiG7DM7V9ueEYFIpM3iVsv3o3eugu7BYGYQGrQHLzihDMU/MyG4mQ1D laMU9eKRkOMj1Ai4G0GuQdV4npOp0VdhIB5ZDXr70l/AdxdZSrvAbrpqbtWkZO+voO y5K2BtyTj7PTCmc3IlEnlBibZRhj7zsq5nU1iF6zC8nam0Ar+SDLVO0NVxoueRSXeC vPH9VU6pvl2+Snd26XrFnnzzU+ReOrgtt+asaPYLbrDWBk6/QhKTyP7CTstqkepEZX TKYDq74usMYVbAl6iRzklK7jt+tfZk4izZQMsp6+6wBCGtjyuL0F62qoNGycJbMUPo pnJmBSflWf47A== Received: from fdanis-ThinkPad-X1.. (unknown [100.64.1.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by bali.collaboradmins.com (Postfix) with ESMTPSA id D09EA17E0E34 for ; Mon, 30 Nov 2026 10:10:59 +0100 (CET) From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v6 5/6] monitor: Fix RFCOMM UIH frame length and credit-only handling Date: Mon, 30 Nov 2026 10:10:51 +0100 Message-ID: <20261130091052.383139-6-frederic.danis@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261130091052.383139-1-frederic.danis@collabora.com> References: <20261130091052.383139-1-frederic.danis@collabora.com> X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit rfcomm_packet() consumed the trailing 1-byte FCS via a separate tmp_frame view over the same bytes, but never trimmed it from l2cap_frame itself, so the FCS byte was still included in the payload handed to uih_frame()/mcc_frame(). For OBEX traffic this showed up as a spurious trailing byte once the OBEX decoder started enforcing PDU lengths strictly; drop the byte from l2cap_frame->size right after it is read. uih_frame() also handed credit-only UIH frames (an RFCOMM credit flow control update carrying no information payload, size 0 once the optional credits octet is consumed) to the OBEX channel check and decoder, which could misdecode them as a 0-length OBEX PDU. Skip decoding entirely when no payload bytes remain. rfcomm_packet() parsed the UIH frame's own declared hdr.length but never bounded the payload by it, so an L2CAP PDU carrying more than one multiplexed RFCOMM frame would feed the next frame's trailing bytes into this frame's payload. Clamp l2cap_frame->size to hdr.length (plus the leading credit octet, when present) instead. Assisted-by: Claude:claude-sonnet-5 --- v2->v3: New in v3. v4->v5: - Bound rfcomm_packet()'s payload by the UIH frame's own declared hdr.length (plus the leading credit octet, when present), instead of handing uih_frame()/mcc_frame() the whole remaining L2CAP PDU, so an L2CAP PDU carrying more than one multiplexed RFCOMM frame doesn't leak the next frame's bytes into this frame's payload. monitor/rfcomm.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/monitor/rfcomm.c b/monitor/rfcomm.c index d830684a9..90ddc3596 100644 --- a/monitor/rfcomm.c +++ b/monitor/rfcomm.c @@ -404,6 +404,12 @@ static bool uih_frame(struct rfcomm_frame *rfcomm_frame, uint8_t indent) print_field("%*cCredits: %d", indent, ' ', hdr->credits); } + /* A credit-only UIH frame (credit-based flow control update) + * carries no information payload; nothing to decode. + */ + if (!frame->size) + return true; + if (obex_channel(frame->index, frame->handle, channel, NULL)) obex_packet(frame, channel, frame->size); else @@ -434,6 +440,7 @@ void rfcomm_packet(const struct l2cap_frame *frame) struct rfcomm_frame rfcomm_frame; struct rfcomm_lhdr hdr; const struct rfcomm_data *rfcomm_data = NULL; + uint32_t max_size; int i; l2cap_frame_pull(&rfcomm_frame.l2cap_frame, frame, 0); @@ -467,9 +474,31 @@ void rfcomm_packet(const struct l2cap_frame *frame) if (!l2cap_frame_get_u8(&tmp_frame, &hdr.fcs)) goto fail; + /* The trailing FCS byte just consumed via tmp_frame is still + * included in l2cap_frame's size (tmp_frame is a separate view + * over the same bytes). Drop it so the information payload + * handed to uih_frame()/mcc_frame() doesn't include it. + */ + l2cap_frame->size -= 1; + /* Decoding frame type */ ctype = RFCOMM_GET_TYPE(hdr.control); + /* An L2CAP PDU may legally carry more than one RFCOMM frame + * back-to-back; bound the information payload to this frame's + * own declared length so trailing bytes belonging to the next + * multiplexed frame aren't mistaken for part of it. A UIH frame + * with the P/F bit set carries a leading credit octet ahead of + * the information field, which isn't covered by hdr.length. + */ + if (ctype == 0xef && GET_PF(hdr.control)) + max_size = (uint32_t) hdr.length + 1; + else + max_size = hdr.length; + + if (l2cap_frame->size > max_size) + l2cap_frame->size = max_size; + for (i = 0; rfcomm_table[i].str; i++) { if (rfcomm_table[i].frame == ctype) { rfcomm_data = &rfcomm_table[i]; -- 2.43.0