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=1796400266; b=DlNvRhTbw+W1Rw8g+hKphBSA24dhGryUePQvCwoM1fgT8ImzGkq6mpEsl99PivOCLb3i pOBM0ufMj1zh7tjMAOLEBh8ESLe81FM7I8iZtkaHrKBb0aiVmftVI89KQUpT8k3MmY/nR FbJmctNbDb8gcJvHV7t8QXmy67KZEqsWsu2bZ+re6uva2+ZXzG8yb4DoS4ifHDuHaKhcL NTxYFqEmubW/jMvL1eJgUd6g7+OOvPp5bTqfw5blT5elCKaL1UryVr2Z/18LMMUy78v4i RfY4TUusbDS6rrwUUNL7XZ0xuYNIQ2GuyGU+DRcO4wTlw9pgSybF5rhdKvzmM2Xc4SA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400266; 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=EL+0hKc0ThqqeWZ4BCdSbtYALDNV8CgI3sFvbqUNoTg=; b=ffAJMr4e1r7qOU0TgRoWoV1z0HVJV79HQtO/5AmumIHkBsXP8zMxR88+JzlxTAFTwfXD pL6BXbPi8rHJjhkNrqmSjdZK7hob/4gBF3tuJ839wqCQo2aJIdoZU+Cf/nKgv0dcZ+4/J hQOyH90mQPt2HxhDQXsx30O2D72i/qTF+v4UcHKLF0Gpm62Ozn1DJduw6mBb09z9TYTOF X7TepkwuNLDeib8aSLJIzB4D69zTcmc9i9Ce3A+g/zL3RB8dIDeZwmTvGKDa95/2jxYza HcvCMfGawSgcLvbUYeQiYnQE073/yh+LqhJaGS9qyHzVEwGb2vJNZjkaTspKgl906jw== 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=B5NtWhH7; 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 2A816606A333 for ; Fri, 4 Dec 2026 16:04:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2A816606A333 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=B5NtWhH7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796400262; bh=bm/YoEkiP//HbA4odLNwyzJgnhBh1vVSzNzJ7BgbwgU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=B5NtWhH7gyccbwbzVl+iFNVgDbp0z4pOOMFGjls+BIXdYVwOHztp1YwTtrTwZfFUS BlNRVsSqwawcmioYVhvjsEqnm4ahWVJAF8VFyiCJFP8TgWa6yOuVmIWXcVWja03P5t 2TUgYgR+0z/+GRB9XQzbAUdSa8JpZPjYv3QXIyvjyaZXtRY11tek3Xrisbz0HFCw1e mqN+EtOpnANNeM+ejjUDlRHq+5nkfQPQW6D1bZeOfHuNrc5FfitQk85As3Smh8SZi6 Fr6QCu/OPtws0j21YjutndulFuo/98BxgmWhYxdOEBf15pST6jd/c2bZva3ug+sPUP IxT0gSFCh9V4A== 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 8CCAE17E129A for ; Fri, 04 Dec 2026 17:04:22 +0100 (CET) From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v8 5/6] monitor: Fix RFCOMM UIH frame length and credit-only handling Date: Fri, 4 Dec 2026 17:04:15 +0100 Message-ID: <20261204160416.1254097-6-frederic.danis@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204160416.1254097-1-frederic.danis@collabora.com> References: <20261204160416.1254097-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 The RFCOMM FCS byte was read but left in the payload passed to uih_frame()/mcc_frame(); remove it, and adjust the mcc_test() and mcc_msc() size checks which accounted for it. Bound the payload of each RFCOMM frame by its declared length (plus the credit octet), read its FCS right after it, and decode the following RFCOMM frames carried in the same L2CAP SDU, instead of treating them as part of the payload of the first one. Don't pass credit-only UIH frames, which have no payload, to the OBEX decoder. Assisted-by: Claude:claude-sonnet-5 Assisted-by: Claude:claude-opus-5-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. v7->v8: - Read the FCS right after the frame's declared length instead of from the last byte of the L2CAP SDU, and decode all RFCOMM frames carried in the same L2CAP SDU. - Adjust the mcc_test() and mcc_msc() size checks, which still accounted for the FCS byte. - Trim commit message. monitor/rfcomm.c | 63 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/monitor/rfcomm.c b/monitor/rfcomm.c index 747c771fa..ca5deeba2 100644 --- a/monitor/rfcomm.c +++ b/monitor/rfcomm.c @@ -142,7 +142,7 @@ static inline bool mcc_test(struct rfcomm_frame *rfcomm_frame, uint8_t indent) display_printf("%*cTest Data: 0x ", indent, ' '); - while (frame->size > 1) { + while (frame->size > 0) { if (!l2cap_frame_get_u8(frame, &data)) return false; display_printf("%2.2x ", data); @@ -171,7 +171,7 @@ static inline bool mcc_msc(struct rfcomm_frame *rfcomm_frame, uint8_t indent) GET_V24_RTR(msc.v24_sig), GET_V24_IC(msc.v24_sig), GET_V24_DV(msc.v24_sig)); - if (frame->size < 2) + if (frame->size < 1) goto done; /* @@ -404,6 +404,9 @@ static bool uih_frame(struct rfcomm_frame *rfcomm_frame, uint8_t indent) print_field("%*cCredits: %d", indent, ' ', hdr->credits); } + if (!frame->size) + return true; + if (obex_channel(frame->index, frame->handle, channel, NULL)) obex_packet(frame, channel, frame->size); else @@ -426,14 +429,17 @@ static const struct rfcomm_data rfcomm_table[] = { { } }; -void rfcomm_packet(const struct l2cap_frame *frame) +/* Decode the RFCOMM frame at the start of frame and return its size */ +static uint16_t rfcomm_frame_packet(const struct l2cap_frame *frame) { uint8_t ctype, length, ex_length, indent = 1; const char *frame_str, *frame_color; - struct l2cap_frame *l2cap_frame, tmp_frame; + struct l2cap_frame *l2cap_frame; struct rfcomm_frame rfcomm_frame; struct rfcomm_lhdr hdr; const struct rfcomm_data *rfcomm_data = NULL; + uint32_t max_size, hdr_len; + uint16_t consumed; int i; l2cap_frame_pull(&rfcomm_frame.l2cap_frame, frame, 0); @@ -462,14 +468,29 @@ void rfcomm_packet(const struct l2cap_frame *frame) if (!l2cap_frame->size) goto fail; - l2cap_frame_pull(&tmp_frame, l2cap_frame, l2cap_frame->size-1); - - if (!l2cap_frame_get_u8(&tmp_frame, &hdr.fcs)) - goto fail; + hdr_len = frame->size - l2cap_frame->size; /* Decoding frame type */ ctype = RFCOMM_GET_TYPE(hdr.control); + /* Credit octet */ + if (ctype == 0xef && GET_PF(hdr.control)) + max_size = (uint32_t) hdr.length + 1; + else + max_size = hdr.length; + + /* An L2CAP SDU may carry several RFCOMM frames */ + if (hdr_len + max_size + 1 <= frame->size) { + hdr.fcs = ((const uint8_t *) l2cap_frame->data)[max_size]; + l2cap_frame->size = max_size; + consumed = hdr_len + max_size + 1; + } else { + hdr.fcs = ((const uint8_t *) l2cap_frame->data) + [l2cap_frame->size - 1]; + l2cap_frame->size -= 1; + consumed = frame->size; + } + for (i = 0; rfcomm_table[i].str; i++) { if (rfcomm_table[i].frame == ctype) { rfcomm_data = &rfcomm_table[i]; @@ -489,8 +510,8 @@ void rfcomm_packet(const struct l2cap_frame *frame) } if (!rfcomm_data) { - packet_hexdump(frame->data, frame->size); - return; + packet_hexdump(frame->data, consumed); + return consumed; } print_indent(6, frame_color, "RFCOMM: ", frame_str, COLOR_OFF, @@ -502,16 +523,32 @@ void rfcomm_packet(const struct l2cap_frame *frame) /* UIH frame */ if (ctype == 0xef) { if (!uih_frame(&rfcomm_frame, indent)) - goto fail; + goto fail_frame; } else if (ctype == 0x43 || ctype == 0x0f) { obex_remove_channel(frame->index, frame->handle, RFCOMM_GET_CHANNEL(hdr.address)); } - return; + return consumed; + +fail_frame: + print_text(COLOR_ERROR, "Frame too short"); + packet_hexdump(frame->data, consumed); + return consumed; fail: print_text(COLOR_ERROR, "Frame too short"); packet_hexdump(frame->data, frame->size); - return; + return frame->size; +} + +void rfcomm_packet(const struct l2cap_frame *frame) +{ + struct l2cap_frame rfcomm; + + l2cap_frame_pull(&rfcomm, frame, 0); + + while (rfcomm.size) + l2cap_frame_pull(&rfcomm, &rfcomm, + rfcomm_frame_packet(&rfcomm)); } -- 2.43.0