From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.147 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796132639; b=uuXgpunIFZO9FkthkkqcB0PWiaG5YN7V6ORzqfNwj083xCwRoIQ360NTJ04YONFHYpsk z+rx6pi96ON2H3GF7N0hr63kDf8bXL1V9Do+qBq7QqXqhMk2DUboATmam6PsY+whjU49l 5LMcT7iT8ggsYtGdDU8S3s8Mv5I7xkjKqVWQAsDiluqi5RPjWuL94RW1L1r1FrZs13hRc /6AIaO3wpvnOyJtsThR341htxbJ5JNzfrB6k2DNSJw59HR+jbRr97WNMlUqgjClT7D6M/ IrkUTUs8v/rQj01D9hhZ5aAaPYgl3bdZJ1wyX49zJfnPUVOR4/A3n0g6fV6UG3anuog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796132639; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; bh=VqGUBNTT+bWWDLV/OJf4cFGpZSuiYazSH1Si5ygGgrE=; b=gS5azsQI1vmpXJSseE9U6MiQ9hyPEIedHgKQ9YIpeAo+a4BJpjFzHTL4+eE9Ue5mU32U 4C2BTqxqTk9YUZF2RHvsPcnbX4IOdH/NCWuuU3LXTdXL1QIoqpwwYyO+yKEX5TQ3LFkfJ 7hq6KvoJ2cuc7eyrVC3QUg0UYn5OUSoaWiIXJxiAwI0wKpGo8DcsVH+VUL1zUC8XCi3XA OVtIxeLmcR4BTNqbBO4CVTB0ot2gfSmIS55xv2apt075mMqbubFu1sh5wbhmbfVVgfGrd ccS92bx6abJwCYDJ4ZD0BGdYeCHICIg7OHPPTUYRgSHjskNvfNDeIJJ1lD+xpOdJtJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=sakamocchi.jp; spf=pass smtp.mailfrom=sakamocchi.jp; dkim=pass header.d=sakamocchi.jp header.i=@sakamocchi.jp header.a=rsa-sha256 header.s=fm3 header.b=UMDvF7VH; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=jkl6nblA; arc=none smtp.remote-ip=202.12.124.147 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DC46606A32E for ; Tue, 1 Dec 2026 13:43:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2DC46606A32E Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sakamocchi.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=sakamocchi.jp header.i=@sakamocchi.jp header.a=rsa-sha256 header.s=fm3 header.b=UMDvF7VH; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=jkl6nblA Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.stl.internal (Postfix) with ESMTP id 847CE1D005B1 for ; Tue, 1 Dec 2026 08:43:53 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 01 Dec 2026 08:43:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sakamocchi.jp; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1796132632; x= 1796219032; bh=VqGUBNTT+bWWDLV/OJf4cFGpZSuiYazSH1Si5ygGgrE=; b=U MDvF7VHEPG9bx5bNcCLuswxxWaa2g5W45XgSw8UaTCHLCK+D5NzUgRB2+KjCFu52 /wJboDa35kKTWjJthjVCi7I5xDNj2tWztqltlW067DOhuKSO/yGSw0fqOrfnH+Tc NtQvHFp0NyjT1/PTnYPdqyV2+sa0+e90efVsW5HSz6f2lQCD9K8e8Qyi833Oiocx SJXdMD9zC7YsEe4dalHCb5+q9L8j08hDNhm5JEz+1RACksqh8Dudp6FXNe/rh1pe uPiO/TYsabDmqYgeHbM8pKUwh5SqlmTkDM3T+TnNa7JIdTH/QN3b3MVcegEzzZbp bXvl7BIiQO2b3RxGPu5Jw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1796132632; x=1796219032; bh=VqGUBNTT+bWWDLV/OJf4cFGpZSuiYazSH1S i5ygGgrE=; b=jkl6nblAne7Sx6TJHeMxhrELd8mNw/Dp3oOc5JjtHljIhmcNk3E oOEjjuOoI9KF2iQGtf+VYAdkYmpZULQWalCL9W0HHhD+Q4vo2tscAPSiSkbWn/Be eZ2VRciV876WjBmhdaVtpm8NLqnw5W9IXcjkqVCdPedXP2UYSYEbLLz512D1yNF+ Avac/jG/wxipVkRnXe9fA2jtABwBIjDBCUvRCwKgh4n4UiH6NPXj/8hXnbnwj3BX 7hMSRl/oaEV7z85SJxuAEJpbTQNR3/XN3eQ1A7hBkgFH19BFbmtroMt+y9pfVoB/ 1u+xqK7B72dWLWeNEcsV4gN8fjMakiEAUmw== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=sakamocchi.jp a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796132632; d=sakamocchi.jp; mf=PG8tdGFrYXNoaUBzYWthbW9jY2hpLmpwPg==; rt=PHN0YWJsZUB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:DZjeyRkzoAiG8lnVNYwFybEGfzwkSN77our1Pubhi72Ob9F EoVV+OURvz0socETKAT8zy7asAdizSIYMa02rnqCwqIeeW+GPdkJA8aPvnHPRQx9 fnHFT+tdNtGlV6qpr1DzqueLMXhd614sFKPV+Xg64L1lJ2jIqfsg+/qEShn6jyTU 2gHYlNX4DvotkxgD+4wfrPMGd+hlFRCK5OjL5dwG7RMBy+uT5PEPMmeJy378w1tX v+jFpJz3lWP647lhNKmV9PwvUs5qtlO99RiJ59lgshiChf5vFBnr/3v8m/FfY04n /i1P//srlKrvLeL+HiI09Xl2W1fkNU/atPcPRog==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:EiPxeY4gm2ZSGLX/bYblTLaLLa5f1E5+Bk+Jl8/4k2E=:HDjtR4Gzo9AwjEGs/cDzTyD0lqMURg+T9lv7UbcZsJU=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEDmSiS+AyeAdTu0vcSmz3D3Ajq9MSBTGDYcNxpWpqESp8KMAbmZPx2Yb3McUIDHE 5z/FiJBBcGm4gfuBWSx4tDhdbI9BEGSa33Bvf7kh43ZyJpep/RAJula79Kan90E0fXtv1a sOPyPnfcw+9cg9upeMrLD3Z03+f9M2pU2ZviPeIQkcXZ+O/nC7xXdIKMRRBEnQa37XTYDt fKOsvBTop+PCSji8mkLcmn5EIENjF7Bky8MPeheXjyCtepVGSDHD6CVcmacD3R+m4h77GB tHczSvrd1Gxlk6FxS4xrOA3BUC8gp51iStx2fBNBYm+VNty/IgaABvp/DtuYp/4dIbqFhA lDMHHicJhHvIN1nLvFBT8At/VHcTWiIKLULGH7Ycp1f3gyGkawY6eG0m1rc+huM93Ho8dt 67L95VFARr1m/ZtK5+x+SUt1Z750agaB4NiKetGNJro6cZD5u3ZvpPoftADf4OskiklWpW o66LSKQiGOY2M0g1jVdMiRgBMH9KYJUscbPqh7VPq+Gs0q2ma0IB+jqIVuPH1swTLim8ah Bzzz5v2rfn7b7cFBH6KHsUy31pgf2/aaaWYhP+nXagsJ7kD/o1HH7Ao7kF4T0vNpCgGZKE Lq46XZocBf30UMkahRtm4iuAZVZPerlSTF3uSHq6rI6/k6j4BGpKzCSjbcFA X-ME-Proxy: Feedback-ID: ie8e14432:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 1 Dec 2026 08:43:50 -0500 (EST) Date: Tue, 1 Dec 2026 22:43:47 +0900 From: Takashi Sakamoto To: Maoyi Xie Cc: Clemens Ladisch , Jaroslav Kysela , Takashi Iwai , linux-sound@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 3/3] ALSA: oxfw: bound the stream format entries to the response length Message-ID: <20261201134347.GA340563@sakamocchi.jp> References: <20261130104949.2216908-1-maoyixie.tju@gmail.com> <20261130104949.2216908-4-maoyixie.tju@gmail.com> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130104949.2216908-4-maoyixie.tju@gmail.com> Hi, Thank you for revising the patch. However, it is no need to validate the stream formats again once they are checked and cached. Validation is only required along the call graph from snd_oxfw_stream_discover() and serves no purpose elsewhere. There is also no need to store the length of the stream formats in the structure. Thanks Takashi Sakamoto On Mon, Nov 30, 2026 at 06:49:49PM +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 copied into a buffer of the response > length and parsed again later. A count that needs more than that length > reads past the copy. > > Pass the length to snd_oxfw_stream_parse_format() and return -EIO when > the entries do not fit. Keep the length of each copy for the later > calls. Formats other than AM824 compound still 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") > Suggested-by: Takashi Sakamoto > Cc: stable@vger.kernel.org > Signed-off-by: Maoyi Xie > --- > I used an LLM to help write the harness and this patch. > > v2: Move the check into snd_oxfw_stream_parse_format() (Takashi Sakamoto). > > sound/firewire/oxfw/oxfw-pcm.c | 44 ++++++++++++++++++++++------ > sound/firewire/oxfw/oxfw-proc.c | 6 ++-- > sound/firewire/oxfw/oxfw-stream.c | 48 +++++++++++++++++++++++-------- > sound/firewire/oxfw/oxfw.h | 3 ++ > 4 files changed, 78 insertions(+), 23 deletions(-) > > diff --git a/sound/firewire/oxfw/oxfw-pcm.c b/sound/firewire/oxfw/oxfw-pcm.c > index 774b8a763795..4b8417ba1227 100644 > --- a/sound/firewire/oxfw/oxfw-pcm.c > +++ b/sound/firewire/oxfw/oxfw-pcm.c > @@ -10,7 +10,10 @@ > static int hw_rule_rate(struct snd_pcm_hw_params *params, > struct snd_pcm_hw_rule *rule) > { > - u8 **formats = rule->private; > + struct snd_pcm_substream *substream = rule->private; > + struct snd_oxfw *oxfw = substream->private_data; > + u8 **formats; > + const unsigned int *lens; > struct snd_interval *r = > hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); > const struct snd_interval *c = > @@ -21,11 +24,19 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params, > struct snd_oxfw_stream_formation formation; > int i, err; > > + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { > + formats = oxfw->tx_stream_formats; > + lens = oxfw->tx_stream_format_lens; > + } else { > + formats = oxfw->rx_stream_formats; > + lens = oxfw->rx_stream_format_lens; > + } > + > for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { > if (formats[i] == NULL) > continue; > > - err = snd_oxfw_stream_parse_format(formats[i], &formation); > + err = snd_oxfw_stream_parse_format(formats[i], lens[i], &formation); > if (err < 0) > continue; > if (!snd_interval_test(c, formation.pcm)) > @@ -41,7 +52,10 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params, > static int hw_rule_channels(struct snd_pcm_hw_params *params, > struct snd_pcm_hw_rule *rule) > { > - u8 **formats = rule->private; > + struct snd_pcm_substream *substream = rule->private; > + struct snd_oxfw *oxfw = substream->private_data; > + u8 **formats; > + const unsigned int *lens; > struct snd_interval *c = > hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); > const struct snd_interval *r = > @@ -50,12 +64,20 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params, > int i, j, err; > unsigned int count, list[SND_OXFW_STREAM_FORMAT_ENTRIES] = {0}; > > + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) { > + formats = oxfw->tx_stream_formats; > + lens = oxfw->tx_stream_format_lens; > + } else { > + formats = oxfw->rx_stream_formats; > + lens = oxfw->rx_stream_format_lens; > + } > + > count = 0; > for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { > if (formats[i] == NULL) > break; > > - err = snd_oxfw_stream_parse_format(formats[i], &formation); > + err = snd_oxfw_stream_parse_format(formats[i], lens[i], &formation); > if (err < 0) > continue; > if (!snd_interval_test(r, formation.rate)) > @@ -77,7 +99,8 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params, > return snd_interval_list(c, count, list, 0); > } > > -static void limit_channels_and_rates(struct snd_pcm_hardware *hw, u8 **formats) > +static void limit_channels_and_rates(struct snd_pcm_hardware *hw, u8 **formats, > + const unsigned int *lens) > { > struct snd_oxfw_stream_formation formation; > int i, err; > @@ -93,7 +116,7 @@ static void limit_channels_and_rates(struct snd_pcm_hardware *hw, u8 **formats) > if (formats[i] == NULL) > break; > > - err = snd_oxfw_stream_parse_format(formats[i], &formation); > + err = snd_oxfw_stream_parse_format(formats[i], lens[i], &formation); > if (err < 0) > continue; > > @@ -111,6 +134,7 @@ static int init_hw_params(struct snd_oxfw *oxfw, > { > struct snd_pcm_runtime *runtime = substream->runtime; > u8 **formats; > + const unsigned int *lens; > struct amdtp_stream *stream; > int err; > > @@ -118,22 +142,24 @@ static int init_hw_params(struct snd_oxfw *oxfw, > runtime->hw.formats = AM824_IN_PCM_FORMAT_BITS; > stream = &oxfw->tx_stream; > formats = oxfw->tx_stream_formats; > + lens = oxfw->tx_stream_format_lens; > } else { > runtime->hw.formats = AM824_OUT_PCM_FORMAT_BITS; > stream = &oxfw->rx_stream; > formats = oxfw->rx_stream_formats; > + lens = oxfw->rx_stream_format_lens; > } > > - limit_channels_and_rates(&runtime->hw, formats); > + limit_channels_and_rates(&runtime->hw, formats, lens); > > err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, > - hw_rule_channels, formats, > + hw_rule_channels, substream, > SNDRV_PCM_HW_PARAM_RATE, -1); > if (err < 0) > goto end; > > err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, > - hw_rule_rate, formats, > + hw_rule_rate, substream, > SNDRV_PCM_HW_PARAM_CHANNELS, -1); > if (err < 0) > goto end; > diff --git a/sound/firewire/oxfw/oxfw-proc.c b/sound/firewire/oxfw/oxfw-proc.c > index 260c60364f39..bcae6299ceca 100644 > --- a/sound/firewire/oxfw/oxfw-proc.c > +++ b/sound/firewire/oxfw/oxfw-proc.c > @@ -30,7 +30,8 @@ static void proc_read_formation(struct snd_info_entry *entry, > if (format == NULL) > continue; > > - err = snd_oxfw_stream_parse_format(format, &formation); > + err = snd_oxfw_stream_parse_format(format, oxfw->rx_stream_format_lens[i], > + &formation); > if (err < 0) > continue; > > @@ -60,7 +61,8 @@ static void proc_read_formation(struct snd_info_entry *entry, > if (format == NULL) > continue; > > - err = snd_oxfw_stream_parse_format(format, &formation); > + err = snd_oxfw_stream_parse_format(format, oxfw->tx_stream_format_lens[i], > + &formation); > if (err < 0) > continue; > > diff --git a/sound/firewire/oxfw/oxfw-stream.c b/sound/firewire/oxfw/oxfw-stream.c > index 5e36d7153a7b..034bdaae09df 100644 > --- a/sound/firewire/oxfw/oxfw-stream.c > +++ b/sound/firewire/oxfw/oxfw-stream.c > @@ -58,6 +58,7 @@ static int set_stream_format(struct snd_oxfw *oxfw, struct amdtp_stream *s, > unsigned int rate, unsigned int pcm_channels) > { > u8 **formats; > + const unsigned int *lens; > struct snd_oxfw_stream_formation formation; > enum avc_general_plug_dir dir; > unsigned int len; > @@ -65,15 +66,17 @@ static int set_stream_format(struct snd_oxfw *oxfw, struct amdtp_stream *s, > > if (s == &oxfw->tx_stream) { > formats = oxfw->tx_stream_formats; > + lens = oxfw->tx_stream_format_lens; > dir = AVC_GENERAL_PLUG_DIR_OUT; > } else { > formats = oxfw->rx_stream_formats; > + lens = oxfw->rx_stream_format_lens; > dir = AVC_GENERAL_PLUG_DIR_IN; > } > > /* Seek stream format for requirements. */ > for (i = 0; i < SND_OXFW_STREAM_FORMAT_ENTRIES; i++) { > - err = snd_oxfw_stream_parse_format(formats[i], &formation); > + err = snd_oxfw_stream_parse_format(formats[i], lens[i], &formation); > if (err < 0) > return err; > > @@ -202,6 +205,7 @@ static int keep_resources(struct snd_oxfw *oxfw, struct amdtp_stream *stream) > { > enum avc_general_plug_dir dir; > u8 **formats; > + const unsigned int *lens; > struct snd_oxfw_stream_formation formation; > struct cmp_connection *conn; > int i; > @@ -210,10 +214,12 @@ static int keep_resources(struct snd_oxfw *oxfw, struct amdtp_stream *stream) > if (stream == &oxfw->rx_stream) { > dir = AVC_GENERAL_PLUG_DIR_IN; > formats = oxfw->rx_stream_formats; > + lens = oxfw->rx_stream_format_lens; > conn = &oxfw->in_conn; > } else { > dir = AVC_GENERAL_PLUG_DIR_OUT; > formats = oxfw->tx_stream_formats; > + lens = oxfw->tx_stream_format_lens; > conn = &oxfw->out_conn; > } > > @@ -227,7 +233,7 @@ static int keep_resources(struct snd_oxfw *oxfw, struct amdtp_stream *stream) > if (formats[i] == NULL) > break; > > - err = snd_oxfw_stream_parse_format(formats[i], &fmt); > + err = snd_oxfw_stream_parse_format(formats[i], lens[i], &fmt); > if (err < 0) > return err; > > @@ -504,7 +510,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 = snd_oxfw_stream_parse_format(format, len, formation); > } > > kfree(format); > @@ -513,22 +519,26 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw, > // command. Use the duplicated hard-coded format, instead. > unsigned int rate; > u8 *const *formats; > + const unsigned int *lens; > int i; > > err = avc_general_get_sig_fmt(oxfw->unit, &rate, dir, 0); > if (err < 0) > return err; > > - if (dir == AVC_GENERAL_PLUG_DIR_IN) > + if (dir == AVC_GENERAL_PLUG_DIR_IN) { > formats = oxfw->rx_stream_formats; > - else > + lens = oxfw->rx_stream_format_lens; > + } else { > formats = oxfw->tx_stream_formats; > + lens = oxfw->tx_stream_format_lens; > + } > > for (i = 0; (i < SND_OXFW_STREAM_FORMAT_ENTRIES); ++i) { > if (!formats[i]) > continue; > > - err = snd_oxfw_stream_parse_format(formats[i], formation); > + err = snd_oxfw_stream_parse_format(formats[i], lens[i], formation); > if (err < 0) > continue; > > @@ -549,6 +559,7 @@ int snd_oxfw_stream_get_current_formation(struct snd_oxfw *oxfw, > * Also 'Clause 12 AM824 sequence adaption layers' in IEC 61883-6:2005 > */ > int snd_oxfw_stream_parse_format(const u8 *format, > + unsigned int len, > struct snd_oxfw_stream_formation *formation) > { > unsigned int i, e, channels, type; > @@ -563,6 +574,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]) > @@ -627,7 +642,7 @@ int snd_oxfw_stream_parse_format(const u8 *format, > static int > assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir, > unsigned int pid, u8 *buf, unsigned int *len, > - u8 **formats) > + u8 **formats, unsigned int *lens) > { > struct snd_oxfw_stream_formation formation; > unsigned int i, eid; > @@ -664,7 +679,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 = snd_oxfw_stream_parse_format(buf, *len, &formation); > if (err < 0) > goto end; > > @@ -674,6 +689,7 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir, > err = -ENOMEM; > goto end; > } > + lens[eid] = *len; > > /* apply the format for each available sampling rate */ > for (i = 0; i < ARRAY_SIZE(oxfw_rate_table); i++) { > @@ -693,6 +709,7 @@ assume_stream_formats(struct snd_oxfw *oxfw, enum avc_general_plug_dir dir, > err = -ENOMEM; > goto end; > } > + lens[eid] = *len; > formats[eid][2] = avc_stream_rate_table[i]; > } > > @@ -707,6 +724,7 @@ static int fill_stream_formats(struct snd_oxfw *oxfw, > unsigned short pid) > { > u8 *buf, **formats; > + unsigned int *lens; > unsigned int len, eid = 0; > struct snd_oxfw_stream_formation dummy; > int err; > @@ -715,10 +733,13 @@ static int fill_stream_formats(struct snd_oxfw *oxfw, > if (buf == NULL) > return -ENOMEM; > > - if (dir == AVC_GENERAL_PLUG_DIR_OUT) > + if (dir == AVC_GENERAL_PLUG_DIR_OUT) { > formats = oxfw->tx_stream_formats; > - else > + lens = oxfw->tx_stream_format_lens; > + } else { > formats = oxfw->rx_stream_formats; > + lens = oxfw->rx_stream_format_lens; > + } > > /* get first entry */ > len = AVC_GENERIC_FRAME_MAXIMUM_BYTES; > @@ -727,7 +748,7 @@ static int fill_stream_formats(struct snd_oxfw *oxfw, > /* LIST subfunction is not implemented */ > len = AVC_GENERIC_FRAME_MAXIMUM_BYTES; > err = assume_stream_formats(oxfw, dir, pid, buf, &len, > - formats); > + formats, lens); > goto end; > } else if (err < 0) { > dev_err(&oxfw->unit->device, > @@ -746,7 +767,7 @@ static int fill_stream_formats(struct snd_oxfw *oxfw, > } > > /* parse and set stream format */ > - err = snd_oxfw_stream_parse_format(buf, &dummy); > + err = snd_oxfw_stream_parse_format(buf, len, &dummy); > if (err < 0) > break; > > @@ -756,6 +777,7 @@ static int fill_stream_formats(struct snd_oxfw *oxfw, > err = -ENOMEM; > break; > } > + lens[eid] = len; > > /* get next entry */ > len = AVC_GENERIC_FRAME_MAXIMUM_BYTES; > @@ -814,6 +836,7 @@ int snd_oxfw_stream_discover(struct snd_oxfw *oxfw) > if (format == NULL) > continue; > err = snd_oxfw_stream_parse_format(format, > + oxfw->tx_stream_format_lens[i], > &formation); > if (err < 0) > continue; > @@ -842,6 +865,7 @@ int snd_oxfw_stream_discover(struct snd_oxfw *oxfw) > if (format == NULL) > continue; > err = snd_oxfw_stream_parse_format(format, > + oxfw->rx_stream_format_lens[i], > &formation); > if (err < 0) > continue; > diff --git a/sound/firewire/oxfw/oxfw.h b/sound/firewire/oxfw/oxfw.h > index aeb83e1595b7..439182c50c8a 100644 > --- a/sound/firewire/oxfw/oxfw.h > +++ b/sound/firewire/oxfw/oxfw.h > @@ -72,6 +72,8 @@ struct snd_oxfw { > bool has_input; > u8 *tx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES]; > u8 *rx_stream_formats[SND_OXFW_STREAM_FORMAT_ENTRIES]; > + unsigned int tx_stream_format_lens[SND_OXFW_STREAM_FORMAT_ENTRIES]; > + unsigned int rx_stream_format_lens[SND_OXFW_STREAM_FORMAT_ENTRIES]; > bool assumed; > struct cmp_connection out_conn; > struct cmp_connection in_conn; > @@ -141,6 +143,7 @@ struct snd_oxfw_stream_formation { > unsigned int midi; > }; > int snd_oxfw_stream_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, > -- > 2.34.1 >