* [PATCH 1/3] ALSA: bebob: bound the channel position walk to the response length
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
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
2 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25 12:12 UTC (permalink / raw)
To: Clemens Ladisch, Takashi Sakamoto
Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, stable
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
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] ALSA: oxfw: bound the stream format entries to the response length
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 ` [PATCH 1/3] ALSA: bebob: bound the channel position walk " Maoyi Xie
2026-11-25 12:12 ` [PATCH 2/3] ALSA: bebob: bound the stream format entries " Maoyi Xie
@ 2026-11-25 12:12 ` Maoyi Xie
2 siblings, 0 replies; 5+ messages in thread
From: Maoyi Xie @ 2026-11-25 12:12 UTC (permalink / raw)
To: Clemens Ladisch, Takashi Sakamoto
Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, stable
snd_oxfw_stream_parse_format() takes the number of two-byte entries of
a stream format from format[4] and never sees the length of the
response. A count of 254 or 255 can read past the 512-byte response
buffer. An accepted format is stored with the length of its response
and parsed again later. A count that needs more than that length reads
past the copy.
Check the length of a response against its entry count before the
format is parsed or stored. Formats other than AM824 compound still
reach the parser and get -ENXIO.
Found with a CodeQL-based static analysis tool. Reproduced in a
userspace harness under AddressSanitizer. Not tested on hardware.
Fixes: 5cd1d3f47a63 ("ALSA: oxfw: Change the way to make PCM rules/constraints")
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/oxfw/oxfw-stream.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 5e36d7153a7b..d8fe136369d8 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -484,6 +484,19 @@ void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw)
}
}
+/*
+ * A format of AM824 compound has five bytes, followed by two bytes for each of its entries.
+ * A response can be shorter than that. The parser rejects every other format before it reads
+ * an entry.
+ */
+static bool format_has_all_entries(const u8 *format, unsigned int len)
+{
+ if (len < 2 || format[0] != 0x90 || format[1] != 0x40)
+ return true;
+
+ return len >= 5 && len >= 5 + format[4] * 2;
+}
+
int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
enum avc_general_plug_dir dir,
struct snd_oxfw_stream_formation *formation)
@@ -501,7 +514,7 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
err = avc_stream_get_format_single(oxfw->unit, dir, 0, format, &len);
if (err >= 0) {
- if (len < 3)
+ if (len < 3 || !format_has_all_entries(format, len))
err = -EIO;
else
err = snd_oxfw_stream_parse_format(format, formation);
@@ -662,6 +675,11 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
*len = 7;
}
+ if (!format_has_all_entries(buf, *len)) {
+ err = -EIO;
+ goto end;
+ }
+
/* parse and set stream format */
eid = 0;
err = snd_oxfw_stream_parse_format(buf, &formation);
@@ -740,7 +758,7 @@ static int fill_stream_formats(struct snd_oxfw *oxfw,
/* LIST subfunction is implemented */
while (eid < SND_OXFW_STREAM_FORMAT_ENTRIES) {
/* The format is too short. */
- if (len < 3) {
+ if (len < 3 || !format_has_all_entries(buf, len)) {
err = -EIO;
break;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread