File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -220,6 +220,7 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
220
220
struct usb_interface_descriptor * altsd ;
221
221
void * control_header ;
222
222
int i , protocol ;
223
+ int rest_bytes ;
223
224
224
225
/* find audiocontrol interface */
225
226
host_iface = & usb_ifnum_to_if (dev , ctrlif )-> altsetting [0 ];
@@ -234,6 +235,15 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
234
235
return - EINVAL ;
235
236
}
236
237
238
+ rest_bytes = (void * )(host_iface -> extra + host_iface -> extralen ) -
239
+ control_header ;
240
+
241
+ /* just to be sure -- this shouldn't hit at all */
242
+ if (rest_bytes <= 0 ) {
243
+ dev_err (& dev -> dev , "invalid control header\n" );
244
+ return - EINVAL ;
245
+ }
246
+
237
247
switch (protocol ) {
238
248
default :
239
249
dev_warn (& dev -> dev ,
@@ -244,11 +254,21 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
244
254
case UAC_VERSION_1 : {
245
255
struct uac1_ac_header_descriptor * h1 = control_header ;
246
256
257
+ if (rest_bytes < sizeof (* h1 )) {
258
+ dev_err (& dev -> dev , "too short v1 buffer descriptor\n" );
259
+ return - EINVAL ;
260
+ }
261
+
247
262
if (!h1 -> bInCollection ) {
248
263
dev_info (& dev -> dev , "skipping empty audio interface (v1)\n" );
249
264
return - EINVAL ;
250
265
}
251
266
267
+ if (rest_bytes < h1 -> bLength ) {
268
+ dev_err (& dev -> dev , "invalid buffer length (v1)\n" );
269
+ return - EINVAL ;
270
+ }
271
+
252
272
if (h1 -> bLength < sizeof (* h1 ) + h1 -> bInCollection ) {
253
273
dev_err (& dev -> dev , "invalid UAC_HEADER (v1)\n" );
254
274
return - EINVAL ;
You can’t perform that action at this time.
0 commit comments