From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v5 5/6] monitor: Fix RFCOMM UIH frame length and credit-only handling
Date: Wed, 25 Nov 2026 14:37:55 +0100 [thread overview]
Message-ID: <20261125133756.551659-6-frederic.danis@collabora.com> (raw)
In-Reply-To: <20261125133756.551659-1-frederic.danis@collabora.com>
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
next prev parent reply other threads:[~2026-11-25 13:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 13:37 [PATCH BlueZ v5 0/6] monitor: Add an OBEX protocol decoder to btmon Frédéric Danis
2026-11-25 13:37 ` [PATCH BlueZ v5 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-11-25 13:37 ` [PATCH BlueZ v5 2/6] monitor: Add OBEX protocol decoder Frédéric Danis
2026-11-25 13:37 ` [PATCH BlueZ v5 3/6] monitor: Decode PBAP/MAP/BIP Application Parameters tags Frédéric Danis
2026-11-25 13:37 ` [PATCH BlueZ v5 4/6] monitor: Reassemble L2CAP ERTM/Streaming SDUs Frédéric Danis
2026-11-25 13:37 ` Frédéric Danis [this message]
2026-11-25 13:37 ` [PATCH BlueZ v5 6/6] monitor: Reassemble OBEX PDUs split across RFCOMM UIH frames Frédéric Danis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125133756.551659-6-frederic.danis@collabora.com \
--to=frederic.danis@collabora.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox