Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v3 0/4] ALSA: bebob/oxfw: bound AV/C response walks to the response length
@ 2026-12-02  7:04 Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 1/4] ALSA: bebob: bound the channel position walk " Maoyi Xie
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Maoyi Xie @ 2026-12-02  7:04 UTC (permalink / raw)
  To: Clemens Ladisch, Takashi Sakamoto
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, stable

The BeBoB and OXFW drivers walk three AV/C responses by counts that the
device puts into the response. None of the walks is checked against the
length of the response. A count that is too large reads past the
response buffer, or later past a stored copy of the format.

Each patch rejects such a response with -EIO. A complete response is
handled as before. The formats in the Griffin FireWave dump at [1] pass
the new check. I found no such dump of a BeBoB device.

Found with a CodeQL-based static analysis tool that we are developing.
Each case was reproduced in a userspace harness under AddressSanitizer.
Not tested on hardware. Compile-tested with W=1 on next-20261116.

I used an LLM to help write the harnesses and these patches.

Changes in v3:
- Patch 3 checks the entries at discovery, as Takashi Sakamoto
  suggested. It no longer checks the cached formats or stores their
  lengths.
- Patch 4 is new and checks the response that
  snd_oxfw_stream_get_current_formation() reads.
- Patches 1 and 2 are unchanged.

Changes in v2:
- Patch 3 checks the length in snd_oxfw_stream_parse_format() instead of
  a new function, as Takashi Sakamoto suggested. The stored formats keep
  their length for the later calls.
- Patches 1 and 2 are unchanged.

v2: https://lore.kernel.org/all/20261130104949.2216908-1-maoyixie.tju@gmail.com/
v1: https://lore.kernel.org/all/20261125121238.1602172-1-maoyixie.tju@gmail.com/

[1] https://lore.kernel.org/all/543FD6AA.5080004@sakamocchi.jp/

Maoyi Xie (4):
  ALSA: bebob: bound the channel position walk to the response length
  ALSA: bebob: bound the stream format entries to the response length
  ALSA: oxfw: bound the stream format entries to the response length
  ALSA: oxfw: bound the current format entries to the response length

 sound/firewire/bebob/bebob.h         |  2 +-
 sound/firewire/bebob/bebob_command.c |  5 +++--
 sound/firewire/bebob/bebob_stream.c  | 15 +++++++++++++--
 sound/firewire/oxfw/oxfw-stream.c    | 16 +++++++++++++++-
 4 files changed, 32 insertions(+), 6 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/4] ALSA: bebob: bound the channel position walk to the response length
  2026-12-02  7:04 [PATCH v3 0/4] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie
@ 2026-12-02  7:04 ` Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 2/4] ALSA: bebob: bound the stream format entries " Maoyi Xie
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Maoyi Xie @ 2026-12-02  7:04 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.

v3: No change.
v2: 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 v3 2/4] ALSA: bebob: bound the stream format entries to the response length
  2026-12-02  7:04 [PATCH v3 0/4] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 1/4] ALSA: bebob: bound the channel position walk " Maoyi Xie
@ 2026-12-02  7:04 ` Maoyi Xie
  2026-12-02  7:15   ` sashiko-bot
  2026-12-02  7:04 ` [PATCH v3 3/4] ALSA: oxfw: " Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 4/4] ALSA: oxfw: bound the current " Maoyi Xie
  3 siblings, 1 reply; 6+ messages in thread
From: Maoyi Xie @ 2026-12-02  7:04 UTC (permalink / raw)
  To: Clemens Ladisch, Takashi Sakamoto
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, stable

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.

v3: No change.
v2: 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

* [PATCH v3 3/4] ALSA: oxfw: bound the stream format entries to the response length
  2026-12-02  7:04 [PATCH v3 0/4] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 1/4] ALSA: bebob: bound the channel position walk " Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 2/4] ALSA: bebob: bound the stream format entries " Maoyi Xie
@ 2026-12-02  7:04 ` Maoyi Xie
  2026-12-02  7:04 ` [PATCH v3 4/4] ALSA: oxfw: bound the current " Maoyi Xie
  3 siblings, 0 replies; 6+ messages in thread
From: Maoyi Xie @ 2026-12-02  7:04 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 copied into a buffer of the response
length and parsed again later. A count that needs more than that length
reads past the copy.

Check the entries of an AM824 compound format against the response
length at discovery, before the format is parsed and cached. The cached
formats need no later check.

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")
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.

v3: Check at discovery and drop the stored lengths (Takashi Sakamoto).
v2: Move the check into snd_oxfw_stream_parse_format()
    (Takashi Sakamoto).

 sound/firewire/oxfw/oxfw-stream.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 5e36d7153a7b..858f4b8a4656 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -662,6 +662,13 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir,
 		*len = 7;
 	}
 
+	/* The entries of AM824 compound should be within the response. */
+	if (buf[0] == 0x90 && buf[1] == 0x40 &&
+	    (*len < 5 || *len < 5 + buf[4] * 2)) {
+		err = -EIO;
+		goto end;
+	}
+
 	/* parse and set stream format */
 	eid = 0;
 	err = snd_oxfw_stream_parse_format(buf, &formation);
@@ -745,6 +752,13 @@ static int fill_stream_formats(struct snd_oxfw *oxfw,
 			break;
 		}
 
+		/* The entries of AM824 compound should be within the response. */
+		if (buf[0] == 0x90 && buf[1] == 0x40 &&
+		    (len < 5 || len < 5 + buf[4] * 2)) {
+			err = -EIO;
+			break;
+		}
+
 		/* parse and set stream format */
 		err = snd_oxfw_stream_parse_format(buf, &dummy);
 		if (err < 0)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 4/4] ALSA: oxfw: bound the current format entries to the response length
  2026-12-02  7:04 [PATCH v3 0/4] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie
                   ` (2 preceding siblings ...)
  2026-12-02  7:04 ` [PATCH v3 3/4] ALSA: oxfw: " Maoyi Xie
@ 2026-12-02  7:04 ` Maoyi Xie
  3 siblings, 0 replies; 6+ messages in thread
From: Maoyi Xie @ 2026-12-02  7:04 UTC (permalink / raw)
  To: Clemens Ladisch, Takashi Sakamoto
  Cc: Jaroslav Kysela, Takashi Iwai, linux-sound, stable

snd_oxfw_stream_get_current_formation() reads the current format from
the unit into a new 512-byte buffer and parses it. A count of 254 or
255 in format[4] can read past that buffer. This response is not
cached, so the check at discovery does not cover it.

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: 3c96101f1900 ("ALSA: oxfw: Add proc interface for debugging purpose")
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.

v3: New.

 sound/firewire/oxfw/oxfw-stream.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c
index 858f4b8a4656..40f0267cd1d6 100644
--- a/sound/firewire/oxfw/oxfw-stream.c
+++ b/sound/firewire/oxfw/oxfw-stream.c
@@ -501,7 +501,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 < 5 || len < 5 + format[4] * 2)
 				err = -EIO;
 			else
 				err = snd_oxfw_stream_parse_format(format, formation);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 2/4] ALSA: bebob: bound the stream format entries to the response length
  2026-12-02  7:04 ` [PATCH v3 2/4] ALSA: bebob: bound the stream format entries " Maoyi Xie
@ 2026-12-02  7:15   ` sashiko-bot
  0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-12-02  7:15 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 fdc1d8bd20b16e5b19616e6a041bb9876894ff4c
Author: Maoyi Xie <maoyixie.tju@gmail.com>

ALSA: bebob: bound the stream format entries to the response length

This commit checks that the stream format entry count in buf[4] fits
within the response length in parse_stream_formation().

> 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]
Should the length check come at the start of parse_stream_formation(),
before buf[0], buf[1], and buf[2] are read?

avc_bridgeco_get_plug_strm_fmt() accepts FCP responses of 12 bytes or
more and shifts err - 11 bytes to the start of buf, so len can be 1..4.
Because parse_stream_formation() checks buf[0..2] first:

sound/firewire/bebob/bebob_stream.c:parse_stream_formation() {
    ...
	if ((buf[0] != 0x90) || (buf[1] != 0x40))
		return -ENOSYS;

	/* check sampling rate */
	for (i = 0; i < ARRAY_SIZE(bridgeco_freq_table); i++) {
		if (buf[2] == bridgeco_freq_table[i])
			break;
	}
    ...
}

when len is 1 or 2, reading buf[1] and buf[2] accesses bytes past the
response length (stale FCP request header bytes in
fill_stream_formations(), or out of bounds if a caller passes a buffer
sized to len) and returns -ENOSYS instead of -EIO.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202070452.732525-1-maoyixie.tju@gmail.com?part=2

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-02  7:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  7:04 [PATCH v3 0/4] ALSA: bebob/oxfw: bound AV/C response walks to the response length Maoyi Xie
2026-12-02  7:04 ` [PATCH v3 1/4] ALSA: bebob: bound the channel position walk " Maoyi Xie
2026-12-02  7:04 ` [PATCH v3 2/4] ALSA: bebob: bound the stream format entries " Maoyi Xie
2026-12-02  7:15   ` sashiko-bot
2026-12-02  7:04 ` [PATCH v3 3/4] ALSA: oxfw: " Maoyi Xie
2026-12-02  7:04 ` [PATCH v3 4/4] ALSA: oxfw: bound the current " Maoyi Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox