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 v3 3/4] ALSA: oxfw: bound the stream format entries to the response length
Date: Wed, 2 Dec 2026 15:04:51 +0800 [thread overview]
Message-ID: <20261202070452.732525-4-maoyixie.tju@gmail.com> (raw)
In-Reply-To: <20261202070452.732525-1-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.
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
next prev parent reply other threads:[~2026-12-02 7:05 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Maoyi Xie [this message]
2026-12-02 7:04 ` [PATCH v3 4/4] ALSA: oxfw: bound the current " Maoyi Xie
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=20261202070452.732525-4-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