Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH BlueZ v4 01/10] avrcp: Fix not checking browsing PDU parameter length
Date: Tue, 24 Nov 2026 13:18:55 +0100	[thread overview]
Message-ID: <20261124121904.3267700-2-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261124121904.3267700-1-simon.mikuda@streamunlimited.com>

The parameter length of a browsing PDU is not checked against the
number of bytes received, so a handler takes the parameters missing
from a short PDU from whatever the buffer held before.

To reproduce, send to the target a GetFolderItems with a parameter
length of 10 but no parameters. It is answered from the zeroed buffer
as a request for the media players 0 to 0:

  btmon: AVRCP: GetFolderItems: len 0x000a
  handle_browsing_pdu() AVRCP Browsing PDU 0x71, len 0x000A
  avrcp_handle_get_folder_items() scope 0x00 start_item 0x00000000
      end_item 0x00000000
  btmon: AVRCP: GetFolderItems: len 0x002c
  btmon: Status: 0x04 (Success)
  btmon: NumOfItems: 0x0001 (1)
  btmon: Name: Player A

Reject a PDU whose parameter length does not match, as the control
channel does since commit e2b0f0d8d63e ("avrcp: Fix not checking if
params_len match number of received bytes").

Fixes: 731aec9cae63 ("AVRCP: Add handler for browsing PDUs")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/avrcp.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 2f214e982..95b1d8c47 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2164,9 +2164,20 @@ static size_t handle_browsing_pdu(struct avctp *conn,
 	const struct browsing_pdu_handler *handler;
 	struct avrcp_browsing_header *pdu = (void *) operands;
 
+	if (operand_count < AVRCP_BROWSING_HEADER_LENGTH)
+		return avrcp_browsing_general_reject(operands);
+
 	DBG("AVRCP Browsing PDU 0x%02X, len 0x%04X", pdu->pdu_id,
 						be16_to_cpu(pdu->param_len));
 
+	if (be16_to_cpu(pdu->param_len) !=
+			operand_count - AVRCP_BROWSING_HEADER_LENGTH) {
+		DBG("AVRCP Browsing PDU parameters length don't match");
+		pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
+		pdu->param_len = cpu_to_be16(1);
+		return AVRCP_BROWSING_HEADER_LENGTH + 1;
+	}
+
 	for (handler = browsing_handlers; handler->pdu_id; handler++) {
 		if (handler->pdu_id == pdu->pdu_id)
 			goto done;
-- 
2.43.0


  reply	other threads:[~2026-11-24 12:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 12:18 [PATCH BlueZ v4 00/10] AVRCP browsing fixes Simon Mikuda
2026-11-24 12:18 ` Simon Mikuda [this message]
2026-11-24 21:03   ` bluez.test.bot
2026-11-24 12:18 ` [PATCH BlueZ v4 02/10] avrcp: Fix listing media players up to item 0xffffffff Simon Mikuda
2026-11-24 12:18 ` [PATCH BlueZ v4 03/10] avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification Simon Mikuda
2026-11-24 12:18 ` [PATCH BlueZ v4 04/10] avrcp: Fix byte order of TRACK_CHANGED identifier Simon Mikuda
2026-11-24 12:18 ` [PATCH BlueZ v4 05/10] avrcp: Fix not browsing a player addressed before it was listed Simon Mikuda
2026-11-24 12:19 ` [PATCH BlueZ v4 06/10] player: Fix crash on Search in a folder whose name has a space Simon Mikuda
2026-11-24 12:19 ` [PATCH BlueZ v4 07/10] player: Fix missing Name of listed Now Playing items Simon Mikuda
2026-11-24 12:19 ` [PATCH BlueZ v4 08/10] avrcp: Fix NumberOfItems set from a reply for another folder Simon Mikuda
2026-11-24 12:19 ` [PATCH BlueZ v4 09/10] unit/test-media-player: Add test for stale NumberOfItems reply Simon Mikuda
2026-11-24 12:19 ` [PATCH BlueZ v4 10/10] player: Fix Now Playing NumberOfItems when its content changes Simon Mikuda

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=20261124121904.3267700-2-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.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