Improve handling of alternate settings in the USB stack.

Limit the number of alternate settings to 256.
Else the alternate index variable may wrap around.

PR:		251856
MFC after:	1 week
Submitted by:	Ma, Horse <Shichun.Ma@dell.com>
Sponsored by:	Mellanox Technologies // NVIDIA Networking
This commit is contained in:
Hans Petter Selasky 2020-12-15 11:51:17 +00:00
parent 1d0272a600
commit 6da5df4700

View file

@ -2,7 +2,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
* Copyright (c) 2008-2020 Hans Petter Selasky. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -141,8 +141,20 @@ usb_idesc_foreach(struct usb_config_descriptor *cd,
break;
if ((id->bDescriptorType == UDESC_INTERFACE) &&
(id->bLength >= sizeof(*id))) {
if (ps->iface_no_last == id->bInterfaceNumber)
if (ps->iface_no_last == id->bInterfaceNumber) {
/*
* Don't allow more than 256 alternate
* settings to avoid overflowing the
* alternate index which is a 8-bit
* variable.
*/
if (ps->iface_index_alt == 255) {
DPRINTF("Interface(%u) has more than 256 alternate settings\n",
id->bInterfaceNumber);
continue;
}
new_iface = 0;
}
ps->iface_no_last = id->bInterfaceNumber;
break;
}