* [PATCH v4 1/3] ALSA: bebob: bound the channel position walk to the response length
2026-12-05 17:14 [PATCH v4 0/3] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie via B4 Relay
@ 2026-12-05 17:14 ` Maoyi Xie via B4 Relay
2026-12-05 17:14 ` [PATCH v4 2/3] ALSA: bebob: bound the stream format entries " Maoyi Xie via B4 Relay
2026-12-05 17:14 ` [PATCH v4 3/3] ALSA: oxfw: " Maoyi Xie via B4 Relay
2 siblings, 0 replies; 6+ messages in thread
From: Maoyi Xie via B4 Relay @ 2026-12-05 17:14 UTC (permalink / raw)
To: Takashi Sakamoto, Clemens Ladisch
Cc: Jaroslav Kysela, Takashi Iwai, Maoyi Xie, linux-sound
From: Maoyi Xie <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.
v4: No change.
---
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] 6+ messages in thread* [PATCH v4 2/3] ALSA: bebob: bound the stream format entries to the response length
2026-12-05 17:14 [PATCH v4 0/3] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie via B4 Relay
2026-12-05 17:14 ` [PATCH v4 1/3] ALSA: bebob: bound the channel position walk " Maoyi Xie via B4 Relay
@ 2026-12-05 17:14 ` Maoyi Xie via B4 Relay
2026-12-05 17:23 ` sashiko-bot
2026-12-05 17:14 ` [PATCH v4 3/3] ALSA: oxfw: " Maoyi Xie via B4 Relay
2 siblings, 1 reply; 6+ messages in thread
From: Maoyi Xie via B4 Relay @ 2026-12-05 17:14 UTC (permalink / raw)
To: Takashi Sakamoto, Clemens Ladisch
Cc: Jaroslav Kysela, Takashi Iwai, Maoyi Xie, linux-sound
From: Maoyi Xie <maoyixie.tju@gmail.com>
parse_stream_formation() takes the number of two-byte entries of a
stream format from buf[4]. It ignores its len argument. A count of 62
or more can read past the 128-byte buffer. A smaller count can still
read bytes that are not part of the response.
Return -EIO when the entries do not fit into the response.
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.
v4: No change.
---
sound/firewire/bebob/bebob_stream.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
index 5850357cb3da..8eceafc70a44 100644
--- a/sound/firewire/bebob/bebob_stream.c
+++ b/sound/firewire/bebob/bebob_stream.c
@@ -730,6 +730,10 @@ parse_stream_formation(u8 *buf, unsigned int len,
if (i == ARRAY_SIZE(bridgeco_freq_table))
return -ENOSYS;
+ /* The entries should be within the response. */
+ if (len < 5 || len < 5 + buf[4] * 2)
+ return -EIO;
+
/* Avoid double count by different entries for the same rate. */
memset(&formation[i], 0, sizeof(struct snd_bebob_stream_formation));
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 2/3] ALSA: bebob: bound the stream format entries to the response length
2026-12-05 17:14 ` [PATCH v4 2/3] ALSA: bebob: bound the stream format entries " Maoyi Xie via B4 Relay
@ 2026-12-05 17:23 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-05 17:23 UTC (permalink / raw)
To: Maoyi Xie; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] ALSA: bebob: parse_stream_formation() reads buf[0..2] before
checking len
--
commit d3d080432ed80d2e85b65474995acaba610e99c9
Author: Maoyi Xie <maoyixie.tju@gmail.com>
ALSA: bebob: bound the stream format entries to the response length
This commit adds a length check in parse_stream_formation() so that the
stream format entries counted by buf[4] are validated against len before
the parsing loop runs.
> diff --git a/sound/firewire/bebob/bebob_stream.c b/sound/firewire/bebob/bebob_stream.c
> index 5850357cb3dad..8eceafc70a447 100644
> --- a/sound/firewire/bebob/bebob_stream.c
> +++ b/sound/firewire/bebob/bebob_stream.c
> @@ -730,6 +730,10 @@ parse_stream_formation(u8 *buf, unsigned int len,
> if (i == ARRAY_SIZE(bridgeco_freq_table))
> return -ENOSYS;
>
> + /* The entries should be within the response. */
> + if (len < 5 || len < 5 + buf[4] * 2)
> + return -EIO;
[Severity: Medium]
Does parse_stream_formation() still read buf[0..2] before checking len?
avc_bridgeco_get_plug_strm_fmt() accepts FCP responses down to 12 bytes,
shifts the payload with memmove(buf, buf + 11, err - 11), and sets
*len = err - 11.
For a 12- or 13-byte response (len of 1 or 2), parse_stream_formation()
reads stale AV/C header bytes in buf[1] or buf[2] past len and returns
-ENOSYS instead of -EIO, making the new len < 5 check unreachable for
len <= 2.
Checking len < 5 before inspecting buf[0..2] would avoid reading past
len and return -EIO consistently for truncated responses.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-firewire-avc-bounds-v4-0-d90e91e0088e@gmail.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v4 3/3] ALSA: oxfw: bound the stream format entries to the response length
2026-12-05 17:14 [PATCH v4 0/3] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie via B4 Relay
2026-12-05 17:14 ` [PATCH v4 1/3] ALSA: bebob: bound the channel position walk " Maoyi Xie via B4 Relay
2026-12-05 17:14 ` [PATCH v4 2/3] ALSA: bebob: bound the stream format entries " Maoyi Xie via B4 Relay
@ 2026-12-05 17:14 ` Maoyi Xie via B4 Relay
2026-12-05 17:29 ` sashiko-bot
2 siblings, 1 reply; 6+ messages in thread
From: Maoyi Xie via B4 Relay @ 2026-12-05 17:14 UTC (permalink / raw)
To: Takashi Sakamoto, Clemens Ladisch
Cc: Jaroslav Kysela, Takashi Iwai, Maoyi Xie, linux-sound
From: Maoyi Xie <maoyixie.tju@gmail.com>
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 copied into a buffer of the response
length and parsed again later. A count that needs more than that length
reads past the copy.
Split the parser in two. check_and_parse_format() keeps the format
checks and returns -EIO when the entries do not fit into the response.
It parses each response from the unit, at discovery and in
snd_oxfw_stream_get_current_formation(). snd_oxfw_stream_parse_format()
only parses the cached formats, which passed these checks.
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")
Fixes: 3c96101f1900 ("ALSA: oxfw: Add proc interface for debugging purpose")
Suggested-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
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.
v4: Split the parser. This patch replaces patches 3 and 4 of v3.
snd_oxfw_stream_get_current_formation() still checks each new response
it reads from the unit, now with the length check too.
---
sound/firewire/oxfw/oxfw-stream.c | 47 ++++++++++++++++++++++++++++++++++-----
1 file changed, 42 insertions(+), 5 deletions(-)
diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 5e36d7153a7b..cc61ad1ee307 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -484,6 +484,9 @@ void snd_oxfw_stream_update_duplex(struct snd_oxfw *oxfw)
}
}
+static int check_and_parse_format(const u8 *format, unsigned int len,
+ struct snd_oxfw_stream_formation *formation);
+
int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
enum avc_general_plug_dir dir,
struct snd_oxfw_stream_formation *formation)
@@ -504,7 +507,7 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
if (len < 3)
err = -EIO;
else
- err = snd_oxfw_stream_parse_format(format, formation);
+ err = check_and_parse_format(format, len, formation);
}
kfree(format);
@@ -548,8 +551,8 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
* in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
* Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
*/
-int snd_oxfw_stream_parse_format(const u8 *format,
- struct snd_oxfw_stream_formation *formation)
+static int check_and_parse_format(const u8 *format, unsigned int len,
+ struct snd_oxfw_stream_formation *formation)
{
unsigned int i, e, channels, type;
@@ -563,6 +566,10 @@ int snd_oxfw_stream_parse_format(const u8 *format,
if ((format[0] != 0x90) || (format[1] != 0x40))
return -ENXIO;
+ /* The entries should be within the response. */
+ if (len < 5 || len < 5 + format[4] * 2)
+ return -EIO;
+
/* check the sampling rate */
for (i = 0; i < ARRAY_SIZE(avc_stream_rate_table); i++) {
if (format[2] == avc_stream_rate_table[i])
@@ -624,6 +631,36 @@ int snd_oxfw_stream_parse_format(const u8 *format,
return 0;
}
+/* The cached formats were checked by check_and_parse_format(). */
+int snd_oxfw_stream_parse_format(const u8 *format,
+ struct snd_oxfw_stream_formation *formation)
+{
+ unsigned int i, e, channels, type;
+
+ memset(formation, 0, sizeof(struct snd_oxfw_stream_formation));
+
+ for (i = 0; i < ARRAY_SIZE(avc_stream_rate_table); i++) {
+ if (format[2] == avc_stream_rate_table[i])
+ break;
+ }
+ if (i == ARRAY_SIZE(avc_stream_rate_table))
+ return -ENXIO;
+
+ formation->rate = oxfw_rate_table[i];
+
+ for (e = 0; e < format[4]; e++) {
+ channels = format[5 + e * 2];
+ type = format[6 + e * 2];
+
+ if (type == 0x00 || type == 0x06)
+ formation->pcm += channels;
+ else if (type == 0x0d)
+ formation->midi = channels;
+ }
+
+ return 0;
+}
+
static int
assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
unsigned int pid, u8 *buf, unsigned int *len,
@@ -664,7 +701,7 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
/* parse and set stream format */
eid = 0;
- err = snd_oxfw_stream_parse_format(buf, &formation);
+ err = check_and_parse_format(buf, *len, &formation);
if (err < 0)
goto end;
@@ -746,7 +783,7 @@ static int fill_stream_formats(struct snd_oxfw *oxfw,
}
/* parse and set stream format */
- err = snd_oxfw_stream_parse_format(buf, &dummy);
+ err = check_and_parse_format(buf, len, &dummy);
if (err < 0)
break;
--
2.34.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH v4 3/3] ALSA: oxfw: bound the stream format entries to the response length
2026-12-05 17:14 ` [PATCH v4 3/3] ALSA: oxfw: " Maoyi Xie via B4 Relay
@ 2026-12-05 17:29 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-05 17:29 UTC (permalink / raw)
To: Maoyi Xie; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] ALSA: oxfw: duplicate AM824 parsing logic in
check_and_parse_format()
--
commit 09d04fde4586e79a8721a40f8fc2146df6f65643
Author: Maoyi Xie <maoyixie.tju@gmail.com>
ALSA: oxfw: bound the stream format entries to the response length
This commit splits stream format parsing into check_and_parse_format(),
which checks that the two-byte format entries fit within the response
length for live responses, and snd_oxfw_stream_parse_format(), which
parses cached formats.
> diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
> index 5e36d7153a7b6..cc61ad1ee3071 100644
> --- a/sound/firewire/oxfw/oxfw-stream.c
> +++ b/sound/firewire/oxfw/oxfw-stream.c
[ ... ]
> @@ -548,8 +551,8 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw,
> * in AV/C Stream Format Information Specification 1.1 (Apr 2005, 1394TA)
> * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005
> */
> -int snd_oxfw_stream_parse_format(const u8 *format,
> - struct snd_oxfw_stream_formation *formation)
> +static int check_and_parse_format(const u8 *format, unsigned int len,
> + struct snd_oxfw_stream_formation *formation)
> {
> unsigned int i, e, channels, type;
>
> @@ -563,6 +566,10 @@ int snd_oxfw_stream_parse_format(const u8 *format,
> if ((format[0] != 0x90) || (format[1] != 0x40))
> return -ENXIO;
>
> + /* The entries should be within the response. */
> + if (len < 5 || len < 5 + format[4] * 2)
> + return -EIO;
> +
> /* check the sampling rate */
> for (i = 0; i < ARRAY_SIZE(avc_stream_rate_table); i++) {
> if (format[2] == avc_stream_rate_table[i])
> @@ -624,6 +631,36 @@ int snd_oxfw_stream_parse_format(const u8 *format,
> return 0;
> }
>
> +/* The cached formats were checked by check_and_parse_format(). */
> +int snd_oxfw_stream_parse_format(const u8 *format,
> + struct snd_oxfw_stream_formation *formation)
> +{
> + unsigned int i, e, channels, type;
> +
> + memset(formation, 0, sizeof(struct snd_oxfw_stream_formation));
> +
> + for (i = 0; i < ARRAY_SIZE(avc_stream_rate_table); i++) {
> + if (format[2] == avc_stream_rate_table[i])
> + break;
> + }
> + if (i == ARRAY_SIZE(avc_stream_rate_table))
> + return -ENXIO;
> +
> + formation->rate = oxfw_rate_table[i];
> +
> + for (e = 0; e < format[4]; e++) {
> + channels = format[5 + e * 2];
> + type = format[6 + e * 2];
> +
> + if (type == 0x00 || type == 0x06)
> + formation->pcm += channels;
> + else if (type == 0x0d)
> + formation->midi = channels;
> + }
> +
> + return 0;
> +}
[Severity: Low]
Does snd_oxfw_stream_parse_format() need to duplicate the memset(),
avc_stream_rate_table lookup, and format[4] entry loop from
check_and_parse_format()? Keeping two copies of the parser in the same
file risks divergence between live and cached format parsing and adds
churn to a stable-tagged fix.
Instead, check_and_parse_format() could just validate format[0..1] and
len, then delegate directly to the existing
snd_oxfw_stream_parse_format().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-firewire-avc-bounds-v4-0-d90e91e0088e@gmail.com?part=3
^ permalink raw reply [flat|nested] 6+ messages in thread