From: Takashi Sakamoto <o-takashi@sakamocchi.jp>
To: Maoyi Xie <maoyixie.tju@gmail.com>
Cc: Clemens Ladisch <clemens@ladisch.de>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
linux-sound@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 3/3] ALSA: oxfw: bound the stream format entries to the response length
Date: Sat, 28 Nov 2026 16:09:06 +0900 [thread overview]
Message-ID: <20261128070906.GA47735@sakamocchi.jp> (raw)
In-Reply-To: <20261125121238.1602172-4-maoyixie.tju@gmail.com>
Hi,
Thank you for suggesting the change. I think the changes in the other two
patches are good, however for this patch I have a concern about adding the
new function.
On Wed, Nov 25, 2026 at 08:12:38PM +0800, Maoyi Xie wrote:
> 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)
Could we perform the length check in snd_oxfw_stream_parse_format() instead
of inserting format_has_all_entries()? The former is called immediately
after the latter with your patch.
> @@ -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
Thanks
Takashi Sakamoto
prev parent reply other threads:[~2026-11-28 7:09 UTC|newest]
Thread overview: 6+ 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 ` [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:20 ` sashiko-bot
2026-11-25 12:12 ` [PATCH 3/3] ALSA: oxfw: " Maoyi Xie
2026-11-28 7:09 ` Takashi Sakamoto [this message]
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=20261128070906.GA47735@sakamocchi.jp \
--to=o-takashi@sakamocchi.jp \
--cc=clemens@ladisch.de \
--cc=linux-sound@vger.kernel.org \
--cc=maoyixie.tju@gmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.