diff options
author | Xi Wang <xi.wang@gmail.com> | 2012-02-14 05:18:48 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2012-02-15 08:58:15 -0500 |
commit | 8866f405efd4171f9d9c91901d2dd02f01bacb60 (patch) | |
tree | 414b07ed6d979f9aad804dc16b4f280247741eaf /sound | |
parent | 27c3afe6e1cf129faac90405121203962da08ff4 (diff) |
ALSA: usb-audio: avoid integer overflow in create_fixed_stream_quirk()
A malicious USB device could feed in a large nr_rates value. This would
cause the subsequent call to kmemdup() to allocate a smaller buffer than
expected, leading to out-of-bounds access.
This patch validates the nr_rates value and reuses the limit introduced
in commit 4fa0e81b ("ALSA: usb-audio: fix possible hang and overflow
in parse_uac2_sample_rate_range()").
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/usb/card.h | 1 | ||||
-rw-r--r-- | sound/usb/format.c | 4 | ||||
-rw-r--r-- | sound/usb/quirks.c | 6 |
3 files changed, 7 insertions, 4 deletions
diff --git a/sound/usb/card.h b/sound/usb/card.h index a39edcc32a93..da5fa1ac4eda 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __USBAUDIO_CARD_H | 1 | #ifndef __USBAUDIO_CARD_H |
2 | #define __USBAUDIO_CARD_H | 2 | #define __USBAUDIO_CARD_H |
3 | 3 | ||
4 | #define MAX_NR_RATES 1024 | ||
4 | #define MAX_PACKS 20 | 5 | #define MAX_PACKS 20 |
5 | #define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */ | 6 | #define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */ |
6 | #define MAX_URBS 8 | 7 | #define MAX_URBS 8 |
diff --git a/sound/usb/format.c b/sound/usb/format.c index e09aba19375c..ddfef57c4c9f 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c | |||
@@ -209,8 +209,6 @@ static int parse_audio_format_rates_v1(struct snd_usb_audio *chip, struct audiof | |||
209 | return 0; | 209 | return 0; |
210 | } | 210 | } |
211 | 211 | ||
212 | #define MAX_UAC2_NR_RATES 1024 | ||
213 | |||
214 | /* | 212 | /* |
215 | * Helper function to walk the array of sample rate triplets reported by | 213 | * Helper function to walk the array of sample rate triplets reported by |
216 | * the device. The problem is that we need to parse whole array first to | 214 | * the device. The problem is that we need to parse whole array first to |
@@ -255,7 +253,7 @@ static int parse_uac2_sample_rate_range(struct audioformat *fp, int nr_triplets, | |||
255 | fp->rates |= snd_pcm_rate_to_rate_bit(rate); | 253 | fp->rates |= snd_pcm_rate_to_rate_bit(rate); |
256 | 254 | ||
257 | nr_rates++; | 255 | nr_rates++; |
258 | if (nr_rates >= MAX_UAC2_NR_RATES) { | 256 | if (nr_rates >= MAX_NR_RATES) { |
259 | snd_printk(KERN_ERR "invalid uac2 rates\n"); | 257 | snd_printk(KERN_ERR "invalid uac2 rates\n"); |
260 | break; | 258 | break; |
261 | } | 259 | } |
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c index a3ddac0deffd..27817266867a 100644 --- a/sound/usb/quirks.c +++ b/sound/usb/quirks.c | |||
@@ -132,10 +132,14 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip, | |||
132 | unsigned *rate_table = NULL; | 132 | unsigned *rate_table = NULL; |
133 | 133 | ||
134 | fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL); | 134 | fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL); |
135 | if (! fp) { | 135 | if (!fp) { |
136 | snd_printk(KERN_ERR "cannot memdup\n"); | 136 | snd_printk(KERN_ERR "cannot memdup\n"); |
137 | return -ENOMEM; | 137 | return -ENOMEM; |
138 | } | 138 | } |
139 | if (fp->nr_rates > MAX_NR_RATES) { | ||
140 | kfree(fp); | ||
141 | return -EINVAL; | ||
142 | } | ||
139 | if (fp->nr_rates > 0) { | 143 | if (fp->nr_rates > 0) { |
140 | rate_table = kmemdup(fp->rate_table, | 144 | rate_table = kmemdup(fp->rate_table, |
141 | sizeof(int) * fp->nr_rates, GFP_KERNEL); | 145 | sizeof(int) * fp->nr_rates, GFP_KERNEL); |