svn commit: r368658 - head/sys/dev/usb
Hans Petter Selasky
hselasky at FreeBSD.org
Tue Dec 15 11:51:18 UTC 2020
Author: hselasky
Date: Tue Dec 15 11:51:17 2020
New Revision: 368658
URL: https://svnweb.freebsd.org/changeset/base/368658
Log:
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 at dell.com>
Sponsored by: Mellanox Technologies // NVIDIA Networking
Modified:
head/sys/dev/usb/usb_parse.c
Modified: head/sys/dev/usb/usb_parse.c
==============================================================================
--- head/sys/dev/usb/usb_parse.c Tue Dec 15 09:43:18 2020 (r368657)
+++ head/sys/dev/usb/usb_parse.c Tue Dec 15 11:51:17 2020 (r368658)
@@ -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;
}
More information about the svn-src-head
mailing list