From: Maoyi Xie <maoyixie.tju@gmail.com>
To: Clemens Ladisch <clemens@ladisch.de>,
Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH 1/3] ALSA: bebob: bound the channel position walk to the response length
Date: Wed, 25 Nov 2026 20:12:36 +0800 [thread overview]
Message-ID: <20261125121238.1602172-2-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261125121238.1602172-1-maoyixie.tju@gmail.com>
map_data_channels() walks the channel position response by the section
and channel counts in that response. Nothing checks the counts against
the length of the response. A section of 128 channels can read past the
256-byte buffer.
Take the length of the data from avc_bridgeco_get_plug_ch_pos(). Return
-EIO for a section that does not fit.
Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.
Fixes: eb7b3a056cd8 ("ALSA: bebob: Add commands and connections/streams management")
Cc: stable@vger.kernel.org
Signed-off-by: Maoyi Xie <maoyixie.tju@gmail.com>
---
I used an LLM to help write the harness and this patch.
sound/firewire/bebob/bebob.h | 2 +-
sound/firewire/bebob/bebob_command.c | 5 +++--
sound/firewire/bebob/bebob_stream.c | 11 +++++++++--
3 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/sound/firewire/bebob/bebob.h b/sound/firewire/bebob/bebob.h
index 41e019b9e24e..7891a5802f1a 100644
--- a/sound/firewire/bebob/bebob.h
+++ b/sound/firewire/bebob/bebob.h
@@ -194,7 +194,7 @@ avc_bridgeco_fill_msu_addr(u8 buf[AVC_BRIDGECO_ADDR_BYTES],
}
int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
u8 addr[AVC_BRIDGECO_ADDR_BYTES],
- u8 *buf, unsigned int len);
+ u8 *buf, unsigned int *len);
int avc_bridgeco_get_plug_type(struct fw_unit *unit,
u8 addr[AVC_BRIDGECO_ADDR_BYTES],
enum avc_bridgeco_plug_type *type);
diff --git a/sound/firewire/bebob/bebob_command.c b/sound/firewire/bebob/bebob_command.c
index 022df09c68ff..2e5a43e24615 100644
--- a/sound/firewire/bebob/bebob_command.c
+++ b/sound/firewire/bebob/bebob_command.c
@@ -181,14 +181,14 @@ end:
int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
u8 addr[AVC_BRIDGECO_ADDR_BYTES],
- u8 *buf, unsigned int len)
+ u8 *buf, unsigned int *len)
{
int err;
/* Info type is 'channel position'. */
avc_bridgeco_fill_plug_info_extension_command(buf, addr, 0x03);
- err = fcp_avc_transaction(unit, buf, 12, buf, 256,
+ err = fcp_avc_transaction(unit, buf, 12, buf, *len,
BIT(1) | BIT(2) | BIT(3) | BIT(4) |
BIT(5) | BIT(6) | BIT(7) | BIT(9));
if (err < 0)
@@ -206,6 +206,7 @@ int avc_bridgeco_get_plug_ch_pos(struct fw_unit *unit,
/* Pick up specific data. */
memmove(buf, buf + 10, err - 10);
+ *len = err - 10;
err = 0;
end:
return err;
diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
index 449cb17717f0..5850357cb3da 100644
--- a/sound/firewire/bebob/bebob_stream.c
+++ b/sound/firewire/bebob/bebob_stream.c
@@ -255,7 +255,7 @@ static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
{
unsigned int sec, sections, ch, channels;
unsigned int pcm, midi, location;
- unsigned int stm_pos, sec_loc, pos;
+ unsigned int stm_pos, sec_loc, pos, len;
u8 *buf, addr[AVC_BRIDGECO_ADDR_BYTES], type;
enum avc_bridgeco_plug_dir dir;
int err;
@@ -274,7 +274,8 @@ static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
dir = AVC_BRIDGECO_PLUG_DIR_IN;
avc_bridgeco_fill_unit_addr(addr, dir, AVC_BRIDGECO_PLUG_UNIT_ISOC, 0);
- err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, 256);
+ len = 256;
+ err = avc_bridgeco_get_plug_ch_pos(bebob->unit, addr, buf, &len);
if (err < 0) {
dev_err(&bebob->unit->device,
"fail to get channel position for isoc %s plug 0: %d\n",
@@ -311,6 +312,12 @@ static int map_data_channels(struct snd_bebob *bebob, struct amdtp_stream *s)
goto end;
}
+ /* this section should be within the response */
+ if (pos >= len || pos + 1 + buf[pos] * 2 > len) {
+ err = -EIO;
+ goto end;
+ }
+
/* the number of channels in this section */
channels = buf[pos++];
--
2.34.1
next prev parent reply other threads:[~2026-11-25 12:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 12:12 [PATCH 0/3] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie
2026-11-25 12:12 ` Maoyi Xie [this message]
2026-11-25 12:12 ` [PATCH 2/3] ALSA: bebob: bound the stream format entries " Maoyi Xie
2026-11-25 12:12 ` [PATCH 3/3] ALSA: oxfw: " Maoyi Xie
2026-11-28 7:09 ` Takashi Sakamoto
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=20261125121238.1602172-2-maoyixie.tju@gmail.com \
--to=maoyixie.tju@gmail.com \
--cc=clemens@ladisch.de \
--cc=linux-sound@vger.kernel.org \
--cc=o-takashi@sakamocchi.jp \
--cc=perex@perex.cz \
--cc=stable@vger.kernel.org \
--cc=tiwai@suse.com \
/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