svn commit: r368658 - head/sys/dev/usb

Hans Petter Selasky <[email protected]> Tue, 15 Dec 2020 11:51:18 +0000 (UTC)
Newsgroups gmane.os.freebsd.devel.cvs
Message-ID <202012151151.0BFBpIUP073790__3895.70355634845$1608033083$gmane$org@repo.freebsd.org>
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 <[email protected]>
  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;
 		}
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"