From: Takashi Iwai <tiwai@suse.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: alsa-devel@alsa-project.org, Daniel Mack <zonque@gmail.com>
Subject: Re: [smatch stuff] reading beyond the end of the array in build_feature_ctl()
Date: Thu, 13 Oct 2011 08:14:11 +0200 [thread overview]
Message-ID: <s5hvcrtzado.wl%tiwai@suse.de> (raw)
In-Reply-To: <20111006133948.GA5217@elgon.mountain>
At Thu, 6 Oct 2011 16:39:48 +0300,
Dan Carpenter wrote:
>
> Hi Daniel,
>
> Smatch complains about a potential read past the end of the array in
> build_feature_ctl().
>
> sound/usb/mixer.c +1035 build_feature_ctl(34)
> error: buffer overflow 'audio_feature_info' 13 <= 14
>
> This is in the init code so probably it's correct, and I've just
> missed how it works. Can you take a look?
>
> The problem is that audio_feature_info[] has 13 elements, but Smatch
> thinks control - 1 can go up to 14 so we're two elements past the end.
>
> 1035 cval->val_type = audio_feature_info[control-1].type;
>
> Smatch get the value for "control" from "i" in parse_audio_feature_unit().
It looks like a flaw, indeed.
audio_feature_info[] should contain all data for UAC2_FU_*.
An easy fix is a patch like below.
(It's anyway better to replace the digits there.)
Later we can add the missing entries to audio_feature_info[].
thanks,
Takashi
---
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index b13b7ac..60f65ac 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -1259,7 +1259,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0);
}
} else { /* UAC_VERSION_2 */
- for (i = 0; i < 30/2; i++) {
+ for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
unsigned int ch_bits = 0;
unsigned int ch_read_only = 0;
prev parent reply other threads:[~2011-10-13 6:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-06 13:39 [smatch stuff] reading beyond the end of the array in build_feature_ctl() Dan Carpenter
2011-10-13 6:14 ` Takashi Iwai [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=s5hvcrtzado.wl%tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=dan.carpenter@oracle.com \
--cc=zonque@gmail.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