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>
This commit is contained in:
@@ -132,10 +132,14 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
|
||||
unsigned *rate_table = NULL;
|
||||
|
||||
fp = kmemdup(quirk->data, sizeof(*fp), GFP_KERNEL);
|
||||
if (! fp) {
|
||||
if (!fp) {
|
||||
snd_printk(KERN_ERR "cannot memdup\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
if (fp->nr_rates > MAX_NR_RATES) {
|
||||
kfree(fp);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (fp->nr_rates > 0) {
|
||||
rate_table = kmemdup(fp->rate_table,
|
||||
sizeof(int) * fp->nr_rates, GFP_KERNEL);
|
||||
|
Reference in New Issue
Block a user